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 2013/01/17 01:32:19 UTC
[1/5] git commit: Make-Ec2Region-s-datacenter-name-configurable patch
by Jason Brown; reviewed by Vijay for CASSANDRA-5155
Make-Ec2Region-s-datacenter-name-configurable
patch by Jason Brown; reviewed by Vijay for CASSANDRA-5155
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/99394583
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/99394583
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/99394583
Branch: refs/heads/trunk
Commit: 993945833ce3d7edf2fdc694d3907cace8f5f149
Parents: 233ea26
Author: Vijay Parthasarathy <vi...@gmail.com>
Authored: Tue Jan 15 10:15:27 2013 -0800
Committer: Vijay Parthasarathy <vi...@gmail.com>
Committed: Tue Jan 15 10:15:27 2013 -0800
----------------------------------------------------------------------
conf/cassandra-rackdc.properties | 6 ++-
.../org/apache/cassandra/locator/Ec2Snitch.java | 3 +
.../locator/GossipingPropertyFileSnitch.java | 42 +----------
.../apache/cassandra/locator/SnitchProperties.java | 54 +++++++++++++++
test/conf/cassandra-rackdc.properties | 24 +++++++
5 files changed, 90 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/99394583/conf/cassandra-rackdc.properties
----------------------------------------------------------------------
diff --git a/conf/cassandra-rackdc.properties b/conf/cassandra-rackdc.properties
index b792885..be2e7d2 100644
--- a/conf/cassandra-rackdc.properties
+++ b/conf/cassandra-rackdc.properties
@@ -14,7 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# This file is specifically for the GossipingPropertyFileSnitch and will
+# These properties are used with GossipingPropertyFileSnitch and will
# indicate the rack and dc for this node
dc=DC1
rack=RAC1
+
+# Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch
+# to append a string to the EC2 region name.
+#dc_suffix=
http://git-wip-us.apache.org/repos/asf/cassandra/blob/99394583/src/java/org/apache/cassandra/locator/Ec2Snitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/Ec2Snitch.java b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
index 1dced95..b0cefee 100644
--- a/src/java/org/apache/cassandra/locator/Ec2Snitch.java
+++ b/src/java/org/apache/cassandra/locator/Ec2Snitch.java
@@ -60,6 +60,9 @@ public class Ec2Snitch extends AbstractNetworkTopologySnitch
ec2region = az.substring(0, az.length() - 1);
if (ec2region.endsWith("1"))
ec2region = az.substring(0, az.length() - 3);
+
+ String datacenterSuffix = SnitchProperties.get("dc_suffix", "");
+ ec2region = ec2region.concat(datacenterSuffix);
logger.info("EC2Snitch using region: " + ec2region + ", zone: " + ec2zone + ".");
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/99394583/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
index 9a22544..72c9bb8 100644
--- a/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
+++ b/src/java/org/apache/cassandra/locator/GossipingPropertyFileSnitch.java
@@ -36,21 +36,16 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
{
private static final Logger logger = LoggerFactory.getLogger(GossipingPropertyFileSnitch.class);
- public static final String RACKDC_PROPERTY_FILENAME = "cassandra-rackdc.properties";
private PropertyFileSnitch psnitch;
private String myDC;
private String myRack;
public GossipingPropertyFileSnitch() throws ConfigurationException
{
- try
- {
- loadConfiguration();
- }
- catch (ConfigurationException e)
- {
- throw new RuntimeException("Unable to load " + RACKDC_PROPERTY_FILENAME + " : ", e);
- }
+ myDC = SnitchProperties.get("dc", null);
+ myRack = SnitchProperties.get("rack", null);
+ if (myDC == null || myRack == null)
+ throw new ConfigurationException("DC or rack not found in snitch properties");
try
{
psnitch = new PropertyFileSnitch();
@@ -62,35 +57,6 @@ public class GossipingPropertyFileSnitch extends AbstractNetworkTopologySnitch
}
}
- private void loadConfiguration() throws ConfigurationException
- {
- InputStream stream = GossipingPropertyFileSnitch.class.getClassLoader().getResourceAsStream(RACKDC_PROPERTY_FILENAME);
- Properties properties = new Properties();
- try
- {
- properties.load(stream);
- }
- catch (Exception e)
- {
- throw new ConfigurationException("Unable to read " + RACKDC_PROPERTY_FILENAME, e);
- }
- finally
- {
- FileUtils.closeQuietly(stream);
- }
- for (Map.Entry<Object, Object> entry : properties.entrySet())
- {
- String key = (String) entry.getKey();
- String value = (String) entry.getValue();
- if (key.equals("dc"))
- myDC = value;
- else if (key.equals("rack"))
- myRack = value;
- }
- if (myDC == null || myRack == null)
- throw new ConfigurationException("DC or rack not found in " + RACKDC_PROPERTY_FILENAME);
- }
-
/**
* Return the data center for which an endpoint resides in
*
http://git-wip-us.apache.org/repos/asf/cassandra/blob/99394583/src/java/org/apache/cassandra/locator/SnitchProperties.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/locator/SnitchProperties.java b/src/java/org/apache/cassandra/locator/SnitchProperties.java
new file mode 100644
index 0000000..16989ff
--- /dev/null
+++ b/src/java/org/apache/cassandra/locator/SnitchProperties.java
@@ -0,0 +1,54 @@
+/*
+ * 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 org.apache.cassandra.locator;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.cassandra.io.util.FileUtils;
+
+public class SnitchProperties
+{
+ public static final String RACKDC_PROPERTY_FILENAME = "cassandra-rackdc.properties";
+ private static Properties properties = new Properties();
+
+ static
+ {
+ InputStream stream = SnitchProperties.class.getClassLoader().getResourceAsStream(RACKDC_PROPERTY_FILENAME);
+ try
+ {
+ properties.load(stream);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to read " + RACKDC_PROPERTY_FILENAME, e);
+ }
+ finally
+ {
+ FileUtils.closeQuietly(stream);
+ }
+ }
+
+ /**
+ * Get a snitch property value or return null if not defined.
+ */
+ public static String get(String propertyName, String defaultValue)
+ {
+ return properties.getProperty(propertyName, defaultValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/99394583/test/conf/cassandra-rackdc.properties
----------------------------------------------------------------------
diff --git a/test/conf/cassandra-rackdc.properties b/test/conf/cassandra-rackdc.properties
new file mode 100644
index 0000000..be2e7d2
--- /dev/null
+++ b/test/conf/cassandra-rackdc.properties
@@ -0,0 +1,24 @@
+# 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.
+
+# These properties are used with GossipingPropertyFileSnitch and will
+# indicate the rack and dc for this node
+dc=DC1
+rack=RAC1
+
+# Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch
+# to append a string to the EC2 region name.
+#dc_suffix=