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;
}
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);
}
}
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);
}
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());
}
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);
}
Aggregations