use of com.sequenceiq.cloudbreak.domain.VmImage in project cloudbreak by hortonworks.
the class CustomImageCatalogService method updateCustomImage.
public CustomImage updateCustomImage(Long workspaceId, String creator, String imageCatalogName, CustomImage customImage) {
LOGGER.debug(String.format("Update custom image '%s' in catalog '%s' in workspace '%d'", customImage.getName(), imageCatalogName, workspaceId));
try {
return transactionService.required(() -> {
ImageCatalog imageCatalog = getImageCatalog(workspaceId, imageCatalogName);
CustomImage savedCustomImage = getCustomImageFromCatalog(imageCatalog, customImage.getName());
if (customImage.getCustomizedImageId() != null) {
savedCustomImage.setCustomizedImageId(customImage.getCustomizedImageId());
}
if (customImage.getImageType() != null) {
savedCustomImage.setImageType(customImage.getImageType());
}
if (customImage.getBaseParcelUrl() != null) {
savedCustomImage.setBaseParcelUrl(customImage.getBaseParcelUrl());
}
if (customImage.getVmImage() != null) {
Set<VmImage> vmImagesToSave = new HashSet<>(customImage.getVmImage());
for (VmImage savedVmImage : savedCustomImage.getVmImage()) {
Optional<VmImage> vmImage = vmImagesToSave.stream().filter(vm -> vm.getRegion().equals(savedVmImage.getRegion())).findFirst();
if (vmImage.isPresent()) {
savedVmImage.setRegion(vmImage.get().getRegion());
savedVmImage.setImageReference(vmImage.get().getImageReference());
vmImagesToSave.remove(vmImage.get());
} else {
savedCustomImage.getVmImage().remove(savedVmImage);
}
}
for (VmImage vmImage : vmImagesToSave) {
vmImage.setCreator(creator);
vmImage.setCustomImage(savedCustomImage);
savedCustomImage.getVmImage().add(vmImage);
}
}
validateSourceImage(savedCustomImage);
ImageCatalog savedImageCatalog = imageCatalogService.pureSave(imageCatalog);
return getCustomImageFromCatalog(savedImageCatalog, customImage.getName());
});
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.error(String.format("Custom image '%s' update failed in custom image catalog '%s' in workspace '%d': %s", customImage.getName(), imageCatalogName, workspaceId, e.getMessage()));
throw new TransactionService.TransactionRuntimeExecutionException(e);
}
}
use of com.sequenceiq.cloudbreak.domain.VmImage in project cloudbreak by hortonworks.
the class CustomImageCatalogV4UpdateImageRequestToCustomImageConverterTest method shouldConvert.
@Test
public void shouldConvert() {
CustomImageCatalogV4UpdateImageRequest source = new CustomImageCatalogV4UpdateImageRequest();
source.setSourceImageId(SOURCE_IMAGE_ID);
source.setBaseParcelUrl(BASE_PARCEL_URL);
source.setImageType(VALID_IMAGE_TYPE);
source.setVmImages(Collections.singleton(getVmImageRequest(REGION, IMAGE_REFERENCE)));
CustomImage result = victim.convert(source);
assertEquals(SOURCE_IMAGE_ID, result.getCustomizedImageId());
assertEquals(BASE_PARCEL_URL, result.getBaseParcelUrl());
assertEquals(ImageType.RUNTIME, result.getImageType());
assertEquals(1, result.getVmImage().size());
VmImage vmImage = result.getVmImage().stream().findFirst().get();
assertEquals(REGION, vmImage.getRegion());
assertEquals(IMAGE_REFERENCE, vmImage.getImageReference());
}
use of com.sequenceiq.cloudbreak.domain.VmImage in project cloudbreak by hortonworks.
the class CustomImageToCustomImageCatalogV4UpdateImageResponseConverterTest method getVmImage.
private VmImage getVmImage(String region, String imageReference) {
VmImage request = new VmImage();
request.setRegion(region);
request.setImageReference(imageReference);
return request;
}
use of com.sequenceiq.cloudbreak.domain.VmImage in project cloudbreak by hortonworks.
the class CustomImageCatalogV4CreateImageRequestToCustomImageConverterTest method shouldConvert.
@Test
public void shouldConvert() {
CustomImageCatalogV4CreateImageRequest source = new CustomImageCatalogV4CreateImageRequest();
source.setSourceImageId(SOURCE_IMAGE_ID);
source.setBaseParcelUrl(BASE_PARCEL_URL);
source.setImageType(VALID_IMAGE_TYPE);
source.setVmImages(Collections.singleton(getVmImageRequest(REGION, IMAGE_REFERENCE)));
CustomImage result = victim.convert(source);
assertEquals(SOURCE_IMAGE_ID, result.getCustomizedImageId());
assertEquals(BASE_PARCEL_URL, result.getBaseParcelUrl());
assertEquals(ImageType.RUNTIME, result.getImageType());
assertEquals(1, result.getVmImage().size());
VmImage vmImage = result.getVmImage().stream().findFirst().get();
assertEquals(REGION, vmImage.getRegion());
assertEquals(IMAGE_REFERENCE, vmImage.getImageReference());
}
use of com.sequenceiq.cloudbreak.domain.VmImage in project cloudbreak by hortonworks.
the class CustomImageCatalogServiceTest method testUpdateCustomImageWithUpdatedVmImage.
@Test
public void testUpdateCustomImageWithUpdatedVmImage() throws TransactionService.TransactionExecutionException {
CustomImage updatedCustomImage = aCustomImage();
CustomImage savedCustomImage = new CustomImage();
VmImage vmImage = new VmImage();
vmImage.setRegion(REGION);
savedCustomImage.getVmImage().add(vmImage);
savedCustomImage.setName(IMAGE_NAME);
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();
assertNull(actualVmImage.getCreator());
assertEquals(REGION, actualVmImage.getRegion());
assertEquals(IMAGE_REFERENCE, actualVmImage.getImageReference());
}
Aggregations