Search in sources :

Example 1 with CloudbreakImageCatalogV2

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 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 2 with CloudbreakImageCatalogV2

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.

the class ImageCatalogProviderTest method testImageCatalogWithoutBaseImages.

@Test
public void testImageCatalogWithoutBaseImages() throws CloudbreakImageCatalogException, IOException {
    String path = getPath(CB_IMAGE_CATALOG_WITHOUT_BASE_IMAGES);
    underTest.setEtcConfigDir(path);
    CloudbreakImageCatalogV2 imageCatalogV2 = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_WITHOUT_BASE_IMAGES);
    Assert.assertNotNull(imageCatalogV2.getImages().getBaseImages());
}
Also used : CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Example 3 with CloudbreakImageCatalogV2

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.

the class ImageCatalogProviderTest method testImageCatalogWithoutHdfImages.

@Test
public void testImageCatalogWithoutHdfImages() throws CloudbreakImageCatalogException, IOException {
    String path = getPath(CB_IMAGE_CATALOG_WITHOUT_HDF_IMAGES);
    underTest.setEtcConfigDir(path);
    CloudbreakImageCatalogV2 imageCatalogV2 = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_WITHOUT_HDF_IMAGES);
    Assert.assertNotNull(imageCatalogV2.getImages().getHdfImages());
}
Also used : CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Example 4 with CloudbreakImageCatalogV2

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.

the class ImageCatalogProviderTest method testImageCatalogFilterNullImages.

@Test
public void testImageCatalogFilterNullImages() throws CloudbreakImageCatalogException, IOException {
    String path = getPath(CB_IMAGE_CATALOG_FILTER_NULL_IMAGES_JSON);
    underTest.setEtcConfigDir(path);
    CloudbreakImageCatalogV2 imageCatalogV2 = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_FILTER_NULL_IMAGES_JSON);
    Assert.assertEquals(1, imageCatalogV2.getImages().getBaseImages().get(0).getImageSetsByProvider().values().size());
}
Also used : CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Example 5 with CloudbreakImageCatalogV2

use of com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2 in project cloudbreak by hortonworks.

the class ImageCatalogServiceDefaultTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    MockitoAnnotations.initMocks(this);
    String catalogJson = FileReaderUtils.readFileFromClasspath(catalogFile);
    CloudbreakImageCatalogV2 catalog = JsonUtil.readValue(catalogJson, CloudbreakImageCatalogV2.class);
    when(imageCatalogProvider.getImageCatalogV2("")).thenReturn(catalog);
    IdentityUser user = getIdentityUser();
    when(authenticatedUserService.getCbUser()).thenReturn(user);
    when(userProfileService.get(user.getAccount(), user.getUserId(), user.getUsername())).thenReturn(new UserProfile());
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) UserProfile(com.sequenceiq.cloudbreak.domain.UserProfile) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Before(org.junit.Before)

Aggregations

CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)10 Test (org.junit.Test)5 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)4 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)3 Before (org.junit.Before)3 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 TestUtil (com.sequenceiq.cloudbreak.TestUtil)1 CloudConstant (com.sequenceiq.cloudbreak.cloud.CloudConstant)1 Versioned (com.sequenceiq.cloudbreak.cloud.model.Versioned)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 Images (com.sequenceiq.cloudbreak.cloud.model.catalog.Images)1 APIResourceType (com.sequenceiq.cloudbreak.common.type.APIResourceType)1 AuthenticatedUserService (com.sequenceiq.cloudbreak.controller.AuthenticatedUserService)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1