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, 17 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/34936/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..47bdef6 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 @@ -34,6 +34,11 @@ @Override public AuditLogType getAuditLogTypeValue() { + if (getCachedShouldSkipCommandExecution()) { + addCustomValue("Action", "Shutdown VM"); + addCustomValue("VmStatus", getVm().getStatus().name()); + return AuditLogType.VM_ALREADY_IN_REQUESTED_STATUS; + } 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..8ab3b54 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,11 @@ @Override public AuditLogType getAuditLogTypeValue() { + if (getCachedShouldSkipCommandExecution()) { + addCustomValue("Action", "Stop VM"); + addCustomValue("VmStatus", getVm().getStatus().name()); + return AuditLogType.VM_ALREADY_IN_REQUESTED_STATUS; + } 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 273b346..fd983f0 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 @@ -75,6 +75,11 @@ return true; } + @Override + protected boolean shouldSkipCommandExecution() { + return getVm() != null && getVm().getStatus() == VMStatus.Down; + } + protected void destroyVm() { boolean wasPaused = (getVm().getStatus() == VMStatus.Paused && getVm().getVmPauseStatus() == VmPauseStatus.NOERR); 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/34936 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I75925d528cca52603660d5a7ec6c5c871304f3d0 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Omer Frenkel <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
