use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityService method checkForUpgrade.
public UpgradeV4Response checkForUpgrade(NameOrCrn nameOrCrn, Long workspaceId, UpgradeV4Request request, String userCrn) {
Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
String accountId = Crn.safeFromString(userCrn).getAccountId();
UpgradeV4Response response = stackUpgradeOperations.checkForClusterUpgrade(accountId, stack, workspaceId, request);
List<ImageInfoV4Response> filteredCandidates = filterCandidates(accountId, stack, request, response);
List<ImageInfoV4Response> razValidatedCandidates = validateRangerRazCandidates(accountId, stack, filteredCandidates);
response.setUpgradeCandidates(razValidatedCandidates);
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityService method filterCandidates.
private List<ImageInfoV4Response> filterCandidates(String accountId, Stack stack, UpgradeV4Request request, UpgradeV4Response upgradeV4Response) {
BlueprintUpgradeOption upgradeOption = stack.getCluster().getBlueprint().getBlueprintUpgradeOption();
if (upgradeOption != BlueprintUpgradeOption.GA) {
LOGGER.debug("Running filtering logic as upgrade option is {}, not GA", upgradeOption);
filterOnlyPatchUpgradesIfRuntimeUpgradeDisabled(accountId, stack.getName(), upgradeV4Response);
}
List<ImageInfoV4Response> filteredCandidates;
String stackName = stack.getName();
boolean differentDataHubAndDataLakeVersionAllowed = entitlementService.isDifferentDataHubAndDataLakeVersionAllowed(accountId);
if (differentDataHubAndDataLakeVersionAllowed) {
LOGGER.info("Different Data Hub version is enabled, not filtering based on Data Lake version, Data Hub: {}", stackName);
filteredCandidates = upgradeV4Response.getUpgradeCandidates();
} else {
LOGGER.info("Filter Data Hub upgrade images based on the Data Lake version, Data Hub: {}", stackName);
filteredCandidates = filterForDatalakeVersion(stack, upgradeV4Response);
}
if (CollectionUtils.isNotEmpty(filteredCandidates) && Objects.nonNull(request)) {
if (LATEST_ONLY == request.getShowAvailableImages()) {
filteredCandidates = filterForLatestImagePerRuntime(filteredCandidates);
} else if (request.isDryRun()) {
filteredCandidates = filterForLatestImage(filteredCandidates);
}
}
return filteredCandidates;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testFilterUpgradeOptionsDefaultCase.
@Test
public void testFilterUpgradeOptionsDefaultCase() {
UpgradeV4Request request = new UpgradeV4Request();
request.setDryRun(true);
UpgradeV4Response response = new UpgradeV4Response();
ImageInfoV4Response imageInfo = new ImageInfoV4Response();
imageInfo.setImageId(IMAGE_ID);
imageInfo.setCreated(1);
imageInfo.setComponentVersions(createExpectedPackageVersions());
ImageInfoV4Response lastImageInfo = new ImageInfoV4Response();
lastImageInfo.setImageId(IMAGE_ID_LAST);
lastImageInfo.setCreated(2);
lastImageInfo.setComponentVersions(createExpectedPackageVersions());
response.setUpgradeCandidates(List.of(imageInfo, lastImageInfo));
underTest.filterUpgradeOptions(ACCOUNT_ID, response, request, true);
assertEquals(2, response.getUpgradeCandidates().size());
assertEquals(2, response.getUpgradeCandidates().stream().map(ImageInfoV4Response::getImageId).collect(Collectors.toSet()).size());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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