Eli Mesika has uploaded a new change for review.

Change subject: [WIP]core : BLL changes for Multi-Tier fencing
......................................................................

[WIP]core : BLL changes for Multi-Tier fencing

this patch includes masically changes in the fencing infrastructures and
supported queries.

Change-Id: I82f243593f2b361ca75d97e06f9aede246d4a1b1
Signed-off-by: Eli Mesika <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FencingExecutor.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceAgentOrder.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
6 files changed, 346 insertions(+), 73 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/10260/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
index b46a10a..261de40 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceVdsBaseCommand.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.bll;
 
 import java.util.List;
+import java.util.concurrent.CountDownLatch;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
@@ -10,6 +11,7 @@
 import org.ovirt.engine.core.common.action.VdcActionParametersBase;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
+import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -31,14 +33,22 @@
 import org.ovirt.engine.core.utils.ThreadUtils;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
+import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil;
 
 public abstract class FenceVdsBaseCommand<T extends FenceVdsActionParameters> 
extends VdsCommand<T> {
     private final int SLEEP_BEFORE_FIRST_ATTEMPT = 5000;
     private static final String INTERNAL_FENCING_USER = "Engine";
     private static Log log = LogFactory.getLog(FenceVdsBaseCommand.class);
-    protected FencingExecutor _executor;
+    protected FencingExecutor executor;
     protected List<VM> mVmList = null;
     private boolean privateFencingSucceeded;
+    private boolean primarySucceeded=true;
+    private boolean secondarySucceeded=true;
+    private VDSReturnValue primaryReturnValue;
+    private VDSReturnValue secondaryReturnValue;
+    private FencingExecutor primaryExecutor = new FencingExecutor(getVds(), 
getParameters().getAction());
+    private FencingExecutor secondaryExecutor = new FencingExecutor(getVds(), 
getParameters().getAction());
+
 
     /**
      * Constructor for command creation when compensation is applied on startup
@@ -110,9 +120,9 @@
                         
DbFacade.getInstance().getAuditLogDao().getTimeToWaitForNextPmOp(getVds().getvds_name(),
 event);
                 if (secondsLeftToNextPmOp <= 0) {
                     // try to get vds status
-                    _executor = createExecutorForProxyCheck();
-                    if (_executor.FindVdsToFence()) {
-                        if (!(retValue = 
_executor.checkProxyHostConnectionToHost())) {
+                    executor = createExecutorForProxyCheck();
+                    if (executor.FindVdsToFence()) {
+                        if (!(retValue = 
executor.checkProxyHostConnectionToHost())) {
                             
addCanDoActionMessage(VdcBllMessages.VDS_FAILED_FENCE_VIA_PROXY_CONNECTION);
                         }
                     } else {
@@ -144,48 +154,17 @@
         try {
             // Set status immediately to prevent a race (BZ 636950/656224)
             setStatus();
-            _executor = new FencingExecutor(getVds(), 
getParameters().getAction());
-            if (_executor.FindVdsToFence()) {
-                vdsReturnValue = _executor.Fence();
-                setFencingSucceeded(vdsReturnValue.getSucceeded());
-                if (getFencingSucceeded()) {
-                    _executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
-                    if (waitForStatus(getVds().getvds_name(), 
getParameters().getAction())) {
-                        handleSpecificCommandActions();
-                    } else {
-                        // since there is a chance that Agent & Host use the 
same power supply and
-                        // a Start command had failed (because we just get 
success on the script
-                        // invocation and not on its result), we have to try 
the Start command again
-                        // before giving up
-                        if (getParameters().getAction() == 
FenceActionType.Start) {
-                            _executor = new FencingExecutor(getVds(), 
FenceActionType.Start);
-                            vdsReturnValue = _executor.Fence();
-                            setFencingSucceeded(vdsReturnValue.getSucceeded());
-                            if (getFencingSucceeded()) {
-                                _executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
-                                if (waitForStatus(getVds().getvds_name(), 
FenceActionType.Start)) {
-                                    handleSpecificCommandActions();
-                                } else {
-                                    setFencingSucceeded(false);
-                                }
-                            } else {
-                                handleError(lastStatus, vdsReturnValue);
-                            }
-
-                        } else {
-
-                            // We reach this if we wait for on/off status
-                            // after start/stop as defined in configurable 
delay/retries and
-                            // did not reach the desired on/off status.
-                            // We assume that fencing operation didn't 
complete successfully
-                            // Setting this flag will cause the appropriate 
Alert to pop
-                            // and to restore host status to it's previous 
value as
-                            // appears in the finally block.
-                            setFencingSucceeded(false);
-                        }
-                    }
-                } else {
-                    handleError(lastStatus, vdsReturnValue);
+            // Check which fencing invocation pattern to invoke
+            // Regular (no secondary agent) , multiple sequential agents or 
multiple concurent agents
+            if (StringUtils.isEmpty(getVds().getPmSecondaryIp())){
+                handleSingleAgent(lastStatus);
+            }
+            else {
+                if (getVds().isPmSecondaryConcurrent()){
+                    handleMultipleConcurrentAgents(lastStatus);
+                }
+                else {
+                    handleMultipleSequentialAgents(lastStatus);
                 }
             }
             setSucceeded(getFencingSucceeded());
@@ -197,7 +176,168 @@
         }
     }
 
-    private void handleError(VDSStatus lastStatus, VDSReturnValue 
vdsReturnValue) {
+    /**
+     * Handling the case of a single fencing agent
+     * @param lastStatus
+     */
+    private void handleSingleAgent(VDSStatus lastStatus) {
+        VDSReturnValue vdsReturnValue;
+        executor = new FencingExecutor(getVds(), getParameters().getAction());
+        if (executor.FindVdsToFence()) {
+            vdsReturnValue = executor.Fence();
+            setFencingSucceeded(vdsReturnValue.getSucceeded());
+            if (getFencingSucceeded()) {
+                executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                if (waitForStatus(getVds().getvds_name(), 
getParameters().getAction(), FenceAgentOrder.Primary)) {
+                    handleSpecificCommandActions();
+                } else {
+                    handleWaitFailure(lastStatus);
+                }
+            } else {
+                handleError(lastStatus, vdsReturnValue);
+            }
+        }
+    }
+
+    /**
+     * Handling the case of a multiple sequential fencing agents
+     * If operation fails on Primary agent, the Secondary agent is used.
+     * @param lastStatus
+     */
+    private void handleMultipleSequentialAgents(VDSStatus lastStatus) {
+        VDSReturnValue vdsReturnValue;
+        executor = new FencingExecutor(getVds(), getParameters().getAction());
+        if (executor.FindVdsToFence()) {
+            vdsReturnValue = executor.Fence(FenceAgentOrder.Primary);
+            setFencingSucceeded(vdsReturnValue.getSucceeded());
+            if (getFencingSucceeded()) {
+                executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                if (waitForStatus(getVds().getvds_name(), 
getParameters().getAction(), FenceAgentOrder.Primary)) {
+                    handleSpecificCommandActions();
+                } else {
+                    vdsReturnValue = executor.Fence(FenceAgentOrder.Secondary);
+                    setFencingSucceeded(vdsReturnValue.getSucceeded());
+                    if (getFencingSucceeded()) {
+                        executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                        if (waitForStatus(getVds().getvds_name(), 
getParameters().getAction(),FenceAgentOrder.Secondary)) {
+                            handleSpecificCommandActions();
+                        }
+                        else {
+                            handleWaitFailure(lastStatus);
+                        }
+                    }
+                    else {
+                        handleError(lastStatus, vdsReturnValue);
+                    }
+                }
+            } else {
+                handleError(lastStatus, vdsReturnValue);
+            }
+        }
+    }
+
+    /**
+     * Handling the case of a multiple concurrent fencing agents
+     * for Stop we should have two concurrent threads and wait for both to 
succeed
+     * for Start  we should have two concurrent threads and wait for one to 
succeed
+     * @param lastStatus
+     */
+    private void handleMultipleConcurrentAgents(VDSStatus lastStatus) {
+        final CountDownLatch latch = (getParameters().getAction() == 
FenceActionType.Stop) ?
+                new CountDownLatch(2) // both agents should succeed in Stop
+                        : (getParameters().getAction() == 
FenceActionType.Start)
+                            ?
+                            new CountDownLatch(1) //only one agent should 
succeed in Start
+                            :
+                            new CountDownLatch(0);
+
+        if (primaryExecutor.FindVdsToFence()) {
+            ThreadPoolUtil.execute(new Runnable() {
+                @Override
+                public void run() {
+                    primaryReturnValue = 
primaryExecutor.Fence(FenceAgentOrder.Primary);
+                    if (primaryReturnValue.getSucceeded()) {
+                        primaryExecutor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                        primarySucceeded = 
waitForStatus(getVds().getvds_name(), getParameters().getAction(), 
FenceAgentOrder.Primary);
+                        latch.countDown();
+                    }
+                }
+            });
+            ThreadPoolUtil.execute(new Runnable() {
+                @Override
+                public void run() {
+                    secondaryReturnValue = 
secondaryExecutor.Fence(FenceAgentOrder.Secondary);
+                    if (secondaryReturnValue.getSucceeded()) {
+                        secondaryExecutor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                        secondarySucceeded = 
waitForStatus(getVds().getvds_name(), getParameters().getAction(), 
FenceAgentOrder.Secondary);
+                        latch.countDown();
+                    }
+                }
+            });
+            try {
+                latch.await();
+            } catch (InterruptedException e) {
+                log.error(e);
+            }
+            switch (getParameters().getAction()) {
+            case Start :
+                if (primarySucceeded || secondarySucceeded){
+                    handleSpecificCommandActions();
+                    setFencingSucceeded(true);
+                }
+                else {
+                    handleError(lastStatus, primaryReturnValue);
+                    handleError(lastStatus, secondaryReturnValue);
+                }
+                break;
+            case Stop:
+                if (primarySucceeded && secondarySucceeded){
+                    handleSpecificCommandActions();
+                    setFencingSucceeded(true);
+                }
+                else {
+                    handleError(lastStatus, (!primarySucceeded) ? 
primaryReturnValue : secondaryReturnValue);
+                }
+                break;
+            default:
+                setFencingSucceeded(true);
+                break;
+
+            }
+        }
+    }
+
+    private void handleWaitFailure(VDSStatus lastStatus) {
+        VDSReturnValue vdsReturnValue;
+        // since there is a chance that Agent & Host use the same power supply 
and
+        // a Start command had failed (because we just get success on the 
script
+        // invocation and not on its result), we have to try the Start command 
again
+        // before giving up
+        if (getParameters().getAction() == FenceActionType.Start) {
+            executor = new FencingExecutor(getVds(), FenceActionType.Start);
+            vdsReturnValue = executor.Fence();
+            setFencingSucceeded(vdsReturnValue.getSucceeded());
+            if (getFencingSucceeded()) {
+                executor = new FencingExecutor(getVds(), 
FenceActionType.Status);
+                if (waitForStatus(getVds().getvds_name(), 
FenceActionType.Start, FenceAgentOrder.Primary)) {
+                    handleSpecificCommandActions();
+                } else {
+                    setFencingSucceeded(false);
+                }
+            } else {
+                handleError(lastStatus, vdsReturnValue);
+            }
+
+        } else {
+            // We reach this if we wait for on/off status after start/stop as 
defined in configurable delay/retries and
+            // did not reach the desired on/off status.We assume that fencing 
operation didn't complete successfully
+            // Setting this flag will cause the appropriate Alert to pop and 
to restore host status to it's previous
+            // value as appears in the finally block.
+            setFencingSucceeded(false);
+        }
+    }
+
+    private void handleError(VDSStatus lastStatus, final VDSReturnValue 
vdsReturnValue) {
         if (!((FenceStatusReturnValue) 
(vdsReturnValue.getReturnValue())).getIsSkipped()) {
             // Since this is a non-transactive command , restore last status
             setSucceeded(false);
@@ -293,7 +433,7 @@
 
 
 
-    protected boolean waitForStatus(String vdsName, FenceActionType 
actionType) {
+    protected boolean waitForStatus(String vdsName, FenceActionType 
actionType, FenceAgentOrder order) {
         final String FENCE_CMD = (actionType == FenceActionType.Start) ? "on" 
: "off";
         final String ACTION_NAME = actionType.name().toLowerCase();
         int i = 1;
@@ -306,8 +446,8 @@
         ThreadUtils.sleep(SLEEP_BEFORE_FIRST_ATTEMPT);
         while (!statusReached && i <= getRerties()) {
             log.infoFormat("Attempt {0} to get vds {1} status", i, vdsName);
-            if (_executor.FindVdsToFence()) {
-                VDSReturnValue returnValue = _executor.Fence();
+            if (executor.FindVdsToFence()) {
+                VDSReturnValue returnValue = executor.Fence(order);
                 if (returnValue != null && returnValue.getReturnValue() != 
null) {
                     FenceStatusReturnValue value = (FenceStatusReturnValue) 
returnValue.getReturnValue();
                     if (FENCE_CMD.equalsIgnoreCase(value.getStatus())) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FencingExecutor.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FencingExecutor.java
index 8ef05c6..a2558b9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FencingExecutor.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FencingExecutor.java
@@ -3,6 +3,7 @@
 import java.util.List;
 
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
+import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 import org.ovirt.engine.core.common.businessentities.VDS;
@@ -117,6 +118,10 @@
     }
 
     public VDSReturnValue Fence() {
+        return Fence(FenceAgentOrder.Primary);
+    }
+
+    public VDSReturnValue Fence(FenceAgentOrder order) {
         VDSReturnValue retValue = null;
         try {
             // skip following code in case of testing a new host status
@@ -132,7 +137,7 @@
                                     new 
SpmStopVDSCommandParameters(_vds.getId(), _vds.getStoragePoolId()));
                 }
             }
-            retValue = runFencingAction(_action);
+            retValue = runFencingAction(_action, order);
         } catch (VdcBLLException e) {
             retValue = new VDSReturnValue();
             retValue.setReturnValue(new FenceStatusReturnValue("unknown", 
e.getMessage()));
@@ -147,7 +152,7 @@
      * @return Whether the proxy host can be used to fence the host 
successfully.
      */
     public boolean checkProxyHostConnectionToHost() {
-        return runFencingAction(FenceActionType.Status).getSucceeded();
+        return runFencingAction(FenceActionType.Status, 
FenceAgentOrder.Primary).getSucceeded();
     }
 
 
@@ -156,31 +161,102 @@
      * @param actionType The action to run.
      * @return The result of running the fencing command.
      */
-    private VDSReturnValue runFencingAction(FenceActionType actionType) {
-        String managementPort = "";
-        if (_vds.getpm_port() != null && _vds.getpm_port() != 0) {
-            managementPort = _vds.getpm_port().toString();
-        }
-        // get real agent and default parameters
-        String agent = VdsFencingOptions.getRealAgent(_vds.getpm_type());
-        String managementOptions = 
VdsFencingOptions.getDefaultAgentOptions(_vds.getpm_type(),_vds.getpm_options());
+    private VDSReturnValue runFencingAction(FenceActionType actionType, 
FenceAgentOrder order) {
+        String managementIp = getManagementIp(order);
+        String managementPort = getManagementPort(order);
+        String managementAgent = getManagementAgent(order);
+        String managementUser = getManagementUser(order);
+        String managementPassword = getManagementPassword(order);
+        String managementOptions = getManagementOptions(order);
+
         log.infoFormat("Executing <{0}> Power Management command, Proxy 
Host:{1}, "
                 + "Agent:{2}, Target Host:{3}, Management IP:{4}, User:{5}, 
Options:{6}", actionType, _vdsToRunName,
-                agent, _vds.getvds_name(), _vds.getManagmentIp(), 
_vds.getpm_user(), managementOptions);
+                managementAgent, _vds.getvds_name(), managementIp, 
managementUser, managementOptions);
         return Backend
                     .getInstance()
                     .getResourceManager()
                     .RunVdsCommand(
                             VDSCommandType.FenceVds,
-                        new FenceVdsVDSCommandParameters(_vdsToRunId, 
_vds.getId(), _vds.getManagmentIp(),
-                                    managementPort, agent, _vds.getpm_user(), 
_vds.getpm_password(),
+                        new FenceVdsVDSCommandParameters(_vdsToRunId, 
_vds.getId(), managementIp,
+                                    managementPort, managementAgent, 
managementUser, managementPassword,
                                     managementOptions, actionType));
+    }
+
+    private String getManagementOptions(FenceAgentOrder order) {
+        String managementOptions = "";
+        if (order == FenceAgentOrder.Primary) {
+            managementOptions = 
VdsFencingOptions.getDefaultAgentOptions(_vds.getpm_type(), 
_vds.getpm_options());
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            managementOptions =
+                    
VdsFencingOptions.getDefaultAgentOptions(_vds.getPmSecondaryType(), 
_vds.getPmSecondaryOptions());
+        }
+        return managementOptions;
+    }
+
+    private String getManagementPassword(FenceAgentOrder order) {
+        String managementPassword = "";
+        if (order == FenceAgentOrder.Primary) {
+            managementPassword = _vds.getpm_password();
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            managementPassword = _vds.getPmSecondaryPassword();
+        }
+        return managementPassword;
+    }
+
+    private String getManagementUser(FenceAgentOrder order) {
+        String managementUser = "";
+        if (order == FenceAgentOrder.Primary) {
+            managementUser = _vds.getpm_user();
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            managementUser = _vds.getPmSecondaryuser();
+        }
+        return managementUser;
+    }
+
+    private String getManagementAgent(FenceAgentOrder order) {
+        String agent = "";
+     // get real agent and default parameters
+        if (order == FenceAgentOrder.Primary) {
+            agent = VdsFencingOptions.getRealAgent(_vds.getpm_type());
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            agent = VdsFencingOptions.getRealAgent(_vds.getPmSecondaryType());
+        }
+        return agent;
+    }
+
+    private String getManagementPort(FenceAgentOrder order) {
+        String managementPort = "";
+        if (order == FenceAgentOrder.Primary) {
+            if (_vds.getpm_port() != null && _vds.getpm_port() != 0) {
+                managementPort = _vds.getpm_port().toString();
+            }
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            if (_vds.getPmSecondaryPort() != null && _vds.getPmSecondaryPort() 
!= 0) {
+                managementPort = _vds.getPmSecondaryPort().toString();
+            }
+        }
+        return managementPort;
+    }
+
+    private String getManagementIp(FenceAgentOrder order) {
+        String managementIp = "";
+        if (order == FenceAgentOrder.Primary) {
+            managementIp = _vds.getManagmentIp();
+        }
+        else if (order == FenceAgentOrder.Secondary) {
+            managementIp = _vds.getPmSecondaryIp();
+        }
+        return managementIp;
     }
 
     private boolean isHostNetworkUnreacable(VDS vds) {
         VdsDynamic vdsDynamic = vds.getDynamicData();
-        return (vdsDynamic.getstatus() == VDSStatus.NonOperational &&
-            vdsDynamic.getNonOperationalReason() == 
NonOperationalReason.NETWORK_UNREACHABLE);
+        return (vdsDynamic.getstatus() == VDSStatus.NonOperational && 
vdsDynamic.getNonOperationalReason() == 
NonOperationalReason.NETWORK_UNREACHABLE);
     }
 
     private static Log log = LogFactory.getLog(FencingExecutor.class);
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
index be745d6..32108be 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetNewVdsFenceStatusQuery.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
+import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.queries.GetNewVdsFenceStatusParameters;
@@ -22,15 +23,24 @@
         VDS tempVar = new VDS();
         tempVar.setId((Guid) ((id != null) ? id : Guid.Empty));
         tempVar.setStoragePoolId(getParameters().getStoragePoolId());
+        if (getParameters().getOrder() == FenceAgentOrder.Primary) {
         tempVar.setManagmentIp(getParameters().getManagementIp());
         tempVar.setPmOptionsMap(getParameters().getFencingOptions());
         tempVar.setpm_type(getParameters().getPmType());
         tempVar.setpm_user(getParameters().getUser());
         tempVar.setpm_password(getParameters().getPassword());
+        }
+        else if (getParameters().getOrder() == FenceAgentOrder.Secondary) {
+            tempVar.setPmSecondaryIp(getParameters().getManagementIp());
+            
tempVar.setPmSecondaryOptionsMap(getParameters().getFencingOptions());
+            tempVar.setPmSecondaryType(getParameters().getPmType());
+            tempVar.setPmSecondaryUser(getParameters().getUser());
+            tempVar.setPmSecondaryPassword(getParameters().getPassword());
+        }
         VDS vds = tempVar;
         FencingExecutor executor = new FencingExecutor(vds, 
FenceActionType.Status);
         if (executor.FindVdsToFence()) {
-            VDSReturnValue returnValue = executor.Fence();
+            VDSReturnValue returnValue = 
executor.Fence(getParameters().getOrder());
             if (returnValue.getReturnValue() != null) {
                 
getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
             }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
index ea8d9f9..a12e3ad 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/GetVdsFenceStatusQuery.java
@@ -2,6 +2,7 @@
 
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.businessentities.FenceActionType;
+import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.common.businessentities.FenceStatusReturnValue;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.queries.VdsIdParametersBase;
@@ -25,16 +26,25 @@
         FencingExecutor executor = new FencingExecutor(vds, 
FenceActionType.Status);
         VDSReturnValue returnValue = null;
         if (executor.FindVdsToFence()) {
-            returnValue = executor.Fence();
+            returnValue = executor.Fence(FenceAgentOrder.Primary);
             if (returnValue.getReturnValue() != null) {
                 if (returnValue.getSucceeded()) {
-                    // Remove all alerts including NOT CONFIG alert
-                    AlertDirector.RemoveAllVdsAlerts(getVdsId(), true);
-                    
getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
+                    boolean succeeded = true;
+                    // check if we have secondary agent settings
+                    if (vds.getPmSecondaryIp() != null && 
!vds.getPmSecondaryIp().isEmpty()) {
+                        returnValue = 
executor.Fence(FenceAgentOrder.Secondary);
+                        succeeded = returnValue.getSucceeded();
+                    }
+                    if (succeeded) {
+                        // Remove all alerts including NOT CONFIG alert
+                        AlertDirector.RemoveAllVdsAlerts(getVdsId(), true);
+                        
getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
+                    }
+                    else {
+                        handleError(returnValue);
+                    }
                 } else {
-                    msg = ((FenceStatusReturnValue) 
returnValue.getReturnValue()).getMessage();
-                    getQueryReturnValue().setReturnValue(new 
FenceStatusReturnValue("unknown", msg));
-                    AlertPowerManagementStatusFailed(msg);
+                    handleError(returnValue);
                 }
             }
         } else {
@@ -44,6 +54,12 @@
             getQueryReturnValue().setReturnValue(new 
FenceStatusReturnValue("unknown", msg));
             
AlertPowerManagementStatusFailed(AuditLogDirector.GetMessage(AuditLogType.VDS_ALERT_FENCING_NO_PROXY_HOST));
         }
+    }
+
+    private void handleError(VDSReturnValue returnValue) {
+        String msg = ((FenceStatusReturnValue) 
returnValue.getReturnValue()).getMessage();
+        getQueryReturnValue().setReturnValue(new 
FenceStatusReturnValue("unknown", msg));
+        AlertPowerManagementStatusFailed(msg);
 
     }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceAgentOrder.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceAgentOrder.java
new file mode 100644
index 0000000..dfc428c
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/FenceAgentOrder.java
@@ -0,0 +1,6 @@
+package org.ovirt.engine.core.common.businessentities;
+
+public enum FenceAgentOrder {
+    Primary,
+    Secondary;
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
index 311739e..3fcc4a9 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetNewVdsFenceStatusParameters.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.common.queries;
 
+import org.ovirt.engine.core.common.businessentities.FenceAgentOrder;
 import org.ovirt.engine.core.compat.Guid;
 
 public class GetNewVdsFenceStatusParameters extends VdcQueryParametersBase {
@@ -18,7 +19,21 @@
         _pmType = pmType;
         _user = user;
         _password = password;
+        this.order = FenceAgentOrder.Primary;
     }
+
+    public GetNewVdsFenceStatusParameters(Guid vds_id, Guid storagePolId, 
String managementIp,
+            ValueObjectMap fencinOptions, String pmType, String user, String 
password, FenceAgentOrder order) {
+        _vds_id = vds_id;
+        _storagePoolId = storagePolId;
+        _managementIp = managementIp;
+        _fencingOptions = fencinOptions;
+        _pmType = pmType;
+        _user = user;
+        _password = password;
+        this.order = order;
+    }
+
 
     private Guid _vds_id;
 
@@ -95,4 +110,14 @@
     public boolean getIsNewHost() {
         return _isNewHost;
     }
+
+    private FenceAgentOrder order;
+
+    public FenceAgentOrder getOrder() {
+        return order;
+    }
+
+    public void setOrder(FenceAgentOrder order) {
+        this.order = order;
+    }
 }


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

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

Reply via email to