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 2012/11/02 10:47:17 UTC
svn commit: r1404902 [2/2] - in
/qpid/branches/java-broker-config-qpid-4390/qpid/java:
bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/
broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/
broker-plugins...
Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java?rev=1404902&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java (added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/plugin/PluginFactory.java Fri Nov 2 09:47:15 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.plugin;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+
+public interface PluginFactory
+{
+ static final String PLUGIN_TYPE = "pluginType";
+
+ ConfiguredObject createInstance(UUID id, Map<String, Object> attributes, Broker broker);
+}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java?rev=1404902&r1=1404901&r2=1404902&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java Fri Nov 2 09:47:15 2012
@@ -22,10 +22,8 @@ package org.apache.qpid.server.registry;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
@@ -42,6 +40,7 @@ import org.apache.qpid.server.configurat
import org.apache.qpid.server.configuration.startup.AuthenticationProviderRecoverer;
import org.apache.qpid.server.configuration.startup.BrokerRecoverer;
import org.apache.qpid.server.configuration.startup.GroupProviderRecoverer;
+import org.apache.qpid.server.configuration.startup.PluginRecoverer;
import org.apache.qpid.server.configuration.startup.PortRecoverer;
import org.apache.qpid.server.configuration.startup.VirtualHostRecoverer;
import org.apache.qpid.server.configuration.store.XMLConfigurationEntryStore;
@@ -57,7 +56,6 @@ import org.apache.qpid.server.logging.ac
import org.apache.qpid.server.logging.actors.GenericActor;
import org.apache.qpid.server.logging.messages.BrokerMessages;
import org.apache.qpid.server.logging.messages.VirtualHostMessages;
-import org.apache.qpid.server.management.plugin.ManagementPlugin;
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.Port;
@@ -66,7 +64,7 @@ import org.apache.qpid.server.model.adap
import org.apache.qpid.server.model.adapter.PortFactory;
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
import org.apache.qpid.server.plugin.GroupManagerFactory;
-import org.apache.qpid.server.plugin.ManagementFactory;
+import org.apache.qpid.server.plugin.PluginFactory;
import org.apache.qpid.server.plugin.QpidServiceLoader;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
@@ -105,8 +103,6 @@ public class ApplicationRegistry impleme
private LogRecorder _logRecorder;
- private final List<ManagementPlugin> _managmentInstanceList = new ArrayList<ManagementPlugin>();
-
private final BrokerOptions _brokerOptions;
protected void setSecurityManager(SecurityManager securityManager)
@@ -245,7 +241,6 @@ public class ApplicationRegistry impleme
// starting the broker
_broker.setDesiredState(State.INITIALISING, State.ACTIVE);
- createAndStartManagementPlugins(_configuration);
CurrentActor.get().message(BrokerMessages.READY());
}
finally
@@ -281,6 +276,8 @@ public class ApplicationRegistry impleme
GroupProviderRecoverer groupProviderRecoverer = new GroupProviderRecoverer(new QpidServiceLoader<GroupManagerFactory>());
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(new QpidServiceLoader<PluginFactory>());
+
BrokerRecoverer brokerRecoverer = new BrokerRecoverer(
portRecoverer,
virtualHostRecoverer,
@@ -288,55 +285,12 @@ public class ApplicationRegistry impleme
authenticationProviderFactory,
portFactory,
groupProviderRecoverer,
+ pluginRecoverer,
this);
_broker = brokerRecoverer.create(store.getRootEntry());
}
- private void createAndStartManagementPlugins(ServerConfiguration configuration) throws Exception
- {
- QpidServiceLoader<ManagementFactory> factories = new QpidServiceLoader<ManagementFactory>();
- for (ManagementFactory managementFactory: factories.instancesOf(ManagementFactory.class))
- {
- ManagementPlugin managementPlugin = managementFactory.createInstance(configuration, _broker);
- if(managementPlugin != null)
- {
- try
- {
- managementPlugin.start();
- }
- catch(Exception e)
- {
- _logger.error("Management plugin " + managementPlugin.getClass().getSimpleName() + " failed to start normally, stopping it now", e);
- managementPlugin.stop();
- throw e;
- }
-
- _managmentInstanceList.add(managementPlugin);
- }
- }
-
- if (_logger.isDebugEnabled())
- {
- _logger.debug("Configured " + _managmentInstanceList.size() + " management instance(s)");
- }
- }
-
- private void closeAllManagementPlugins()
- {
- for (ManagementPlugin managementPlugin : _managmentInstanceList)
- {
- try
- {
- managementPlugin.stop();
- }
- catch (Exception e)
- {
- _logger.error("Exception thrown whilst stopping management plugin " + managementPlugin.getClass().getSimpleName(), e);
- }
- }
- }
-
public void initialiseStatisticsReporting()
{
long report = _configuration.getStatisticsReportingPeriod() * 1000; // convert to ms
@@ -471,8 +425,6 @@ public class ApplicationRegistry impleme
_reportingTimer.cancel();
}
- closeAllManagementPlugins();
-
if (_broker != null)
{
_broker.setDesiredState(_broker.getActualState(), State.STOPPED);
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java?rev=1404902&r1=1404901&r2=1404902&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/BrokerRecovererTest.java Fri Nov 2 09:47:15 2012
@@ -29,6 +29,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.UUID;
@@ -37,6 +38,7 @@ import junit.framework.TestCase;
import org.apache.qpid.server.configuration.ConfigurationEntry;
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
import org.apache.qpid.server.model.ConfiguredObjectType;
import org.apache.qpid.server.model.GroupProvider;
import org.apache.qpid.server.model.Port;
@@ -65,13 +67,14 @@ public class BrokerRecovererTest extends
private UUID _brokerId = UUID.randomUUID();
private Map<ConfiguredObjectType, Collection<ConfigurationEntry>> _entryChildren = new HashMap<ConfiguredObjectType, Collection<ConfigurationEntry>>();
+ private PluginRecoverer _pluginRecoverer = mock(PluginRecoverer.class);
+
@Override
protected void setUp() throws Exception
{
super.setUp();
-
_brokerRecoverer = new BrokerRecoverer(_portRecoverer, _virtualHostRecoverer, _authenticationProviderRecoverer,
- _authenticationProviderFactory, _portFactory, _groupProviderRecoverer, _applicationRegistry);
+ _authenticationProviderFactory, _portFactory, _groupProviderRecoverer, _pluginRecoverer, _applicationRegistry);
when(_entry.getId()).thenReturn(_brokerId);
when(_entry.getChildren()).thenReturn(_entryChildren);
@@ -142,4 +145,19 @@ public class BrokerRecovererTest extends
assertEquals(_brokerId, broker.getId());
assertEquals(Collections.singletonList(groupProvider), broker.getGroupProviders());
}
+
+ public void testCreateBrokerWithPlugins()
+ {
+ ConfigurationEntry pluginEntry = mock(ConfigurationEntry.class);
+ ConfiguredObject plugin = mock(ConfiguredObject.class);
+ _entryChildren.put(ConfiguredObjectType.PLUGIN, Arrays.asList(pluginEntry));
+
+ when(_pluginRecoverer.create(same(pluginEntry), any(Broker.class))).thenReturn(plugin);
+
+ Broker broker = _brokerRecoverer.create(_entry);
+
+ assertNotNull(broker);
+ assertEquals(_brokerId, broker.getId());
+ assertEquals(Collections.singleton(plugin), new HashSet<ConfiguredObject>(broker.getChildren(ConfiguredObject.class)));
+ }
}
Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java?rev=1404902&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java (added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/PluginRecovererTest.java Fri Nov 2 09:47:15 2012
@@ -0,0 +1,116 @@
+/*
+ *
+ * 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.configuration.startup;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.qpid.server.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.plugin.PluginFactory;
+import org.apache.qpid.server.plugin.QpidServiceLoader;
+
+public class PluginRecovererTest extends TestCase
+{
+ private UUID _id;
+ private Map<String, Object> _attributes;
+
+ private PluginFactory _factory;
+ private QpidServiceLoader<PluginFactory> _pluginFactoryServiceLoader;
+ private Broker _broker;
+ private ConfigurationEntry _configurationEntry;
+
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ _id = UUID.randomUUID();
+ _attributes = new HashMap<String, Object>();
+
+ _factory = mock(PluginFactory.class);
+
+ _pluginFactoryServiceLoader = mock(QpidServiceLoader.class);
+ when(_pluginFactoryServiceLoader.instancesOf(PluginFactory.class)).thenReturn(Collections.singletonList(_factory ));
+
+ _broker = mock(Broker.class);
+
+ _configurationEntry = mock(ConfigurationEntry.class);
+ when(_configurationEntry.getId()).thenReturn(_id);
+ when(_configurationEntry.getAttributes()).thenReturn(_attributes);
+ }
+
+ public void testCreate()
+ {
+ ConfiguredObject pluginFromFactory = mock(ConfiguredObject.class);
+ when(pluginFromFactory.getId()).thenReturn(_id);
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ ConfiguredObject pluginFromRecoverer = pluginRecoverer.create(_configurationEntry, _broker);
+ assertNotNull("Null group provider", pluginFromRecoverer);
+ assertSame("Unexpected plugin", pluginFromFactory, pluginFromRecoverer);
+ assertEquals("Unexpected ID", _id, pluginFromRecoverer.getId());
+ }
+
+ public void testCreateThrowsExceptionForUnexpectedId()
+ {
+ ConfiguredObject pluginFromFactory = mock(ConfiguredObject.class);
+ when(pluginFromFactory.getId()).thenReturn(UUID.randomUUID());
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(pluginFromFactory);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(_configurationEntry, _broker);
+ fail("An exception should be thrown for incorrect id");
+ }
+ catch(IllegalStateException e)
+ {
+ //pass
+ }
+ }
+
+ public void testCreateThrowsExceptionWhenNoPluginIsCreated()
+ {
+ when(_factory.createInstance(_id, _attributes, _broker)).thenReturn(null);
+
+ PluginRecoverer pluginRecoverer = new PluginRecoverer(_pluginFactoryServiceLoader);
+ try
+ {
+ pluginRecoverer.create(_configurationEntry, _broker);
+ fail("Configuration exception should be thrown when plugin is not created");
+ }
+ catch(IllegalConfigurationException e)
+ {
+ // pass
+ }
+ }
+
+}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java?rev=1404902&r1=1404901&r2=1404902&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/store/MessageStoreTest.java Fri Nov 2 09:47:15 2012
@@ -98,7 +98,7 @@ public class MessageStoreTest extends In
public void setUp() throws Exception
{
getConfigXml().addProperty("management.enabled", "false");
-
+ getConfigXml().addProperty("management.http.enabled", "false");
super.setUp();
String storePath = System.getProperty("QPID_WORK") + File.separator + getName();
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java?rev=1404902&r1=1404901&r2=1404902&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/TestApplicationRegistry.java Fri Nov 2 09:47:15 2012
@@ -43,6 +43,7 @@ public class TestApplicationRegistry ext
{
LoggingManagementFacade.configure("test-profiles/log4j-test.xml");
getConfiguration().getConfig().addProperty("security." + TestAuthenticationManagerFactory.TEST_AUTH_MANAGER_MARKER, "");
+
super.initialise();
CurrentActor.setDefault(new BrokerActor(new NullRootMessageLogger()));
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org