summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2013-05-04 21:43:02 +0000
committerRobert Gemmell <robbie@apache.org>2013-05-04 21:43:02 +0000
commit3d56781a5a7815ca3cbc09c1d283e79f3c623ced (patch)
tree3f8aec369334d0a75a5d71c0ac89e18c49ef29e3
parentc7f20a1b639fcc66a4928c44c7bdd36d23ac8b47 (diff)
downloadqpid-python-3d56781a5a7815ca3cbc09c1d283e79f3c623ced.tar.gz
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. merged from trunk r1479176 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.22@1479186 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java88
-rw-r--r--qpid/java/broker/src/main/resources/initial-config.json4
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java101
3 files changed, 126 insertions, 67 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
index 3ba4ae6e91..ac6ee55c86 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/BrokerOptions.java
@@ -33,6 +33,21 @@ import org.apache.qpid.server.util.StringUtil;
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);
+ }
}
diff --git a/qpid/java/broker/src/main/resources/initial-config.json b/qpid/java/broker/src/main/resources/initial-config.json
index 02fe942f55..f01ffca140 100644
--- a/qpid/java/broker/src/main/resources/initial-config.json
+++ b/qpid/java/broker/src/main/resources/initial-config.json
@@ -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",
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
index 4b7c99baf1..47710ed485 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
@@ -175,31 +175,6 @@ public class BrokerOptionsTest extends QpidTestCase
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 QpidTestCase
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));