Martin Peřina has uploaded a new change for review.

Change subject: core: Refactor fence proxy source handling in FenceProxyLocator
......................................................................

core: Refactor fence proxy source handling in FenceProxyLocator

Refactors FenceProxyLocator to use VDS.*FenceProxySources() methods
instead of its own internal objects.

Change-Id: I2f0fbf86f9903cc15ceae2bd64fa936d300a4b8d
Bug-Url: https://bugzilla.redhat.com/1182510
Signed-off-by: Martin Perina <mper...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceProxyLocator.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
2 files changed, 28 insertions(+), 55 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/62/39762/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceProxyLocator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceProxyLocator.java
index 96b9cc3..e37cde9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceProxyLocator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/FenceProxyLocator.java
@@ -3,22 +3,23 @@
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.FenceAgent;
 import org.ovirt.engine.core.common.businessentities.FencingPolicy;
 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.VdsDynamic;
+import org.ovirt.engine.core.common.businessentities.pm.FenceProxySourceType;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.utils.FencingPolicyHelper;
+import org.ovirt.engine.core.common.utils.pm.FenceProxySourceTypeHelper;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.utils.pm.VdsFenceOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.ovirt.engine.core.utils.pm.VdsFenceOptions;
 
 public class FenceProxyLocator {
 
@@ -56,8 +57,8 @@
         int delayInMs = 1000 * Config.<Integer> 
getValue(ConfigValues.FindFenceProxyDelayBetweenRetriesInSec);
         VDS proxyHost = null;
         // get PM Proxy preferences or use defaults if not defined
-        for (PMProxyOptions proxyOption : getPmProxyPreferences()) {
-            proxyHost = chooseBestProxy(proxyOption, excludedHostId);
+        for (FenceProxySourceType fenceProxySource : getFenceProxySources()) {
+            proxyHost = chooseBestProxy(fenceProxySource, excludedHostId);
             int count = 0;
             // If can not find a proxy host retry and delay between retries as 
configured.
             while (proxyHost == null && withRetries && count < retries) {
@@ -67,7 +68,7 @@
                 } catch (Exception e) {
                     log.error(e.getMessage());
                 }
-                proxyHost = chooseBestProxy(proxyOption, excludedHostId);
+                proxyHost = chooseBestProxy(fenceProxySource, excludedHostId);
             }
             if (proxyHost != null) {
                 break;
@@ -81,21 +82,16 @@
         return proxyHost;
     }
 
-
-    private PMProxyOptions[] getPmProxyPreferences() {
-        String pmProxyPreferences = 
(StringUtils.isEmpty(_vds.getPmProxyPreferences()))
-                ?
-                Config.<String> 
getValue(ConfigValues.FenceProxyDefaultPreferences)
-                : _vds.getPmProxyPreferences();
-        String[] pmProxyOptions = pmProxyPreferences.split(",");
-        PMProxyOptions[] proxyOptions = new 
PMProxyOptions[pmProxyOptions.length];
-        for (int i = 0; i < pmProxyOptions.length; i++) {
-            proxyOptions[i] = getProxyOption(pmProxyOptions[i]);
+    private List<FenceProxySourceType> getFenceProxySources() {
+        List<FenceProxySourceType> fenceProxySources = 
_vds.getFenceProxySources();
+        if (fenceProxySources == null || fenceProxySources.isEmpty()) {
+            fenceProxySources = FenceProxySourceTypeHelper.parseFromString(
+                    Config.<String> 
getValue(ConfigValues.FenceProxyDefaultPreferences));
         }
-        return proxyOptions;
+        return fenceProxySources;
     }
 
-    private VDS chooseBestProxy(PMProxyOptions proxyOption, Guid 
excludedHostId) {
+    private VDS chooseBestProxy(FenceProxySourceType fenceProxySource, Guid 
excludedHostId) {
         List<VDS> hosts = DbFacade.getInstance().getVdsDao().getAll();
         Version minSupportedVersion = null;
         if (fencingPolicy != null) {
@@ -106,7 +102,7 @@
             VDS host = iterator.next();
             if (host.getId().equals(_vds.getId())
                     || host.getId().equals(excludedHostId)
-                    || !matchesOption(host, proxyOption)
+                    || !matchesOption(host, fenceProxySource)
                     || !areAgentsVersionCompatible(host)
                     || (fencingPolicy != null && 
!isFencingPolicySupported(host, minSupportedVersion))
                     || isHostNetworkUnreacable(host)) {
@@ -121,17 +117,21 @@
         return hosts.size() == 0 ? null : hosts.get(0);
     }
 
-    private boolean matchesOption(VDS host, PMProxyOptions proxyOption) {
-        if (proxyOption == PMProxyOptions.CLUSTER) {
-            return host.getVdsGroupId().equals(_vds.getVdsGroupId());
+    private boolean matchesOption(VDS host, FenceProxySourceType 
fenceProxySource) {
+        boolean matches = false;
+        switch (fenceProxySource) {
+            case CLUSTER:
+                matches = host.getVdsGroupId().equals(_vds.getVdsGroupId());
+                break;
+
+            case DC:
+                matches = 
host.getStoragePoolId().equals(_vds.getStoragePoolId());
+                break;
+
+            case OTHER_DC:
+                matches = 
!host.getStoragePoolId().equals(_vds.getStoragePoolId());
         }
-        if (proxyOption == PMProxyOptions.DC) {
-            return host.getStoragePoolId().equals(_vds.getStoragePoolId());
-        }
-        if (proxyOption == PMProxyOptions.OTHER_DC) {
-            return !host.getStoragePoolId().equals(_vds.getStoragePoolId());
-        }
-        return false;
+        return matches;
     }
 
     private boolean areAgentsVersionCompatible(VDS vds) {
@@ -157,27 +157,6 @@
                 || (vdsDynamic.getStatus() == VDSStatus.NonOperational
         && vdsDynamic.getNonOperationalReason() == 
NonOperationalReason.NETWORK_UNREACHABLE));
     }
-
-    private PMProxyOptions getProxyOption(String pmProxyOption) {
-        if (pmProxyOption.equalsIgnoreCase(PMProxyOptions.CLUSTER.name())) {
-            return PMProxyOptions.CLUSTER;
-        }
-        else if (pmProxyOption.equalsIgnoreCase(PMProxyOptions.DC.name())) {
-            return PMProxyOptions.DC;
-        }
-        else if 
(pmProxyOption.equalsIgnoreCase(PMProxyOptions.OTHER_DC.name())) {
-            return PMProxyOptions.OTHER_DC;
-        } else {
-            log.error("Illegal value in PM Proxy Preferences string {}, 
skipped.", pmProxyOption);
-            return null;
-        }
-    }
-
-    private enum PMProxyOptions {
-        CLUSTER,
-        DC,
-        OTHER_DC;
-    };
 
     public FencingPolicy getFencingPolicy() {
         return fencingPolicy;
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
index f0cf883..63a74ab 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
@@ -13,7 +13,6 @@
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.pm.FenceProxySourceType;
 import org.ovirt.engine.core.common.utils.ObjectUtils;
-import org.ovirt.engine.core.common.utils.pm.FenceProxySourceTypeHelper;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.RpmVersion;
 import org.ovirt.engine.core.compat.Version;
@@ -929,11 +928,6 @@
 
     public void setPmEnabled(boolean value) {
         vdsStatic.setPmEnabled(value);
-    }
-
-    // TODO: Remove method when all callers use List<FenceProxySourceType>
-    public String getPmProxyPreferences() {
-        return FenceProxySourceTypeHelper.saveAsString(getFenceProxySources());
     }
 
     public List<FenceProxySourceType> getFenceProxySources() {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f0fbf86f9903cc15ceae2bd64fa936d300a4b8d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Peřina <mper...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to