Search in sources :

Example 1 with StatedImages

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

Example 2 with StatedImages

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());
}
Also used : StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImages(com.sequenceiq.cloudbreak.service.image.StatedImages) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image)

Example 3 with StatedImages

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());
}
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 4 with StatedImages

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

Example 5 with StatedImages

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

Aggregations

StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)14 Test (org.junit.jupiter.api.Test)10 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)5 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)4 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)4 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)3 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)3 StatedImages.statedImages (com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages)2 Collections (java.util.Collections)2 List (java.util.List)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 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)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 ImageCatalogPlatform.imageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform.imageCatalogPlatform)1