You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by db...@apache.org on 2014/05/04 06:21:25 UTC

[1/2] git commit: make sure streams get closed

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.0 4233ee43d -> 2e955d481


make sure streams get closed


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

Branch: refs/heads/cassandra-2.0
Commit: c454807a75a55bf7a12dbe7c641266bcaf33d6e1
Parents: 2f32783
Author: Dave Brosius <db...@mebigfatguy.com>
Authored: Sun May 4 00:19:51 2014 -0400
Committer: Dave Brosius <db...@mebigfatguy.com>
Committed: Sun May 4 00:19:51 2014 -0400

----------------------------------------------------------------------
 .../cassandra/locator/CloudstackSnitch.java     | 78 +++++++++++++-------
 1 file changed, 51 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/c454807a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
index af26ef9..57c973b 100644
--- a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@ -57,7 +57,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
 
     private static final String DEFAULT_DC = "UNKNOWN-DC";
     private static final String DEFAULT_RACK = "UNKNOWN-RACK";
-    private static final String[] LEASE_FILES = {
+    private static final String[] LEASE_FILES = 
+    {
         "file:///var/lib/dhcp/dhclient.eth0.leases",
         "file:///var/lib/dhclient/dhclient.eth0.leases"
     };
@@ -71,7 +72,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
         String zone = csQueryMetadata(endpoint + ZONE_NAME_QUERY_URI);
         String zone_parts[] = zone.split("-");
 
-        if (zone_parts.length != 3) {
+        if (zone_parts.length != 3) 
+        {
             throw new ConfigurationException("CloudstackSnitch cannot handle invalid zone format: " + zone);
         }
         csZoneDc = zone_parts[0] + "-" + zone_parts[1];
@@ -83,7 +85,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
         if (endpoint.equals(FBUtilities.getBroadcastAddress()))
             return csZoneRack;
         EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
-        if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+        if (state == null || state.getApplicationState(ApplicationState.RACK) == null) 
+        {
             if (savedEndpoints == null)
                 savedEndpoints = SystemTable.loadDcRackInfo();
             if (savedEndpoints.containsKey(endpoint))
@@ -98,7 +101,8 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
         if (endpoint.equals(FBUtilities.getBroadcastAddress()))
             return csZoneDc;
         EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
-        if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+        if (state == null || state.getApplicationState(ApplicationState.DC) == null) 
+        {
             if (savedEndpoints == null)
                 savedEndpoints = SystemTable.loadDcRackInfo();
             if (savedEndpoints.containsKey(endpoint))
@@ -113,14 +117,19 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
         HttpURLConnection conn = null;
         DataInputStream is = null;
 
-        try {
+        try 
+        {
             conn = (HttpURLConnection) new URL(url).openConnection();
-        } catch (Exception e) {
+        } 
+        catch (Exception e) 
+        {
             throw new ConfigurationException("CloudstackSnitch cannot query wrong metadata URL: " + url);
         }
-        try {
+        try 
+        {
             conn.setRequestMethod("GET");
-            if (conn.getResponseCode() != 200) {
+            if (conn.getResponseCode() != 200) 
+            {
                 throw new ConfigurationException("CloudstackSnitch was unable to query metadata.");
             }
 
@@ -129,27 +138,31 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
             is = new DataInputStream(new BufferedInputStream(conn.getInputStream()));
             is.readFully(b);
             return new String(b, StandardCharsets.UTF_8);
-        } finally {
+        } 
+        finally 
+        {
             FileUtils.close(is);
             conn.disconnect();
         }
-
     }
 
     String csMetadataEndpoint() throws ConfigurationException
     {
-        for (String lease_uri: LEASE_FILES) {
-            try {
+        for (String lease_uri: LEASE_FILES) 
+        {
+            try 
+            {
                 File lease_file = new File(new URI(lease_uri));
-                if (lease_file.exists()) {
+                if (lease_file.exists()) 
+                {
                     return csEndpointFromLease(lease_file);
                 }
-
-            } catch (Exception e) {
+            } 
+            catch (Exception e) 
+            {
                 continue;
             }
 
-
         }
 
         throw new ConfigurationException("No valid DHCP lease file could be found.");
@@ -163,21 +176,32 @@ public class CloudstackSnitch extends AbstractNetworkTopologySnitch
         String endpoint = null;
         Pattern identifierPattern = Pattern.compile("^[ \t]*option dhcp-server-identifier (.*);$");
 
-        try {
+        try 
+        {
             reader = new BufferedReader(new FileReader(lease));
-        } catch (Exception e) {
-            throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
-        }
-
-        while ((line = reader.readLine()) != null) {
-            Matcher matcher = identifierPattern.matcher(line);
-
-            if (matcher.find()) {
-                endpoint = matcher.group(1);
+            
+            while ((line = reader.readLine()) != null) 
+            {
+                Matcher matcher = identifierPattern.matcher(line);
+
+                if (matcher.find()) 
+                {
+                    endpoint = matcher.group(1);
+                    break;
+                }
             }
+        } 
+        catch (Exception e)  
+        {
+            throw new ConfigurationException("CloudstackSnitch cannot access lease file.");
+        } 
+        finally
+        {
+        	FileUtils.closeQuietly(reader);
         }
 
-        if (endpoint == null) {
+        if (endpoint == null) 
+        {
             throw new ConfigurationException("No metadata server could be found in lease file.");
         }
 


[2/2] git commit: Merge branch 'cassandra-1.2' into cassandra-2.0

Posted by db...@apache.org.
Merge branch 'cassandra-1.2' into cassandra-2.0


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

Branch: refs/heads/cassandra-2.0
Commit: 2e955d4818708ff865898bd0f57a29cb4e93f0a8
Parents: 4233ee4 c454807
Author: Dave Brosius <db...@mebigfatguy.com>
Authored: Sun May 4 00:20:21 2014 -0400
Committer: Dave Brosius <db...@mebigfatguy.com>
Committed: Sun May 4 00:20:21 2014 -0400

----------------------------------------------------------------------
 .../cassandra/locator/CloudstackSnitch.java     | 78 +++++++++++++-------
 1 file changed, 51 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2e955d48/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/locator/CloudstackSnitch.java
index 43ae996,57c973b..0200f0f
--- a/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
+++ b/src/java/org/apache/cassandra/locator/CloudstackSnitch.java
@@@ -83,9 -85,10 +85,10 @@@ public class CloudstackSnitch extends A
          if (endpoint.equals(FBUtilities.getBroadcastAddress()))
              return csZoneRack;
          EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
-         if (state == null || state.getApplicationState(ApplicationState.RACK) == null) {
+         if (state == null || state.getApplicationState(ApplicationState.RACK) == null) 
+         {
              if (savedEndpoints == null)
 -                savedEndpoints = SystemTable.loadDcRackInfo();
 +                savedEndpoints = SystemKeyspace.loadDcRackInfo();
              if (savedEndpoints.containsKey(endpoint))
                  return savedEndpoints.get(endpoint).get("rack");
              return DEFAULT_RACK;
@@@ -98,9 -101,10 +101,10 @@@
          if (endpoint.equals(FBUtilities.getBroadcastAddress()))
              return csZoneDc;
          EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
-         if (state == null || state.getApplicationState(ApplicationState.DC) == null) {
+         if (state == null || state.getApplicationState(ApplicationState.DC) == null) 
+         {
              if (savedEndpoints == null)
 -                savedEndpoints = SystemTable.loadDcRackInfo();
 +                savedEndpoints = SystemKeyspace.loadDcRackInfo();
              if (savedEndpoints.containsKey(endpoint))
                  return savedEndpoints.get(endpoint).get("data_center");
              return DEFAULT_DC;