Author: jbellis
Date: Tue Aug 24 14:49:23 2010
New Revision: 988578

URL: http://svn.apache.org/viewvc?rev=988578&view=rev
Log:
allow loading cassandra.yaml from url specified by cassandra.config system 
property.  patch by jbellis; reviewed by gdusbabek for CASSANDRA-1126

Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
    
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java

Modified: cassandra/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=988578&r1=988577&r2=988578&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Tue Aug 24 14:49:23 2010
@@ -29,6 +29,8 @@ dev
  * config-converter properly handles snitches and framed support 
    (CASSANDRA-1420)
  * remove keyspace argument from multiget_count (CASSANDRA-1422)
+ * allow specifying cassandra.yaml location as (local or remote) URL
+   (CASSANDRA-1126)
 
 
 0.7-beta1

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java?rev=988578&r1=988577&r2=988578&view=diff
==============================================================================
--- 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java 
(original)
+++ 
cassandra/trunk/src/java/org/apache/cassandra/config/DatabaseDescriptor.java 
Tue Aug 24 14:49:23 2010
@@ -23,6 +23,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.net.InetAddress;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.*;
@@ -43,7 +44,6 @@ import org.apache.cassandra.db.clock.Abs
 import org.apache.cassandra.db.clock.TimestampReconciler;
 import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.migration.Migration;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.util.FileUtils;
@@ -78,16 +78,13 @@ public class DatabaseDescriptor
     /* Hashing strategy Random or OPHF */
     private static IPartitioner partitioner;
 
-    // the path qualified config file (cassandra.yaml) name
-    private static String configFileName;
-
     private static Config.DiskAccessMode indexAccessMode;
     
     private static Config conf;
 
     private static IAuthenticator authenticator = new AllowAllAuthenticator();
 
-    private final static String STORAGE_CONF_FILE = "cassandra.yaml";
+    private final static String DEFAULT_CONFIGURATION = "cassandra.yaml";
 
     private static IRequestScheduler requestScheduler;
     private static RequestSchedulerId requestSchedulerId;
@@ -97,27 +94,39 @@ public class DatabaseDescriptor
     private static UUID defsVersion = INITIAL_VERSION;
 
     /**
-     * Inspect the classpath to find STORAGE_CONF_FILE.
+     * Inspect the classpath to find storage configuration file
      */
-    static String getStorageConfigPath() throws ConfigurationException
+    static URL getStorageConfigURL() throws ConfigurationException
     {
-        ClassLoader loader = DatabaseDescriptor.class.getClassLoader();
-        URL scpurl = loader.getResource(STORAGE_CONF_FILE);
-        if (scpurl != null)
-            return scpurl.getFile();
-        throw new ConfigurationException("Cannot locate " + STORAGE_CONF_FILE 
+ " on the classpath");
+        String configUrl = System.getProperty("cassandra.config");
+        if (configUrl == null)
+            configUrl = DEFAULT_CONFIGURATION;
+
+        URL url;
+        try
+        {
+            url = new URL(configUrl);
+        }
+        catch (MalformedURLException e)
+        {
+            ClassLoader loader = DatabaseDescriptor.class.getClassLoader();
+            url = loader.getResource(configUrl);
+            if (url == null)
+                throw new ConfigurationException("Cannot locate " + configUrl);
+        }
+
+        return url;
     }
 
     static
     {
         try
         {
-            configFileName = getStorageConfigPath();
-
+            URL url = getStorageConfigURL();
             if (logger.isDebugEnabled())
-                logger.info("Loading settings from " + configFileName);
+                logger.info("Loading settings from " + url);
             
-            InputStream input = new FileInputStream(new File(configFileName));
+            InputStream input = url.openStream();
             org.yaml.snakeyaml.constructor.Constructor constructor = new 
org.yaml.snakeyaml.constructor.Constructor(Config.class);
             TypeDescription desc = new TypeDescription(Config.class);
             desc.putListPropertyType("keyspaces", RawKeyspace.class);
@@ -510,8 +519,8 @@ public class DatabaseDescriptor
             
             // since we loaded definitions from local storage, log a warning 
if definitions exist in yaml.
             if (conf.keyspaces != null && conf.keyspaces.size() > 0)
-                logger.warn("Schema definitions were defined both locally and 
in " + STORAGE_CONF_FILE +
-                    ". Definitions in " + STORAGE_CONF_FILE + " were 
ignored.");
+                logger.warn("Schema definitions were defined both locally and 
in " + DEFAULT_CONFIGURATION +
+                    ". Definitions in " + DEFAULT_CONFIGURATION + " were 
ignored.");
             
         }
         CFMetaData.fixMaxId();
@@ -805,10 +814,6 @@ public class DatabaseDescriptor
         return conf.cluster_name;
     }
 
-    public static String getConfigFileName() {
-        return configFileName;
-    }
-
     public static String getJobJarLocation()
     {
         return conf.job_jar_file_location;

Modified: 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java?rev=988578&r1=988577&r2=988578&view=diff
==============================================================================
--- 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
 (original)
+++ 
cassandra/trunk/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java
 Tue Aug 24 14:49:23 2010
@@ -52,12 +52,6 @@ public class DatabaseDescriptorTest
     }
 
     @Test
-    public void testShouldHaveConfigFileNameAvailable()
-    {
-        assertNotNull(DatabaseDescriptor.getConfigFileName(), 
"DatabaseDescriptor should always be able to return the file name of the config 
file");
-    }
-
-    @Test
     public void testCFMetaDataSerialization() throws IOException, 
ConfigurationException
     {
         // test serialization of all defined test CFs.


Reply via email to