Search in sources :

Example 16 with ImageFilterParams

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));
}
Also used : PackageLocationFilter(com.sequenceiq.cloudbreak.service.upgrade.image.PackageLocationFilter) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.jupiter.api.Test)

Example 17 with ImageFilterParams

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());
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Example 18 with ImageFilterParams

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);
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.Test)

Example 19 with ImageFilterParams

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());
}
Also used : RepairValidation(com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) UpgradeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response) ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 20 with ImageFilterParams

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);
}
Also used : ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) InternalUpgradeSettings(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.Test)

Aggregations

ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)26 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)20 Test (org.junit.Test)18 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)15 InternalUpgradeSettings (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.InternalUpgradeSettings)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)9 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)8 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)8 Test (org.junit.jupiter.api.Test)7 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)6 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)2 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)2 Result (com.sequenceiq.cloudbreak.service.cluster.model.Result)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 RepairValidation (com.sequenceiq.cloudbreak.service.cluster.model.RepairValidation)1