use of com.sequenceiq.cloudbreak.service.image.StatedImages in project cloudbreak by hortonworks.
the class ImageBasedDefaultCDHEntries method getEntries.
public Map<String, ImageBasedDefaultCDHInfo> getEntries(Long workspaceId, String platform, String imageCatalogName) throws CloudbreakImageCatalogException {
String catalogName = Optional.ofNullable(imageCatalogName).orElse(ImageCatalogService.CDP_DEFAULT_CATALOG_NAME);
StatedImages images = imageCatalogService.getImages(workspaceId, catalogName, platform);
if (images.getImages().getCdhImages().isEmpty()) {
LOGGER.warn("Missing CDH images for cloud platform: {}. Falling back to AWS.", platform);
images = imageCatalogService.getImages(workspaceId, catalogName, CloudPlatform.AWS.name());
}
return getEntries(images.getImages());
}
use of com.sequenceiq.cloudbreak.service.image.StatedImages in project cloudbreak by hortonworks.
the class RawImageProvider method getImages.
public StatedImages getImages(CloudbreakImageCatalogV3 imageCatalogV3, ImageFilter imageFilter) {
Images catalogImages = imageCatalogV3.getImages();
Set<ImageCatalogPlatform> platforms = imageFilter.getPlatforms();
List<Image> baseImages = filterImagesByPlatforms(platforms, catalogImages.getBaseImages());
List<Image> cdhImages = filterImagesByPlatforms(platforms, catalogImages.getCdhImages());
List<Image> freeipaImages = filterImagesByPlatforms(platforms, catalogImages.getFreeIpaImages());
return statedImages(new Images(baseImages, cdhImages, freeipaImages, catalogImages.getSuppertedVersions()), imageFilter.getImageCatalog().getImageCatalogUrl(), imageFilter.getImageCatalog().getName());
}
use of com.sequenceiq.cloudbreak.service.image.StatedImages in project cloudbreak by hortonworks.
the class VersionBasedImageProvider method getImages.
public StatedImages getImages(CloudbreakImageCatalogV3 imageCatalogV3, ImageFilter imageFilter) {
Set<String> suppertedVersions;
Set<String> vMImageUUIDs = new HashSet<>();
Set<String> defaultVMImageUUIDs = new HashSet<>();
String currentCbVersion;
List<CloudbreakVersion> cloudbreakVersions = cloudbreakVersionListProvider.getVersions(imageCatalogV3);
currentCbVersion = getCBVersion(imageFilter, cloudbreakVersions);
List<CloudbreakVersion> exactMatchedImages = cloudbreakVersions.stream().filter(cloudbreakVersion -> cloudbreakVersion.getVersions().contains(currentCbVersion)).collect(toList());
if (!exactMatchedImages.isEmpty()) {
for (CloudbreakVersion exactMatchedImg : exactMatchedImages) {
vMImageUUIDs.addAll(exactMatchedImg.getImageIds());
defaultVMImageUUIDs.addAll(exactMatchedImg.getDefaults());
}
suppertedVersions = Collections.singleton(currentCbVersion);
} else {
LOGGER.debug("No image found with exact match for version {} Trying prefix matching", currentCbVersion);
PrefixMatchImages prefixMatchImages = prefixMatcherService.prefixMatchForCBVersion(imageFilter.getCbVersion(), cloudbreakVersions);
vMImageUUIDs.addAll(prefixMatchImages.getvMImageUUIDs());
defaultVMImageUUIDs.addAll(prefixMatchImages.getDefaultVMImageUUIDs());
suppertedVersions = prefixMatchImages.getSupportedVersions();
}
LOGGER.info("The following images are matching for CB version ({}): {} ", currentCbVersion, vMImageUUIDs);
List<Image> baseImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getBaseImages(), vMImageUUIDs);
List<Image> cdhImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getCdhImages(), vMImageUUIDs);
List<Image> freeipaImages = filterImagesByPlatforms(imageFilter.getPlatforms(), imageCatalogV3.getImages().getFreeIpaImages(), vMImageUUIDs);
List<Image> defaultImages = defaultVMImageUUIDs.stream().map(imageId -> getImage(imageId, imageCatalogV3.getImages())).flatMap(Optional::stream).collect(Collectors.toList());
Collection<String> latestDefaultImageUuids = latestDefaultImageUuidProvider.getLatestDefaultImageUuids(imageFilter.getPlatforms(), defaultImages);
(!freeipaImages.isEmpty() ? freeipaImages.stream() : Stream.of(baseImages.stream(), cdhImages.stream()).reduce(Stream::concat).orElseGet(Stream::empty)).forEach(img -> img.setDefaultImage(latestDefaultImageUuids.contains(img.getUuid())));
if (!imageFilter.isBaseImageEnabled()) {
baseImages.clear();
}
return statedImages(new Images(baseImages, cdhImages, freeipaImages, suppertedVersions), imageFilter.getImageCatalog().getImageCatalogUrl(), imageFilter.getImageCatalog().getName());
}
use of com.sequenceiq.cloudbreak.service.image.StatedImages in project cloudbreak by hortonworks.
the class ImageBasedDefaultCDHEntriesTest method shouldFallBackToAwsInCaseOfMissingCdhImages.
@Test
public void shouldFallBackToAwsInCaseOfMissingCdhImages() throws CloudbreakImageCatalogException {
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(CloudPlatform.YARN.name());
List<Image> imageList = getImages();
when(images.getCdhImages()).thenReturn(imageList);
when(emptyImages.getCdhImages()).thenReturn(Collections.emptyList());
StatedImages statedImages = StatedImages.statedImages(images, null, null);
StatedImages emptyStatedImages = StatedImages.statedImages(emptyImages, null, null);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(emptyStatedImages);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(statedImages);
Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, imageCatalogPlatform, IMAGE_CATALOG_NAME);
Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get();
verify(image, actual.get(IMAGE_VERSION));
}
use of com.sequenceiq.cloudbreak.service.image.StatedImages in project cloudbreak by hortonworks.
the class ImageBasedDefaultCDHEntriesTest method shouldReturnImageBasedDefaultCDHInfoMapByPlatformAndImageCatalog.
@Test
public void shouldReturnImageBasedDefaultCDHInfoMapByPlatformAndImageCatalog() throws CloudbreakImageCatalogException {
List<Image> imageList = getImages();
when(images.getCdhImages()).thenReturn(imageList);
ImageCatalogPlatform imageCatalogPlatform = imageCatalogPlatform(PLATFORM);
StatedImages statedImages = StatedImages.statedImages(images, null, null);
when(imageCatalogService.getImages(0L, IMAGE_CATALOG_NAME, imageCatalogPlatform)).thenReturn(statedImages);
Map<String, ImageBasedDefaultCDHInfo> actual = victim.getEntries(0L, imageCatalogPlatform, IMAGE_CATALOG_NAME);
Image image = imageList.stream().filter(Image::isDefaultImage).findFirst().get();
verify(image, actual.get(IMAGE_VERSION));
}
Aggregations