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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
Aggregations