use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.
the class EntitlementDrivenPackageLocationFilterTest method testEntitlementEnabled.
@Test
public void testEntitlementEnabled() {
PackageLocationFilter filter = mock(PackageLocationFilter.class);
when(entitlementService.isInternalRepositoryForUpgradeAllowed(anyString())).thenReturn(Boolean.TRUE);
lenient().when(imageFilterParams.getCurrentImage()).thenReturn(currentImage);
EntitlementDrivenPackageLocationFilter underTest = new EntitlementDrivenPackageLocationFilter(entitlementService, Set.of(filter));
List<Image> images = List.of(this.image1, image2);
ImageFilterResult imageFilterResult = new ImageFilterResult(images);
ImageFilterResult actual = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.filter(imageFilterResult, imageFilterParams));
assertEquals(images, actual.getImages());
assertTrue(actual.getReason().isEmpty());
verify(filter, never()).filterImage(any(Image.class), any(Image.class), any(ImageFilterParams.class));
}
use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testGetImagesToUpgradeShouldReturnListWhenTheClusterIsNotAvailable.
@Test
public void testGetImagesToUpgradeShouldReturnListWhenTheClusterIsNotAvailable() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
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();
ImageInfoV4Response imageInfo = new ImageInfoV4Response();
imageInfo.setImageId(IMAGE_ID);
imageInfo.setCreated(1);
imageInfo.setComponentVersions(createExpectedPackageVersions());
response.setUpgradeCandidates(List.of(imageInfo));
Stack stack = createStack(createStackStatus(Status.CREATE_FAILED), StackType.WORKLOAD);
ImageFilterParams imageFilterParams = createImageFilterParams(stack, currentImageFromCatalog);
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenReturn(imageCatalogDomain);
when(imageCatalogProvider.getImageCatalogV3(CATALOG_URL)).thenReturn(imageCatalog);
when(imageFilterParamsFactory.create(currentImageFromCatalog, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
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);
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertNull(actual.getCurrent());
assertEquals(1, actual.getUpgradeCandidates().size());
assertEquals("Cannot upgrade cluster because it is in CREATE_FAILED state.", actual.getReason());
}
use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testFilterUpgradeOptionsFromCustomImageCatalog.
@Test
public void testFilterUpgradeOptionsFromCustomImageCatalog() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Stack stack = createStack(createStackStatus(Status.AVAILABLE), StackType.WORKLOAD);
com.sequenceiq.cloudbreak.cloud.model.Image currentImage = createCurrentImageWithoutImageCatalogUrl();
Image image = mock(Image.class);
ImageFilterParams imageFilterParams = mock(ImageFilterParams.class);
Image imageAvailableForUpgrade = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
ImageFilterResult filteredImages = createFilteredImages(imageAvailableForUpgrade);
UpgradeV4Response upgradeResponse = mock(UpgradeV4Response.class);
CloudbreakImageCatalogV3 imageCatalog = createImageCatalog(List.of(image));
ImageCatalog imageCatalogDomain = createImageCatalogDomain();
when(imageService.getImage(stack.getId())).thenReturn(currentImage);
when(imageProvider.getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog)).thenReturn(image);
when(imageCatalogService.getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME)).thenReturn(imageCatalogDomain);
when(imageCatalogProvider.getImageCatalogV3(imageCatalogDomain.getImageCatalogUrl())).thenReturn(imageCatalog);
when(imageFilterParamsFactory.create(image, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS)).thenReturn(imageFilterParams);
when(clusterUpgradeImageFilter.filter(ACCOUNT_ID, imageCatalog, imageFilterParams)).thenReturn(filteredImages);
when(upgradeOptionsResponseFactory.createV4Response(image, filteredImages, CLOUD_PLATFORM, REGION, CATALOG_NAME)).thenReturn(upgradeResponse);
when(upgradeResponse.getReason()).thenReturn("done");
UpgradeV4Response actual = underTest.checkForUpgradesByName(stack, lockComponents, true, INTERNAL_UPGRADE_SETTINGS);
assertEquals(upgradeResponse, actual);
verify(imageService).getImage(stack.getId());
verify(imageProvider).getCurrentImageFromCatalog(CURRENT_IMAGE_ID, imageCatalog);
verify(imageCatalogService).getImageCatalogByName(stack.getWorkspace().getId(), CATALOG_NAME);
verify(imageCatalogProvider).getImageCatalogV3(imageCatalogDomain.getImageCatalogUrl());
verify(imageFilterParamsFactory).create(image, lockComponents, stack, INTERNAL_UPGRADE_SETTINGS);
verify(clusterUpgradeImageFilter).filter(ACCOUNT_ID, imageCatalog, imageFilterParams);
verify(upgradeOptionsResponseFactory).createV4Response(image, filteredImages, CLOUD_PLATFORM, REGION, CATALOG_NAME);
}
use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams 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.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.
the class ImageFilterParamsFactoryTest method testCreateShouldReturnsANewImageFilterParamsInstanceWhenTheStackTypeIsDataLake.
@Test
public void testCreateShouldReturnsANewImageFilterParamsInstanceWhenTheStackTypeIsDataLake() {
Image image = mock(Image.class);
Stack stack = createStack(StackType.DATALAKE);
Set<ClusterComponent> clusterComponents = createCdhClusterComponent();
String cdhName = com.sequenceiq.cloudbreak.cloud.model.component.StackType.CDH.name();
String cdhVersion = "7.2.0";
when(platformStringTransformer.getPlatformStringForImageCatalog(anyString(), anyString())).thenReturn(imageCatalogPlatform(CLOUD_PLATFORM));
when(parcelService.getParcelComponentsByBlueprint(stack)).thenReturn(clusterComponents);
when(clouderaManagerProductsProvider.findCdhProduct(clusterComponents)).thenReturn(Optional.of(createCMProduct(cdhName, cdhVersion)));
ImageFilterParams actual = underTest.create(image, true, stack, new InternalUpgradeSettings(false, true, true));
assertEquals(image, actual.getCurrentImage());
assertTrue(actual.isLockComponents());
assertEquals(cdhVersion, actual.getStackRelatedParcels().get(cdhName));
assertEquals(StackType.DATALAKE, actual.getStackType());
assertEquals(blueprint, actual.getBlueprint());
assertEquals(STACK_ID, actual.getStackId());
assertEquals(CLOUD_PLATFORM, actual.getCloudPlatform().nameToUpperCase());
verify(parcelService).getParcelComponentsByBlueprint(stack);
verify(clouderaManagerProductsProvider).findCdhProduct(clusterComponents);
}
Aggregations