Search in sources :

Example 31 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 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 32 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class LockedComponentService method isComponentsLocked.

public boolean isComponentsLocked(Stack stack, String targetImageId) {
    try {
        Image currentImage = componentConfigProviderService.getImage(stack.getId());
        CloudbreakImageCatalogV3 imageCatalog = imageCatalogProvider.getImageCatalogV3(currentImage.getImageCatalogUrl());
        com.sequenceiq.cloudbreak.cloud.model.catalog.Image currentCatalogImage = imageProvider.getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog);
        com.sequenceiq.cloudbreak.cloud.model.catalog.Image targetCatalogImage = imageProvider.getCurrentImageFromCatalog(targetImageId, imageCatalog);
        LOGGER.info("Determining that the stack {} component versions are the same on the current image {} and the target image {}", stack.getName(), currentCatalogImage.getUuid(), targetCatalogImage.getUuid());
        return lockedComponentChecker.isUpgradePermitted(currentCatalogImage, targetCatalogImage, imageFilterParamsFactory.getStackRelatedParcels(stack));
    } catch (Exception ex) {
        String msg = "Exception during determining the lockComponents parameter.";
        LOGGER.warn(msg, ex);
        throw new CloudbreakRuntimeException(msg, ex);
    }
}
Also used : CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudbreakRuntimeException(com.sequenceiq.cloudbreak.service.CloudbreakRuntimeException)

Example 33 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 in project cloudbreak by hortonworks.

the class LockedComponentServiceTest method testIsComponentsLockedShouldReturnTrueWhenTheComponentVersionsAreNotMatches.

@Test
public void testIsComponentsLockedShouldReturnTrueWhenTheComponentVersionsAreNotMatches() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Image currentImage = new Image("imageName", Map.of(), "redhat6", "redhat6", "", "default", "default-id", Map.of());
    when(componentConfigProviderService.getImage(STACK_ID)).thenReturn(currentImage);
    CloudbreakImageCatalogV3 imageCatalog = new CloudbreakImageCatalogV3(null, null);
    when(imageCatalogProvider.getImageCatalogV3(currentImage.getImageCatalogUrl())).thenReturn(imageCatalog);
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image currentCatalogImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    when(imageProvider.getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog)).thenReturn(currentCatalogImage);
    com.sequenceiq.cloudbreak.cloud.model.catalog.Image targetCatalogImage = mock(com.sequenceiq.cloudbreak.cloud.model.catalog.Image.class);
    when(imageProvider.getCurrentImageFromCatalog(TARGET_IMAGE_ID, imageCatalog)).thenReturn(targetCatalogImage);
    when(imageFilterParamsFactory.getStackRelatedParcels(stack)).thenReturn(ACTIVATED_PARCELS);
    when(lockedComponentChecker.isUpgradePermitted(currentCatalogImage, targetCatalogImage, ACTIVATED_PARCELS)).thenReturn(true);
    assertTrue(underTest.isComponentsLocked(stack, TARGET_IMAGE_ID));
    verify(componentConfigProviderService).getImage(STACK_ID);
    verify(imageCatalogProvider).getImageCatalogV3(currentImage.getImageCatalogUrl());
    verify(imageProvider).getCurrentImageFromCatalog(currentImage.getImageId(), imageCatalog);
    verify(imageProvider).getCurrentImageFromCatalog(TARGET_IMAGE_ID, imageCatalog);
    verify(imageFilterParamsFactory).getStackRelatedParcels(stack);
    verify(lockedComponentChecker).isUpgradePermitted(currentCatalogImage, targetCatalogImage, ACTIVATED_PARCELS);
}
Also used : CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Test(org.junit.Test)

Example 34 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 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 35 with CloudbreakImageCatalogV3

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3 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)

Aggregations

CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)48 Test (org.junit.jupiter.api.Test)21 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)17 Test (org.junit.Test)14 ImageFilterResult (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterResult)10 UpgradeV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response)8 ImageFilterParams (com.sequenceiq.cloudbreak.service.upgrade.image.ImageFilterParams)8 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)7 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)6 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)5 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)5 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)5 Image (com.sequenceiq.cloudbreak.cloud.model.Image)4 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)4 List (java.util.List)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Versions (com.sequenceiq.cloudbreak.cloud.model.catalog.Versions)3 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)3 ImageCatalogWrapper (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogWrapper)3