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