Search in sources :

Example 1 with ImageFilter

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());
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) LatestDefaultImageUuidProvider(com.sequenceiq.cloudbreak.service.image.LatestDefaultImageUuidProvider) Inject(javax.inject.Inject) HashSet(java.util.HashSet) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) ImageCatalogVersionFilter(com.sequenceiq.cloudbreak.service.image.ImageCatalogVersionFilter) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) PrefixMatcherService(com.sequenceiq.cloudbreak.service.image.PrefixMatcherService) PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Set(java.util.Set) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Collectors(java.util.stream.Collectors) ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) CloudbreakVersionListProvider(com.sequenceiq.cloudbreak.service.image.CloudbreakVersionListProvider) Component(org.springframework.stereotype.Component) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Optional(java.util.Optional) Collections(java.util.Collections) PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) Stream(java.util.stream.Stream) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) HashSet(java.util.HashSet)

Example 2 with ImageFilter

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());
}
Also used : ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Test(org.junit.jupiter.api.Test)

Example 3 with ImageFilter

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);
}
Also used : ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 4 with ImageFilter

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())));
}
Also used : Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) ImageCatalogPlatform.imageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform.imageCatalogPlatform) Test(org.junit.jupiter.api.Test) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) AZURE(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Collections(java.util.Collections) ImageFilter(com.sequenceiq.cloudbreak.service.image.ImageFilter) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) CloudbreakImageCatalogV3(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) Test(org.junit.jupiter.api.Test)

Aggregations

ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)4 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)3 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)2 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)2 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)2 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)2 Collections (java.util.Collections)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)1 AWS (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS)1 AZURE (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AZURE)1 CloudbreakVersionListProvider (com.sequenceiq.cloudbreak.service.image.CloudbreakVersionListProvider)1 ImageCatalogVersionFilter (com.sequenceiq.cloudbreak.service.image.ImageCatalogVersionFilter)1 LatestDefaultImageUuidProvider (com.sequenceiq.cloudbreak.service.image.LatestDefaultImageUuidProvider)1 PrefixMatchImages (com.sequenceiq.cloudbreak.service.image.PrefixMatchImages)1 PrefixMatcherService (com.sequenceiq.cloudbreak.service.image.PrefixMatcherService)1 StatedImages.statedImages (com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages)1 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)1 ImageCatalogPlatform.imageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform.imageCatalogPlatform)1