use of com.sequenceiq.cloudbreak.cloud.model.catalog.Images in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method testGetImagesWhenCustomImageCatalogDoesNotExists.
@Test
public void testGetImagesWhenCustomImageCatalogDoesNotExists() throws Exception {
when(imageCatalogRepository.findByName("name", "userId", "account")).thenReturn(null);
Images images = underTest.getImages("name", "aws").getImages();
verify(imageCatalogProvider, times(0)).getImageCatalogV2("");
Assert.assertTrue("Base images should be empty!", images.getBaseImages().isEmpty());
Assert.assertTrue("HDF images should be empty!", images.getHdfImages().isEmpty());
Assert.assertTrue("HDP images should be empty!", images.getHdpImages().isEmpty());
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Images in project cloudbreak by hortonworks.
the class ImageCatalogV1Controller method getPublicByName.
@Override
public ImageCatalogResponse getPublicByName(String name, boolean withImages) {
ImageCatalogResponse imageCatalogResponse = convert(imageCatalogService.get(name));
Images images = imageCatalogService.propagateImagesIfRequested(name, withImages);
if (images != null) {
imageCatalogResponse.setImagesResponse(conversionService.convert(images, ImagesResponse.class));
}
return imageCatalogResponse;
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Images in project cloudbreak by hortonworks.
the class ImageCatalogService method getImages.
public StatedImages getImages(String imageCatalogUrl, String imageCatalogName, Set<String> platforms, String cbVersion) throws CloudbreakImageCatalogException {
LOGGER.info("Determine images for imageCatalogUrl: '{}', platforms: '{}' and Cloudbreak version: '{}'.", imageCatalogUrl, platforms, cbVersion);
StatedImages images;
CloudbreakImageCatalogV2 imageCatalog = imageCatalogProvider.getImageCatalogV2(imageCatalogUrl);
if (imageCatalog != null) {
Set<String> vMImageUUIDs = new HashSet<>();
List<CloudbreakVersion> cloudbreakVersions = imageCatalog.getVersions().getCloudbreakVersions();
String cbv = UNSPECIFIED_VERSION.equals(cbVersion) ? latestCloudbreakVersion(cloudbreakVersions) : cbVersion;
List<CloudbreakVersion> exactMatchedImgs = cloudbreakVersions.stream().filter(cloudbreakVersion -> cloudbreakVersion.getVersions().contains(cbv)).collect(Collectors.toList());
if (!exactMatchedImgs.isEmpty()) {
exactMatchedImgs.forEach(cloudbreakVersion -> vMImageUUIDs.addAll(cloudbreakVersion.getImageIds()));
} else {
vMImageUUIDs.addAll(prefixMatchForCBVersion(cbVersion, cloudbreakVersions));
}
List<Image> baseImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getBaseImages(), vMImageUUIDs);
List<Image> hdpImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdpImages(), vMImageUUIDs);
List<Image> hdfImages = filterImagesByPlatforms(platforms, imageCatalog.getImages().getHdfImages(), vMImageUUIDs);
images = statedImages(new Images(baseImages, hdpImages, hdfImages), imageCatalogUrl, imageCatalogName);
} else {
images = statedImages(emptyImages(), imageCatalogUrl, imageCatalogName);
}
return images;
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Images in project cloudbreak by hortonworks.
the class ImageCatalogServiceTest method testGetImagesWhenExactVersionExistsInCatalogAndMorePlatformRequested.
@Test
public void testGetImagesWhenExactVersionExistsInCatalogAndMorePlatformRequested() throws Exception {
String cbVersion = "1.12.0";
StatedImages images = underTest.getImages("", "default", ImmutableSet.of("aws", "azure"), cbVersion);
boolean awsAndAzureWerePresentedInTheTest = false;
Assert.assertEquals(2, images.getImages().getHdpImages().size());
for (Image image : images.getImages().getHdpImages()) {
boolean containsAws = images.getImages().getHdpImages().stream().anyMatch(img -> img.getImageSetsByProvider().entrySet().stream().anyMatch(platformImages -> platformImages.getKey().equals("aws")));
boolean containsAzure = images.getImages().getHdpImages().stream().anyMatch(img -> img.getImageSetsByProvider().entrySet().stream().anyMatch(platformImages -> platformImages.getKey().equals("azure_rm")));
if (image.getImageSetsByProvider().size() == 2) {
awsAndAzureWerePresentedInTheTest = true;
Assert.assertTrue("Result doesn't contain the required Ambari image with id.", containsAws && containsAzure);
} else if (image.getImageSetsByProvider().size() == 1) {
Assert.assertTrue("Result doesn't contain the required Ambari image with id.", containsAws || containsAzure);
}
}
Assert.assertTrue(awsAndAzureWerePresentedInTheTest);
}
use of com.sequenceiq.cloudbreak.cloud.model.catalog.Images in project cloudbreak by hortonworks.
the class ImageCatalogService method getImage.
public StatedImage getImage(String catalogUrl, String catalogName, String imageId) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
Images images = imageCatalogProvider.getImageCatalogV2(catalogUrl).getImages();
Optional<? extends Image> image = getImage(imageId, images);
if (!image.isPresent()) {
images = imageCatalogProvider.getImageCatalogV2(catalogUrl, true).getImages();
image = getImage(imageId, images);
}
if (!image.isPresent()) {
throw new CloudbreakImageNotFoundException(String.format("Could not find any image with id: '%s'.", imageId));
}
return statedImage(image.get(), catalogUrl, catalogName);
}
Aggregations