Search in sources :

Example 1 with ImageCatalog

use of com.sequenceiq.cloudbreak.domain.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogService method delete.

public void delete(String name) {
    if (isEnvDefault(name)) {
        throw new BadRequestException(String.format("%s cannot be deleted because it is an environment default image catalog.", name));
    }
    ImageCatalog imageCatalog = get(name);
    authorizationService.hasWritePermission(imageCatalog);
    imageCatalog.setArchived(true);
    setImageCatalogAsDefault(null);
    imageCatalog.setImageCatalogName(generateArchiveName(name));
    imageCatalogRepository.save(imageCatalog);
    LOGGER.info("Image catalog has been archived: {}", imageCatalog);
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 2 with ImageCatalog

use of com.sequenceiq.cloudbreak.domain.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogService method removeDefaultFlag.

private void removeDefaultFlag() {
    ImageCatalog imageCatalog = getDefaultImageCatalog();
    if (imageCatalog != null) {
        setImageCatalogAsDefault(null);
        imageCatalogRepository.save(imageCatalog);
    }
}
Also used : ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 3 with ImageCatalog

use of com.sequenceiq.cloudbreak.domain.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogService method setAsDefault.

public ImageCatalog setAsDefault(String name) {
    removeDefaultFlag();
    if (!isEnvDefault(name)) {
        ImageCatalog imageCatalog = get(name);
        checkImageCatalog(imageCatalog, name);
        authorizationService.hasWritePermission(imageCatalog);
        setImageCatalogAsDefault(imageCatalog);
        return imageCatalog;
    }
    return getCloudbreakDefaultImageCatalog();
}
Also used : ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 4 with ImageCatalog

use of com.sequenceiq.cloudbreak.domain.ImageCatalog 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 5 with ImageCatalog

use of com.sequenceiq.cloudbreak.domain.ImageCatalog in project cloudbreak by hortonworks.

the class ImageCatalogService method get.

public ImageCatalog get(String name) {
    ImageCatalog imageCatalog;
    if (isEnvDefault(name)) {
        imageCatalog = getCloudbreakDefaultImageCatalog();
    } else {
        IdentityUser user = authenticatedUserService.getCbUser();
        imageCatalog = imageCatalogRepository.findByName(name, user.getUserId(), user.getAccount());
    }
    return imageCatalog;
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Aggregations

ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)17 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)7 Test (org.junit.Test)4 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 UserProfile (com.sequenceiq.cloudbreak.domain.UserProfile)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Versioned (com.sequenceiq.cloudbreak.cloud.model.Versioned)1 CloudbreakImageCatalogV2 (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakImageCatalogV2)1 CloudbreakVersion (com.sequenceiq.cloudbreak.cloud.model.catalog.CloudbreakVersion)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 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)1 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)1 ImageCatalogRepository (com.sequenceiq.cloudbreak.repository.ImageCatalogRepository)1 AuthorizationService (com.sequenceiq.cloudbreak.service.AuthorizationService)1 AccountPreferencesService (com.sequenceiq.cloudbreak.service.account.AccountPreferencesService)1 StatedImage.statedImage (com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage)1