use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testGetImagesToUpgradeShouldReturnEmptyListWhenTheClusterIsNotRepairable.
@Test
public void testGetImagesToUpgradeShouldReturnEmptyListWhenTheClusterIsNotRepairable() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
Result<Map<HostGroupName, Set<InstanceMetaData>>, RepairValidation> result = mock(Result.class);
Image currentImageFromCatalog = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image properImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
Image otherImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(properImage, otherImage, currentImageFromCatalog));
UpgradeV4Response response = new UpgradeV4Response();
ImageInfoV4Response imageInfo = new ImageInfoV4Response();
imageInfo.setImageId(IMAGE_ID);
imageInfo.setCreated(1);
imageInfo.setComponentVersions(createExpectedPackageVersions());
response.setUpgradeCandidates(List.of(imageInfo));
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
RepairValidation repairValidation = mock(RepairValidation.class);
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
when(clusterRepairService.repairWithDryRun(stack.getId())).thenReturn(result);
when(result.isError()).thenReturn(true);
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenReturn(imageCatalogDomain);
when(imageCatalogProvider.getImageCatalogV3(CATALOG_URL)).thenReturn(imageCatalog);
ImageFilterResult filteredImages = createFilteredImages(properImage);
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
when(upgradeOptionsResponseFactory.createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName())).thenReturn(response);
when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(currentImageFromCatalog);
String validationError = "External RDS is not attached.";
when(result.getError()).thenReturn(repairValidation);
when(repairValidation.getValidationErrors()).thenReturn(Collections.singletonList(validationError));
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertNull(actual.getCurrent());
assertEquals(1, actual.getUpgradeCandidates().size());
assertEquals(validationError, actual.getReason());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class CustomImageProviderTest method getImageFromCatalog.
private Image getImageFromCatalog(String catalogFile, String imageId) throws IOException, CloudbreakImageNotFoundException {
String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
CloudbreakImageCatalogV3 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV3.class);
Images images = catalog.getImages();
List<Image> imagesAll = List.of(images.getBaseImages(), images.getCdhImages(), images.getFreeIpaImages()).stream().flatMap(List::stream).collect(Collectors.toList());
Optional<? extends Image> image = findImageByImageId(imageId, imagesAll);
if (image.isEmpty()) {
throw new CloudbreakImageNotFoundException(String.format("No image was found with id %s", imageId));
}
return image.get();
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class DefaultImageCatalogServiceTest method testGetImageFromDefaultCatalogWithoutRuntime.
@Test
public void testGetImageFromDefaultCatalogWithoutRuntime() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
CloudbreakImageCatalogV3 freeipaImageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
Images images = mock(Images.class);
Image expected = mock(Image.class);
Image notExpectedByCreated = mock(Image.class);
Image notExpectedByProvider = mock(Image.class);
Map<String, Map<String, String>> expectedImageSetByProvider = Map.of("aws", Map.of());
Map<String, Map<String, String>> notExpectedImageSetByProvider = Map.of("azure", Map.of());
List<Image> imageList = List.of(expected, notExpectedByCreated, notExpectedByProvider);
when(imageCatalogProvider.getImageCatalogV3(DEFAULT_FREEIPA_CATALOG_URL)).thenReturn(freeipaImageCatalogV3);
when(freeipaImageCatalogV3.getImages()).thenReturn(images);
when(images.getFreeIpaImages()).thenReturn(imageList);
when(expected.getImageSetsByProvider()).thenReturn(expectedImageSetByProvider);
when(expected.getCreated()).thenReturn(2L);
when(notExpectedByCreated.getImageSetsByProvider()).thenReturn(expectedImageSetByProvider);
when(notExpectedByCreated.getCreated()).thenReturn(1L);
when(notExpectedByProvider.getImageSetsByProvider()).thenReturn(notExpectedImageSetByProvider);
when(notExpectedByProvider.getCreated()).thenReturn(0L);
StatedImage actual = victim.getImageFromDefaultCatalog(ImageType.FREEIPA.name(), imageCatalogPlatform("aws"));
assertEquals(expected, actual.getImage());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ImageCatalogProviderTest method shouldReturnImageCatalogWithForceRefresh.
@Test
public void shouldReturnImageCatalogWithForceRefresh() throws CloudbreakImageCatalogException {
ImageCatalogWrapper imageCatalogWrapper = mock(ImageCatalogWrapper.class);
CloudbreakImageCatalogV3 imageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
when(cachedImageCatalogWrapperProvider.getImageCatalogWrapper(IMAGE_CATALOG_URL)).thenReturn(imageCatalogWrapper);
when(imageCatalogWrapper.getImageCatalog()).thenReturn(imageCatalogV3);
CloudbreakImageCatalogV3 actual = victim.getImageCatalogV3(IMAGE_CATALOG_URL, true);
assertEquals(imageCatalogV3, actual);
verify(cachedImageCatalogWrapperProvider).evictImageCatalogCache(IMAGE_CATALOG_URL);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method setupImageCatalogProviderWithoutVersions.
private void setupImageCatalogProviderWithoutVersions(String catalogUrl, String catalogFile) throws IOException, CloudbreakImageCatalogException {
String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
CloudbreakImageCatalogV3 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV3.class);
ReflectionTestUtils.setField(catalog, "versions", null);
when(imageCatalog.getImageCatalogUrl()).thenReturn(catalogUrl);
when(imageCatalogProvider.getImageCatalogV3(catalogUrl)).thenReturn(catalog);
}
Aggregations