Search in sources :

Example 1 with PrefixMatchImages

use of com.sequenceiq.cloudbreak.service.image.PrefixMatchImages in project cloudbreak by hortonworks.

the class VersionBasedImageCatalogService method getImageIds.

private Set<String> getImageIds(CloudbreakImageCatalogV3 imageCatalogV3) {
    Set<String> imageIds = new HashSet<>();
    List<CloudbreakVersion> cbVersionsFromImageCatalog = cloudbreakVersionListProvider.getVersions(imageCatalogV3);
    String currentCbVersion = getCurrentCBVersion(cbVersionsFromImageCatalog);
    List<CloudbreakVersion> exactMatchedImages = getExtractMatchedImages(cbVersionsFromImageCatalog, currentCbVersion);
    if (!exactMatchedImages.isEmpty()) {
        for (CloudbreakVersion exactMatchedImg : exactMatchedImages) {
            imageIds.addAll(exactMatchedImg.getImageIds());
        }
    } else {
        LOGGER.debug("No image found with exact match for version {} Trying prefix matching", currentCbVersion);
        PrefixMatchImages prefixMatchImages = prefixMatcherService.prefixMatchForCBVersion(cbVersion, cbVersionsFromImageCatalog);
        imageIds.addAll(prefixMatchImages.getvMImageUUIDs());
    }
    return imageIds;
}
Also used : PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) HashSet(java.util.HashSet)

Example 2 with PrefixMatchImages

use of com.sequenceiq.cloudbreak.service.image.PrefixMatchImages 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 3 with PrefixMatchImages

use of com.sequenceiq.cloudbreak.service.image.PrefixMatchImages in project cloudbreak by hortonworks.

the class VersionBasedImageCatalogServiceTest method testGetFreeipaImagesForCbVersionShouldReturnsEmptyListWhenThereAreNoSupportedImagesForCbVersion.

@Test
public void testGetFreeipaImagesForCbVersionShouldReturnsEmptyListWhenThereAreNoSupportedImagesForCbVersion() {
    ReflectionTestUtils.setField(victim, "cbVersion", "2.18");
    Image properImage = createImage(PROPER_IMAGE_ID);
    Image otherImage = createImage(OTHER_IMAGE_ID);
    when(imageCatalogV3.getImages()).thenReturn(images);
    when(prefixMatcherService.prefixMatchForCBVersion(eq("2.18"), any())).thenReturn(new PrefixMatchImages(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()));
    when(images.getFreeIpaImages()).thenReturn(List.of(properImage, otherImage));
    Versions versions = createFreeipaVersions();
    when(cloudbreakVersionListProvider.getVersions(any())).thenReturn(versions.getFreeipaVersions());
    List<Image> actual = victim.getImageFilterResult(imageCatalogV3).getImages();
    assertTrue(actual.isEmpty());
}
Also used : PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) Versions(com.sequenceiq.cloudbreak.cloud.model.catalog.Versions) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.jupiter.api.Test)

Example 4 with PrefixMatchImages

use of com.sequenceiq.cloudbreak.service.image.PrefixMatchImages in project cloudbreak by hortonworks.

the class VersionBasedImageCatalogServiceTest method testGetCdhImagesForCbVersionShouldReturnsEmptyListWhenThereAreNoSupportedImagesForCbVersion.

@Test
public void testGetCdhImagesForCbVersionShouldReturnsEmptyListWhenThereAreNoSupportedImagesForCbVersion() {
    ReflectionTestUtils.setField(victim, "cbVersion", "2.18");
    Image properImage = createImage(PROPER_IMAGE_ID);
    Image otherImage = createImage(OTHER_IMAGE_ID);
    when(imageCatalogV3.getImages()).thenReturn(images);
    when(prefixMatcherService.prefixMatchForCBVersion(eq("2.18"), any())).thenReturn(new PrefixMatchImages(Collections.emptySet(), Collections.emptySet(), Collections.emptySet()));
    when(images.getCdhImages()).thenReturn(List.of(properImage, otherImage));
    Versions versions = createCbVersions();
    when(cloudbreakVersionListProvider.getVersions(any())).thenReturn(versions.getCloudbreakVersions());
    List<Image> actual = victim.getImageFilterResult(imageCatalogV3).getImages();
    assertTrue(actual.isEmpty());
}
Also used : PrefixMatchImages(com.sequenceiq.cloudbreak.service.image.PrefixMatchImages) Versions(com.sequenceiq.cloudbreak.cloud.model.catalog.Versions) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.jupiter.api.Test)

Aggregations

PrefixMatchImages (com.sequenceiq.cloudbreak.service.image.PrefixMatchImages)4 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)3 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)2 Versions (com.sequenceiq.cloudbreak.cloud.model.catalog.Versions)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 CloudbreakImageCatalogV3 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV3)1 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)1 CloudbreakVersionListProvider (com.sequenceiq.cloudbreak.service.image.CloudbreakVersionListProvider)1 ImageCatalogVersionFilter (com.sequenceiq.cloudbreak.service.image.ImageCatalogVersionFilter)1 ImageFilter (com.sequenceiq.cloudbreak.service.image.ImageFilter)1 LatestDefaultImageUuidProvider (com.sequenceiq.cloudbreak.service.image.LatestDefaultImageUuidProvider)1 PrefixMatcherService (com.sequenceiq.cloudbreak.service.image.PrefixMatcherService)1 StatedImages (com.sequenceiq.cloudbreak.service.image.StatedImages)1 StatedImages.statedImages (com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages)1 ImageCatalogPlatform (com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1