cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/5] git commit: updated refs/heads/master to 219da64
Date Wed, 18 Nov 2015 12:13:33 GMT
CLOUDSTACK-8956: Log NSX Api Version


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2386ae5e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2386ae5e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2386ae5e

Branch: refs/heads/master
Commit: 2386ae5e5ab7aecc664c927aadf2c863633f77fc
Parents: d05c1f4
Author: nvazquez <nicolas.m.vazquez@gmail.com>
Authored: Mon Oct 19 16:26:24 2015 -0200
Committer: nvazquez <nicovazquez90@gmail.com>
Committed: Mon Nov 16 11:29:30 2015 -0800

----------------------------------------------------------------------
 .../network/nicira/ControlClusterStatus.java    | 18 ++++++
 .../network/resource/NiciraNvpResource.java     | 23 +++++++-
 .../nicira/nvp/plugin/NiciraNvpApiVersion.java  | 60 ++++++++++++++++++++
 3 files changed, 100 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2386ae5e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ControlClusterStatus.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ControlClusterStatus.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ControlClusterStatus.java
index 8d6399e..1ed7039 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ControlClusterStatus.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ControlClusterStatus.java
@@ -29,6 +29,11 @@ public class ControlClusterStatus {
     private Stats zoneStats;
     private Stats routerStats;
     private Stats securityProfileStats;
+    private ClusterRoleConfig[] configuredRoles;
+
+    public ClusterRoleConfig[] getConfiguredRoles() {
+        return configuredRoles;
+    }
 
     public String getClusterStatus() {
         return clusterStatus;
@@ -84,4 +89,17 @@ public class ControlClusterStatus {
         }
 
     }
+
+    public class ClusterRoleConfig {
+        public String majorityVersion;
+        public String role;
+
+        public String getMajorityVersion(){
+            return majorityVersion;
+        }
+
+        public String getRole(){
+            return role;
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2386ae5e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java
index d6355b2..8ac2844 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/NiciraNvpResource.java
@@ -37,6 +37,7 @@ import com.cloud.agent.api.StartupNiciraNvpCommand;
 import com.cloud.host.Host;
 import com.cloud.host.Host.Type;
 import com.cloud.network.nicira.ControlClusterStatus;
+import com.cloud.network.nicira.ControlClusterStatus.ClusterRoleConfig;
 import com.cloud.network.nicira.DestinationNatRule;
 import com.cloud.network.nicira.Match;
 import com.cloud.network.nicira.NatRule;
@@ -47,6 +48,7 @@ import com.cloud.network.utils.CommandRetryUtility;
 import com.cloud.resource.ServerResource;
 import com.cloud.utils.rest.CloudstackRESTException;
 import com.cloud.utils.rest.HttpClientHelper;
+import com.cloud.utils.nicira.nvp.plugin.NiciraNvpApiVersion;
 
 public class NiciraNvpResource implements ServerResource {
 
@@ -172,6 +174,7 @@ public class NiciraNvpResource implements ServerResource {
     public PingCommand getCurrentStatus(final long id) {
         try {
             final ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus();
+            getApiProviderMajorityVersion(ccs);
             if (!"stable".equals(ccs.getClusterStatus())) {
                 s_logger.error("ControlCluster state is not stable: " + ccs.getClusterStatus());
                 return null;
@@ -183,6 +186,24 @@ public class NiciraNvpResource implements ServerResource {
         return new PingCommand(Host.Type.L2Networking, id);
     }
 
+    private void getApiProviderMajorityVersion(ControlClusterStatus ccs) {
+        ClusterRoleConfig[] configuredRoles = ccs.getConfiguredRoles();
+        if (configuredRoles != null){
+            String apiProviderMajorityVersion = searchApiProvider(configuredRoles);
+            NiciraNvpApiVersion.pingNiciraApiVersion(apiProviderMajorityVersion);
+            NiciraNvpApiVersion.logNiciraApiVersion();
+        }
+    }
+
+    private String searchApiProvider(ClusterRoleConfig[] configuredRoles) {
+        for (int i = 0; i < configuredRoles.length; i++) {
+            if (configuredRoles[i].getRole() != null && configuredRoles[i].getRole().equals("api_provider")){
+                return configuredRoles[i].getMajorityVersion();
+            }
+        }
+        return null;
+    }
+
     @Override
     public Answer executeRequest(final Command cmd) {
         final NiciraNvpRequestWrapper wrapper = NiciraNvpRequestWrapper.getInstance();
@@ -332,4 +353,4 @@ public class NiciraNvpResource implements ServerResource {
         // TODO Auto-generated method stub
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2386ae5e/utils/src/main/java/com/cloud/utils/nicira/nvp/plugin/NiciraNvpApiVersion.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/nicira/nvp/plugin/NiciraNvpApiVersion.java
b/utils/src/main/java/com/cloud/utils/nicira/nvp/plugin/NiciraNvpApiVersion.java
new file mode 100755
index 0000000..b2d6e16
--- /dev/null
+++ b/utils/src/main/java/com/cloud/utils/nicira/nvp/plugin/NiciraNvpApiVersion.java
@@ -0,0 +1,60 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.utils.nicira.nvp.plugin;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.maint.Version;
+
+public class NiciraNvpApiVersion {
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpApiVersion.class);
+
+    private static String niciraApiVersion = null;
+
+    public static void pingNiciraApiVersion(String apiVersion){
+        if (apiVersion == null){
+            niciraApiVersion = null;
+        }
+        else{
+            if (niciraApiVersion == null){
+                setNiciraApiVersion(apiVersion);
+            }
+            else {
+                if (! apiVersion.equals(niciraApiVersion)){
+                    setNiciraApiVersion(apiVersion);
+                }
+            }
+        }
+    }
+
+    private static void setNiciraApiVersion(String apiVersion){
+        niciraApiVersion = apiVersion;
+    }
+
+    public static boolean isApiVersionLowerThan(String apiVersion){
+        int compare = Version.compare(niciraApiVersion, apiVersion);
+        return (compare < 0);
+    }
+
+    public static void logNiciraApiVersion(){
+        s_logger.info("NSX API VERSION: " + ((niciraApiVersion != null) ? niciraApiVersion
: " NOT PRESENT"));
+    }
+
+}


Mime
View raw message