use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion 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.CloudbreakVersion in project cloudbreak by hortonworks.
the class ImageCatalogProviderTest method testReadImageCatalogFromFile.
@Test
public void testReadImageCatalogFromFile() throws Exception {
String path = getPath(CB_IMAGE_CATALOG_V2_JSON);
underTest.setEtcConfigDir(path);
CloudbreakImageCatalogV2 catalog = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_V2_JSON);
Assert.assertNotNull("Check that the parsed ImageCatalog not null.", catalog);
Optional<CloudbreakVersion> ver = catalog.getVersions().getCloudbreakVersions().stream().filter(v -> v.getVersions().contains(CB_VERSION)).findFirst();
Assert.assertTrue("Check that the parsed ImageCatalog contains the desired version of Cloudbreak.", ver.isPresent());
List<String> imageIds = ver.get().getImageIds();
Assert.assertNotNull("Check that the parsed ImageCatalog contains the desired version of Cloudbreak with image id(s).", imageIds);
Optional<String> imageIdOptional = imageIds.stream().findFirst();
Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image reference for the Cloudbreak version.", imageIdOptional.isPresent());
String imageId = imageIdOptional.get();
boolean baseImageFound = false;
boolean hdpImageFound = false;
boolean hdfImageFoiund = false;
if (catalog.getImages().getBaseImages() != null) {
baseImageFound = catalog.getImages().getBaseImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
if (catalog.getImages().getHdpImages() != null) {
hdpImageFound = catalog.getImages().getHdpImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
if (catalog.getImages().getHdfImages() != null) {
hdfImageFoiund = catalog.getImages().getHdfImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
}
boolean anyImageFoundForVersion = baseImageFound || hdpImageFound || hdfImageFoiund;
Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image for the Cloudbreak version.", anyImageFoundForVersion);
}
Aggregations