incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cr...@apache.org
Subject [27/30] git commit: Fixed the usage of the ZookeeperClusterStatus Object
Date Thu, 07 Nov 2013 02:41:50 GMT
Fixed the usage of the ZookeeperClusterStatus Object


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2734f46d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2734f46d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2734f46d

Branch: refs/heads/blur-console-v2
Commit: 2734f46dedc5a665a81baa3d472fcdc797a46ace
Parents: ca61e41
Author: Chris Rohr <crohr@nearinfinity.com>
Authored: Wed Nov 6 21:00:54 2013 -0500
Committer: Chris Rohr <crohr@nearinfinity.com>
Committed: Wed Nov 6 21:00:54 2013 -0500

----------------------------------------------------------------------
 .../org/apache/blur/console/util/Config.java    |  19 +++-
 .../org/apache/blur/console/util/NodeUtil.java  | 101 ++++++++++---------
 2 files changed, 67 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2734f46d/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
index 87dcbac..b732004 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/Config.java
@@ -18,6 +18,7 @@ package org.apache.blur.console.util;
  */
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.blur.BlurConfiguration;
@@ -26,8 +27,9 @@ import org.apache.commons.lang.StringUtils;
 
 public class Config {
 	private static int port = 8080;
-	
 	private static BlurConfiguration blurConfig;
+	private static ZookeeperClusterStatus zk;
+	private static String blurConnection;
 
 	public static int getConsolePort() {
 		return port;
@@ -38,12 +40,21 @@ public class Config {
 	
 	public static void setupConfig() throws IOException {
 		blurConfig = new BlurConfiguration();
+		zk = new ZookeeperClusterStatus(blurConfig.get("blur.zookeeper.connection"), blurConfig);
+		blurConnection = buildConnectionString();
 	}
 	
 	public static String getConnectionString() throws IOException {
-		ZookeeperClusterStatus zk = new ZookeeperClusterStatus(blurConfig.get("blur.zookeeper.connection"),
blurConfig);
-		List<String> allControllers = zk.getControllerServerList();
-		zk.close();
+		return blurConnection;
+	}
+	
+	public static ZookeeperClusterStatus getZookeeper() {
+		return zk;
+	}
+	
+	private static String buildConnectionString() {
+		List<String> allControllers = new ArrayList<String>();
+		allControllers = zk.getControllerServerList();
 		return StringUtils.join(allControllers, ",");
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2734f46d/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java
----------------------------------------------------------------------
diff --git a/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java
b/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java
index 93b133d..4e317aa 100644
--- a/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java
+++ b/contrib/blur-console/src/main/java/org/apache/blur/console/util/NodeUtil.java
@@ -38,17 +38,12 @@ import org.apache.commons.collections.CollectionUtils;
 public class NodeUtil {
 	@SuppressWarnings("unchecked")
 	public static Map<String, Object> getControllerStatus() throws IOException {
-		ZookeeperClusterStatus zk = new ZookeeperClusterStatus(Config.getBlurConfig().get("blur.zookeeper.connection"),
-				Config.getBlurConfig());
-
+		ZookeeperClusterStatus zk = Config.getZookeeper();
+		
 		List<String> allControllers = new ArrayList<String>();
 		List<String> oControllers = new ArrayList<String>();
-		try {
-			allControllers = zk.getOnlineControllerList();
-			oControllers = zk.getControllerServerList();
-		} finally {
-			zk.close();
-		}
+		allControllers = zk.getOnlineControllerList();
+		oControllers = zk.getControllerServerList();
 		
 		Collection<String> onlineControllers = CollectionUtils.intersection(allControllers,
oControllers);
 		Collection<String> offlineControllers = CollectionUtils.subtract(allControllers,
oControllers);
@@ -83,46 +78,41 @@ public class NodeUtil {
 	}
 
 	public static List<Map<String, Object>> getClusterStatus() throws IOException
{
-		ZookeeperClusterStatus zk = new ZookeeperClusterStatus(Config.getBlurConfig().get("blur.zookeeper.connection"),
-				Config.getBlurConfig());
+		ZookeeperClusterStatus zk = Config.getZookeeper();
 
 		List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
-		try {
-			List<String> clusters = zk.getClusterList(false);
-	
-			for (String cluster : clusters) {
-				Map<String, Object> clusterObj = new HashMap<String, Object>();
-				clusterObj.put("name", cluster);
-	
-				List<String> offlineShardServers = zk.getOfflineShardServers(false, cluster);
-				List<String> onlineShardServers = zk.getOnlineShardServers(false, cluster);
-	
-				clusterObj.put("online", onlineShardServers);
-				clusterObj.put("offline", offlineShardServers);
-	
-				List<Map<String, Object>> clusterData = new ArrayList<Map<String,Object>>();
-				
-				Map<String, Object> online = new HashMap<String, Object>();
-				online.put("data", new int[][]{{0,onlineShardServers.size()}});
-				online.put("label", "Online");
-				online.put("color", "#7DC77D");
-	
-				Map<String, Object> offline = new HashMap<String, Object>();
-				offline.put("data", new int[][]{{0,offlineShardServers.size()}});
-				offline.put("label", "Offline");
-				offline.put("color", "#FF1919");
-	
-				clusterData.add(online);
-				clusterData.add(offline);
-				clusterObj.put("chart", clusterData);
-				if (offlineShardServers.isEmpty() && onlineShardServers.isEmpty()) {
-					clusterObj.put("errmsg", "Unable to find any nodes for cluster [" + cluster + "]");
-				}
-	
-				data.add(clusterObj);
+		List<String> clusters = zk.getClusterList(false);
+
+		for (String cluster : clusters) {
+			Map<String, Object> clusterObj = new HashMap<String, Object>();
+			clusterObj.put("name", cluster);
+
+			List<String> offlineShardServers = zk.getOfflineShardServers(false, cluster);
+			List<String> onlineShardServers = zk.getOnlineShardServers(false, cluster);
+
+			clusterObj.put("online", onlineShardServers);
+			clusterObj.put("offline", offlineShardServers);
+
+			List<Map<String, Object>> clusterData = new ArrayList<Map<String,Object>>();
+			
+			Map<String, Object> online = new HashMap<String, Object>();
+			online.put("data", new int[][]{{0,onlineShardServers.size()}});
+			online.put("label", "Online");
+			online.put("color", "#7DC77D");
+
+			Map<String, Object> offline = new HashMap<String, Object>();
+			offline.put("data", new int[][]{{0,offlineShardServers.size()}});
+			offline.put("label", "Offline");
+			offline.put("color", "#FF1919");
+
+			clusterData.add(online);
+			clusterData.add(offline);
+			clusterObj.put("chart", clusterData);
+			if (offlineShardServers.isEmpty() && onlineShardServers.isEmpty()) {
+				clusterObj.put("errmsg", "Unable to find any nodes for cluster [" + cluster + "]");
 			}
-		} finally {
-			zk.close();
+
+			data.add(clusterObj);
 		}
 
 		return data;
@@ -134,6 +124,9 @@ public class NodeUtil {
 		Set<String> offlineZookeepers = new HashSet<String>();
 		
 		for (String connection : connections) {
+			Socket socket = null;
+			InputStream response = null;
+			OutputStream question = null;
 			try {
 				URI parsedConnection = new URI("my://" + connection);
 				String host = parsedConnection.getHost();
@@ -141,14 +134,14 @@ public class NodeUtil {
 				byte[] reqBytes = new byte[4];
 				ByteBuffer req = ByteBuffer.wrap(reqBytes);
 				req.putInt(ByteBuffer.wrap("ruok".getBytes()).getInt());
-				Socket socket = new Socket();
+				socket = new Socket();
 				socket.setSoLinger(false, 10);
 				socket.setSoTimeout(20000);
 				parsedConnection.getPort();
 				socket.connect(new InetSocketAddress(host, port));
 
-				InputStream response = socket.getInputStream();
-				OutputStream question = socket.getOutputStream();
+				response = socket.getInputStream();
+				question = socket.getOutputStream();
 
 				question.write(reqBytes);
 
@@ -166,6 +159,16 @@ public class NodeUtil {
 				question.close();
 			} catch (Exception e) {
 				offlineZookeepers.add(connection);
+			} finally {
+				if (socket != null) {
+					socket.close();
+				}
+				if (response != null) {
+					response.close();
+				}
+				if (question != null) {
+					question.close();
+				}
 			}
 		}
 		


Mime
View raw message