Search in sources :

Example 1 with CustomImageCatalogV4GetImageResponse

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse 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 2 with CustomImageCatalogV4GetImageResponse

use of com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse 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 3 with CustomImageCatalogV4GetImageResponse

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

the class CustomImageToCustomImageCatalogV4GetImageResponseConverterTest method shouldConvert.

@Test
public void shouldConvert() throws CloudbreakImageNotFoundException, CloudbreakImageCatalogException {
    CustomImage customImage = new CustomImage();
    customImage.setName(IMAGE_ID);
    customImage.setImageType(ImageType.RUNTIME);
    customImage.setBaseParcelUrl(BASE_PARCEL_URL);
    customImage.setCustomizedImageId(SOURCE_IMAGE_ID);
    customImage.setVmImage(Collections.singleton(getVmImage(REGION, IMAGE_REFERENCE)));
    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());
    CustomImageCatalogV4GetImageResponse result = victim.convert(customImage);
    assertEquals(IMAGE_ID, result.getImageId());
    assertEquals(SOURCE_IMAGE_ID, result.getSourceImageId());
    assertEquals(BASE_PARCEL_URL, result.getBaseParcelUrl());
    assertEquals(ImageType.RUNTIME.name(), result.getImageType());
    assertEquals(1, result.getVmImages().size());
    assertNotNull(result.getImageDate());
    assertEquals(SOURCE_IMAGE_DATE, result.getSourceImageDate());
    assertEquals(CLOUD_PROVIDER, result.getCloudProvider());
    assertNotNull(result.getVersions());
    CustomImageCatalogV4VmImageResponse vmImage = result.getVmImages().stream().findFirst().get();
    assertEquals(REGION, vmImage.getRegion());
    assertEquals(IMAGE_REFERENCE, vmImage.getImageReference());
}
Also used : CustomImageCatalogV4VmImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse) CustomImage(com.sequenceiq.cloudbreak.domain.CustomImage) CustomImageCatalogV4GetImageResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse) Test(org.junit.jupiter.api.Test)

Example 4 with CustomImageCatalogV4GetImageResponse

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

the class CustomImageCatalogV4ControllerTest method testGetCustomImage.

@Test
public void testGetCustomImage() {
    CustomImage customImage = new CustomImage();
    Image sourceImage = createTestImage();
    CustomImageCatalogV4GetImageResponse expected = new CustomImageCatalogV4GetImageResponse();
    expected.setSourceImageDate(12345L);
    when(restRequestThreadLocalService.getRequestedWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(customImageCatalogService.getCustomImage(WORKSPACE_ID, IMAGE_CATALOG_NAME, IMAGE_ID)).thenReturn(customImage);
    when(customImageToCustomImageCatalogV4GetImageResponseConverter.convert(customImage)).thenReturn(expected);
    when(customImageCatalogService.getSourceImage(customImage)).thenReturn(sourceImage);
    CustomImageCatalogV4GetImageResponse actual = victim.getCustomImage(IMAGE_CATALOG_NAME, IMAGE_ID, ACCOUNT_ID);
    assertEquals(expected, actual);
}
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) Test(org.junit.jupiter.api.Test)

Aggregations

CustomImageCatalogV4GetImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4GetImageResponse)4 CustomImage (com.sequenceiq.cloudbreak.domain.CustomImage)4 Image (com.sequenceiq.cloudbreak.cloud.model.catalog.Image)3 Test (org.junit.jupiter.api.Test)2 CheckPermissionByResourceName (com.sequenceiq.authorization.annotation.CheckPermissionByResourceName)1 CustomImageCatalogV4VmImageResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.customimage.response.CustomImageCatalogV4VmImageResponse)1 ConversionException (com.sequenceiq.cloudbreak.converter.ConversionException)1 VmImage (com.sequenceiq.cloudbreak.domain.VmImage)1