use of com.sequenceiq.cloudbreak.service.image.ImageFilter 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.ImageFilter in project cloudbreak by hortonworks.
the class AdvertisedImageProviderTest method shouldSetUpImageCatalogNameAndUrl.
@Test
public void shouldSetUpImageCatalogNameAndUrl() {
ImageFilter imageFilter = createImageFilter(false);
StatedImages actual = victim.getImages(anImageCatalogV3(), createImageFilter(false));
assertEquals(imageFilter.getImageCatalog().getImageCatalogUrl(), actual.getImageCatalogUrl());
assertEquals(imageFilter.getImageCatalog().getName(), actual.getImageCatalogName());
}
use of com.sequenceiq.cloudbreak.service.image.ImageFilter in project cloudbreak by hortonworks.
the class RawImageProviderTest method createImageFilter.
private ImageFilter createImageFilter() {
ImageCatalog imageCatalog = new ImageCatalog();
imageCatalog.setImageCatalogUrl(IMAGE_CATALOG_URL);
imageCatalog.setName(IMAGE_CATALOG_NAME);
return new ImageFilter(imageCatalog, Collections.singleton(imageCatalogPlatform(AWS.name())), null);
}
use of com.sequenceiq.cloudbreak.service.image.ImageFilter in project cloudbreak by hortonworks.
the class RawImageProviderTest method testGetImagesShouldReturnOnlyTheAwsImagesFromTheImageCatalog.
@Test
void testGetImagesShouldReturnOnlyTheAwsImagesFromTheImageCatalog() {
ImageFilter imageFilter = createImageFilter();
CloudbreakImageCatalogV3 imageCatalogV3 = createImageCatalog();
StatedImages actual = underTest.getImages(imageCatalogV3, imageFilter);
assertEquals(IMAGE_CATALOG_NAME, actual.getImageCatalogName());
assertEquals(IMAGE_CATALOG_URL, actual.getImageCatalogUrl());
Images images = actual.getImages();
assertTrue(images.getBaseImages().stream().anyMatch(image -> BASE_IMAGE_AWS.equals(image.getUuid())));
assertTrue(images.getBaseImages().stream().noneMatch(image -> BASE_IMAGE_AZURE.equals(image.getUuid())));
assertTrue(images.getCdhImages().stream().anyMatch(image -> CDH_IMAGE_AWS.equals(image.getUuid())));
assertTrue(images.getCdhImages().stream().noneMatch(image -> CDH_IMAGE_AZURE.equals(image.getUuid())));
assertTrue(images.getFreeIpaImages().stream().anyMatch(image -> FREEIPA_IMAGE_AWS.equals(image.getUuid())));
assertTrue(images.getFreeIpaImages().stream().noneMatch(image -> FREEIPA_IMAGE_AZURE.equals(image.getUuid())));
}
Aggregations