Moti Asayag has uploaded a new change for review.

Change subject: core: skip execution of stop vm if it is down
......................................................................

core: skip execution of stop vm if it is down

If vm is down, instead of failing in canDoAction,
skip execution and notify the user in audit log.

Change-Id: I0634e8afcb331c9a839965e41b660d1ba11c283e
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
5 files changed, 28 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/33/35033/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
index 287b650..10a6f9b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ShutdownVmCommand.java
@@ -10,6 +10,7 @@
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
@@ -34,6 +35,10 @@
 
     @Override
     public AuditLogType getAuditLogTypeValue() {
+        if (stepSkipped(StepEnum.EXECUTING)) {
+            return getAuditLogForSkippedAction("Shutdown VM");
+        }
+
         if (getSuspendedVm()) {
             return getSucceeded() ? AuditLogType.USER_STOP_SUSPENDED_VM : 
AuditLogType.USER_STOP_SUSPENDED_VM_FAILED;
         } else {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
index 4253214..63191cc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommand.java
@@ -4,6 +4,7 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.StopVmParameters;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.compat.Guid;
 
 @NonTransactiveCommandAttribute(forceCompensation=true)
@@ -29,6 +30,10 @@
 
     @Override
     public AuditLogType getAuditLogTypeValue() {
+        if (stepSkipped(StepEnum.EXECUTING)) {
+            return getAuditLogForSkippedAction("Stop VM");
+        }
+
         if (getSuspendedVm()) {
             return getSucceeded() ? AuditLogType.USER_STOP_SUSPENDED_VM : 
AuditLogType.USER_STOP_SUSPENDED_VM_FAILED;
         } else {
@@ -51,4 +56,6 @@
         addCanDoActionMessage(VdcBllMessages.VAR__ACTION__STOP);
         addCanDoActionMessage(VdcBllMessages.VAR__TYPE__VM);
     }
+
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
index 273b346..eb8cdc7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
@@ -11,6 +11,7 @@
 import org.ovirt.engine.core.bll.quota.QuotaVdsDependent;
 import org.ovirt.engine.core.bll.quota.QuotaVdsGroupConsumptionParameter;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
 import 
org.ovirt.engine.core.common.action.RemoveVmHibernationVolumesParameters;
 import org.ovirt.engine.core.common.action.StopVmParametersBase;
@@ -22,6 +23,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmPauseStatus;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.UpdateVmDynamicDataVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -256,4 +258,16 @@
     public void addQuotaPermissionSubject(List<PermissionSubject> 
quotaPermissionList) {
         //
     }
+
+    @Override
+    protected void markCommandStepsToSkip() {
+        skip(StepEnum.VALIDATING, StepEnum.EXECUTING).when(getVm() != null && 
getVm().getStatus() == VMStatus.Down);
+    }
+
+    protected final AuditLogType getAuditLogForSkippedAction(String 
skippedAction) {
+        addCustomValue("Action", skippedAction);
+        addCustomValue("VmStatus", getVm().getStatus().name());
+        return AuditLogType.VM_ALREADY_IN_REQUESTED_STATUS;
+    }
+
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
index 0fca89b..2065fe7 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
@@ -167,6 +167,7 @@
     USER_STOP_VM(33), // User issued stopVm command
     USER_STOP_SUSPENDED_VM(111),
     USER_STOP_SUSPENDED_VM_FAILED(112, AuditLogSeverity.ERROR),
+    VM_ALREADY_IN_REQUESTED_STATUS(254),
     USER_FAILED_STOP_VM(56, AuditLogSeverity.ERROR),
     USER_ADD_VM(34),
     USER_ADD_VM_STARTED(37),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
index 10795eb..9a0c841 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -186,6 +186,7 @@
 USER_REBOOT_VM=User ${UserName} initiated reboot of VM ${VmName}.
 USER_FAILED_REBOOT_VM=Failed to reboot VM ${VmName} (User: ${UserName}).
 USER_STOP_VM=VM ${VmName} powered off by ${UserName} (Host: ${VdsName}) 
(Reason: ${Reason}).
+VM_ALREADY_IN_REQUESTED_STATUS=VM ${VmName} is already ${VmStatus}, ${Action} 
was skipped. User: ${UserName}.
 USER_STOP_SUSPENDED_VM=Suspended VM ${VmName} has had its save state cleared 
by ${UserName} (Reason: ${Reason}).
 USER_STOP_SUSPENDED_VM_FAILED=Failed to power off suspended VM ${VmName} 
(User: ${UserName}).
 USER_TRY_BACK_TO_SNAPSHOT=Snapshot-Preview ${SnapshotName} for VM ${VmName} 
was initiated by ${UserName}.


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

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

Reply via email to