use of com.sequenceiq.cloudbreak.cloud.model.catalog.Image in project cloudbreak by hortonworks.
the class ImageCatalogService method getImages.
public StatedImages getImages(String imageCatalogUrl, String imageCatalogName, Set<String> platforms, String cbVersion) throws CloudbreakImageCatalogException {
LOGGER.info("Determine images for imageCatalogUrl: '{}', platforms: '{}' and Cloudbreak version: '{}'.", imageCatalogUrl, platforms, cbVersion);
StatedImages images;
CloudbreakImageCatalogV2 imageCatalog = imageCatalogProvider.getImageCatalogV2(imageCatalogUrl);
if (imageCatalog != null) {
Set<String> vMImageUUIDs = new HashSet<>();
List<CloudbreakVersion> cloudbreakVersions = imageCatalog.getVersions().getCloudbreakVersions();
String cbv = UNSPECIFIED_VERSION.equals(cbVersion) ? latestCloudbreakVersion(cloudbreakVersions) : cbVersion;
List<CloudbreakVersion> exactMatchedImgs = cloudbreakVersions.stream().filter(cloudbreakVersion -> cloudbreakVersion.getVersions().contains(cbv)).collect(Collectors.toList());
if (!exactMatchedImgs.isEmpty()) {
exactMatchedImgs.forEach(cloudbreakVersion -> vMImageUUIDs.addAll(cloudbreakVersion.getImageIds()));
} else {
vMImageUUIDs.addAll(prefixMatchForCBVersion(cbVersion, cloudbreakVersions));
}
List<Image> baseImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getBaseImages(), vMImageUUIDs);
List<Image> hdpImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdpImages(), vMImageUUIDs);
List<Image> hdfImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdfImages(), vMImageUUIDs);
images = statedImages(new Images(baseImages, hdpImages, hdfImages), imageCatalogUrl, imageCatalogName);
} else {
images = statedImages(emptyImages(), imageCatalogUrl, imageCatalogName);
}
return images;
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Image in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method testGetImagesWhenExactVersionExistsInCatalogAndMorePlatformRequested.
@Test
public void testGetImagesWhenExactVersionExistsInCatalogAndMorePlatformRequested() throws Exception {
String cbVersion = "1.12.0";
StatedImages images = underTest.getImages("", "default", ImmutableSet.of("aws", "azure"), cbVersion);
boolean awsAndAzureWerePresentedInTheTest = false;
Assert.assertEquals(2, images.getImages().getHdpImages().size());
for (Image image : images.getImages().getHdpImages()) {
boolean containsAws = images.getImages().getHdpImages().stream().anyMatch(img -> img.getImageSetsByProvider().entrySet().stream().anyMatch(platformImages -> platformImages.getKey().equals("aws")));
boolean containsAzure = images.getImages().getHdpImages().stream().anyMatch(img -> img.getImageSetsByProvider().entrySet().stream().anyMatch(platformImages -> platformImages.getKey().equals("azure_rm")));
if (image.getImageSetsByProvider().size() == 2) {
awsAndAzureWerePresentedInTheTest = true;
Assert.assertTrue("Result doesn't contain the required Ambari image with id.", containsAws && containsAzure);
} else if (image.getImageSetsByProvider().size() == 1) {
Assert.assertTrue("Result doesn't contain the required Ambari image with id.", containsAws || containsAzure);
}
}
Assert.assertTrue(awsAndAzureWerePresentedInTheTest);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Image in project cloudbreak by hortonworks.
the class ImagesToImagesResponseJsonConverter method convert.
@Override
public ImagesResponse convert(Images source) {
ImagesResponse res = new ImagesResponse();
List<BaseImageResponse> baseImages = getBaseImageResponses(source);
res.setBaseImages(baseImages);
List<ImageResponse> hdpImages = new ArrayList<>();
for (Image hdpImg : source.getHdpImages()) {
ImageResponse hdpImgJson = new ImageResponse();
copyImageFieldsToJson(hdpImg, hdpImgJson);
hdpImgJson.setStackDetails(convertStackDetailsToJson(hdpImg.getStackDetails()));
hdpImages.add(hdpImgJson);
}
res.setHdpImages(hdpImages);
List<ImageResponse> hdfImages = new ArrayList<>();
for (Image hdfImg : source.getHdfImages()) {
ImageResponse hdfImgJson = new ImageResponse();
copyImageFieldsToJson(hdfImg, hdfImgJson);
hdfImgJson.setStackDetails(convertStackDetailsToJson(hdfImg.getStackDetails()));
hdfImages.add(hdfImgJson);
}
res.setHdfImages(hdfImages);
return res;
}
Aggregations