use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameAndSomeInstancesAreStopped.
@Test
public void testCheckForUpgradesByNameAndSomeInstancesAreStopped() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
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));
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
UpgradeV4Response response = new UpgradeV4Response();
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
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(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);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(true);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals("Cannot upgrade cluster because there is stopped instance.", actual.getReason());
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesAndRepairNotChecked.
@Test
public void testCheckForUpgradesByNameShouldReturnImagesWhenThereAreAvailableImagesAndRepairNotChecked() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImage();
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
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();
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);
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
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);
when(instanceMetaDataService.anyInstanceStopped(stack.getId())).thenReturn(false);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, false, INTERNAL_UPGRADE_SETTINGS);
assertEquals(response, actual);
verify(imageService).getImage(stack.getId());
verify(imageCatalogProvider).getImageCatalogV3(CATALOG_URL);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(currentImageFromCatalog, filteredImages, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
verifyNoInteractions(clusterRepairService);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class DefaultImageCatalogServiceTest method testGetImageFromDefaultCatalogWithoutRuntimeThrowsCloudbreakImageNotFoundException.
@Test
public void testGetImageFromDefaultCatalogWithoutRuntimeThrowsCloudbreakImageNotFoundException() throws CloudbreakImageCatalogException {
CloudbreakImageCatalogV3 freeipaImageCatalogV3 = mock(CloudbreakImageCatalogV3.class);
Images images = mock(Images.class);
Image expected = mock(Image.class);
Image notExpected = mock(Image.class);
Map<String, Map<String, String>> imageSetByProvider = Map.of();
List<Image> imageList = List.of(expected, notExpected);
when(imageCatalogProvider.getImageCatalogV3(DEFAULT_FREEIPA_CATALOG_URL)).thenReturn(freeipaImageCatalogV3);
when(freeipaImageCatalogV3.getImages()).thenReturn(images);
when(images.getFreeIpaImages()).thenReturn(imageList);
when(expected.getImageSetsByProvider()).thenReturn(imageSetByProvider);
when(expected.getCreated()).thenReturn(2L);
when(notExpected.getImageSetsByProvider()).thenReturn(imageSetByProvider);
when(notExpected.getCreated()).thenReturn(1L);
assertThrows(CloudbreakImageNotFoundException.class, () -> victim.getImageFromDefaultCatalog(ImageType.FREEIPA.name(), imageCatalogPlatform("aws")));
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class GenerateImageCatalogServiceTest method shouldGenerateImageCatalog.
@Test
public void shouldGenerateImageCatalog() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
when(stackImageService.getCurrentImage(stack)).thenReturn(image);
when(image.getImageCatalogUrl()).thenReturn(IMAGE_CATALOG_URL);
when(image.getImageCatalogName()).thenReturn(IMAGE_CATALOG_NAME);
when(image.getImageId()).thenReturn(IMAGE_ID);
when(imageCatalogService.getImage(IMAGE_CATALOG_URL, IMAGE_CATALOG_NAME, IMAGE_ID)).thenReturn(statedImage);
when(statedImage.getImage()).thenReturn(catalogImage);
CloudbreakImageCatalogV3 actual = victim.generateImageCatalogForStack(stack);
assertThat(actual.getImages().getCdhImages()).first().returns(catalogImage.getCreated(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getCreated).returns(catalogImage.getDate(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getDate).returns(catalogImage.getDescription(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getDescription).returns(catalogImage.getOs(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getOs).returns(catalogImage.getUuid(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getUuid).returns(catalogImage.getRepo(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getRepo).returns(catalogImage.getImageSetsByProvider(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getImageSetsByProvider).returns(catalogImage.getStackDetails(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getStackDetails).returns(catalogImage.getOsType(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getOsType).returns(catalogImage.getPackageVersions(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getPackageVersions).returns(catalogImage.getPreWarmParcels(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getPreWarmParcels).returns(catalogImage.getPreWarmCsd(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getPreWarmCsd).returns(catalogImage.getCmBuildNumber(), com.sequenceiq.cloudbreak.cloud.model.catalog.Image::getCmBuildNumber).returns(true, com.sequenceiq.cloudbreak.cloud.model.catalog.Image::isAdvertised);
assertThat(actual.getImages().getSuppertedVersions()).isEmpty();
assertThat(actual.getVersions()).isNull();
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.
the class ImageCatalogProviderTest method shouldReturnImageCatalogWithoutForceRefresh.
@Test
public void shouldReturnImageCatalogWithoutForceRefresh() 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);
assertEquals(imageCatalogV3, actual);
verifyNoMoreInteractions(cachedImageCatalogWrapperProvider);
}
Aggregations