You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/02/27 09:51:09 UTC

git commit: updated refs/heads/master to a0f9324

Repository: cloudstack
Updated Branches:
  refs/heads/master bb6fddf43 -> a0f932437


Move mysql ha strategy to a plugin. Activate this plugin using the mysqlha profile or the noredist flag


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

Branch: refs/heads/master
Commit: a0f932437c9ac9a0a82cc9b45b1aa6f17e8a478a
Parents: bb6fddf
Author: Hugo Trippaers <ht...@schubergphilis.com>
Authored: Thu Feb 27 09:48:55 2014 +0100
Committer: Hugo Trippaers <ht...@schubergphilis.com>
Committed: Thu Feb 27 09:51:02 2014 +0100

----------------------------------------------------------------------
 client/pom.xml                                  |  15 +++
 framework/db/pom.xml                            |   5 -
 .../src/com/cloud/utils/db/StaticStrategy.java  | 131 -------------------
 plugins/database/mysql-ha/pom.xml               |  28 ++++
 .../src/com/cloud/utils/db/StaticStrategy.java  | 131 +++++++++++++++++++
 plugins/pom.xml                                 |  11 ++
 6 files changed, 185 insertions(+), 136 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/client/pom.xml
----------------------------------------------------------------------
diff --git a/client/pom.xml b/client/pom.xml
index 0980b64..78fab6f 100644
--- a/client/pom.xml
+++ b/client/pom.xml
@@ -719,6 +719,21 @@
       </dependencies>
     </profile>
     <profile>
+      <id>mysqlha</id>
+      <activation>
+        <property>
+          <name>noredist</name>
+        </property>
+      </activation>
+      <dependencies>
+        <dependency>
+          <groupId>org.apache.cloudstack</groupId>
+          <artifactId>cloud-plugin-database-myqslha</artifactId>
+          <version>${project.version}</version>
+        </dependency>
+      </dependencies>
+    </profile>
+    <profile>
       <id>quickcloud</id>
       <activation>
         <property>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/framework/db/pom.xml
----------------------------------------------------------------------
diff --git a/framework/db/pom.xml b/framework/db/pom.xml
index e9fefd2..8b41703 100644
--- a/framework/db/pom.xml
+++ b/framework/db/pom.xml
@@ -48,11 +48,6 @@
       <artifactId>cloud-utils</artifactId>
       <version>${project.version}</version>
     </dependency>
-    <dependency>
-      <groupId>mysql</groupId>
-      <artifactId>mysql-connector-java</artifactId>
-      <scope>provided</scope>
-    </dependency>
   </dependencies>
   <build>
     <plugins>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/framework/db/src/com/cloud/utils/db/StaticStrategy.java
----------------------------------------------------------------------
diff --git a/framework/db/src/com/cloud/utils/db/StaticStrategy.java b/framework/db/src/com/cloud/utils/db/StaticStrategy.java
deleted file mode 100644
index c8d21dd..0000000
--- a/framework/db/src/com/cloud/utils/db/StaticStrategy.java
+++ /dev/null
@@ -1,131 +0,0 @@
-// 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
-// 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.db;
-
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import com.mysql.jdbc.BalanceStrategy;
-import com.mysql.jdbc.Connection;
-import com.mysql.jdbc.ConnectionImpl;
-import com.mysql.jdbc.LoadBalancingConnectionProxy;
-import com.mysql.jdbc.SQLError;
-
-public class StaticStrategy implements BalanceStrategy {
-
-    public StaticStrategy() {
-    }
-
-    @Override
-    public void destroy() {
-        // we don't have anything to clean up
-    }
-
-    @Override
-    public void init(Connection conn, Properties props) throws SQLException {
-        // we don't have anything to initialize
-    }
-
-    @Override
-    public ConnectionImpl pickConnection(LoadBalancingConnectionProxy proxy, List<String> configuredHosts, Map<String, ConnectionImpl> liveConnections,
-        long[] responseTimes, int numRetries) throws SQLException {
-        int numHosts = configuredHosts.size();
-
-        SQLException ex = null;
-
-        List<String> whiteList = new ArrayList<String>(numHosts);
-        whiteList.addAll(configuredHosts);
-
-        Map<String, Long> blackList = proxy.getGlobalBlacklist();
-
-        whiteList.removeAll(blackList.keySet());
-
-        Map<String, Integer> whiteListMap = this.getArrayIndexMap(whiteList);
-
-        for (int attempts = 0; attempts < numRetries;) {
-            if (whiteList.size() == 0) {
-                throw SQLError.createSQLException("No hosts configured", null);
-            }
-
-            String hostPortSpec = whiteList.get(0);     //Always take the first host
-
-            ConnectionImpl conn = liveConnections.get(hostPortSpec);
-
-            if (conn == null) {
-                try {
-                    conn = proxy.createConnectionForHost(hostPortSpec);
-                } catch (SQLException sqlEx) {
-                    ex = sqlEx;
-
-                    if (proxy.shouldExceptionTriggerFailover(sqlEx)) {
-
-                        Integer whiteListIndex = whiteListMap.get(hostPortSpec);
-
-                        // exclude this host from being picked again
-                        if (whiteListIndex != null) {
-                            whiteList.remove(whiteListIndex.intValue());
-                            whiteListMap = this.getArrayIndexMap(whiteList);
-                        }
-                        proxy.addToGlobalBlacklist(hostPortSpec);
-
-                        if (whiteList.size() == 0) {
-                            attempts++;
-                            try {
-                                Thread.sleep(250);
-                            } catch (InterruptedException e) {
-                            }
-
-                            // start fresh
-                            whiteListMap = new HashMap<String, Integer>(numHosts);
-                            whiteList.addAll(configuredHosts);
-                            blackList = proxy.getGlobalBlacklist();
-
-                            whiteList.removeAll(blackList.keySet());
-                            whiteListMap = this.getArrayIndexMap(whiteList);
-                        }
-
-                        continue;
-                    }
-
-                    throw sqlEx;
-                }
-            }
-
-            return conn;
-        }
-
-        if (ex != null) {
-            throw ex;
-        }
-
-        return null; // we won't get here, compiler can't tell
-    }
-
-    private Map<String, Integer> getArrayIndexMap(List<String> l) {
-        Map<String, Integer> m = new HashMap<String, Integer>(l.size());
-        for (int i = 0; i < l.size(); i++) {
-            m.put(l.get(i), Integer.valueOf(i));
-        }
-        return m;
-
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/plugins/database/mysql-ha/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/database/mysql-ha/pom.xml b/plugins/database/mysql-ha/pom.xml
new file mode 100644
index 0000000..5ce6d6f
--- /dev/null
+++ b/plugins/database/mysql-ha/pom.xml
@@ -0,0 +1,28 @@
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>cloud-plugin-database-mysqlha</artifactId>
+  <name>Apache CloudStack Plugin - MySQL HA Strategy</name>
+  <parent>
+    <groupId>org.apache.cloudstack</groupId>
+    <artifactId>cloudstack-plugins</artifactId>
+    <version>4.4.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+  <dependencies>
+    <dependency>
+      <groupId>mysql</groupId>
+      <artifactId>mysql-connector-java</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/plugins/database/mysql-ha/src/com/cloud/utils/db/StaticStrategy.java
----------------------------------------------------------------------
diff --git a/plugins/database/mysql-ha/src/com/cloud/utils/db/StaticStrategy.java b/plugins/database/mysql-ha/src/com/cloud/utils/db/StaticStrategy.java
new file mode 100644
index 0000000..c8d21dd
--- /dev/null
+++ b/plugins/database/mysql-ha/src/com/cloud/utils/db/StaticStrategy.java
@@ -0,0 +1,131 @@
+// 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
+// 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.db;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import com.mysql.jdbc.BalanceStrategy;
+import com.mysql.jdbc.Connection;
+import com.mysql.jdbc.ConnectionImpl;
+import com.mysql.jdbc.LoadBalancingConnectionProxy;
+import com.mysql.jdbc.SQLError;
+
+public class StaticStrategy implements BalanceStrategy {
+
+    public StaticStrategy() {
+    }
+
+    @Override
+    public void destroy() {
+        // we don't have anything to clean up
+    }
+
+    @Override
+    public void init(Connection conn, Properties props) throws SQLException {
+        // we don't have anything to initialize
+    }
+
+    @Override
+    public ConnectionImpl pickConnection(LoadBalancingConnectionProxy proxy, List<String> configuredHosts, Map<String, ConnectionImpl> liveConnections,
+        long[] responseTimes, int numRetries) throws SQLException {
+        int numHosts = configuredHosts.size();
+
+        SQLException ex = null;
+
+        List<String> whiteList = new ArrayList<String>(numHosts);
+        whiteList.addAll(configuredHosts);
+
+        Map<String, Long> blackList = proxy.getGlobalBlacklist();
+
+        whiteList.removeAll(blackList.keySet());
+
+        Map<String, Integer> whiteListMap = this.getArrayIndexMap(whiteList);
+
+        for (int attempts = 0; attempts < numRetries;) {
+            if (whiteList.size() == 0) {
+                throw SQLError.createSQLException("No hosts configured", null);
+            }
+
+            String hostPortSpec = whiteList.get(0);     //Always take the first host
+
+            ConnectionImpl conn = liveConnections.get(hostPortSpec);
+
+            if (conn == null) {
+                try {
+                    conn = proxy.createConnectionForHost(hostPortSpec);
+                } catch (SQLException sqlEx) {
+                    ex = sqlEx;
+
+                    if (proxy.shouldExceptionTriggerFailover(sqlEx)) {
+
+                        Integer whiteListIndex = whiteListMap.get(hostPortSpec);
+
+                        // exclude this host from being picked again
+                        if (whiteListIndex != null) {
+                            whiteList.remove(whiteListIndex.intValue());
+                            whiteListMap = this.getArrayIndexMap(whiteList);
+                        }
+                        proxy.addToGlobalBlacklist(hostPortSpec);
+
+                        if (whiteList.size() == 0) {
+                            attempts++;
+                            try {
+                                Thread.sleep(250);
+                            } catch (InterruptedException e) {
+                            }
+
+                            // start fresh
+                            whiteListMap = new HashMap<String, Integer>(numHosts);
+                            whiteList.addAll(configuredHosts);
+                            blackList = proxy.getGlobalBlacklist();
+
+                            whiteList.removeAll(blackList.keySet());
+                            whiteListMap = this.getArrayIndexMap(whiteList);
+                        }
+
+                        continue;
+                    }
+
+                    throw sqlEx;
+                }
+            }
+
+            return conn;
+        }
+
+        if (ex != null) {
+            throw ex;
+        }
+
+        return null; // we won't get here, compiler can't tell
+    }
+
+    private Map<String, Integer> getArrayIndexMap(List<String> l) {
+        Map<String, Integer> m = new HashMap<String, Integer>(l.size());
+        for (int i = 0; i < l.size(); i++) {
+            m.put(l.get(i), Integer.valueOf(i));
+        }
+        return m;
+
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a0f93243/plugins/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/pom.xml b/plugins/pom.xml
index a9cf617..097f224 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -174,6 +174,17 @@
       </modules>
     </profile>
     <profile>
+      <id>mysqlha</id>
+      <activation>
+        <property>
+          <name>noredist</name>
+        </property>
+      </activation>
+      <modules>
+        <module>database/mysql-ha</module>
+      </modules>
+    </profile>
+    <profile>
       <id>simulator</id>
       <activation>
         <property>