Search in sources :

Example 1 with CloudbreakVersion

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

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

the class ImageCatalogProviderTest method testReadImageCatalogFromFile.

@Test
public void testReadImageCatalogFromFile() throws Exception {
    String path = getPath(CB_IMAGE_CATALOG_V2_JSON);
    underTest.setEtcConfigDir(path);
    CloudbreakImageCatalogV2 catalog = underTest.getImageCatalogV2(CB_IMAGE_CATALOG_V2_JSON);
    Assert.assertNotNull("Check that the parsed ImageCatalog not null.", catalog);
    Optional<CloudbreakVersion> ver = catalog.getVersions().getCloudbreakVersions().stream().filter(v -> v.getVersions().contains(CB_VERSION)).findFirst();
    Assert.assertTrue("Check that the parsed ImageCatalog contains the desired version of Cloudbreak.", ver.isPresent());
    List<String> imageIds = ver.get().getImageIds();
    Assert.assertNotNull("Check that the parsed ImageCatalog contains the desired version of Cloudbreak with image id(s).", imageIds);
    Optional<String> imageIdOptional = imageIds.stream().findFirst();
    Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image reference for the Cloudbreak version.", imageIdOptional.isPresent());
    String imageId = imageIdOptional.get();
    boolean baseImageFound = false;
    boolean hdpImageFound = false;
    boolean hdfImageFoiund = false;
    if (catalog.getImages().getBaseImages() != null) {
        baseImageFound = catalog.getImages().getBaseImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
    }
    if (catalog.getImages().getHdpImages() != null) {
        hdpImageFound = catalog.getImages().getHdpImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
    }
    if (catalog.getImages().getHdfImages() != null) {
        hdfImageFoiund = catalog.getImages().getHdfImages().stream().anyMatch(i -> i.getUuid().equals(imageId));
    }
    boolean anyImageFoundForVersion = baseImageFound || hdpImageFound || hdfImageFoiund;
    Assert.assertTrue("Check that the parsed ImageCatalog contains Ambari image for the Cloudbreak version.", anyImageFoundForVersion);
}
Also used : InjectMocks(org.mockito.InjectMocks) List(java.util.List) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) RunWith(org.junit.runner.RunWith) Optional(java.util.Optional) TestUtil(com.sequenceiq.cloudbreak.TestUtil) IOException(java.io.IOException) Test(org.junit.Test) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Assert(org.junit.Assert) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) CloudbreakVersion(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion) CloudbreakImageCatalogV2(com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2) Test(org.junit.Test)

Aggregations

CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)2 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)2 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)2 List (java.util.List)2 Optional (java.util.Optional)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 TestUtil (com.sequenceiq.cloudbreak.TestUtil)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 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 APIResourceType (com.sequenceiq.cloudbreak.common.type.APIResourceType)1 AuthenticatedUserService (com.sequenceiq.cloudbreak.controller.AuthenticatedUserService)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)1 ImageCatalogRepository (com.sequenceiq.cloudbreak.repository.ImageCatalogRepository)1 AuthorizationService (com.sequenceiq.cloudbreak.service.AuthorizationService)1