Source:
<code>protected void executeVmCommand() { Set<Guid> mImagesToBeRemoved = new HashSet<Guid>(); List<DiskImage> images = getParameters().Images; if (images == null) { images = ImagesHandler.filterImageDisks(DbFacade.getInstance().getDiskDao().getAllForVm(getVmId()), true, false); } for (DiskImage image : images) { if (Boolean.TRUE.equals(image.getActive())) { mImagesToBeRemoved.add(image.getImageId()); } } Collection<DiskImage> failedRemoving = new LinkedList<>(); for (final DiskImage image : images) { if (mImagesToBeRemoved.contains(image.getImageId())) { VdcReturnValueBase vdcReturnValue = Backend.getInstance().runInternalAction(VdcActionType.RemoveImage, buildRemoveImageParameters(image), ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); if (vdcReturnValue.getSucceeded()) { getReturnValue().getInternalVdsmTaskIdList().addAll(vdcReturnValue.getInternalVdsmTaskIdList()); } else { failedRemoving.add(image); log.errorFormat("Can't remove image id: {0} for VM id: {1} due to: {2}.", image.getImageId(), getParameters().getVmId(), vdcReturnValue.getFault().getMessage()); if (getParameters().getParentCommand() != VdcActionType.RemoveVmFromImportExport <START> && getParameters().getParentCommand() != VdcActionType.RemoveVmTemplateFromImportExport) { <END> log.error("Image will be set at illegal state with no snapshot id."); TransactionSupport.executeInScope(TransactionScopeOption.Required, new TransactionMethod<Object>() { @Override public Object runInTransaction() { updateDiskImagesToIllegal(image); return true; } }); } else { log.error("Image is on an import domain and will not be marked as illegal."); } } } } setActionReturnValue(failedRemoving); setSucceeded(true); }</code><technical_language>a fan of this solution - creates additional coupling commands. approach - update status if image is a DATA domain: [pseudo code] StorageDomain sd = getStorageDomainDao().get(image.getStorageDoaminIds().get(0); if (sd.getStorageDomainType().isData()) { // update status illegal... }</technical_language>

Target:
protected void executeVmCommand() { Set<Guid> mImagesToBeRemoved = new HashSet<Guid>(); List<DiskImage> images = getParameters().Images; if (images == null) { images = ImagesHandler.filterImageDisks(DbFacade.getInstance().getDiskDao().getAllForVm(getVmId()), true, false); } for (DiskImage image : images) { if (Boolean.TRUE.equals(image.getActive())) { mImagesToBeRemoved.add(image.getImageId()); } } Collection<DiskImage> failedRemoving = new LinkedList<>(); for (final DiskImage image : images) { if (mImagesToBeRemoved.contains(image.getImageId())) { VdcReturnValueBase vdcReturnValue = Backend.getInstance().runInternalAction(VdcActionType.RemoveImage, buildRemoveImageParameters(image), ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); if (vdcReturnValue.getSucceeded()) { getReturnValue().getInternalVdsmTaskIdList().addAll(vdcReturnValue.getInternalVdsmTaskIdList()); } else { StorageDomain domain = DbFacade.getInstance().getStorageDomainDao().get(image.getStorageIds().get(0)); failedRemoving.add(image); log.errorFormat("Can't remove image id: {0} for VM id: {1} from domain id: {2} due to: {3}.", image.getImageId(), getParameters().getVmId(), image.getStorageIds().get(0), vdcReturnValue.getFault().getMessage()); if (domain.getStorageDomainType() == StorageDomainType.Data) { log.error("Image will be set at illegal state with no snapshot id."); TransactionSupport.executeInScope(TransactionScopeOption.Required, new TransactionMethod<Object>() { @Override public Object runInTransaction() { updateDiskImagesToIllegal(image); return true; } }); } else { log.error("The image is not on a data domain and will not be marked as illegal."); } } } } setActionReturnValue(failedRemoving); setSucceeded(true); }