Search in sources :

Example 21 with CustomImage

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

the class CustomImageCatalogServiceTest method testUpdateCustomImageWithNullsHasNoAffect.

@Test
public void testUpdateCustomImageWithNullsHasNoAffect() throws TransactionService.TransactionExecutionException {
    CustomImage updatedCustomImage = new CustomImage();
    updatedCustomImage.setVmImage(null);
    updatedCustomImage.setName(IMAGE_NAME);
    CustomImage savedCustomImage = aCustomImage();
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.getCustomImages().add(savedCustomImage);
    doAnswer(invocation -> ((Supplier<CustomImage>) invocation.getArgument(0)).get()).when(transactionService).required(any(Supplier.class));
    when(imageCatalogService.getImageCatalogByName(WORKSPACE_ID, IMAGE_CATALOG_NAME)).thenReturn(imageCatalog);
    when(imageCatalogService.pureSave(imageCatalog)).thenReturn(imageCatalog);
    CustomImage actual = victim.updateCustomImage(WORKSPACE_ID, CREATOR, IMAGE_CATALOG_NAME, updatedCustomImage);
    assertEquals(1, imageCatalog.getCustomImages().size());
    assertEquals(CUSTOMIZED_IMAGE_ID, actual.getCustomizedImageId());
    assertEquals(BASE_PARCEL_URL, actual.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME, actual.getImageType());
    assertEquals(1, actual.getVmImage().size());
    VmImage actualVmImage = actual.getVmImage().stream().findFirst().get();
    assertEquals(REGION, actualVmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, actualVmImage.getImageReference());
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Supplier(java.util.function.Supplier) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Example 22 with CustomImage

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

the class CustomImageCatalogV4CreateImageRequestToCustomImageConverter method convert.

public CustomImage convert(CustomImageCatalogV4CreateImageRequest source) {
    CustomImage result = new CustomImage();
    result.setImageType(ImageType.valueOf(source.getImageType()));
    result.setBaseParcelUrl(source.getBaseParcelUrl());
    result.setCustomizedImageId(source.getSourceImageId());
    result.setVmImage(getVmImages(source.getVmImages()));
    return result;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 23 with CustomImage

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

the class CustomImageCatalogV4UpdateImageRequestToCustomImageConverter method convert.

public CustomImage convert(CustomImageCatalogV4UpdateImageRequest source) {
    CustomImage result = new CustomImage();
    result.setImageType(source.getImageType() != null ? ImageType.valueOf(source.getImageType()) : null);
    result.setBaseParcelUrl(source.getBaseParcelUrl());
    result.setCustomizedImageId(source.getSourceImageId());
    result.setVmImage(source.getVmImages() != null ? getVmImages(source.getVmImages()) : null);
    return result;
}
Also used : CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage)

Example 24 with CustomImage

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

the class CustomImageToCustomImageCatalogV4GetImageResponseConverter method convert.

public CustomImageCatalogV4GetImageResponse convert(CustomImage source) {
    CustomImageCatalogV4GetImageResponse result = new CustomImageCatalogV4GetImageResponse();
    result.setImageId(source.getName());
    result.setImageType(source.getImageType() != null ? source.getImageType().name() : null);
    result.setSourceImageId(source.getCustomizedImageId());
    result.setBaseParcelUrl(source.getBaseParcelUrl());
    result.setVmImages(getVmImages(source.getVmImage()));
    result.setImageDate(source.getCreated());
    try {
        Image image = imageCatalogService.getSourceImageByImageType(source).getImage();
        result.setSourceImageDate(image.getCreated());
        result.setVersions(imageVersionsConverter.convert(image));
        result.setCloudProvider(image.getImageSetsByProvider().keySet().stream().findFirst().orElse(null));
    } catch (Exception ex) {
        throw new ConversionException(ex.getMessage());
    }
    return result;
}
Also used : ConversionException(com.sequenceiq.cloudbreak.converter.ConversionException) CustomImageCatalogV4GetImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) VmImage(com.sequenceiq.cloudbreak.domain.VmImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ConversionException(com.sequenceiq.cloudbreak.converter.ConversionException)

Example 25 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<ImageCatalogPlatform> 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(prv -> prv.name().equalsIgnoreCase(p))) {
                    images.add(customImageProvider.mergeSourceImageAndCustomImageProperties(sourceImage, customImage, imageCatalog.getImageCatalogUrl(), imageCatalog.getName()).getImage());
                }
            });
        }
    }
    return images;
}
Also used : 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