Search in sources :

Example 1 with Images

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());
}
Also used : Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) Test(org.junit.Test)

Example 2 with Images

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;
}
Also used : ImageCatalogResponse(com.sequenceiq.cloudbreak.api.model.imagecatalog.ImageCatalogResponse) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) ImagesResponse(com.sequenceiq.cloudbreak.api.model.imagecatalog.ImagesResponse)

Example 3 with Images

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;
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfileService(com.sequenceiq.cloudbreak.service.user.UserProfileService) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Matcher(java.util.regex.Matcher) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) AuthenticatedUserService(com.sequenceiq.cloudbreak.controller.AuthenticatedUserService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) SqlUtil.getProperSqlErrorMessage(com.sequenceiq.cloudbreak.util.SqlUtil.getProperSqlErrorMessage) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) AccountPreferencesService(com.sequenceiq.cloudbreak.service.account.AccountPreferencesService) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) ImageCatalogRepository(com.sequenceiq.cloudbreak.repository.ImageCatalogRepository) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) Set(java.util.Set) NotFoundException(com.sequenceiq.cloudbreak.controller.NotFoundException) Collectors(java.util.stream.Collectors) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Versioned(com.sequenceiq.cloudbreak.cloud.model.Versioned) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) List(java.util.List) Component(org.springframework.stereotype.Component) APIResourceType(com.sequenceiq.cloudbreak.common.type.APIResourceType) TreeMap(java.util.TreeMap) CollectionUtils(org.springframework.util.CollectionUtils) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) NameUtil.generateArchiveName(com.sequenceiq.cloudbreak.util.NameUtil.generateArchiveName) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Comparator(java.util.Comparator) SortedMap(java.util.SortedMap) StringUtils(org.springframework.util.StringUtils) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) StatedImages.statedImages(com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) HashSet(java.util.HashSet)

Example 4 with 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);
}
Also used : Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfileService(com.sequenceiq.cloudbreak.service.user.UserProfileService) Date(java.util.Date) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) CloudConstant(com.sequenceiq.cloudbreak.cloud.CloudConstant) AuthenticatedUserService(com.sequenceiq.cloudbreak.controller.AuthenticatedUserService) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Spy(org.mockito.Spy) Images(com.sequenceiq.cloudbreak.cloud.model.catalog.Images) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) AuthorizationService(com.sequenceiq.cloudbreak.service.AuthorizationService) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) AccountPreferencesService(com.sequenceiq.cloudbreak.service.account.AccountPreferencesService) InjectMocks(org.mockito.InjectMocks) ImmutableSet(com.google.common.collect.ImmutableSet) ImageCatalogRepository(com.sequenceiq.cloudbreak.repository.ImageCatalogRepository) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Rule(org.junit.Rule) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) Assert(org.junit.Assert) Collections(java.util.Collections) JsonUtil(com.sequenceiq.cloudbreak.util.JsonUtil) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Test(org.junit.Test)

Example 5 with Images

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

Aggregations

Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)6 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)3 List (java.util.List)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImagesResponse (com.sequenceiq.cloudbreak.api.model.imagecatalog.ImagesResponse)2 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)2 AuthenticatedUserService (com.sequenceiq.cloudbreak.controller.AuthenticatedUserService)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)2 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)2 ImageCatalogRepository (com.sequenceiq.cloudbreak.repository.ImageCatalogRepository)2 AuthorizationService (com.sequenceiq.cloudbreak.service.AuthorizationService)2 AccountPreferencesService (com.sequenceiq.cloudbreak.service.account.AccountPreferencesService)2 StatedImages.statedImages (com.sequenceiq.cloudbreak.service.image.StatedImages.statedImages)2 UserProfileService (com.sequenceiq.cloudbreak.service.user.UserProfileService)2 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2