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;
}
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());
}
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());
}
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());
}
Aggregations