Search in sources :

Example 46 with CustomImage

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

the class CustomImageCatalogServiceTest method testCreateCustomImageShouldFailInCaseOfMissingSourceImage.

@Test
public void testCreateCustomImageShouldFailInCaseOfMissingSourceImage() throws TransactionService.TransactionExecutionException {
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setImageCatalogUrl(IMAGE_CATALOG_URL);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    assertThrows(BadRequestException.class, () -> victim.createCustomImage(WORKSPACE_ID, ACCOUNT_ID, CREATOR, IMAGE_CATALOG_NAME, null));
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 47 with CustomImage

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

the class ImageCatalogService method getImages.

private List<Image> getImages(ImageType imageType, ImageCatalog imageCatalog, Set<String> providers) throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    List<Image> images = new ArrayList<>();
    for (CustomImage customImage : imageCatalog.getCustomImages()) {
        if (imageType == customImage.getImageType()) {
            StatedImage sourceImage = getSourceImageByImageType(customImage);
            Optional<String> provider = sourceImage.getImage().getImageSetsByProvider().keySet().stream().findFirst();
            provider.ifPresent(p -> {
                if (providers.stream().anyMatch(p::equalsIgnoreCase)) {
                    images.add(customImageProvider.mergeSourceImageAndCustomImageProperties(sourceImage, customImage, imageCatalog.getImageCatalogUrl(), imageCatalog.getName()).getImage());
                }
            });
        }
    }
    return images;
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) ArrayList(java.util.ArrayList) StatedImage.statedImage(com.sequenceiq.cloudbreak.service.image.StatedImage.statedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

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