qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1479176 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/BrokerOptions.java main/resources/initial-config.json test/java/org/apache/qpid/server/BrokerOptionsTest.java
Date Sat, 04 May 2013 21:03:37 GMT
Author: robbie
Date: Sat May  4 21:02:20 2013
New Revision: 1479176

URL: http://svn.apache.org/r1479176
Log:
QPID-4809: change initial-config.json to using qpid.work_dir and qpid.home_dir config variables
instead of QPID_WORK and QPID_HOME system properties

Enables us to default the former when QPID_WORK is not set and allows the latter to be set
on a per-instance basis.

Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
    qpid/trunk/qpid/java/broker/src/main/resources/initial-config.json
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java?rev=1479176&r1=1479175&r2=1479176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java Sat
May  4 21:02:20 2013
@@ -33,6 +33,21 @@ import org.apache.qpid.server.util.Strin
 
 public class BrokerOptions
 {
+    /**
+     * Configuration property name for the absolute path to use for the broker work directory.
+     *
+     * If not otherwise set, the value for this configuration property defaults to the location
+     * set in the "QPID_WORK" system property if that was set, or the 'work' sub-directory
of
+     * the JVM working directory ("user.dir" property) for the Java process if it was not.
+     */
+    public static final String QPID_WORK_DIR  = "qpid.work_dir";
+    /**
+     * Configuration property name for the absolute path to use for the broker home directory.
+     *
+     * If not otherwise set, the value for this configuration property defaults to the location
+     * set in the "QPID_HOME" system property if that was set, or remains unset if it was
not.
+     */
+    public static final String QPID_HOME_DIR  = "qpid.home_dir";
     public static final String QPID_AMQP_PORT = "qpid.amqp_port";
     public static final String QPID_HTTP_PORT = "qpid.http_port";
     public static final String QPID_RMI_PORT  = "qpid.rmi_port";
@@ -52,6 +67,8 @@ public class BrokerOptions
     public static final String MANAGEMENT_MODE_USER_NAME = "mm_admin";
     private static final int MANAGEMENT_MODE_PASSWORD_LENGTH = 10;
 
+    private static final File FALLBACK_WORK_DIR = new File(System.getProperty("user.dir"),
"work");
+
     private String _logConfigFile;
     private Integer _logWatchFrequency = 0;
 
@@ -66,7 +83,6 @@ public class BrokerOptions
     private int _managementModeConnectorPort;
     private int _managementModeHttpPort;
     private String _managementModePassword;
-    private String _workingDir;
     private boolean _skipLoggingConfiguration;
     private boolean _overwriteConfigurationStore;
     private Map<String, String> _configProperties = new HashMap<String,String>();
@@ -188,7 +204,8 @@ public class BrokerOptions
     /**
      * Get the broker configuration store location.
      *
-     * Defaults to {@value #DEFAULT_CONFIG_NAME_PREFIX}.{@literal <store type>} (see
{@link BrokerOptions#getConfigurationStoreType()}) within the broker work directory (see {@link
BrokerOptions#getWorkDir()}).
+     * Defaults to {@value #DEFAULT_CONFIG_NAME_PREFIX}.{@literal <store type>} (see
{@link BrokerOptions#getConfigurationStoreType()})
+     * within the broker work directory (gathered via config property {@link #QPID_WORK_DIR}).
      *
      * @return the previously set configuration store location, or the default location if
none was set.
      */
@@ -234,40 +251,6 @@ public class BrokerOptions
     }
 
     /**
-     * Get the broker work directory location.
-     *
-     * Defaults to the location set in the "QPID_WORK" system property if it is set, or the
'work' sub-directory
-     * of the user working directory ("user.dir" property) for the Java process if it is
not.
-     *
-     * @return the previously set configuration store location, or the default location if
none was set.
-     */
-    public String getWorkDir()
-    {
-        if(_workingDir == null)
-        {
-            String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
-            if (qpidWork == null)
-            {
-                return new File(System.getProperty("user.dir"), "work").getAbsolutePath();
-            }
-
-            return qpidWork;
-        }
-
-        return _workingDir;
-    }
-
-    /**
-     * Set the absolute path to use for the broker work directory.
-     *
-     * Passing null clears any previously set value and returns to the default.
-     */
-    public void setWorkDir(String workingDir)
-    {
-        _workingDir = workingDir;
-    }
-
-    /**
      * Get the broker initial JSON configuration location.
      *
      * Defaults to an internal configuration file within the broker jar.
@@ -338,7 +321,40 @@ public class BrokerOptions
         properties.putIfAbsent(QPID_HTTP_PORT, String.valueOf(DEFAULT_HTTP_PORT_NUMBER));
         properties.putIfAbsent(QPID_RMI_PORT, String.valueOf(DEFAULT_RMI_PORT_NUMBER));
         properties.putIfAbsent(QPID_JMX_PORT, String.valueOf(DEFAULT_JMX_PORT_NUMBER));
+        properties.putIfAbsent(QPID_WORK_DIR, getWorkDir());
+
+        String homeDir = getHomeDir();
+        if(homeDir != null)
+        {
+            properties.putIfAbsent(QPID_HOME_DIR, homeDir);
+        }
 
         return Collections.unmodifiableMap(properties);
     }
+
+    private String getWorkDir()
+    {
+        if(!_configProperties.containsKey(QPID_WORK_DIR))
+        {
+            String qpidWork = System.getProperty(BrokerProperties.PROPERTY_QPID_WORK);
+            if (qpidWork == null)
+            {
+                return FALLBACK_WORK_DIR.getAbsolutePath();
+            }
+
+            return qpidWork;
+        }
+
+        return _configProperties.get(QPID_WORK_DIR);
+    }
+
+    private String getHomeDir()
+    {
+        if(!_configProperties.containsKey(QPID_HOME_DIR))
+        {
+            return System.getProperty(BrokerProperties.PROPERTY_QPID_HOME);
+        }
+
+        return _configProperties.get(QPID_HOME_DIR);
+    }
 }

Modified: qpid/trunk/qpid/java/broker/src/main/resources/initial-config.json
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/resources/initial-config.json?rev=1479176&r1=1479175&r2=1479176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/resources/initial-config.json (original)
+++ qpid/trunk/qpid/java/broker/src/main/resources/initial-config.json Sat May  4 21:02:20
2013
@@ -26,7 +26,7 @@
   "authenticationproviders" : [ {
     "name" : "passwordFile",
     "type" : "PlainPasswordFile",
-    "path" : "${QPID_HOME}/etc/passwd"
+    "path" : "${qpid.home_dir}/etc/passwd"
   } ],
   "ports" : [  {
     "name" : "AMQP",
@@ -50,7 +50,7 @@
   "virtualhosts" : [ {
     "name" : "default",
     "storeType" : "DERBY",
-    "storePath" : "${QPID_WORK}/derbystore/default"
+    "storePath" : "${qpid.work_dir}/derbystore/default"
   } ],
   "plugins" : [ {
     "pluginType" : "MANAGEMENT-HTTP",

Modified: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1479176&r1=1479175&r2=1479176&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
(original)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
Sat May  4 21:02:20 2013
@@ -175,31 +175,6 @@ public class BrokerOptionsTest extends Q
         assertEquals(5555, _options.getManagementModeHttpPort());
     }
 
-    public void testDefaultWorkDirWithQpidWork()
-    {
-        String qpidWork = "/test/value";
-        setTestSystemProperty("QPID_WORK", qpidWork);
-
-        String expectedPath = new File(qpidWork).getAbsolutePath();
-        assertEquals (expectedPath, _options.getWorkDir());
-    }
-
-    public void testDefaultWorkDirWithoutQpidWork()
-    {
-        setTestSystemProperty("QPID_WORK", null);
-        String userDir = System.getProperty("user.dir");
-
-        String expectedPath = new File(userDir, "work").getAbsolutePath();
-        assertEquals (expectedPath, _options.getWorkDir());
-    }
-
-    public void testOverriddenWorkDir()
-    {
-        final String testWorkDir = "/my/test/work/dir";
-        _options.setWorkDir(testWorkDir);
-        assertEquals(testWorkDir, _options.getWorkDir());
-    }
-
     public void testDefaultSkipLoggingConfiguration()
     {
         assertFalse(_options.isSkipLoggingConfiguration());
@@ -230,40 +205,108 @@ public class BrokerOptionsTest extends Q
 
     public void testGetDefaultConfigProperties()
     {
+        //Unset QPID_WORK and QPID_HOME for this test.
+        //See below for specific tests of behaviour depending on their value
+        setTestSystemProperty("QPID_WORK", null);
+        setTestSystemProperty("QPID_HOME", null);
+
         Map<String,String> props = _options.getConfigProperties();
 
-        assertEquals("unexpected number of entries", 4, props.keySet().size());
+        assertEquals("unexpected number of entries", 5, props.keySet().size());
 
         assertEquals(BrokerOptions.DEFAULT_AMQP_PORT_NUMBER, props.get(BrokerOptions.QPID_AMQP_PORT));
         assertEquals(BrokerOptions.DEFAULT_HTTP_PORT_NUMBER, props.get(BrokerOptions.QPID_HTTP_PORT));
         assertEquals(BrokerOptions.DEFAULT_RMI_PORT_NUMBER, props.get(BrokerOptions.QPID_RMI_PORT));
         assertEquals(BrokerOptions.DEFAULT_JMX_PORT_NUMBER, props.get(BrokerOptions.QPID_JMX_PORT));
+        assertEquals(BrokerOptions.DEFAULT_JMX_PORT_NUMBER, props.get(BrokerOptions.QPID_JMX_PORT));
+        assertTrue(props.containsKey(BrokerOptions.QPID_WORK_DIR));
+        assertFalse(props.containsKey(BrokerOptions.QPID_HOME_DIR));
+    }
+
+    public void testDefaultWorkDirWithQpidWork()
+    {
+        String qpidWork = "/test/value";
+        setTestSystemProperty("QPID_WORK", qpidWork);
+
+        String expectedPath = new File(qpidWork).getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigProperties().get(BrokerOptions.QPID_WORK_DIR));
+    }
+
+    public void testDefaultWorkDirWithoutQpidWork()
+    {
+        setTestSystemProperty("QPID_WORK", null);
+        String userDir = System.getProperty("user.dir");
+
+        String expectedPath = new File(userDir, "work").getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigProperties().get(BrokerOptions.QPID_WORK_DIR));
+    }
+
+    public void testOverriddenWorkDir()
+    {
+        final String testWorkDir = "/my/test/work/dir";
+        _options.setConfigProperty(BrokerOptions.QPID_WORK_DIR, testWorkDir);
+        assertEquals(testWorkDir, _options.getConfigProperties().get(BrokerOptions.QPID_WORK_DIR));
+    }
+
+    public void testDefaultHomeDirWithQpidHome()
+    {
+        String qpidHome = "/test/value";
+        setTestSystemProperty("QPID_HOME", qpidHome);
+
+        String expectedPath = new File(qpidHome).getAbsolutePath();
+        assertEquals (expectedPath, _options.getConfigProperties().get(BrokerOptions.QPID_HOME_DIR));
+        assertEquals("unexpected number of entries", 6, _options.getConfigProperties().keySet().size());
+    }
+
+    public void testDefaultomeDirWithoutQpidHome()
+    {
+        setTestSystemProperty("QPID_HOME", null);
+
+        assertNull(_options.getConfigProperties().get(BrokerOptions.QPID_HOME_DIR));
+        assertFalse(_options.getConfigProperties().containsKey(BrokerOptions.QPID_HOME_DIR));
+        assertEquals("unexpected number of entries", 5, _options.getConfigProperties().keySet().size());
+    }
+
+    public void testOverriddenHomeDir()
+    {
+        final String testHomeDir = "/my/test/home/dir";
+        _options.setConfigProperty(BrokerOptions.QPID_HOME_DIR, testHomeDir);
+        assertEquals(testHomeDir, _options.getConfigProperties().get(BrokerOptions.QPID_HOME_DIR));
+        assertEquals("unexpected number of entries", 6, _options.getConfigProperties().keySet().size());
     }
 
     public void testSetDefaultConfigProperties()
     {
+        //Unset QPID_WORK and QPID_HOME for this test.
+        //See above for specific tests of behaviour depending on their value
+        setTestSystemProperty("QPID_WORK", null);
+        setTestSystemProperty("QPID_HOME", null);
+
         String oldPort = BrokerOptions.DEFAULT_AMQP_PORT_NUMBER;
         String newPort = "12345";
 
+        //set a new value for a previously defaulted port number property
         _options.setConfigProperty(BrokerOptions.QPID_AMQP_PORT, newPort);
         Map<String,String> props = _options.getConfigProperties();
-        assertEquals("unexpected number of entries", 4, props.keySet().size());
+        assertEquals("unexpected number of entries", 5, props.keySet().size());
         assertEquals(newPort, props.get(BrokerOptions.QPID_AMQP_PORT));
         assertEquals(BrokerOptions.DEFAULT_HTTP_PORT_NUMBER, props.get(BrokerOptions.QPID_HTTP_PORT));
         assertEquals(BrokerOptions.DEFAULT_RMI_PORT_NUMBER, props.get(BrokerOptions.QPID_RMI_PORT));
         assertEquals(BrokerOptions.DEFAULT_JMX_PORT_NUMBER, props.get(BrokerOptions.QPID_JMX_PORT));
 
+        //clear the value to ensure the default returns
         _options.setConfigProperty(BrokerOptions.QPID_AMQP_PORT, null);
         props = _options.getConfigProperties();
-        assertEquals("unexpected number of entries", 4, props.keySet().size());
+        assertEquals("unexpected number of entries", 5, props.keySet().size());
         assertEquals(oldPort, props.get(BrokerOptions.QPID_AMQP_PORT));
         assertEquals(BrokerOptions.DEFAULT_HTTP_PORT_NUMBER, props.get(BrokerOptions.QPID_HTTP_PORT));
         assertEquals(BrokerOptions.DEFAULT_RMI_PORT_NUMBER, props.get(BrokerOptions.QPID_RMI_PORT));
         assertEquals(BrokerOptions.DEFAULT_JMX_PORT_NUMBER, props.get(BrokerOptions.QPID_JMX_PORT));
 
+        //set a user specified property
         _options.setConfigProperty("name", "value");
         props = _options.getConfigProperties();
-        assertEquals("unexpected number of entries", 5, props.keySet().size());
+        assertEquals("unexpected number of entries", 6, props.keySet().size());
         assertEquals(oldPort, props.get(BrokerOptions.QPID_AMQP_PORT));
         assertEquals(BrokerOptions.DEFAULT_HTTP_PORT_NUMBER, props.get(BrokerOptions.QPID_HTTP_PORT));
         assertEquals(BrokerOptions.DEFAULT_RMI_PORT_NUMBER, props.get(BrokerOptions.QPID_RMI_PORT));



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message