cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r934661 - in /cassandra/trunk: contrib/property_snitch/ contrib/property_snitch/conf/ contrib/property_snitch/src/java/org/apache/cassandra/locator/ src/java/org/apache/cassandra/config/
Date Fri, 16 Apr 2010 01:38:34 GMT
Author: jbellis
Date: Fri Apr 16 01:38:33 2010
New Revision: 934661

URL: http://svn.apache.org/viewvc?rev=934661&view=rev
Log:
load cassandra-rack.properties from classpath; clean up configuration loading to throw ConfigurationException
on error.  patch by Erick Tryzelaar and jbellis for CASSANDRA-984

Added:
    cassandra/trunk/contrib/property_snitch/conf/cassandra-rack.properties
      - copied, changed from r934604, cassandra/trunk/contrib/property_snitch/conf/rack.properties
Removed:
    cassandra/trunk/contrib/property_snitch/conf/rack.properties
Modified:
    cassandra/trunk/contrib/property_snitch/README.txt
    cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
    cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
    cassandra/trunk/src/java/org/apache/cassandra/config/ConfigurationException.java

Modified: cassandra/trunk/contrib/property_snitch/README.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/contrib/property_snitch/README.txt?rev=934661&r1=934660&r2=934661&view=diff
==============================================================================
--- cassandra/trunk/contrib/property_snitch/README.txt (original)
+++ cassandra/trunk/contrib/property_snitch/README.txt Fri Apr 16 01:38:33 2010
@@ -9,8 +9,8 @@ specifying node locations in a standard 
 
 Properties File
 ---------------
-The EndPointSnitch expects to find a standard properties file at
-/etc/cassandra/rack.properties in the following format:
+The EndPointSnitch expects to find a file on the classapth named
+cassandra-rack.properties in the following format:
 
   <node IP>\:<port>=<data center name>:<rack name>
 
@@ -19,23 +19,26 @@ return for unconfigured nodes:
 
   default=<data center name>:<rack name>
 
-See conf/rack.properties for an annotated example config.
+See conf/cassandra-rack.properties for an annotated example config.
 
 
 Installing
 ----------
  * Run the ant jar target 
- * Add build/cassandra-propsnitch.jar to the CLASSPATH
- * Edit storage-conf.xml and set ReplicaPlacementStrategy to
-   org.apache.cassandra.locator.RackAwareStrategy
+ * Copy build/cassandra-propsnitch.jar to your Cassandra lib/
+   directory, or otherwise add it to the CLASSPATH
+   (see http://wiki.apache.org/cassandra/RunningCassandra)
  * Edit the EndPointSnitch element of storage-conf.xml to use
    org.apache.cassandra.locator.PropertyFileEndPointSnitch
- * Create the file /etc/cassandra/rack.properties
+ * Create the cassandra-rack.properties in your classpath
+   (e.g. in your Cassandra conf/ directory)
+ * Optionally set ReplicaPlacementStrategy in cassandra.xml to
+   org.apache.cassandra.locator.RackAwareStrategy
 
 
 Running/Managing
 ----------------
-This endpointsnitch also registers itself as an MBean which can be used to
-reload the configuration file in the case the rack.properties file has
-changed.  Additionally, the current rack information can be retrieved as
-well.
+This endpointsnitch also registers itself as an MBean which can be
+used to reload the configuration file in the case the properties file
+has changed.  Additionally, the current rack information can be
+retrieved.

Copied: cassandra/trunk/contrib/property_snitch/conf/cassandra-rack.properties (from r934604,
cassandra/trunk/contrib/property_snitch/conf/rack.properties)
URL: http://svn.apache.org/viewvc/cassandra/trunk/contrib/property_snitch/conf/cassandra-rack.properties?p2=cassandra/trunk/contrib/property_snitch/conf/cassandra-rack.properties&p1=cassandra/trunk/contrib/property_snitch/conf/rack.properties&r1=934604&r2=934661&rev=934661&view=diff
==============================================================================
    (empty)

Modified: cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java?rev=934661&r1=934660&r2=934661&view=diff
==============================================================================
--- cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
(original)
+++ cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitch.java
Fri Apr 16 01:38:33 2010
@@ -16,21 +16,22 @@
  * limitations under the License.
  */
 
-package src.java.org.apache.cassandra.locator;
+package org.apache.cassandra.locator;
 
-import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.lang.management.ManagementFactory;
 import java.net.UnknownHostException;
+import java.net.URL;
 import java.util.Properties;
 import java.util.StringTokenizer;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.apache.cassandra.locator.EndPointSnitch;
 import java.net.InetAddress;
+
+import org.apache.cassandra.config.ConfigurationException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,8 +41,6 @@ import org.slf4j.LoggerFactory;
  * PropertyFileEndPointSnitch is used by Digg to determine if two IP's are in the same
  * datacenter or on the same rack.
  * 
- * @author Sammy Yu <syu@sammyyu.net>
- * 
  */
 public class PropertyFileEndPointSnitch extends EndPointSnitch implements PropertyFileEndPointSnitchMBean
{
     /**
@@ -52,7 +51,7 @@ public class PropertyFileEndPointSnitch 
     /**
      * The default rack property file to be read.
      */
-    private static String DEFAULT_RACK_PROPERTY_FILE = "/etc/cassandra/rack.properties";

+    private static String RACK_PROPERTY_FILENAME = "cassandra-rack.properties";
 
     /**
      * Whether to use the parent for detection of same node
@@ -62,9 +61,10 @@ public class PropertyFileEndPointSnitch 
     /**
      * Reference to the logger.
      */
-    private static Logger logger_ = LoggerFactory.getLogger(PropertyFileEndPointSnitch.class);
    
+    private static Logger logger_ = LoggerFactory.getLogger(PropertyFileEndPointSnitch.class);
 
-    public PropertyFileEndPointSnitch() throws IOException {
+    public PropertyFileEndPointSnitch() throws ConfigurationException
+    {
         reloadConfiguration();
         try
         {
@@ -146,35 +146,35 @@ public class PropertyFileEndPointSnitch 
         return getRackForEndPoint(host).equals(getRackForEndPoint(host2)); 
     }
 
-    @Override
     public String displayConfiguration() {
         StringBuffer configurationString = new StringBuffer("Current rack configuration\n=================\n");
         for (Object key: hostProperties.keySet()) {
             String endpoint = (String) key;
             String value = hostProperties.getProperty(endpoint);
-            configurationString.append(endpoint + "=" + value + "\n");
+            configurationString.append(endpoint).append("=").append(value).append("\n");
         }
         return configurationString.toString();
     }
     
-    @Override
-    public void reloadConfiguration() throws IOException {        
-        String rackPropertyFilename = System.getProperty("rackFile", DEFAULT_RACK_PROPERTY_FILE);
-        try 
+    public void reloadConfiguration() throws ConfigurationException
+    {
+        ClassLoader loader = PropertyFileEndPointSnitch.class.getClassLoader();
+        URL scpurl = loader.getResource(RACK_PROPERTY_FILENAME);
+        if (scpurl == null)
+            throw new ConfigurationException("unable to locate " + RACK_PROPERTY_FILENAME);
+
+        String rackPropertyFilename = scpurl.getFile();
+
+        try
         {
             Properties localHostProperties = new Properties();
             localHostProperties.load(new FileReader(rackPropertyFilename));
             hostProperties = localHostProperties;
             runInBaseMode = false;
         }
-        catch (FileNotFoundException fnfe) {
-            logger_.error("Could not find " + rackPropertyFilename + ", using default EndPointSnitch",
fnfe);
-            runInBaseMode = true;
-        }
-        catch (IOException ioe) {
-            logger_.error("Could not process " + rackPropertyFilename, ioe);
-            throw ioe;
+        catch (IOException ioe) 
+        {
+            throw new ConfigurationException("Could not process " + rackPropertyFilename,
ioe);
         }
     }
-
 }

Modified: cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java?rev=934661&r1=934660&r2=934661&view=diff
==============================================================================
--- cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
(original)
+++ cassandra/trunk/contrib/property_snitch/src/java/org/apache/cassandra/locator/PropertyFileEndPointSnitchMBean.java
Fri Apr 16 01:38:33 2010
@@ -16,10 +16,12 @@
  * limitations under the License.
  */
 
-package src.java.org.apache.cassandra.locator;
+package org.apache.cassandra.locator;
 
 import java.io.IOException;
 
+import org.apache.cassandra.config.ConfigurationException;
+
 /**
  * PropertyFileEndPointSnitchMBean
  * 
@@ -37,7 +39,7 @@ public interface PropertyFileEndPointSni
     /**
      * Reload the rack configuration
      */
-    public void reloadConfiguration() throws IOException;
+    public void reloadConfiguration() throws ConfigurationException;
     
     /**
      * Display the current configuration

Modified: cassandra/trunk/src/java/org/apache/cassandra/config/ConfigurationException.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/ConfigurationException.java?rev=934661&r1=934660&r2=934661&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/config/ConfigurationException.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/config/ConfigurationException.java Fri Apr
16 01:38:33 2010
@@ -18,10 +18,17 @@
 
 package org.apache.cassandra.config;
 
+import java.io.IOException;
+
 public class ConfigurationException extends Exception
 {
     public ConfigurationException(String message)
     {
         super(message);
     }
+
+    public ConfigurationException(String message, IOException ioe)
+    {
+        super(message, ioe);
+    }
 }



Mime
View raw message