Maor Lipchuk has uploaded a new change for review.

Change subject: core: Support remove of cinder snapshot
......................................................................

core: Support remove of cinder snapshot

Add support for removing Cinder snapshot disk while removing a VM
snapshot.

Change-Id: Ic5fdaa6924019cff4b90072afa017e4559dccc52
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Maor Lipchuk <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java
1 file changed, 49 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/64/41464/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java
index acde305..6bdf085 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java
@@ -5,6 +5,8 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter;
@@ -33,7 +35,10 @@
 import org.ovirt.engine.core.common.businessentities.Snapshot;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.common.businessentities.storage.CinderDisk;
+import org.ovirt.engine.core.common.businessentities.storage.Disk;
 import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
+import org.ovirt.engine.core.common.businessentities.storage.DiskStorageType;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
@@ -169,8 +174,42 @@
         }
     }
 
+    private boolean isImagesExists() {
+        for (DiskImage diskImage : getSourceImages()) {
+            if (diskImage.getDiskStorageType() == DiskStorageType.IMAGE) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private ImagesContainterParametersBase 
buildChildCommandParameters(DiskImage snapshotCinderDisk) {
+        ImagesContainterParametersBase createParams = new 
ImagesContainterParametersBase(snapshotCinderDisk.getImageId());
+        createParams.setDestinationImageId(snapshotCinderDisk.getImageId());
+        
createParams.setStorageDomainId(snapshotCinderDisk.getStorageIds().get(0));
+        createParams.setParentHasTasks(isImagesExists());
+        return withRootCommandInfo(createParams, getActionType());
+    }
+
     private void removeImages() {
         for (final DiskImage source : getSourceImages()) {
+            if (source.getDiskStorageType() == DiskStorageType.CINDER) {
+                ImagesContainterParametersBase params = 
buildChildCommandParameters(source);
+
+                Future<VdcReturnValueBase> future = 
CommandCoordinatorUtil.executeAsyncCommand(
+                        VdcActionType.RemoveCinderSnapshotDisk,
+                        params,
+                        cloneContextAndDetachFromParent());
+                try {
+                    VdcReturnValueBase vdcReturnValueBase = future.get();
+                    if (!vdcReturnValueBase.getSucceeded()) {
+                        log.error("Error creating snapshot for Cinder disk 
'{}'", source.getDiskAlias());
+                    }
+                } catch (InterruptedException | ExecutionException e) {
+                    log.error("Error creating snapshot for Cinder disk '{}': 
{}", source.getDiskAlias(), e.getMessage());
+                }
+                continue;
+            }
 
             // The following is ok because we have tested in the candoaction 
that the vm
             // is not a template and the vm is not in preview mode and that
@@ -388,8 +427,8 @@
     }
 
     protected boolean validateImages() {
-        List<DiskImage> imagesToValidate =
-                
ImagesHandler.filterImageDisks(getDiskDao().getAllForVm(getVmId()), true, 
false, true);
+        List<DiskImage> imagesToValidate = getDiskImagesToValidate();
+
         DiskImagesValidator diskImagesValidator = new 
DiskImagesValidator(imagesToValidate);
 
         return validate(diskImagesValidator.diskImagesNotLocked()) &&
@@ -397,6 +436,14 @@
                  || validate(diskImagesValidator.diskImagesNotIllegal()));
     }
 
+    private List<DiskImage> getDiskImagesToValidate() {
+        List<Disk> disks = getDiskDao().getAllForVm(getVmId());
+        List<DiskImage> allDisks = ImagesHandler.filterImageDisks(disks, true, 
false, true);
+        List<CinderDisk> cinderDisks = 
ImagesHandler.filterDisksBasedOnCinder(disks);
+        allDisks.addAll(cinderDisks);
+        return allDisks;
+    }
+
     protected boolean validateImageNotInTemplate() {
         return getVmTemplateDAO().get(getRepresentativeSourceImageId()) == 
null;
     }


-- 
To view, visit https://gerrit.ovirt.org/41464
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5fdaa6924019cff4b90072afa017e4559dccc52
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Maor Lipchuk <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to