Omer Frenkel has uploaded a new change for review.

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

core: skip execution of stop vm if its down

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

Change-Id: I75925d528cca52603660d5a7ec6c5c871304f3d0
Signed-off-by: Omer Frenkel <[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, 24 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/11/35611/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 74d23c0..e6b3caa 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
@@ -33,6 +33,9 @@
 
     @Override
     public AuditLogType getAuditLogTypeValue() {
+        if (shouldSkipCommandExecutionCached()) {
+            return logCommandExecutionSkipped("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..0b52774 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
@@ -29,6 +29,9 @@
 
     @Override
     public AuditLogType getAuditLogTypeValue() {
+        if (shouldSkipCommandExecutionCached()) {
+            return logCommandExecutionSkipped("Stop 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/StopVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
index b5d8890..765495b 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;
@@ -54,6 +55,10 @@
 
     @Override
     protected boolean canDoAction() {
+        if (shouldSkipCommandExecutionCached()) {
+            return true;
+        }
+
         if (getVm() == null) {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND);
         }
@@ -256,4 +261,15 @@
     public void addQuotaPermissionSubject(List<PermissionSubject> 
quotaPermissionList) {
         //
     }
+
+    @Override
+    protected  boolean shouldSkipCommandExecution() {
+        return getVm() != null && getVm().getStatus() == VMStatus.Down;
+    }
+
+    protected AuditLogType logCommandExecutionSkipped(String actionName) {
+        addCustomValue("Action", actionName);
+        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 a50530d..993663e 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 c7aa292..f0e87ed 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -188,6 +188,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/35611
To unsubscribe, visit http://gerrit.ovirt.org/settings

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

Reply via email to