use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testFilterUpgradeOptionsLockComponents.
@Test
public void testFilterUpgradeOptionsLockComponents() {
UpgradeV4Request request = new UpgradeV4Request();
request.setLockComponents(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());
assertTrue(response.getUpgradeCandidates().stream().map(ImageInfoV4Response::getImageId).anyMatch(id -> id.equals(IMAGE_ID_LAST)));
assertTrue(response.getUpgradeCandidates().stream().map(ImageInfoV4Response::getImageId).anyMatch(id -> id.equals(IMAGE_ID)));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response 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());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testFilterUpgradeOptionsImageIdInvalid.
@Test
public void testFilterUpgradeOptionsImageIdInvalid() {
UpgradeV4Request request = new UpgradeV4Request();
request.setImageId(ANOTHER_IMAGE_ID);
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));
Exception e = Assertions.assertThrows(BadRequestException.class, () -> underTest.filterUpgradeOptions(ACCOUNT_ID, response, request, true));
Assert.assertEquals("The given image (another-image-id) is not eligible for the cluster upgrade. " + "Please choose an id from the following image(s): image-id-first,image-id-last", e.getMessage());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class ClusterUpgradeAvailabilityServiceTest method testFilterUpgradeOptionsRuntimeInvalid.
@Test
public void testFilterUpgradeOptionsRuntimeInvalid() {
UpgradeV4Request request = new UpgradeV4Request();
request.setRuntime(ANOTHER_TARGET_RUNTIME);
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));
Exception e = Assertions.assertThrows(BadRequestException.class, () -> underTest.filterUpgradeOptions(ACCOUNT_ID, response, request, true));
Assert.assertEquals("There is no image eligible for the cluster upgrade with runtime: 7.2.0. " + "Please choose a runtime from the following: 7.0.2", e.getMessage());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeV4Response in project cloudbreak by hortonworks.
the class UpgradeOptionsResponseFactoryTest method testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters.
@Test
public void testCreateV4ResponseShouldReturnTheUpgradeOptionsFromTheGivenParameters() throws CloudbreakImageNotFoundException {
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CLOUD_PLATFORM);
Map<String, String> packageVersions = createPackageVersions();
ImageComponentVersions expectedPackageVersions = creatExpectedPackageVersions();
Image currentImage = createImage(packageVersions);
ImageFilterResult availableImages = createAvailableImages(packageVersions);
when(platformStringTransformer.getPlatformStringForImageCatalogByRegion(anyString(), anyString())).thenReturn(imageCatalogPlatform);
when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, currentImage)).thenReturn(IMAGE_NAME);
when(imageService.determineImageName(CLOUD_PLATFORM, imageCatalogPlatform, REGION, availableImages.getImages().get(0))).thenReturn(IMAGE_NAME);
when(componentVersionProvider.getComponentVersions(eq(packageVersions), any(), any())).thenReturn(expectedPackageVersions);
UpgradeV4Response actual = underTest.createV4Response(currentImage, availableImages, CLOUD_PLATFORM, REGION, IMAGE_CATALOG_NAME);
assertEquals(IMAGE_ID, actual.getCurrent().getImageId());
assertEquals(IMAGE_CATALOG_NAME, actual.getCurrent().getImageCatalogName());
assertEquals(IMAGE_NAME, actual.getCurrent().getImageName());
assertEquals(expectedPackageVersions, actual.getCurrent().getComponentVersions());
assertEquals(CREATION_DATE, actual.getCurrent().getCreated());
assertEquals(IMAGE_ID, actual.getUpgradeCandidates().get(0).getImageId());
assertEquals(IMAGE_CATALOG_NAME, actual.getUpgradeCandidates().get(0).getImageCatalogName());
assertEquals(IMAGE_NAME, actual.getUpgradeCandidates().get(0).getImageName());
assertEquals(expectedPackageVersions, actual.getUpgradeCandidates().get(0).getComponentVersions());
assertEquals(CREATION_DATE, actual.getUpgradeCandidates().get(0).getCreated());
}
Aggregations