Arik Hadas has uploaded a new change for review.

Change subject: core: remove memory volumes without tasks on snapshot creation 
failure
......................................................................

core: remove memory volumes without tasks on snapshot creation failure

On the end-action phase of snapshot creation command, we check if the VM
is runningto see whether we should take live snapshot or not. If the VM
is not running and we created images that will be used to store the
memory, we try to remove those images. There was a problem that the
remove image operations created tasks that were not polled (they are not
polled automatically since we're in the end-action phase, and we didn't
explicitly asked to poll them).

Since we have nothing to do in case of failure (if the file deletion
didn't work, it most probably won't work on retry), we now don't create
tasks on those delete image operations.

New command RemoveMemoryVolumesCommand is added to do so, to achieve
better separation of concerns, which will also make it possible to reuse
it on other cases.

Change-Id: I3830992f46b2c3fbea47e69f21a6711718408e95
Bug-Url: https://bugzilla.redhat.com/1011474
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveMemoryVolumesCommand.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveMemoryVolumesParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
4 files changed, 160 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/19568/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
index 45432ec..7bfb51f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
@@ -8,6 +8,7 @@
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
+import org.ovirt.engine.core.bll.job.ExecutionHandler;
 import org.ovirt.engine.core.bll.memory.LiveSnapshotMemoryImageBuilder;
 import org.ovirt.engine.core.bll.memory.MemoryImageBuilder;
 import org.ovirt.engine.core.bll.memory.NullableMemoryImageBuilder;
@@ -27,6 +28,7 @@
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.CreateAllSnapshotsFromVmParameters;
 import org.ovirt.engine.core.common.action.ImagesActionsParametersBase;
+import org.ovirt.engine.core.common.action.RemoveMemoryVolumesParameters;
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
@@ -271,7 +273,19 @@
             getSnapshotDao().removeMemoryFromSnapshot(snapshot.getId());
         }
 
-        return removeMemoryVolumes(memoryVolume, getActionType(), false);
+        return removeMemoryVolumes(memoryVolume);
+    }
+
+    private boolean removeMemoryVolumes(String memoryVolumes) {
+        RemoveMemoryVolumesParameters parameters = new 
RemoveMemoryVolumesParameters(memoryVolumes, getVmId());
+        parameters.setParentCommand(getActionType());
+        parameters.setEntityInfo(getParameters().getEntityInfo());
+        parameters.setParentParameters(getParameters());
+
+        return getBackend().runInternalAction(
+                VdcActionType.RemoveMemoryVolumes,
+                parameters,
+                
ExecutionHandler.createDefaultContexForTasks(getExecutionContext())).getSucceeded();
     }
 
     private boolean isLiveSnapshotApplicable() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveMemoryVolumesCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveMemoryVolumesCommand.java
new file mode 100644
index 0000000..da03968
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveMemoryVolumesCommand.java
@@ -0,0 +1,109 @@
+package org.ovirt.engine.core.bll;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.ovirt.engine.core.bll.memory.HibernationVolumesRemover;
+import org.ovirt.engine.core.bll.tasks.TaskHandlerCommand;
+import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.action.RemoveMemoryVolumesParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.asynctasks.AsyncTaskCreationInfo;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.NotImplementedException;
+
+/**
+ * Command for removing the given memory volumes.
+ * Note that no tasks are created, so we don't monitor whether
+ * the operation succeed or not as we can't do much when if fails.
+ */
+@NonTransactiveCommandAttribute
+@InternalCommandAttribute
+public class RemoveMemoryVolumesCommand<T extends 
RemoveMemoryVolumesParameters> extends CommandBase<T> implements 
TaskHandlerCommand<T> {
+    /** fictive list of task IDs, used when we don't want to add tasks */
+    private static final ArrayList<Guid> dummyTaskIdList = new ArrayList<>();
+
+    public RemoveMemoryVolumesCommand(T parameters) {
+        super(parameters);
+    }
+
+    protected RemoveMemoryVolumesCommand(Guid commandId) {
+        super(commandId);
+    }
+
+    @Override
+    protected void executeCommand() {
+        HibernationVolumesRemover hibernationVolumesRemover =
+                new HibernationVolumesRemover(
+                        getParameters().getMemoryVolumes(),
+                        getParameters().getVmId(),
+                        this);
+
+        setSucceeded(hibernationVolumesRemover.remove());
+    }
+
+    //////////////////////////////////
+    /// TaskHandler implementation ///
+    //////////////////////////////////
+
+    @Override
+    public VdcActionType getActionType() {
+        return super.getActionType();
+    }
+
+    /**
+     * Not adding tasks
+     */
+    @Override
+    public Guid createTask(Guid taskId, AsyncTaskCreationInfo 
asyncTaskCreationInfo, VdcActionType parentCommand) {
+        return Guid.Empty;
+    }
+
+    /**
+     * Not adding tasks
+     */
+    @Override
+    public Guid createTask(Guid taskId,
+            AsyncTaskCreationInfo asyncTaskCreationInfo,
+            VdcActionType parentCommand,
+            VdcObjectType vdcObjectType,
+            Guid... entityIds) {
+        return Guid.Empty;
+    }
+
+    /**
+     * Not adding task IDs
+     */
+    @Override
+    public ArrayList<Guid> getTaskIdList() {
+        return dummyTaskIdList;
+    }
+
+    @Override
+    public void preventRollback() {
+        throw new NotImplementedException();
+    }
+
+    /**
+     * Not adding place holders
+     */
+    @Override
+    public Guid persistAsyncTaskPlaceHolder() {
+        return Guid.Empty;
+    }
+
+    /**
+     * Not adding place holders
+     */
+    @Override
+    public Guid persistAsyncTaskPlaceHolder(String taskKey) {
+        return Guid.Empty;
+    }
+
+    @Override
+    public List<PermissionSubject> getPermissionCheckSubjects() {
+        return Collections.emptyList();
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveMemoryVolumesParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveMemoryVolumesParameters.java
new file mode 100644
index 0000000..ca0593c
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/RemoveMemoryVolumesParameters.java
@@ -0,0 +1,35 @@
+package org.ovirt.engine.core.common.action;
+
+import org.ovirt.engine.core.compat.Guid;
+
+public class RemoveMemoryVolumesParameters extends VdcActionParametersBase {
+    /** comma-separated string of UUIDs representing the memory volumes */
+    private String memoryVolumes;
+    private Guid vmId;
+
+    public RemoveMemoryVolumesParameters(String memoryVolumes, Guid vmId) {
+        this.memoryVolumes = memoryVolumes;
+        this.vmId = vmId;
+    }
+
+    public RemoveMemoryVolumesParameters() {
+        this.memoryVolumes = "";
+        this.vmId = Guid.Empty;
+    }
+
+    public String getMemoryVolumes() {
+        return memoryVolumes;
+    }
+
+    public void setMemoryVolumes(String memoryVolumes) {
+        this.memoryVolumes = memoryVolumes;
+    }
+
+    public Guid getVmId() {
+        return vmId;
+    }
+
+    public void setVmId(Guid vmId) {
+        this.vmId = vmId;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
index 1fea633..ccb2fbc 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
@@ -122,6 +122,7 @@
     MoveImageGroup(231, QuotaDependency.STORAGE),
     GetDiskAlignment(232, QuotaDependency.NONE),
     RemoveVmHibernationVolumes(233, QuotaDependency.NONE),
+    RemoveMemoryVolumes(234, QuotaDependency.NONE),
     // VmPoolCommands
     AddVmPool(301, QuotaDependency.NONE),
     AddVmPoolWithVms(304, ActionGroup.CREATE_VM_POOL, QuotaDependency.BOTH),


-- 
To view, visit http://gerrit.ovirt.org/19568
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3830992f46b2c3fbea47e69f21a6711718408e95
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <aha...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to