Piotr Kliczewski has uploaded a new change for review.

Change subject: core: protocol fall back for older vdsms
......................................................................

core: protocol fall back for older vdsms

When we try to install new host which only supports xmlrpc and we have
cluster with compatibility level set to 3.5+ the code will fail.
Solution for this issue is attempting to connect by using jsonrpc and if
it fails falling back to xmlrpc.

Change-Id: Ie9af3129a4adf839f2d4c2e110425a6c69e45256
Signed-off-by: pkliczewski <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsInternalCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/transport/ProtocolDetector.java
2 files changed, 37 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/34255/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsInternalCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsInternalCommand.java
index 7b4a58e..f8a3bf6 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsInternalCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/InstallVdsInternalCommand.java
@@ -6,6 +6,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.network.NetworkConfigurator;
+import org.ovirt.engine.core.bll.transport.ProtocolDetector;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.FeatureSupported;
 import org.ovirt.engine.core.common.action.InstallVdsParameters;
@@ -14,7 +15,9 @@
 import 
org.ovirt.engine.core.common.businessentities.OpenstackNetworkProviderProperties;
 import org.ovirt.engine.core.common.businessentities.Provider;
 import org.ovirt.engine.core.common.businessentities.ProviderType;
+import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
+import org.ovirt.engine.core.common.businessentities.VdsProtocol;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.utils.Pair;
@@ -160,6 +163,18 @@
                     RunSleepOnReboot(getStatusOnReboot());
                 break;
                 case Complete:
+                    if (checkProtocolTofallback(getVds())) {
+                        // we need to check whether we are connecting to vdsm 
which supports xmlrpc only
+                        ProtocolDetector detector = new 
ProtocolDetector(getVds());
+                        if (!detector.attemptConnection()) {
+                            detector.stopConnection();
+                            if (detector.attemptFallbackProtocol()) {
+                                detector.setFallbackProtocol();
+                            } else {
+                                throw new 
VdsInstallException(VDSStatus.InstallFailed, "Host not reachable");
+                            }
+                        }
+                    }
                     if (!configureNetworkUsingHostDeploy) {
                         configureManagementNetwork();
                     }
@@ -184,6 +199,10 @@
         }
     }
 
+    private boolean checkProtocolTofallback(VDS vds) {
+        return VdsProtocol.STOMP.equals(vds.getProtocol());
+    }
+
     private void configureManagementNetwork() {
         final NetworkConfigurator networkConfigurator = new 
NetworkConfigurator(getVds(), getContext());
         if (!networkConfigurator.awaitVdsmResponse()) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/transport/ProtocolDetector.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/transport/ProtocolDetector.java
index d24a1be..e14728e 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/transport/ProtocolDetector.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/transport/ProtocolDetector.java
@@ -26,6 +26,8 @@
  */
 public class ProtocolDetector {
 
+    private static final Integer CONNECT_WAIT = 5000;
+
     private VDS vds;
 
     public ProtocolDetector(VDS vds) {
@@ -34,24 +36,29 @@
 
     /**
      * Attempts to connect to vdsm using a proxy from {@code VdsManager} for a 
host.
+     * There are 3 attempts to connect.
      *
      * @return <code>true</code> if connected or <code>false</code> if 
connection failed.
      */
     public boolean attemptConnection() {
+        boolean connected = false;
         try {
-            long timeout = Config.<Integer> 
getValue(ConfigValues.SetupNetworksPollingTimeout);
-            FutureVDSCall<VDSReturnValue> task =
-                    
Backend.getInstance().getResourceManager().runFutureVdsCommand(FutureVDSCommandType.TimeBoundPoll,
-                            new TimeBoundPollVDSCommandParameters(vds.getId(), 
timeout, TimeUnit.SECONDS));
-            VDSReturnValue returnValue =
-                    task.get(timeout, TimeUnit.SECONDS);
-
-            if (returnValue.getSucceeded()) {
-                return true;
+            for (int i = 0; i < 3; i++) {
+                long timeout = Config.<Integer> 
getValue(ConfigValues.SetupNetworksPollingTimeout);
+                FutureVDSCall<VDSReturnValue> task =
+                        
Backend.getInstance().getResourceManager().runFutureVdsCommand(FutureVDSCommandType.TimeBoundPoll,
+                                new 
TimeBoundPollVDSCommandParameters(vds.getId(), timeout, TimeUnit.SECONDS));
+                VDSReturnValue returnValue =
+                        task.get(timeout, TimeUnit.SECONDS);
+                connected = returnValue.getSucceeded();
+                if (connected) {
+                    break;
+                }
+                Thread.sleep(CONNECT_WAIT);
             }
-        } catch (TimeoutException ignored) {
+        } catch (TimeoutException | InterruptedException ignored) {
         }
-        return false;
+        return connected;
     }
 
     /**


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

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

Reply via email to