use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeServiceTest method testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime.
@Test
public void testShowLatestOnlyShouldReturnLatestUpgradeCandidatesPerRuntime() {
when(entitlementService.runtimeUpgradeEnabled(any())).thenReturn(true);
ImageComponentVersions imageComponentVersionsFor702 = new ImageComponentVersions();
imageComponentVersionsFor702.setCm(V_7_0_2);
imageComponentVersionsFor702.setCdp(V_7_0_2);
ImageComponentVersions imageComponentVersionsFor703 = new ImageComponentVersions();
imageComponentVersionsFor703.setCm(V_7_0_3);
imageComponentVersionsFor703.setCdp(V_7_0_3);
ImageInfoV4Response imageInfo1 = new ImageInfoV4Response();
imageInfo1.setImageId(IMAGE_ID + 1);
imageInfo1.setCreated(1);
imageInfo1.setComponentVersions(imageComponentVersionsFor702);
ImageInfoV4Response imageInfo2 = new ImageInfoV4Response();
imageInfo2.setImageId(IMAGE_ID + 2);
imageInfo2.setCreated(2);
imageInfo2.setComponentVersions(imageComponentVersionsFor702);
ImageInfoV4Response imageInfo3 = new ImageInfoV4Response();
imageInfo3.setImageId(IMAGE_ID + 3);
imageInfo3.setCreated(3);
imageInfo3.setComponentVersions(imageComponentVersionsFor703);
UpgradeV4Response upgradeV4Response = new UpgradeV4Response();
upgradeV4Response.setUpgradeCandidates(List.of(imageInfo1, imageInfo2, imageInfo3));
sdxUpgradeRequest.setShowAvailableImages(SdxUpgradeShowAvailableImages.LATEST_ONLY);
UpgradeV4Response actualResponse = underTest.filterSdxUpgradeResponse(ACCOUNT_ID, sdxCluster.getClusterName(), sdxUpgradeRequest, upgradeV4Response);
assertEquals(2, actualResponse.getUpgradeCandidates().size());
assertFalse(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 1)));
assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 2)));
assertTrue(actualResponse.getUpgradeCandidates().stream().anyMatch(imageInfoV4Response -> imageInfoV4Response.getImageId().equals(IMAGE_ID + 3)));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.
the class SdxRuntimeUpgradeService method validateRuntime.
private String validateRuntime(List<ImageInfoV4Response> upgradeCandidates, String runtime) {
String imageId;
Supplier<Stream<ImageInfoV4Response>> imagesWithMatchingRuntime = () -> upgradeCandidates.stream().filter(imageInfoV4Response -> runtime.equals(imageInfoV4Response.getComponentVersions().getCdp()));
boolean hasCompatibleImageWithRuntime = imagesWithMatchingRuntime.get().anyMatch(e -> true);
if (!hasCompatibleImageWithRuntime) {
String availableRuntimes = upgradeCandidates.stream().map(ImageInfoV4Response::getComponentVersions).map(ImageComponentVersions::getCdp).distinct().collect(Collectors.joining(","));
String errorMessage;
if (StringUtils.isEmpty(availableRuntimes)) {
errorMessage = String.format("There is no image eligible for the cluster upgrade with runtime: %s.", runtime);
} else {
errorMessage = String.format("There is no image eligible for the cluster upgrade with runtime: %s. " + "Please choose a runtime from the following: %s", runtime, availableRuntimes);
}
throw new BadRequestException(errorMessage);
} else {
ImageInfoV4Response imageInfoV4Response = imagesWithMatchingRuntime.get().max(ImageInfoV4Response.creationBasedComparator()).orElseThrow();
imageId = imageInfoV4Response.getImageId();
}
return imageId;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.
the class DistroXUpgradeAvailabilityServiceTest method createImageResponse.
private ImageInfoV4Response createImageResponse(long creation, String cdp) {
ImageInfoV4Response image = new ImageInfoV4Response();
image.setCreated(creation);
image.setComponentVersions(new ImageComponentVersions("dontcare", "dontcare", cdp, "dontcare", "dontcare", "dontcare", List.of()));
return image;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions in project cloudbreak by hortonworks.
the class ComponentVersionProviderTest method testGetComponentVersions.
@Test
void testGetComponentVersions() {
ImageComponentVersions componentVersions = underTest.getComponentVersions(createPackageVersions(), CENTOS_7, OS_PATCH_LEVEL);
List<ParcelInfoResponse> parcelInfoResponseList = componentVersions.getParcelInfoResponseList();
assertEquals(4, parcelInfoResponseList.size());
assertIterableEquals(createParcelInfoList(), parcelInfoResponseList);
assertEquals(CENTOS_7, componentVersions.getOs());
assertEquals(OS_PATCH_LEVEL, componentVersions.getOsPatchLevel());
assertEquals("7.2.10", componentVersions.getCdp());
assertEquals("7.4.2", componentVersions.getCm());
assertEquals("16151091", componentVersions.getCdpGBN());
assertEquals("15633910", componentVersions.getCmGBN());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageComponentVersions 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