Search in sources :

Example 1 with CustomImage

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

the class ImageCatalogService method getCustomStatedImage.

private StatedImage getCustomStatedImage(ImageCatalog imageCatalog, String imageId) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    Optional<CustomImage> optionalCustomImage = getCustomImage(imageCatalog, imageId);
    if (optionalCustomImage.isPresent()) {
        CustomImage customImage = optionalCustomImage.get();
        LOGGER.info("Custom image is available with id '{}'. Searching for source image '{}'.", imageId, customImage.getCustomizedImageId());
        StatedImage sourceImage = getSourceImageByImageType(customImage);
        LOGGER.info("Custom image '{}' is a {} image '{}' customization.", imageId, customImage.getImageType(), customImage.getCustomizedImageId());
        return customImageProvider.mergeSourceImageAndCustomImageProperties(sourceImage, customImage, imageCatalog.getImageCatalogUrl(), imageCatalog.getName());
    } else {
        return getImage(imageCatalog.getImageCatalogUrl(), imageCatalog.getName(), imageId);
    }
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 2 with CustomImage

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

the class CustomImageCatalogService method deleteCustomImage.

public CustomImage deleteCustomImage(Long workspaceId, String imageCatalogName, String imageId) {
    LOGGER.debug(String.format("Delete custom image '%s' from catalog '%s' in workspace '%d'", imageId, imageCatalogName, workspaceId));
    try {
        return transactionService.required(() -> {
            ImageCatalog imageCatalog = getImageCatalog(workspaceId, imageCatalogName);
            CustomImage customImage = getCustomImageFromCatalog(imageCatalog, imageId);
            imageCatalog.getCustomImages().remove(customImage);
            imageCatalogService.pureSave(imageCatalog);
            return customImage;
        });
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error(String.format("Custom image '%s' delete failed from custom image catalog '%s' in workspace '%d': %s", imageId, imageCatalogName, workspaceId, e.getMessage()));
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
}
Also used : TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog)

Example 3 with CustomImage

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

the class CustomImageCatalogService method updateCustomImage.

public CustomImage updateCustomImage(Long workspaceId, String creator, String imageCatalogName, CustomImage customImage) {
    LOGGER.debug(String.format("Update custom image '%s' in catalog '%s' in workspace '%d'", customImage.getName(), imageCatalogName, workspaceId));
    try {
        return transactionService.required(() -> {
            ImageCatalog imageCatalog = getImageCatalog(workspaceId, imageCatalogName);
            CustomImage savedCustomImage = getCustomImageFromCatalog(imageCatalog, customImage.getName());
            if (customImage.getCustomizedImageId() != null) {
                savedCustomImage.setCustomizedImageId(customImage.getCustomizedImageId());
            }
            if (customImage.getImageType() != null) {
                savedCustomImage.setImageType(customImage.getImageType());
            }
            if (customImage.getBaseParcelUrl() != null) {
                savedCustomImage.setBaseParcelUrl(customImage.getBaseParcelUrl());
            }
            if (customImage.getVmImage() != null) {
                Set<VmImage> vmImagesToSave = new HashSet<>(customImage.getVmImage());
                for (VmImage savedVmImage : savedCustomImage.getVmImage()) {
                    Optional<VmImage> vmImage = vmImagesToSave.stream().filter(vm -> vm.getRegion().equals(savedVmImage.getRegion())).findFirst();
                    if (vmImage.isPresent()) {
                        savedVmImage.setRegion(vmImage.get().getRegion());
                        savedVmImage.setImageReference(vmImage.get().getImageReference());
                        vmImagesToSave.remove(vmImage.get());
                    } else {
                        savedCustomImage.getVmImage().remove(savedVmImage);
                    }
                }
                for (VmImage vmImage : vmImagesToSave) {
                    vmImage.setCreator(creator);
                    vmImage.setCustomImage(savedCustomImage);
                    savedCustomImage.getVmImage().add(vmImage);
                }
            }
            validateSourceImage(savedCustomImage);
            ImageCatalog savedImageCatalog = imageCatalogService.pureSave(imageCatalog);
            return getCustomImageFromCatalog(savedImageCatalog, customImage.getName());
        });
    } catch (TransactionService.TransactionExecutionException e) {
        LOGGER.error(String.format("Custom image '%s' update failed in custom image catalog '%s' in workspace '%d': %s", customImage.getName(), imageCatalogName, workspaceId, e.getMessage()));
        throw new TransactionService.TransactionRuntimeExecutionException(e);
    }
}
Also used : BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) RegionAwareCrnGenerator(com.sequenceiq.cloudbreak.auth.crn.RegionAwareCrnGenerator) Set(java.util.Set) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) UUID(java.util.UUID) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) CrnResourceDescriptor(com.sequenceiq.cloudbreak.auth.crn.CrnResourceDescriptor) Component(org.springframework.stereotype.Component) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Optional(java.util.Optional) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) HashSet(java.util.HashSet)

Example 4 with CustomImage

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

the class CustomImageCatalogV4Controller method getCustomImage.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.DESCRIBE_IMAGE_CATALOG)
public CustomImageCatalogV4GetImageResponse getCustomImage(@ResourceName String name, String imageId, @AccountId String accountId) {
    CustomImage customImage = customImageCatalogService.getCustomImage(restRequestThreadLocalService.getRequestedWorkspaceId(), name, imageId);
    Image sourceImage = customImageCatalogService.getSourceImage(customImage);
    CustomImageCatalogV4GetImageResponse response = customImageToCustomImageCatalogV4GetImageResponseConverter.convert(customImage);
    response.setSourceImageDate(sourceImage.getCreated());
    return response;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Example 5 with CustomImage

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

the class CustomImageCatalogV4Controller method updateCustomImage.

@Override
@CheckPermissionByResourceName(action = AuthorizationResourceAction.EDIT_IMAGE_CATALOG)
public CustomImageCatalogV4UpdateImageResponse updateCustomImage(@ResourceName String name, String imageId, @Valid CustomImageCatalogV4UpdateImageRequest request, @AccountId String accountId) {
    String creator = ThreadBasedUserCrnProvider.getUserCrn();
    CustomImage customImage = customImageCatalogV4UpdateImageRequestToCustomImageConverter.convert(request);
    customImage.setName(imageId);
    CustomImage savedCustomImage = customImageCatalogService.updateCustomImage(restRequestThreadLocalService.getRequestedWorkspaceId(), creator, name, customImage);
    return customImageToCustomImageCatalogV4UpdateImageResponseConverter.convert(savedCustomImage);
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CheckPermissionByResourceName(com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)

Aggregations

CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)47 Test (org.junit.jupiter.api.Test)26 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)18 VmImage (com.sequenceiq.cloudbreak.domain.VmImage)13 Supplier (java.util.function.Supplier)11 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)9 CustomImageCatalogV4GetImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse)4 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)3 CustomImageCatalogV4UpdateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4UpdateImageRequest)3 CustomImageCatalogV4VmImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse)3 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)3 Test (org.junit.Test)3 CustomImageCatalogV4CreateImageRequest (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.request.CustomImageCatalogV4CreateImageRequest)2 CustomImageCatalogV4CreateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4CreateImageResponse)2 CustomImageCatalogV4DeleteImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4DeleteImageResponse)2 CustomImageCatalogV4ImageListItemResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse)2 CustomImageCatalogV4UpdateImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4UpdateImageResponse)2 TransactionService (com.sequenceiq.cloudbreak.common.service.TransactionService)2 ConversionException (com.sequenceiq.cloudbreak.converter.ConversionException)2 StatedImage.statedImage (com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage)2