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