You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2015/02/13 18:13:35 UTC

svn commit: r1659613 - in /qpid/trunk/qpid/java: broker-core/src/main/java/org/apache/qpid/server/ broker-core/src/main/resources/ broker-core/src/test/java/org/apache/qpid/server/ broker/src/main/java/org/apache/qpid/server/

Author: orudyy
Date: Fri Feb 13 17:13:35 2015
New Revision: 1659613

URL: http://svn.apache.org/r1659613
Log:
QPID-6390: [Java Broker] Move setting of initial properties from Main into Broker

Added:
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerTest.java
Removed:
    qpid/trunk/qpid/java/broker-core/src/main/resources/system.properties
Modified:
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/BrokerOptions.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java?rev=1659613&r1=1659612&r2=1659613&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java Fri Feb 13 17:13:35 2015
@@ -23,9 +23,12 @@ package org.apache.qpid.server;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
 import java.util.Properties;
+import java.util.Set;
 
 import javax.security.auth.Subject;
 
@@ -33,6 +36,7 @@ import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
+import org.apache.qpid.common.QpidProperties;
 import org.apache.qpid.server.configuration.BrokerProperties;
 import org.apache.qpid.server.configuration.updater.TaskExecutor;
 import org.apache.qpid.server.configuration.updater.TaskExecutorImpl;
@@ -147,6 +151,8 @@ public class Broker implements BrokerShu
 
     private void startupImpl(final BrokerOptions options) throws Exception
     {
+        populateSystemPropertiesFromDefaults(options.getInitialSystemProperties());
+
         String storeLocation = options.getConfigurationStoreLocation();
         String storeType = options.getConfigurationStoreType();
 
@@ -314,6 +320,34 @@ public class Broker implements BrokerShu
         }
     }
 
+    private void populateSystemPropertiesFromDefaults(final String initialProperties) throws IOException
+    {
+        URL initialPropertiesLocation;
+        if(initialProperties == null)
+        {
+            initialPropertiesLocation = getClass().getClassLoader().getResource("system.properties");
+        }
+        else
+        {
+            initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
+        }
+
+        Properties props = new Properties(QpidProperties.asProperties());
+        if(initialPropertiesLocation != null)
+        {
+            props.load(initialPropertiesLocation.openStream());
+        }
+
+        Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
+        propertyNames.removeAll(System.getProperties().stringPropertyNames());
+        for (String propName : propertyNames)
+        {
+            System.setProperty(propName, props.getProperty(propName));
+        }
+
+    }
+
+
     private class ShutdownService implements Runnable
     {
         public void run()

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/BrokerOptions.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/BrokerOptions.java?rev=1659613&r1=1659612&r2=1659613&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/BrokerOptions.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/BrokerOptions.java Fri Feb 13 17:13:35 2015
@@ -78,6 +78,7 @@ public class BrokerOptions
     private boolean _overwriteConfigurationStore;
     private Map<String, String> _configProperties = new HashMap<String,String>();
     private boolean _startupLoggedToSystemOut = true;
+    private String _initialSystemProperties;
 
     public Map<String, Object> convertToSystemConfigAttributes()
     {
@@ -390,4 +391,24 @@ public class BrokerOptions
     {
         this._startupLoggedToSystemOut = startupLoggedToSystemOut;
     }
+
+    /**
+     * Get the location of initial JVM system properties to set. This can be URL or a file path
+     *
+     * @return the location of initial JVM system properties to set.
+     */
+    public String getInitialSystemProperties()
+    {
+        return _initialSystemProperties;
+    }
+
+    /**
+     * Set the location of initial properties file to set as JVM system properties. This can be URL or a file path
+     *
+     * @param initialSystemProperties the location of initial JVM system properties.
+     */
+    public void setInitialSystemProperties(String initialSystemProperties)
+    {
+        _initialSystemProperties = initialSystemProperties;
+    }
 }

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java?rev=1659613&r1=1659612&r2=1659613&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerOptionsTest.java Fri Feb 13 17:13:35 2015
@@ -309,4 +309,14 @@ public class BrokerOptionsTest extends Q
         assertEquals("unexpected number of entries", 2, props.keySet().size());
         assertEquals("value", props.get("name"));
     }
+
+
+    public void testSetInitialSystemProperties()
+    {
+        assertNull("Unexpected default value for initial system properties", _options.getInitialSystemProperties());
+
+        _options.setInitialSystemProperties("test.properties");
+
+        assertEquals("test.properties", _options.getInitialSystemProperties());
+    }
 }

Added: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerTest.java?rev=1659613&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerTest.java (added)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/BrokerTest.java Fri Feb 13 17:13:35 2015
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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.qpid.server;
+
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+
+import org.apache.qpid.server.model.BrokerModel;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.test.utils.TestFileUtils;
+import org.apache.qpid.util.FileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+
+public class BrokerTest extends QpidTestCase
+{
+    private static final String INITIAL_SYSTEM_PROPERTY = "test";
+    private static final String INITIAL_SYSTEM_PROPERTY_VALUE = "testValue";
+
+    private File _initialSystemProperties;
+    private File _initialConfiguration;
+    private File _brokerWork;
+    private Broker _broker;
+
+    @Override
+    public void setUp() throws Exception
+    {
+        super.setUp();
+
+        // create empty initial configuration
+        Map<String,Object> initialConfig = new HashMap<>();
+        initialConfig.put(ConfiguredObject.NAME, "test");
+        initialConfig.put(org.apache.qpid.server.model.Broker.MODEL_VERSION, BrokerModel.MODEL_VERSION);
+
+        ObjectMapper mapper = new ObjectMapper();
+        String config = mapper.writeValueAsString(initialConfig);
+        _initialConfiguration = TestFileUtils.createTempFile(this, ".initial-config.json", config);
+        _brokerWork = TestFileUtils.createTestDirectory("qpid-work", true);
+        _initialSystemProperties = TestFileUtils.createTempFile(this, ".initial-system.properties",
+                INITIAL_SYSTEM_PROPERTY + "=" + INITIAL_SYSTEM_PROPERTY_VALUE
+                + "\nQPID_WORK=" +  _brokerWork.getAbsolutePath() + "_test");
+        setTestSystemProperty("QPID_WORK", _brokerWork.getAbsolutePath());
+    }
+
+    public void tearDown() throws Exception
+    {
+        try
+        {
+            super.tearDown();
+        }
+        finally
+        {
+            if (_broker != null)
+            {
+                _broker.shutdown();
+            }
+            System.clearProperty(INITIAL_SYSTEM_PROPERTY);
+            FileUtils.delete(_brokerWork, true);
+            FileUtils.delete(_initialSystemProperties, false);
+            FileUtils.delete(_initialConfiguration, false);
+        }
+    }
+
+    public void testInitialSystemPropertiesAreSetOnBrokerStartup() throws Exception
+    {
+        BrokerOptions options = new BrokerOptions();
+        options.setInitialSystemProperties(_initialSystemProperties.getAbsolutePath());
+        options.setSkipLoggingConfiguration(true);
+        options.setStartupLoggedToSystemOut(true);
+        options.setInitialConfigurationLocation(_initialConfiguration.getAbsolutePath());
+        _broker = new Broker();
+        _broker.startup(options);
+
+        // test JVM system property should be set from initial system config file
+        assertEquals("Unexpected JVM system property", INITIAL_SYSTEM_PROPERTY_VALUE, System.getProperty(INITIAL_SYSTEM_PROPERTY));
+
+        // existing system property should not be overridden
+        assertEquals("Unexpected QPID_WORK system property", _brokerWork.getAbsolutePath(), System.getProperty("QPID_WORK"));
+    }
+}

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java?rev=1659613&r1=1659612&r2=1659613&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/Main.java Fri Feb 13 17:13:35 2015
@@ -25,9 +25,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.HashSet;
-import java.util.Properties;
-import java.util.Set;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.HelpFormatter;
@@ -179,11 +176,14 @@ public class Main
 
     protected void execute() throws Exception
     {
-        String initialProperties = _commandLine.getOptionValue(OPTION_INITIAL_SYSTEM_PROPERTIES.getOpt());
-        populateSystemPropertiesFromDefaults(initialProperties);
-
         BrokerOptions options = new BrokerOptions();
 
+        String initialProperties = _commandLine.getOptionValue(OPTION_INITIAL_SYSTEM_PROPERTIES.getOpt());
+        if (initialProperties != null)
+        {
+            options.setInitialSystemProperties(initialProperties);
+        }
+
         String initialConfigLocation = _commandLine.getOptionValue(OPTION_INITIAL_CONFIGURATION_PATH.getOpt());
         if (initialConfigLocation != null)
         {
@@ -320,33 +320,6 @@ public class Main
         }
     }
 
-    private void populateSystemPropertiesFromDefaults(final String initialProperties) throws IOException
-    {
-        URL initialPropertiesLocation;
-        if(initialProperties == null)
-        {
-            initialPropertiesLocation = getClass().getClassLoader().getResource("system.properties");
-        }
-        else
-        {
-            initialPropertiesLocation = (new File(initialProperties)).toURI().toURL();
-        }
-
-        Properties props = new Properties(QpidProperties.asProperties());
-        if(initialPropertiesLocation != null)
-        {
-            props.load(initialPropertiesLocation.openStream());
-        }
-
-        Set<String> propertyNames = new HashSet<>(props.stringPropertyNames());
-        propertyNames.removeAll(System.getProperties().stringPropertyNames());
-        for (String propName : propertyNames)
-        {
-            System.setProperty(propName, props.getProperty(propName));
-        }
-
-    }
-
     private void copyInitialConfigFile(final BrokerOptions options, final File destinationFile)
     {
         String initialConfigLocation = options.getInitialConfigurationLocation();



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