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());
}
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();
}
}
Aggregations