Search in sources :

Example 1 with ImageNotFoundException

use of com.sequenceiq.freeipa.service.image.ImageNotFoundException in project cloudbreak by hortonworks.

the class UpgradeImageServiceTest method testFindTargetImagesCurrentImageMissingDateAndNoImageFoundInCatalog.

@Test
public void testFindTargetImagesCurrentImageMissingDateAndNoImageFoundInCatalog() {
    Stack stack = new Stack();
    stack.setCloudPlatform("AWS");
    stack.setRegion("reg");
    ImageSettingsRequest imageSettingsRequest = new ImageSettingsRequest();
    Image image = createImage("2021-09-01");
    ImageWrapper imageWrapper = new ImageWrapper(image, "catalogURL", "catalogName");
    when(imageService.fetchImagesWrapperAndName(stack, imageSettingsRequest)).thenReturn(List.of(Pair.of(imageWrapper, "imageName")));
    ArgumentCaptor<ImageSettingsRequest> captor = ArgumentCaptor.forClass(ImageSettingsRequest.class);
    when(imageService.getImage(captor.capture(), eq(stack.getRegion()), eq(stack.getCloudPlatform().toLowerCase()))).thenThrow(new ImageNotFoundException("Image not found"));
    ImageInfoResponse currentImage = new ImageInfoResponse();
    currentImage.setId("222-333");
    currentImage.setCatalogName("cat");
    currentImage.setOs("zOs");
    List<ImageInfoResponse> targetImages = underTest.findTargetImages(stack, imageSettingsRequest, currentImage);
    assertTrue(targetImages.isEmpty());
    ImageSettingsRequest settingsRequest = captor.getValue();
    assertEquals(currentImage.getCatalogName(), settingsRequest.getCatalog());
    assertEquals(currentImage.getId(), settingsRequest.getId());
    assertEquals(currentImage.getOs(), settingsRequest.getOs());
}
Also used : ImageInfoResponse(com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse) ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImageNotFoundException(com.sequenceiq.freeipa.service.image.ImageNotFoundException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with ImageNotFoundException

use of com.sequenceiq.freeipa.service.image.ImageNotFoundException in project cloudbreak by hortonworks.

the class UpgradeImageService method getCurrentImageDateFromCatalog.

private Optional<String> getCurrentImageDateFromCatalog(Stack stack, ImageInfoResponse currentImage) {
    try {
        String catalog = Optional.ofNullable(currentImage.getCatalog()).orElse(currentImage.getCatalogName());
        LOGGER.debug("Current image date field is empty. Using catalog [{}] to get image date", catalog);
        ImageSettingsRequest imageSettings = new ImageSettingsRequest();
        imageSettings.setCatalog(catalog);
        imageSettings.setId(currentImage.getId());
        imageSettings.setOs(currentImage.getOs());
        ImageWrapper image = imageService.getImage(imageSettings, stack.getRegion(), stack.getCloudPlatform().toLowerCase());
        LOGGER.debug("Image date from catalog: {}", image.getImage().getDate());
        return Optional.ofNullable(image.getImage().getDate());
    } catch (ImageNotFoundException e) {
        LOGGER.warn("Image not found, returning empty date", e);
        return Optional.empty();
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImageNotFoundException(com.sequenceiq.freeipa.service.image.ImageNotFoundException)

Aggregations

ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)2 ImageWrapper (com.sequenceiq.freeipa.dto.ImageWrapper)2 ImageNotFoundException (com.sequenceiq.freeipa.service.image.ImageNotFoundException)2 Image (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image)1 ImageInfoResponse (com.sequenceiq.freeipa.api.v1.freeipa.upgrade.model.ImageInfoResponse)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 Test (org.junit.jupiter.api.Test)1