Moti Asayag has uploaded a new change for review.

Change subject: engine: Use VdsCommand.setVdsStatus when possible
......................................................................

engine: Use VdsCommand.setVdsStatus when possible

Change-Id: I595b0dfbbde45475f49b4fb2a418642e50347200
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetNonOperationalVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/ApproveVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/FenceVdsBaseCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/RestartVdsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/VdsKdumpDetectionCommand.java
8 files changed, 26 insertions(+), 54 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/10/41110/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
index 37511d3..968051e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ActivateVdsCommand.java
@@ -20,7 +20,6 @@
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
 import 
org.ovirt.engine.core.common.vdscommands.SetHaMaintenanceModeVDSCommandParameters;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.utils.lock.EngineLock;
@@ -62,9 +61,7 @@
         final VDS vds = getVds();
         try (EngineLock monitoringLock = acquireMonitorLock()) {
             ExecutionHandler.updateSpecificActionJobCompleted(vds.getId(), 
VdcActionType.MaintenanceVds, false);
-            setSucceeded(runVdsCommand(VDSCommandType.SetVdsStatus,
-                    new SetVdsStatusVDSCommandParameters(getVdsId(), 
VDSStatus.Unassigned)).getSucceeded()
-            );
+            setSucceeded(setVdsStatus(VDSStatus.Unassigned).getSucceeded());
 
             if (getSucceeded()) {
                 TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java
index 3f57e6d..430e75d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/MaintenanceVdsCommand.java
@@ -5,6 +5,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
@@ -26,7 +27,6 @@
 import org.ovirt.engine.core.common.job.Step;
 import org.ovirt.engine.core.common.job.StepEnum;
 import 
org.ovirt.engine.core.common.vdscommands.SetHaMaintenanceModeVDSCommandParameters;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
@@ -76,8 +76,7 @@
             if (getVds().getStatus() == VDSStatus.NonResponsive
                     || getVds().getStatus() == VDSStatus.Connecting
                     || getVds().getStatus() == VDSStatus.Down) {
-                runVdsCommand(VDSCommandType.SetVdsStatus,
-                                new 
SetVdsStatusVDSCommandParameters(getVdsId(), VDSStatus.Maintenance));
+                setVdsStatus(VDSStatus.Maintenance);
             }
         }
         // if there's VM(s) in this VDS which is migrating, mark this command 
as async
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetNonOperationalVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetNonOperationalVdsCommand.java
index b434d6b..bcf04cd 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetNonOperationalVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/SetNonOperationalVdsCommand.java
@@ -14,8 +14,6 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 
 /**
@@ -42,10 +40,7 @@
      */
     @Override
     protected void executeCommand() {
-        runVdsCommand(VDSCommandType.SetVdsStatus,
-                        new SetVdsStatusVDSCommandParameters(getVdsId(),
-                                VDSStatus.NonOperational,
-                                getParameters().getNonOperationalReason()));
+        setVdsStatus(VDSStatus.NonOperational, 
getParameters().getNonOperationalReason());
         if (getVdsGroup() != null && getVdsGroup().supportsGlusterService()) {
             updateBrickStatusDown();
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
index 2e4eb32..44ee2a3 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsCommand.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.VdcObjectType;
 import org.ovirt.engine.core.common.action.VdsActionParameters;
+import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
@@ -94,8 +95,7 @@
         log.info("Waiting {} seconds, for server to finish reboot process.",
                 sleepTimeInSec);
         ThreadUtils.sleep(sleepTimeInSec * 1000);
-        runVdsCommand(VDSCommandType.SetVdsStatus,
-                        new SetVdsStatusVDSCommandParameters(getVdsId(), 
status));
+        setVdsStatus(status);
     }
 
     /**
@@ -281,17 +281,18 @@
         _failureMessage = e.getMessage();
     }
 
-    /**
-     * Set vds object status.
-     *
-     * @param status
-     *            new status.
-     */
-    protected void setVdsStatus(VDSStatus status) {
-        runVdsCommand(
-                VDSCommandType.SetVdsStatus,
-                new SetVdsStatusVDSCommandParameters(getVdsId(), status)
-        );
+    protected VDSReturnValue setVdsStatus(VDSStatus status) {
+        SetVdsStatusVDSCommandParameters parameters = new 
SetVdsStatusVDSCommandParameters(getVdsId(), status);
+        return invokeSetHostStatus(parameters);
+    }
+
+    protected VDSReturnValue setVdsStatus(VDSStatus status, 
NonOperationalReason reason) {
+        SetVdsStatusVDSCommandParameters parameters = new 
SetVdsStatusVDSCommandParameters(getVdsId(), status, reason);
+        return invokeSetHostStatus(parameters);
+    }
+
+    private VDSReturnValue 
invokeSetHostStatus(SetVdsStatusVDSCommandParameters parameters) {
+        return runVdsCommand(VDSCommandType.SetVdsStatus, parameters);
     }
 
     protected String getErrorMessage(String msg) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/ApproveVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/ApproveVdsCommand.java
index b64c7c2..424d1f5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/ApproveVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/hostdeploy/ApproveVdsCommand.java
@@ -9,8 +9,6 @@
 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.vdscommands.SetVdsStatusVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 
 @NonTransactiveCommandAttribute
 public class ApproveVdsCommand<T extends ApproveVdsParameters> extends 
InstallVdsInternalCommand<T> {
@@ -61,12 +59,10 @@
             setSucceeded(true);
         }
         if (getSucceeded()) {
-            runVdsCommand(VDSCommandType.SetVdsStatus,
-                            new 
SetVdsStatusVDSCommandParameters(getVds().getId(), VDSStatus.Unassigned));
+            setVdsStatus(VDSStatus.Unassigned);
         } else if (getParameters().isApprovedByRegister()) {
             // In case of Approval of oVirt host process, the status of the 
host is re-initialized to PendingApproval
-            runVdsCommand(VDSCommandType.SetVdsStatus,
-                            new 
SetVdsStatusVDSCommandParameters(getVds().getId(), VDSStatus.PendingApproval));
+            setVdsStatus(VDSStatus.PendingApproval);
         }
     }
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/FenceVdsBaseCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/FenceVdsBaseCommand.java
index 01d23a3..350f894 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/FenceVdsBaseCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/FenceVdsBaseCommand.java
@@ -4,7 +4,6 @@
 import java.util.List;
 import java.util.Map;
 
-import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
 import org.ovirt.engine.core.bll.VdsCommand;
 import org.ovirt.engine.core.bll.context.CommandContext;
@@ -26,8 +25,6 @@
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
@@ -158,10 +155,7 @@
     }
 
     protected void setStatus() {
-        Backend.getInstance()
-                .getResourceManager()
-                .RunVdsCommand(VDSCommandType.SetVdsStatus,
-                        new SetVdsStatusVDSCommandParameters(getVdsId(), 
VDSStatus.Reboot));
+        setVdsStatus(VDSStatus.Reboot);
         runSleepOnReboot();
     }
 
@@ -169,8 +163,7 @@
         // we need to load current status from db
         VdsDynamic currentHost = 
getDbFacade().getVdsDynamicDao().get(getVds().getId());
         if (currentHost != null && currentHost.getStatus() != status) {
-            
getBackend().getResourceManager().RunVdsCommand(VDSCommandType.SetVdsStatus,
-                    new SetVdsStatusVDSCommandParameters(getVds().getId(), 
status));
+            setVdsStatus(status);
         }
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/RestartVdsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/RestartVdsCommand.java
index 2d6255f..d12ad2f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/RestartVdsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/RestartVdsCommand.java
@@ -30,8 +30,6 @@
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
-import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
@@ -130,8 +128,7 @@
             // fence execution was skipped due to fencing policy, host should 
be alive
             skippedDueToFencingPolicy = true;
             setSucceeded(false);
-            runVdsCommand(VDSCommandType.SetVdsStatus, new 
SetVdsStatusVDSCommandParameters(vdsId,
-                    VDSStatus.NonResponsive));
+            setVdsStatus(VDSStatus.NonResponsive);
             return;
         } else if (returnValue.getSucceeded()) {
             executeFenceVdsManuallyAction(vdsId, sessionId);
@@ -147,8 +144,7 @@
             log.warn("Restart host action failed, updating host '{}' to '{}'",
                     vdsId,
                     VDSStatus.NonResponsive.name());
-            runVdsCommand(VDSCommandType.SetVdsStatus, new 
SetVdsStatusVDSCommandParameters(vdsId,
-                    VDSStatus.NonResponsive));
+            setVdsStatus(VDSStatus.NonResponsive);
         }
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/VdsKdumpDetectionCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/VdsKdumpDetectionCommand.java
index 57857a6..2fc0d07 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/VdsKdumpDetectionCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/pm/VdsKdumpDetectionCommand.java
@@ -22,7 +22,6 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.utils.Pair;
-import 
org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.UpdateVdsVMsClearedVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase;
@@ -139,9 +138,7 @@
                     auditLogDirector.log(base, 
AuditLogType.KDUMP_FLOW_DETECTED_ON_VDS);
 
                     // set status to Kdumping to prevent Host Monitoring 
errors and wait until kdump finishes
-                    runVdsCommand(VDSCommandType.SetVdsStatus,
-                                    new 
SetVdsStatusVDSCommandParameters(getVdsId(), VDSStatus.Kdumping)
-                            );
+                    setVdsStatus(VDSStatus.Kdumping);
 
                     // restart VMs running on Vds
                     restartVdsVms();
@@ -152,9 +149,7 @@
 
                 if (kdumpStatus.getStatus() == KdumpFlowStatus.FINISHED) {
                     // host finished its kdump flow, set status to Non 
Responsive
-                    runVdsCommand(VDSCommandType.SetVdsStatus,
-                                    new 
SetVdsStatusVDSCommandParameters(getVdsId(), VDSStatus.NonResponsive)
-                            );
+                    setVdsStatus(VDSStatus.NonResponsive);
                     return KdumpDetectionResult.KDUMP_FINISHED;
                 }
             }


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

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

Reply via email to