summaryrefslogtreecommitdiff
path: root/qpid/java/broker/src
diff options
context:
space:
mode:
authorAlex Rudyy <orudyy@apache.org>2013-03-11 18:30:31 +0000
committerAlex Rudyy <orudyy@apache.org>2013-03-11 18:30:31 +0000
commit3f138e2ddc02857c61e578aaaf12c82d9eefc93c (patch)
tree3de578ab99d630bc1610a263452c6715a0f0d901 /qpid/java/broker/src
parent66de8678fb2ab2af8dc5b6d653402b1efd70779b (diff)
downloadqpid-python-3f138e2ddc02857c61e578aaaf12c82d9eefc93c.tar.gz
QPID-4639: Add UI to add/delete virtual hosts into java broker web management console
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1455274 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/broker/src')
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java1
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java30
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java6
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java41
-rw-r--r--qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java5
-rw-r--r--qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java11
6 files changed, 87 insertions, 7 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
index 4bfa0ca7a3..48d80592f6 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java
@@ -51,6 +51,7 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker>
StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(entry.getStore());
BrokerAdapter broker = new BrokerAdapter(entry.getId(), entry.getAttributes(), _statisticsGatherer, _virtualHostRegistry,
_logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor);
+
broker.addChangeListener(storeChangeListener);
Map<String, Collection<ConfigurationEntry>> childEntries = entry.getChildren();
for (String type : childEntries.keySet())
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
index d053dd3fe2..5528a05360 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/logging/LogRecorder.java
@@ -24,6 +24,7 @@ import org.apache.log4j.Logger;
import org.apache.log4j.spi.ErrorHandler;
import org.apache.log4j.spi.Filter;
import org.apache.log4j.spi.LoggingEvent;
+import org.apache.log4j.spi.ThrowableInformation;
public class LogRecorder implements Appender, Iterable<LogRecorder.Record>
{
@@ -54,7 +55,34 @@ public class LogRecorder implements Appender, Iterable<LogRecorder.Record>
_timestamp = event.timeStamp;
_threadName = event.getThreadName();
_level = event.getLevel().toString();
- _message = event.getRenderedMessage();
+ StringBuilder message = new StringBuilder();
+ String renderedMessage = event.getRenderedMessage();
+ if (renderedMessage != null)
+ {
+ message.append(renderedMessage);
+ }
+ ThrowableInformation ti = event.getThrowableInformation();
+ if (ti != null)
+ {
+ Throwable t = ti.getThrowable();
+ if (t != null)
+ {
+ if (message.length() > 0)
+ {
+ message.append(":");
+ }
+ String exceptionMessage = t.getMessage();
+ if (exceptionMessage != null && !"".equals(exceptionMessage))
+ {
+ message.append(t.getMessage());
+ }
+ else
+ {
+ message.append(t.getClass().getName());
+ }
+ }
+ }
+ _message = message.toString();
}
public long getId()
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
index 6b7cf98c8a..628ba5a099 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
@@ -63,6 +63,7 @@ import org.apache.qpid.server.security.group.GroupPrincipalAccessor;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.security.SubjectCreator;
import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.server.store.MessageStoreCreator;
import org.apache.qpid.server.util.MapValueConverter;
import org.apache.qpid.server.virtualhost.VirtualHostRegistry;
@@ -168,6 +169,8 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat
private final UUID _defaultKeyStoreId;
private final UUID _defaultTrustStoreId;
+ private Collection<String> _supportedStoreTypes;
+
public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry,
LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory,
PortFactory portFactory, TaskExecutor taskExecutor)
@@ -185,6 +188,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat
_defaultKeyStoreId = UUIDGenerator.generateBrokerChildUUID(KeyStore.class.getSimpleName(), DEFAULT_KEY_STORE_NAME);
_defaultTrustStoreId = UUIDGenerator.generateBrokerChildUUID(TrustStore.class.getSimpleName(), DEFAULT_TRUST_STORE_NAME);
createBrokerChildrenFromAttributes();
+ _supportedStoreTypes = new MessageStoreCreator().getStoreTypes();
}
/*
@@ -646,7 +650,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat
}
else if(SUPPORTED_STORE_TYPES.equals(name))
{
- // TODO
+ return _supportedStoreTypes;
}
else if(SUPPORTED_AUTHENTICATION_PROVIDERS.equals(name))
{
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
index 40af67f211..8680911000 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/VirtualHostAdapter.java
@@ -115,9 +115,9 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
public VirtualHostAdapter(UUID id, Map<String, Object> attributes, Broker broker, StatisticsGatherer brokerStatisticsGatherer, TaskExecutor taskExecutor)
{
super(id, null, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor);
- validateAttributes();
_broker = broker;
_brokerStatisticsGatherer = brokerStatisticsGatherer;
+ validateAttributes();
addParent(Broker.class, broker);
}
@@ -145,11 +145,22 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
{
invalidAttributes = true;
}
+
}
if (invalidAttributes)
{
throw new IllegalConfigurationException("Please specify either the 'configPath' attribute or 'storeType' and 'storePath' attributes");
}
+
+ // pre-load the configuration in order to validate
+ try
+ {
+ createVirtualHostConfiguration(name);
+ }
+ catch(ConfigurationException e)
+ {
+ throw new IllegalConfigurationException("Failed to validate configuration", e);
+ }
}
private void populateExchanges()
@@ -504,11 +515,19 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
{
if(childClass == Exchange.class)
{
- return (C) createExchange(attributes);
+ createExchange(attributes);
+
+ // return null to avoid double notification of VirtualHostMBean
+ // as we already notify it in the exchangeRegistered
+ return null;
}
else if(childClass == Queue.class)
{
- return (C) createQueue(attributes);
+ createQueue(attributes);
+
+ // return null to avoid double notification of VirtualHostMBean
+ // as we already notify it in the queueRegistered
+ return null;
}
else if(childClass == VirtualHostAlias.class)
{
@@ -969,12 +988,24 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
{
throw new IntegrityViolationException("Cannot delete default virtual host '" + hostName + "'");
}
+ String storePath = (String)getAttribute(STORE_PATH);
if (_virtualHost != null && _virtualHost.getState() == org.apache.qpid.server.virtualhost.State.ACTIVE)
{
setDesiredState(currentState, State.STOPPED);
}
_virtualHost = null;
setAttribute(VirtualHost.STATE, getActualState(), State.DELETED);
+ if (storePath != null)
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug("Deleting store at " + storePath);
+ }
+ if (!FileUtils.delete(new File(storePath), true))
+ {
+ LOGGER.warn("Cannot delete " + storePath);
+ }
+ }
return true;
}
return false;
@@ -1034,6 +1065,10 @@ public final class VirtualHostAdapter extends AbstractAdapter implements Virtual
}
else
{
+ if (!new File(configurationFile).exists())
+ {
+ throw new IllegalConfigurationException("Configuration file '" + configurationFile + "' does not exist");
+ }
configuration = new VirtualHostConfiguration(virtualHostName, new File(configurationFile) , _broker);
}
return configuration;
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
index 0bc83c89d2..d67ccfd8a4 100644
--- a/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
+++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/store/MessageStoreCreator.java
@@ -64,4 +64,9 @@ public class MessageStoreCreator
{
return Collections.unmodifiableCollection(_factories.values());
}
+
+ public Collection<String> getStoreTypes()
+ {
+ return Collections.unmodifiableCollection(_factories.keySet());
+ }
}
diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
index eb5b2b350f..adb1f81a43 100644
--- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
+++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/startup/VirtualHostRecovererTest.java
@@ -23,6 +23,7 @@ package org.apache.qpid.server.configuration.startup;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -34,6 +35,7 @@ import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.security.SecurityManager;
import org.apache.qpid.server.stats.StatisticsGatherer;
+import org.apache.qpid.test.utils.TestFileUtils;
public class VirtualHostRecovererTest extends TestCase
{
@@ -43,12 +45,16 @@ public class VirtualHostRecovererTest extends TestCase
SecurityManager securityManager = mock(SecurityManager.class);
ConfigurationEntry entry = mock(ConfigurationEntry.class);
Broker parent = mock(Broker.class);
+ when(parent.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(3000l);
when(parent.getSecurityManager()).thenReturn(securityManager);
VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);
Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(VirtualHost.NAME, getName());
- attributes.put(VirtualHost.CONFIG_PATH, "/path/to/virtualhost.xml");
+ String name = getName();
+ attributes.put(VirtualHost.NAME, name);
+ File file = TestFileUtils.createTempFile(this, ".xml", "<virtualhosts><virtualhost><name>" + name + "</name><" + name
+ + "></" + name + "></virtualhost></virtualhosts>");
+ attributes.put(VirtualHost.CONFIG_PATH, file.getAbsolutePath());
when(entry.getAttributes()).thenReturn(attributes);
VirtualHost host = recoverer.create(null, entry, parent);
@@ -63,6 +69,7 @@ public class VirtualHostRecovererTest extends TestCase
SecurityManager securityManager = mock(SecurityManager.class);
ConfigurationEntry entry = mock(ConfigurationEntry.class);
Broker parent = mock(Broker.class);
+ when(parent.getAttribute(Broker.HOUSEKEEPING_CHECK_PERIOD)).thenReturn(3000l);
when(parent.getSecurityManager()).thenReturn(securityManager);
VirtualHostRecoverer recoverer = new VirtualHostRecoverer(statisticsGatherer);