Search in sources :

Example 1 with CustomImageCatalogV4ImageListItemResponse

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse in project cloudbreak by hortonworks.

the class ImageCatalogToCustomImageCatalogV4GetResponseConverter method getImage.

private CustomImageCatalogV4ImageListItemResponse getImage(CustomImage source) {
    CustomImageCatalogV4ImageListItemResponse result = new CustomImageCatalogV4ImageListItemResponse();
    result.setImageId(source.getName());
    result.setImageType(source.getImageType() != null ? source.getImageType().name() : null);
    result.setSourceImageId(source.getCustomizedImageId());
    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) CustomImageCatalogV4ImageListItemResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) ConversionException(com.sequenceiq.cloudbreak.converter.ConversionException)

Example 2 with CustomImageCatalogV4ImageListItemResponse

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse in project cloudbreak by hortonworks.

the class ImageCatalogToCustomImageCatalogV4GetResponseConverterTest method shouldConvert.

@Test
public void shouldConvert() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CustomImage customImage = getCustomImage(IMAGE_ID);
    ImageCatalog imageCatalog = new ImageCatalog();
    imageCatalog.setName(NAME);
    customImage.setImageType(ImageType.RUNTIME);
    customImage.setCustomizedImageId(SOURCE_IMAGE_ID);
    imageCatalog.setDescription(DESCRIPTION);
    imageCatalog.setCustomImages(Collections.singleton(customImage));
    when(imageCatalogService.getSourceImageByImageType(customImage)).thenReturn(statedImage);
    when(statedImage.getImage()).thenReturn(image);
    when(image.getCreated()).thenReturn(SOURCE_IMAGE_DATE);
    when(image.getImageSetsByProvider()).thenReturn(Map.of(CLOUD_PROVIDER, Map.of()));
    when(imageVersionsConverter.convert(image)).thenReturn(Collections.emptyMap());
    CustomImageCatalogV4GetResponse result = victim.convert(imageCatalog);
    assertEquals(NAME, result.getName());
    assertEquals(DESCRIPTION, result.getDescription());
    assertEquals(1, result.getImages().size());
    CustomImageCatalogV4ImageListItemResponse imageResult = result.getImages().stream().findFirst().get();
    assertEquals(IMAGE_ID, imageResult.getImageId());
    assertEquals(SOURCE_IMAGE_ID, imageResult.getSourceImageId());
    assertNotNull(imageResult.getImageDate());
    assertEquals(SOURCE_IMAGE_DATE, imageResult.getSourceImageDate());
    assertEquals(CLOUD_PROVIDER, imageResult.getCloudProvider());
    assertNotNull(imageResult.getVersions());
    assertEquals(ImageType.RUNTIME.name(), imageResult.getImageType());
}
Also used : CustomImageCatalogV4ImageListItemResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetResponse) ImageCatalog(com.sequenceiq.cloudbreak.domain.ImageCatalog) Test(org.junit.jupiter.api.Test)

Aggregations

CustomImageCatalogV4ImageListItemResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4ImageListItemResponse)2 CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)2 CustomImageCatalogV4GetResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetResponse)1 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)1 ConversionException (com.sequenceiq.cloudbreak.converter.ConversionException)1 ImageCatalog (com.sequenceiq.cloudbreak.domain.ImageCatalog)1 Test (org.junit.jupiter.api.Test)1