Search in sources :

Example 11 with ImageFilterParams

use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams 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());
}
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 12 with ImageFilterParams

use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams 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);
}
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 13 with ImageFilterParams

use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.

the class ClusterUpgradeAvailabilityService method checkForUpgrades.

private UpgradeV4Response checkForUpgrades(Stack stack, boolean lockComponents, InternalUpgradeSettings internalUpgradeSettings) {
    String accountId = Crn.safeFromString(stack.getResourceCrn()).getAccountId();
    UpgradeV4Response upgradeOptions = new UpgradeV4Response();
    try {
        LOGGER.info(String.format("Retrieving images for upgrading stack %s", stack.getName()));
        com.sequenceiq.cloudbreak.cloud.model.Image currentImage = getImage(stack);
        CloudbreakImageCatalogV3 imageCatalog = getImagesFromCatalog(stack.getWorkspace(), currentImage.getImageCatalogName(), currentImage.getImageCatalogUrl());
        Image image = getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog);
        ImageFilterParams imageFilterParams = createImageFilterParams(image, lockComponents, stack, internalUpgradeSettings);
        ImageFilterResult imageFilterResult = filterImages(accountId, imageCatalog, imageFilterParams);
        LOGGER.info(String.format("%d possible image found for stack upgrade.", imageFilterResult.getImages().size()));
        upgradeOptions = createResponse(image, imageFilterResult, stack.getCloudPlatform(), stack.getRegion(), currentImage.getImageCatalogName());
    } catch (CloudbreakImageNotFoundException | CloudbreakImageCatalogException | NotFoundException e) {
        LOGGER.warn("Failed to get images", e);
        upgradeOptions.setReason(String.format("Failed to retrieve image due to %s", e.getMessage()));
    }
    return upgradeOptions;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) 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)

Example 14 with ImageFilterParams

use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.

the class CmAndStackVersionUpgradeImageFilterTest method testFilterShouldReturnTrueIfLockedAndCheckerReturnsTrue.

@Test
public void testFilterShouldReturnTrueIfLockedAndCheckerReturnsTrue() {
    ImageFilterParams imageFilterParams = createImageFilterParams(true);
    when(lockedComponentChecker.isUpgradePermitted(currentImage, candidateImage, activatedParcels)).thenReturn(Boolean.TRUE);
    ImageFilterResult actual = underTest.filter(new ImageFilterResult(List.of(candidateImage)), imageFilterParams);
    assertFalse(actual.getImages().isEmpty());
    assertTrue(actual.getReason().isEmpty());
}
Also used : ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.jupiter.api.Test)

Example 15 with ImageFilterParams

use of com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams in project cloudbreak by hortonworks.

the class CmAndStackVersionUpgradeImageFilterTest method testFilterShouldReturnFalseIfLockedAndCheckerReturnsFalse.

@Test
public void testFilterShouldReturnFalseIfLockedAndCheckerReturnsFalse() {
    ImageFilterParams imageFilterParams = createImageFilterParams(true);
    when(lockedComponentChecker.isUpgradePermitted(currentImage, candidateImage, activatedParcels)).thenReturn(Boolean.FALSE);
    ImageFilterResult actual = underTest.filter(new ImageFilterResult(List.of(candidateImage)), imageFilterParams);
    assertLockedCommon(actual);
}
Also used : ImageFilterParams(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams) ImageFilterResult(com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult) Test(org.junit.jupiter.api.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