diff options
author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-04 21:06:08 +0000 |
---|---|---|
committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-04 21:06:08 +0000 |
commit | 0a64e2b857dc189a621d51dffedf573746bd08e5 (patch) | |
tree | f5a63a23efb6730afbd080936b0293eda7e19811 | |
parent | 127bb406f3ce57cb091bf849580b579411b472a6 (diff) | |
download | qpid-python-0a64e2b857dc189a621d51dffedf573746bd08e5.tar.gz |
removed references to ConfigurationEntry
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/java-broker-config-store-changes@1584910 13f79535-47bb-0310-9956-ffa450edef68
52 files changed, 888 insertions, 846 deletions
diff --git a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java index 67c89718f6..07e5999429 100644 --- a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java +++ b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBBackupTest.java @@ -61,7 +61,7 @@ public class BDBBackupTest extends QpidBrokerTestCase super.setUp(); _backupToDir = new File(SYSTEM_TMP_DIR + File.separator + getTestName()); _backupToDir.mkdirs(); - Map<String, Object> virtualHostAttributes = getBrokerConfiguration().getObjectAttributes(TEST_VHOST); + Map<String, Object> virtualHostAttributes = getBrokerConfiguration().getObjectAttributes(VirtualHost.class,TEST_VHOST); Map<String, Object> messageStoreSettings = (Map<String, Object>) virtualHostAttributes.get(VirtualHost.MESSAGE_STORE_SETTINGS); _backupFromDir = new File((String)messageStoreSettings.get(MessageStore.STORE_PATH)); boolean fromDirExistsAndIsDir = _backupFromDir.isDirectory(); diff --git a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java index 921eb916ea..a7b6ea107d 100644 --- a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java +++ b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBUpgradeTest.java @@ -42,6 +42,9 @@ import javax.jms.TopicSubscriber; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularDataSupport; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.qpid.management.common.mbeans.ManagedExchange; import org.apache.qpid.management.common.mbeans.ManagedQueue; import org.apache.qpid.server.model.VirtualHost; @@ -50,8 +53,6 @@ import org.apache.qpid.test.utils.JMXTestUtils; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.util.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Tests upgrading a BDB store on broker startup. @@ -84,7 +85,7 @@ public class BDBUpgradeTest extends QpidBrokerTestCase public void setUp() throws Exception { assertNotNull("QPID_WORK must be set", QPID_WORK_ORIG); - Map<String, Object> virtualHostAttributes = getBrokerConfiguration().getObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + Map<String, Object> virtualHostAttributes = getBrokerConfiguration().getObjectAttributes(VirtualHost.class,TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); @SuppressWarnings("unchecked") Map<String, Object> messageStoreSettings = (Map<String, Object>) virtualHostAttributes.get(VirtualHost.MESSAGE_STORE_SETTINGS); _storeLocation = (String)messageStoreSettings.get(MessageStore.STORE_PATH); diff --git a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java index 4efe1967ce..7711ce1bf6 100644 --- a/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java +++ b/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java @@ -38,8 +38,10 @@ import java.util.concurrent.TimeUnit; import javax.jms.Connection; +import com.sleepycat.je.rep.ReplicationConfig; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; + import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQConnectionURL; import org.apache.qpid.server.model.VirtualHost; @@ -49,8 +51,6 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.url.URLSyntaxException; -import com.sleepycat.je.rep.ReplicationConfig; - public class HATestClusterCreator { protected static final Logger LOGGER = Logger.getLogger(HATestClusterCreator.class); @@ -117,8 +117,8 @@ public class HATestClusterCreator TestBrokerConfiguration brokerConfiguration = _testcase.getBrokerConfiguration(brokerPort); brokerConfiguration.addJmxManagementConfiguration(); - brokerConfiguration.setObjectAttribute(_virtualHostName, VirtualHost.TYPE, BDBHAVirtualHostFactory.TYPE); - brokerConfiguration.setObjectAttribute(_virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); + brokerConfiguration.setObjectAttribute(VirtualHost.class, _virtualHostName, VirtualHost.TYPE, BDBHAVirtualHostFactory.TYPE); + brokerConfiguration.setObjectAttribute(VirtualHost.class, _virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); brokerPort = _testcase.getNextAvailable(bdbPort + 1); } @@ -133,9 +133,9 @@ public class HATestClusterCreator } TestBrokerConfiguration config = _testcase.getBrokerConfiguration(_primaryBrokerPort); @SuppressWarnings("unchecked") - Map<String, Object> storeSetting = (Map<String, Object>) config.getObjectAttributes(_virtualHostName).get(VirtualHost.MESSAGE_STORE_SETTINGS); + Map<String, Object> storeSetting = (Map<String, Object>) config.getObjectAttributes(VirtualHost.class, _virtualHostName).get(VirtualHost.MESSAGE_STORE_SETTINGS); storeSetting.put(ReplicatedEnvironmentFacadeFactory.DESIGNATED_PRIMARY, designatedPrimary); - config.setObjectAttribute(_virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, storeSetting); + config.setObjectAttribute(VirtualHost.class, _virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, storeSetting); config.setSaved(false); } @@ -274,7 +274,8 @@ public class HATestClusterCreator return new AMQConnectionURL(String.format(MANY_BROKER_URL_FORMAT, _virtualHostName, brokerList, FAILOVER_CYCLECOUNT)); } - public AMQConnectionURL getConnectionUrlForSingleNodeWithoutRetry(final int brokerPortNumber) throws URLSyntaxException + public AMQConnectionURL getConnectionUrlForSingleNodeWithoutRetry(final int brokerPortNumber) throws + URLSyntaxException { return getConnectionUrlForSingleNode(brokerPortNumber, false); } @@ -370,13 +371,13 @@ public class HATestClusterCreator TestBrokerConfiguration config = _testcase.getBrokerConfiguration(brokerPortNumberToBeMoved); @SuppressWarnings("unchecked") - Map<String, Object> storeSetting = (Map<String, Object>) config.getObjectAttributes(_virtualHostName).get(VirtualHost.MESSAGE_STORE_SETTINGS); + Map<String, Object> storeSetting = (Map<String, Object>) config.getObjectAttributes(VirtualHost.class, _virtualHostName).get(VirtualHost.MESSAGE_STORE_SETTINGS); String oldBdbHostPort = (String) storeSetting.get(ReplicatedEnvironmentFacadeFactory.NODE_ADDRESS); String[] oldHostAndPort = StringUtils.split(oldBdbHostPort, ":"); String oldHost = oldHostAndPort[0]; String newBdbHostPort = oldHost + ":" + newBdbPort; storeSetting.put(ReplicatedEnvironmentFacadeFactory.NODE_ADDRESS, newBdbHostPort); - config.setObjectAttribute(_virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, storeSetting); + config.setObjectAttribute(VirtualHost.class, _virtualHostName, VirtualHost.MESSAGE_STORE_SETTINGS, storeSetting); config.setSaved(false); } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java index 4c70787af2..810f2d43c7 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/Broker.java @@ -29,10 +29,12 @@ import java.util.List; import java.util.Properties; import java.util.Set; +import javax.security.auth.Subject; + import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; + import org.apache.qpid.server.configuration.BrokerConfigurationStoreCreator; import org.apache.qpid.server.configuration.store.ManagementModeStoreHandler; import org.apache.qpid.server.configuration.updater.TaskExecutor; @@ -46,8 +48,7 @@ import org.apache.qpid.server.model.SystemContext; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.registry.IApplicationRegistry; import org.apache.qpid.server.security.SecurityManager; - -import javax.security.auth.Subject; +import org.apache.qpid.server.store.DurableConfigurationStore; public class Broker { @@ -137,7 +138,7 @@ public class Broker SystemContext systemContext = new SystemContext(taskExecutor, configuredObjectFactory, _eventLogger, logRecorder, options); BrokerConfigurationStoreCreator storeCreator = new BrokerConfigurationStoreCreator(); - ConfigurationEntryStore store = storeCreator.createStore(systemContext, storeType, options.getInitialConfigurationLocation(), + DurableConfigurationStore store = storeCreator.createStore(systemContext, storeType, options.getInitialConfigurationLocation(), options.isOverwriteConfigurationStore(), options.getConfigProperties()); if (options.isManagementMode()) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java index fbc56d7bf3..dd33d9ab09 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/BrokerConfigurationStoreCreator.java @@ -67,7 +67,7 @@ public class BrokerConfigurationStoreCreator */ public ConfigurationEntryStore createStore(SystemContext systemContext, String storeType, String initialConfigLocation, boolean overwrite, Map<String, String> configProperties) { - ConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(initialConfigLocation, null, configProperties); + ConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(systemContext, initialConfigLocation, null, configProperties); ConfigurationStoreFactory factory = _factories.get(storeType.toLowerCase()); if (factory == null) { diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryImpl.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryImpl.java index fd5a12da45..46fd5e0e0a 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryImpl.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryImpl.java @@ -28,6 +28,8 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; + public class ConfigurationEntryImpl implements ConfigurationEntry { @@ -35,10 +37,10 @@ public class ConfigurationEntryImpl implements ConfigurationEntry private final String _type; private final Map<String, Object> _attributes; private final Set<UUID> _childrenIds; - private final ConfigurationEntryStore _store; + private final MemoryConfigurationEntryStore _store; public ConfigurationEntryImpl(UUID id, String type, Map<String, Object> attributes, Set<UUID> childrenIds, - ConfigurationEntryStore store) + MemoryConfigurationEntryStore store) { super(); _id = id; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java index ab8f3d19cf..11e92fcff9 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java @@ -20,54 +20,12 @@ */ package org.apache.qpid.server.configuration; -import org.apache.qpid.server.model.ConfiguredObject; -import org.apache.qpid.server.store.ConfigurationRecoveryHandler; -import org.apache.qpid.server.store.ConfiguredObjectRecord; import org.apache.qpid.server.store.DurableConfigurationStore; -import org.apache.qpid.server.store.StoreException; - -import java.util.UUID; public interface ConfigurationEntryStore extends DurableConfigurationStore { /** - * Returns stored root configuration entry - * - * @return root entry - */ - ConfigurationEntry getRootEntry(); - - /** - * Returns the configuration entry with a given id. - * - * @return entry with a given id or null if entry does not exists - */ - ConfigurationEntry getEntry(UUID id); - - /** - * Saves given entries in the store. - * - * @param entries entries to store - * @throws IllegalConfigurationException if save operation fails - */ - void save(ConfigurationEntry... entries); - - void create(ConfiguredObjectRecord object); - void update(boolean createIfNecessary, ConfiguredObjectRecord... records) throws StoreException; - - - /** - * Removes the entries with given IDs and all their children - * - * @param records records to remove - * @return IDs of removed record - * @throws IllegalConfigurationException if remove operation fails - */ - - UUID[] remove(ConfiguredObjectRecord... records); - - /** * Copies the store into the given location * * @param target location to copy store into diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java index cc2e6160c3..1446cca156 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/BrokerStoreUpgrader.java @@ -19,8 +19,17 @@ package org.apache.qpid.server.configuration.startup;/* * */ +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + import org.apache.log4j.Logger; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; + import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener; import org.apache.qpid.server.model.Broker; @@ -33,8 +42,6 @@ import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.DurableConfigurationStoreUpgrader; import org.apache.qpid.server.store.NonNullUpgrader; -import java.util.*; - public class BrokerStoreUpgrader { private static Logger LOGGER = Logger.getLogger(BrokerStoreUpgrader.class); @@ -574,7 +581,7 @@ public class BrokerStoreUpgrader - public Broker upgrade(ConfigurationEntryStore store) + public Broker upgrade(DurableConfigurationStore store) { final BrokerStoreRecoveryHandler recoveryHandler = new BrokerStoreRecoveryHandler(_systemContext); store.openConfigurationStore(_systemContext, Collections.<String,Object>emptyMap()); diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java index 08e3ebeb50..21fffea80f 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java @@ -20,17 +20,23 @@ */ package org.apache.qpid.server.configuration.store; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + import org.apache.log4j.Logger; + import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; 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.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.SystemContext; import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.ConfigurationRecoveryHandler; import org.apache.qpid.server.store.ConfiguredObjectRecord; @@ -39,9 +45,7 @@ import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.StoreException; import org.apache.qpid.server.util.MapValueConverter; -import java.util.*; - -public class ManagementModeStoreHandler implements ConfigurationEntryStore +public class ManagementModeStoreHandler implements DurableConfigurationStore { private static final Logger LOGGER = Logger.getLogger(ManagementModeStoreHandler.class); @@ -52,50 +56,19 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore private static final Object MANAGEMENT_MODE_AUTH_PROVIDER = "mm-auth"; - private final ConfigurationEntryStore _store; - private final Map<UUID, ConfigurationEntry> _cliEntries; + private final DurableConfigurationStore _store; + private Map<UUID, ConfiguredObjectRecord> _cliEntries; private final Map<UUID, Object> _quiescedEntriesOriginalState; - private final UUID _rootId; private final BrokerOptions _options; private ConfiguredObject<?> _parent; + private HashMap<UUID, ConfiguredObjectRecord> _records; - public ManagementModeStoreHandler(ConfigurationEntryStore store, BrokerOptions options) + public ManagementModeStoreHandler(DurableConfigurationStore store, + BrokerOptions options) { - ConfigurationEntry storeRoot = store.getRootEntry(); _options = options; _store = store; - _rootId = storeRoot.getId(); - _cliEntries = createPortsFromCommandLineOptions(options); - _quiescedEntriesOriginalState = quiesceEntries(storeRoot, options); - } - - @Override - public ConfigurationEntry getRootEntry() - { - return getEntry(_rootId); - } - - @Override - public ConfigurationEntry getEntry(UUID id) - { - synchronized (_store) - { - if (_cliEntries.containsKey(id)) - { - return _cliEntries.get(id); - } - - ConfigurationEntry entry = _store.getEntry(id); - if (_quiescedEntriesOriginalState.containsKey(id)) - { - entry = createEntryWithState(entry, State.QUIESCED); - } - else if (id == _rootId) - { - entry = createRootWithCLIEntries(entry); - } - return entry; - } + _quiescedEntriesOriginalState = quiesceEntries(options); } @Override @@ -104,13 +77,9 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { _parent = parent; _store.openConfigurationStore(parent,storeSettings); - } - @Override - public void recoverConfigurationStore(final ConfigurationRecoveryHandler recoveryHandler) throws StoreException - { - final Map<UUID,ConfiguredObjectRecord> records = new HashMap<UUID, ConfiguredObjectRecord>(); + _records = new HashMap<UUID, ConfiguredObjectRecord>(); final ConfigurationRecoveryHandler localRecoveryHandler = new ConfigurationRecoveryHandler() { private int _version; @@ -177,12 +146,12 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore Map<String,Object> modifiedAttributes = new HashMap<String, Object>(attributes); modifiedAttributes.put(ATTRIBUTE_STATE, State.QUIESCED); ConfiguredObjectRecord record = new ConfiguredObjectRecordImpl(object.getId(), object.getType(), modifiedAttributes, object.getParents()); - records.put(record.getId(), record); + _records.put(record.getId(), record); } else { - records.put(object.getId(), object); + _records.put(object.getId(), object); } } @@ -194,22 +163,29 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore } }; - ConfiguredObjectRecord parent = records.get(_parent.getId()); - if(parent == null) - { - parent = _parent.asObjectRecord(); - } - for(ConfigurationEntry entry : _cliEntries.values()) + + + + _store.recoverConfigurationStore(localRecoveryHandler); + + _cliEntries = createPortsFromCommandLineOptions(_options); + + for(ConfiguredObjectRecord entry : _cliEntries.values()) { - records.put(entry.getId(),new ConfiguredObjectRecordImpl(entry.getId(), entry.getType(), entry.getAttributes(), Collections.singletonMap(parent.getType(), parent))); + _records.put(entry.getId(),entry); } - _store.recoverConfigurationStore(localRecoveryHandler); + } + + @Override + public void recoverConfigurationStore(final ConfigurationRecoveryHandler recoveryHandler) throws StoreException + { + recoveryHandler.beginConfigurationRecovery(this,0); - for(ConfiguredObjectRecord record : records.values()) + for(ConfiguredObjectRecord record : _records.values()) { recoveryHandler.configuredObject(record); } @@ -222,26 +198,9 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { synchronized (_store) { - Collection<ConfigurationEntry> entriesToSave = new ArrayList<ConfigurationEntry>(); - entriesToSave.add(new ConfigurationEntryImpl(object.getId(), - object.getType(), - object.getAttributes(), - Collections.<UUID>emptySet(), - this)); - for (ConfiguredObjectRecord parent : object.getParents().values()) - { - ConfigurationEntry parentEntry = getEntry(parent.getId()); - Set<UUID> children = new HashSet<UUID>(parentEntry.getChildrenIds()); - children.add(object.getId()); - ConfigurationEntry replacementEntry = new ConfigurationEntryImpl(parentEntry.getId(), - parent.getType(), - parent.getAttributes(), - children, - this); - entriesToSave.add(replacementEntry); - } - save(entriesToSave.toArray(new ConfigurationEntry[entriesToSave.size()])); + _store.create(object); } + _records.put(object.getId(), object); } @Override @@ -249,77 +208,28 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { synchronized (_store) { - Map<UUID, ConfigurationEntry> updates = new HashMap<UUID, ConfigurationEntry>(); + Collection<ConfiguredObjectRecord> actualUpdates = new ArrayList<ConfiguredObjectRecord>(); - for (ConfiguredObjectRecord record : records) + for(ConfiguredObjectRecord record : records) { - Set<UUID> currentChildren; - - final ConfigurationEntry entry = getEntry(record.getId()); - - if (entry == null) + if (_cliEntries.containsKey(record.getId())) { - if (createIfNecessary) - { - currentChildren = new HashSet<UUID>(); - } - else - { - throw new StoreException("Cannot update record with id " - + record.getId() - + " as it does not exist"); - } + throw new IllegalConfigurationException("Cannot save configuration provided as command line argument:" + + record); } - else + else if (_quiescedEntriesOriginalState.containsKey(record.getId())) { - currentChildren = new HashSet<UUID>(entry.getChildrenIds()); - } - - updates.put(record.getId(), - new ConfigurationEntryImpl(record.getId(), - record.getType(), - record.getAttributes(), - currentChildren, - this) - ); - } - - for (ConfiguredObjectRecord record : records) - { - for (ConfiguredObjectRecord parent : record.getParents().values()) - { - ConfigurationEntry existingParentEntry = updates.get(parent.getId()); - if (existingParentEntry == null) - { - existingParentEntry = getEntry(parent.getId()); - if (existingParentEntry == null) - { - if(parent.getType().equals(SystemContext.class.getSimpleName())) - { - continue; - } - throw new StoreException("Unknown parent of type " + parent.getType() + " with id " + parent - .getId()); - } - - Set<UUID> children = new HashSet<UUID>(existingParentEntry.getChildrenIds()); - if (!children.contains(record.getId())) - { - children.add(record.getId()); - ConfigurationEntry newParentEntry = new ConfigurationEntryImpl(existingParentEntry.getId(), - existingParentEntry.getType(), - existingParentEntry.getAttributes(), - children, - this); - updates.put(newParentEntry.getId(), newParentEntry); - } - } + // save entry with the original state + record = createEntryWithState(record, _quiescedEntriesOriginalState.get(record.getId())); } - + actualUpdates.add(record); } - - save(updates.values().toArray(new ConfigurationEntry[updates.size()])); + _store.update(createIfNecessary, actualUpdates.toArray(new ConfiguredObjectRecord[actualUpdates.size()])); + } + for(ConfiguredObjectRecord record : records) + { + _records.put(record.getId(), record); } } @@ -328,44 +238,6 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { } - @Override - public void save(ConfigurationEntry... entries) - { - synchronized (_store) - { - ConfigurationEntry[] entriesToSave = new ConfigurationEntry[entries.length]; - - for (int i = 0; i < entries.length; i++) - { - ConfigurationEntry entry = entries[i]; - UUID id = entry.getId(); - if (_cliEntries.containsKey(id)) - { - throw new IllegalConfigurationException("Cannot save configuration provided as command line argument:" - + entry); - } - else if (_quiescedEntriesOriginalState.containsKey(id)) - { - // save entry with the original state - entry = createEntryWithState(entry, _quiescedEntriesOriginalState.get(id)); - } - else if (_rootId.equals(id)) - { - // save root without command line entries - Set<UUID> childrenIds = new HashSet<UUID>(entry.getChildrenIds()); - if (!_cliEntries.isEmpty()) - { - childrenIds.removeAll(_cliEntries.keySet()); - } - HashMap<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); - entry = new ConfigurationEntryImpl(entry.getId(), entry.getType(), attributes, childrenIds, this); - } - entriesToSave[i] = entry; - } - - _store.save(entriesToSave); - } - } @Override public synchronized UUID[] remove(final ConfiguredObjectRecord... records) @@ -394,38 +266,15 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore _quiescedEntriesOriginalState.remove(id); } } + for(ConfiguredObjectRecord record : records) + { + _records.remove(record.getId()); + } return result; } } - @Override - public void copyTo(String copyLocation) - { - synchronized (_store) - { - _store.copyTo(copyLocation); - } - } - - @Override - public String getStoreLocation() - { - return _store.getStoreLocation(); - } - - @Override - public int getVersion() - { - return _store.getVersion(); - } - - @Override - public String getType() - { - return _store.getType(); - } - - private Map<UUID, ConfigurationEntry> createPortsFromCommandLineOptions(BrokerOptions options) + private Map<UUID, ConfiguredObjectRecord> createPortsFromCommandLineOptions(BrokerOptions options) { int managementModeRmiPortOverride = options.getManagementModeRmiPortOverride(); if (managementModeRmiPortOverride < 0) @@ -442,32 +291,34 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { throw new IllegalConfigurationException("Invalid http port is specified: " + managementModeHttpPortOverride); } - Map<UUID, ConfigurationEntry> cliEntries = new HashMap<UUID, ConfigurationEntry>(); + Map<UUID, ConfiguredObjectRecord> cliEntries = new HashMap<UUID, ConfiguredObjectRecord>(); if (managementModeRmiPortOverride != 0) { - ConfigurationEntry entry = createCLIPortEntry(managementModeRmiPortOverride, Protocol.RMI); + ConfiguredObjectRecord entry = createCLIPortEntry(managementModeRmiPortOverride, Protocol.RMI); cliEntries.put(entry.getId(), entry); if (managementModeJmxPortOverride == 0) { - ConfigurationEntry connectorEntry = createCLIPortEntry(managementModeRmiPortOverride + 100, Protocol.JMX_RMI); + ConfiguredObjectRecord connectorEntry = createCLIPortEntry(managementModeRmiPortOverride + 100, Protocol.JMX_RMI); cliEntries.put(connectorEntry.getId(), connectorEntry); } } if (managementModeJmxPortOverride != 0) { - ConfigurationEntry entry = createCLIPortEntry(managementModeJmxPortOverride, Protocol.JMX_RMI); + ConfiguredObjectRecord entry = createCLIPortEntry(managementModeJmxPortOverride, Protocol.JMX_RMI); cliEntries.put(entry.getId(), entry); } if (managementModeHttpPortOverride != 0) { - ConfigurationEntry entry = createCLIPortEntry(managementModeHttpPortOverride, Protocol.HTTP); + ConfiguredObjectRecord entry = createCLIPortEntry(managementModeHttpPortOverride, Protocol.HTTP); cliEntries.put(entry.getId(), entry); } return cliEntries; } - private ConfigurationEntry createCLIPortEntry(int port, Protocol protocol) + private ConfiguredObjectRecord createCLIPortEntry(int port, Protocol protocol) { + ConfiguredObjectRecord parent = findBroker(); + Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(Port.PORT, port); attributes.put(Port.PROTOCOLS, Collections.singleton(protocol)); @@ -476,8 +327,8 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { attributes.put(Port.AUTHENTICATION_PROVIDER, MANAGEMENT_MODE_AUTH_PROVIDER); } - ConfigurationEntry portEntry = new ConfigurationEntryImpl(UUID.randomUUID(), PORT_TYPE, attributes, - Collections.<UUID> emptySet(), this); + ConfiguredObjectRecord portEntry = new ConfiguredObjectRecordImpl(UUID.randomUUID(), PORT_TYPE, attributes, + Collections.singletonMap(parent.getType(),parent)); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Add management mode port configuration " + portEntry + " for port " + port + " and protocol " @@ -486,79 +337,97 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore return portEntry; } - private ConfigurationEntry createRootWithCLIEntries(ConfigurationEntry storeRoot) + private ConfiguredObjectRecord findBroker() { - Set<UUID> childrenIds = new HashSet<UUID>(storeRoot.getChildrenIds()); - if (!_cliEntries.isEmpty()) + for(ConfiguredObjectRecord record : _records.values()) { - childrenIds.addAll(_cliEntries.keySet()); + if(record.getType().equals(Broker.class.getSimpleName())) + { + return record; + } } - ConfigurationEntry root = new ConfigurationEntryImpl(storeRoot.getId(), storeRoot.getType(), new HashMap<String, Object>( - storeRoot.getAttributes()), childrenIds, this); - return root; + return null; } - private Map<UUID, Object> quiesceEntries(ConfigurationEntry storeRoot, BrokerOptions options) + + private Map<UUID, Object> quiesceEntries(final BrokerOptions options) { - Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>(); - Set<UUID> childrenIds; - int managementModeRmiPortOverride = options.getManagementModeRmiPortOverride(); - int managementModeJmxPortOverride = options.getManagementModeJmxPortOverride(); - int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride(); - childrenIds = storeRoot.getChildrenIds(); - for (UUID id : childrenIds) + final Map<UUID, Object> quiescedEntries = new HashMap<UUID, Object>(); + final int managementModeRmiPortOverride = options.getManagementModeRmiPortOverride(); + final int managementModeJmxPortOverride = options.getManagementModeJmxPortOverride(); + final int managementModeHttpPortOverride = options.getManagementModeHttpPortOverride(); + + _store.recoverConfigurationStore(new ConfigurationRecoveryHandler() { - ConfigurationEntry entry = _store.getEntry(id); - String entryType = entry.getType(); - Map<String, Object> attributes = entry.getAttributes(); - boolean quiesce = false; - if (VIRTUAL_HOST_TYPE.equals(entryType) && options.isManagementModeQuiesceVirtualHosts()) + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) { - quiesce = true; + } - else if (PORT_TYPE.equals(entryType)) + + @Override + public void configuredObject(final ConfiguredObjectRecord entry) { - if (attributes == null) - { - throw new IllegalConfigurationException("Port attributes are not set in " + entry); - } - Set<Protocol> protocols = getPortProtocolsAttribute(attributes); - if (protocols == null) + String entryType = entry.getType(); + Map<String, Object> attributes = entry.getAttributes(); + boolean quiesce = false; + if (VIRTUAL_HOST_TYPE.equals(entryType) && options.isManagementModeQuiesceVirtualHosts()) { quiesce = true; } - else + else if (PORT_TYPE.equals(entryType)) { - for (Protocol protocol : protocols) + if (attributes == null) { - switch (protocol) + throw new IllegalConfigurationException("Port attributes are not set in " + entry); + } + Set<Protocol> protocols = getPortProtocolsAttribute(attributes); + if (protocols == null) + { + quiesce = true; + } + else + { + for (Protocol protocol : protocols) { - case JMX_RMI: - quiesce = managementModeJmxPortOverride > 0 || managementModeRmiPortOverride > 0; - break; - case RMI: - quiesce = managementModeRmiPortOverride > 0; - break; - case HTTP: - quiesce = managementModeHttpPortOverride > 0; - break; - default: - quiesce = true; + switch (protocol) + { + case JMX_RMI: + quiesce = managementModeJmxPortOverride > 0 || managementModeRmiPortOverride > 0; + break; + case RMI: + quiesce = managementModeRmiPortOverride > 0; + break; + case HTTP: + quiesce = managementModeHttpPortOverride > 0; + break; + default: + quiesce = true; + } } } } - } - if (quiesce) - { - if (LOGGER.isDebugEnabled()) + if (quiesce) { - LOGGER.debug("Management mode quiescing entry " + entry); + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug("Management mode quiescing entry " + entry); + } + + // save original state + quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE)); } + } + - // save original state - quiescedEntries.put(entry.getId(), attributes.get(ATTRIBUTE_STATE)); + @Override + public int completeConfigurationRecovery() + { + return 0; } - } + }); + + return quiescedEntries; } @@ -572,7 +441,7 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore return MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class); } - private ConfigurationEntry createEntryWithState(ConfigurationEntry entry, Object state) + private ConfiguredObjectRecord createEntryWithState(ConfiguredObjectRecord entry, Object state) { Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); if (state == null) @@ -583,13 +452,7 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore { attributes.put(ATTRIBUTE_STATE, state); } - Set<UUID> originalChildren = entry.getChildrenIds(); - Set<UUID> children = null; - if (originalChildren != null) - { - children = new HashSet<UUID>(originalChildren); - } - return new ConfigurationEntryImpl(entry.getId(), entry.getType(), attributes, children, entry.getStore()); + return new ConfiguredObjectRecordImpl(entry.getId(), entry.getType(), attributes, entry.getParents()); } } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java index 016788496c..b4f095b51e 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java @@ -20,6 +20,35 @@ */ package org.apache.qpid.server.configuration.store; +import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.UUID; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonNode; +import org.codehaus.jackson.JsonParser; +import org.codehaus.jackson.JsonProcessingException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; +import org.codehaus.jackson.node.ArrayNode; + import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryImpl; import org.apache.qpid.server.configuration.ConfigurationEntryStore; @@ -31,26 +60,10 @@ import org.apache.qpid.server.model.SystemContext; import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.store.ConfigurationRecoveryHandler; import org.apache.qpid.server.store.ConfiguredObjectRecord; +import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.StoreException; import org.apache.qpid.util.Strings; import org.apache.qpid.util.Strings.ChainedResolver; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParser; -import org.codehaus.jackson.JsonProcessingException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.codehaus.jackson.node.ArrayNode; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.*; - -import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME; public class MemoryConfigurationEntryStore implements ConfigurationEntryStore { @@ -100,22 +113,48 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore } } - public MemoryConfigurationEntryStore(String initialStoreLocation, ConfigurationEntryStore initialStore, Map<String, String> configProperties) + public MemoryConfigurationEntryStore(ConfiguredObject parentObject, String initialStoreLocation, ConfigurationEntryStore initialStore, Map<String, String> configProperties) { this(configProperties); if (initialStore == null && (initialStoreLocation == null || "".equals(initialStoreLocation) )) { throw new IllegalConfigurationException("Cannot instantiate the memory broker store as neither initial store nor initial store location is provided"); } - + _parent = parentObject; if (initialStore != null) { if (initialStore instanceof MemoryConfigurationEntryStore) { _storeLocation = initialStore.getStoreLocation(); } - _rootId = initialStore.getRootEntry().getId(); - copyEntry(_rootId, initialStore, _entries); + final Collection<ConfiguredObjectRecord> records = new ArrayList<ConfiguredObjectRecord>(); + final ConfigurationRecoveryHandler replayHandler = new ConfigurationRecoveryHandler() + { + private int _configVersion; + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) + { + _configVersion = configVersion; + } + + @Override + public void configuredObject(ConfiguredObjectRecord record) + { + records.add(record); + } + + @Override + public int completeConfigurationRecovery() + { + return _configVersion; + } + }; + + initialStore.openConfigurationStore(parentObject, Collections.<String,Object>emptyMap()); + initialStore.recoverConfigurationStore(replayHandler); + + update(true, records.toArray(new ConfiguredObjectRecord[records.size()])); + } else { @@ -165,19 +204,16 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore return removedIds.toArray(new UUID[removedIds.size()]); } - @Override public synchronized void save(ConfigurationEntry... entries) { replaceEntries(entries); } - @Override public ConfigurationEntry getRootEntry() { return getEntry(_rootId); } - @Override public synchronized ConfigurationEntry getEntry(UUID id) { return _entries.get(id); @@ -520,31 +556,6 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore } } - protected void copyEntry(UUID entryId, ConfigurationEntryStore initialStore, Map<UUID,ConfigurationEntry> entries) - { - ConfigurationEntry entry = initialStore.getEntry(entryId); - if (entry != null) - { - if (entries.containsKey(entryId)) - { - throw new IllegalConfigurationException("Duplicate id is found: " + entryId - + "! The following configuration entries have the same id: " + entries.get(entryId) + ", " + entry); - } - - Set<UUID> children = entry.getChildrenIds(); - Set<UUID> childrenCopy = children == null? null : new HashSet<UUID>(children); - ConfigurationEntry copy = new ConfigurationEntryImpl(entryId, entry.getType(), new HashMap<String, Object>(entry.getAttributes()), childrenCopy, this); - entries.put(entryId, copy); - if (children != null) - { - for (UUID uuid : children) - { - copyEntry(uuid, initialStore, entries); - } - } - } - } - private void loadFromJson(String json) { ByteArrayInputStream bais = null; diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java index d4eda0857e..8af654084b 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/factory/MemoryConfigurationStoreFactory.java @@ -32,7 +32,7 @@ public class MemoryConfigurationStoreFactory implements ConfigurationStoreFacto @Override public ConfigurationEntryStore createStore(SystemContext systemContext, ConfigurationEntryStore initialStore, boolean overwrite, Map<String, String> configProperties) { - return new MemoryConfigurationEntryStore(null, initialStore, configProperties); + return new MemoryConfigurationEntryStore(systemContext, null, initialStore, configProperties); } @Override diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index 0bcb9d99b9..be24a09dfb 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -24,15 +24,17 @@ import org.apache.log4j.Logger; import org.apache.qpid.common.QpidProperties; import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.configuration.BrokerProperties; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.configuration.startup.BrokerStoreUpgrader; -import org.apache.qpid.server.logging.*; +import org.apache.qpid.server.logging.CompositeStartupMessageLogger; +import org.apache.qpid.server.logging.EventLogger; +import org.apache.qpid.server.logging.Log4jMessageLogger; +import org.apache.qpid.server.logging.MessageLogger; +import org.apache.qpid.server.logging.SystemOutMessageLogger; import org.apache.qpid.server.logging.messages.BrokerMessages; import org.apache.qpid.server.model.Broker; -import org.apache.qpid.server.model.ConfiguredObjectFactory; import org.apache.qpid.server.model.State; -import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.model.SystemContext; +import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.util.SystemUtils; @@ -50,9 +52,9 @@ public class ApplicationRegistry implements IApplicationRegistry private Broker _broker; - private ConfigurationEntryStore _store; + private DurableConfigurationStore _store; - public ApplicationRegistry(ConfigurationEntryStore store, SystemContext systemContext) + public ApplicationRegistry(DurableConfigurationStore store, SystemContext systemContext) { _store = store; _systemContext = systemContext; diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java index befd63f940..d9a07bc2e9 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java @@ -20,25 +20,33 @@ */ package org.apache.qpid.server.configuration.store; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.model.*; +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.GroupProvider; +import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.PreferencesProvider; +import org.apache.qpid.server.model.Transport; +import org.apache.qpid.server.model.TrustStore; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager; import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager; import org.apache.qpid.server.store.ConfiguredObjectRecord; import org.apache.qpid.test.utils.QpidTestCase; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase { - private ConfigurationEntryStore _store; + private MemoryConfigurationEntryStore _store; private UUID _brokerId; private UUID _virtualHostId; @@ -87,7 +95,7 @@ public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase // ??? perhaps it should not be abstract - protected abstract ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception; + protected abstract MemoryConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception; protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId); @@ -96,7 +104,7 @@ public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase addConfiguration(id, type, attributes, _brokerId); } - protected ConfigurationEntryStore getStore() + protected MemoryConfigurationEntryStore getStore() { return _store; } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java index 195f59177b..c8003d909f 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java @@ -20,10 +20,27 @@ */ package org.apache.qpid.server.configuration.store; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.SerializationConfig; + import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.configuration.updater.TaskExecutor; import org.apache.qpid.server.logging.EventLogger; @@ -35,23 +52,6 @@ import org.apache.qpid.server.model.SystemContext; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.test.utils.TestFileUtils; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; - -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase @@ -138,7 +138,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest @Override protected void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId) { - ConfigurationEntryStore store = getStore(); + MemoryConfigurationEntryStore store = getStore(); ConfigurationEntry parentEntry = getStore().getEntry(parentId); Set<UUID> children = new HashSet<UUID>(parentEntry.getChildrenIds()); children.add(id); @@ -151,7 +151,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest String defaultVhost = getTestName(); setTestSystemProperty("my.test.property", defaultVhost); - ConfigurationEntryStore store = getStore(); + MemoryConfigurationEntryStore store = getStore(); ConfigurationEntry brokerConfigEntry = store.getRootEntry(); Map<String, Object> attributes = new HashMap<String, Object>(brokerConfigEntry.getAttributes()); attributes.put(Broker.DEFAULT_VIRTUAL_HOST, "${my.test.property}"); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java index d09a9d3a68..0fe9d1ac49 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandlerTest.java @@ -20,12 +20,13 @@ */ package org.apache.qpid.server.configuration.store; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.any; +import static org.mockito.Mockito.when; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -33,61 +34,117 @@ import java.util.HashSet; import java.util.Map; import java.util.UUID; +import org.mockito.ArgumentCaptor; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.logging.EventLogger; +import org.apache.qpid.server.logging.LogRecorder; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObjectFactory; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.State; +import org.apache.qpid.server.model.SystemContext; import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.store.ConfigurationRecoveryHandler; import org.apache.qpid.server.store.ConfiguredObjectRecord; +import org.apache.qpid.server.store.ConfiguredObjectRecordImpl; +import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.test.utils.QpidTestCase; public class ManagementModeStoreHandlerTest extends QpidTestCase { private ManagementModeStoreHandler _handler; private BrokerOptions _options; - private ConfigurationEntryStore _store; - private ConfigurationEntry _root; - private ConfigurationEntry _portEntry; + private DurableConfigurationStore _store; + private ConfiguredObjectRecord _root; + private ConfiguredObjectRecord _portEntry; private UUID _rootId, _portEntryId; + private SystemContext _systemContext; protected void setUp() throws Exception { super.setUp(); _rootId = UUID.randomUUID(); _portEntryId = UUID.randomUUID(); - _store = mock(ConfigurationEntryStore.class); - _root = mock(ConfigurationEntry.class); - _portEntry = mock(ConfigurationEntry.class); - when(_store.getRootEntry()).thenReturn(_root); - when(_root.getId()).thenReturn(_rootId); + _store = mock(DurableConfigurationStore.class); + + + _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(), mock( + EventLogger.class), mock(LogRecorder.class), new BrokerOptions()); + + + ConfiguredObjectRecord systemContextRecord = _systemContext.asObjectRecord(); + + + + _root = new ConfiguredObjectRecordImpl(_rootId, Broker.class.getSimpleName(), Collections.<String,Object>emptyMap(), Collections.singletonMap(SystemContext.class.getSimpleName(), systemContextRecord)); + + _portEntry = mock(ConfiguredObjectRecord.class); when(_portEntry.getId()).thenReturn(_portEntryId); - when(_store.getEntry(_portEntryId)).thenReturn(_portEntry); - when(_store.getEntry(_rootId)).thenReturn(_root); - when(_root.getChildrenIds()).thenReturn(Collections.singleton(_portEntryId)); + when(_portEntry.getParents()).thenReturn(Collections.singletonMap(Broker.class.getSimpleName(), _root)); when(_portEntry.getType()).thenReturn(Port.class.getSimpleName()); + + final ArgumentCaptor<ConfigurationRecoveryHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfigurationRecoveryHandler.class); + doAnswer( + new Answer() + { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable + { + ConfigurationRecoveryHandler recoverer = recovererArgumentCaptor.getValue(); + recoverer.configuredObject(_root); + recoverer.configuredObject(_portEntry); + return null; + } + } + ).when(_store).recoverConfigurationStore(recovererArgumentCaptor.capture()); _options = new BrokerOptions(); _handler = new ManagementModeStoreHandler(_store, _options); + + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + } + + private ConfiguredObjectRecord getRootEntry() + { + BrokerFinder brokerFinder = new BrokerFinder(); + _handler.recoverConfigurationStore(brokerFinder); + return brokerFinder.getBrokerRecord(); + } + + private ConfiguredObjectRecord getEntry(UUID id) + { + RecordFinder recordFinder = new RecordFinder(id); + _handler.recoverConfigurationStore(recordFinder); + return recordFinder.getFoundRecord(); + } + + private Collection<UUID> getChildrenIds(ConfiguredObjectRecord record) + { + ChildFinder childFinder = new ChildFinder(record); + _handler.recoverConfigurationStore(childFinder); + return childFinder.getChildIds(); } public void testGetRootEntryWithEmptyOptions() { - ConfigurationEntry root = _handler.getRootEntry(); + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds()); + assertEquals("Unexpected children", Collections.singleton(_portEntryId), getChildrenIds(root)); } public void testGetRootEntryWithHttpPortOverriden() { _options.setManagementModeHttpPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); - ConfigurationEntry root = _handler.getRootEntry(); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - Collection<UUID> childrenIds = root.getChildrenIds(); + Collection<UUID> childrenIds = getChildrenIds(root); assertEquals("Unexpected children size", 2, childrenIds.size()); assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId)); } @@ -96,9 +153,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeRmiPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); - ConfigurationEntry root = _handler.getRootEntry(); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - Collection<UUID> childrenIds = root.getChildrenIds(); + Collection<UUID> childrenIds = getChildrenIds(root); assertEquals("Unexpected children size", 3, childrenIds.size()); assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId)); } @@ -107,9 +166,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeJmxPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); - ConfigurationEntry root = _handler.getRootEntry(); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - Collection<UUID> childrenIds = root.getChildrenIds(); + Collection<UUID> childrenIds = getChildrenIds(root); assertEquals("Unexpected children size", 2, childrenIds.size()); assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId)); } @@ -120,25 +181,27 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase _options.setManagementModeRmiPortOverride(2000); _options.setManagementModeJmxPortOverride(3000); _handler = new ManagementModeStoreHandler(_store, _options); - ConfigurationEntry root = _handler.getRootEntry(); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - Collection<UUID> childrenIds = root.getChildrenIds(); + Collection<UUID> childrenIds = getChildrenIds(root); assertEquals("Unexpected children size", 4, childrenIds.size()); assertTrue("Store port entry id is not found", childrenIds.contains(_portEntryId)); } public void testGetEntryByRootId() { - ConfigurationEntry root = _handler.getEntry(_rootId); + ConfiguredObjectRecord root = getEntry(_rootId); assertEquals("Unexpected root id", _rootId, root.getId()); - assertEquals("Unexpected children", Collections.singleton(_portEntryId), root.getChildrenIds()); + assertEquals("Unexpected children", Collections.singleton(_portEntryId), getChildrenIds(root)); } public void testGetEntryByPortId() { - ConfigurationEntry portEntry = _handler.getEntry(_portEntryId); + ConfiguredObjectRecord portEntry = getEntry(_portEntryId); assertEquals("Unexpected entry id", _portEntryId, portEntry.getId()); - assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty()); + assertTrue("Unexpected children", getChildrenIds(portEntry).isEmpty()); assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE)); } @@ -146,9 +209,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeJmxPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + UUID optionsPort = getOptionsPortId(); - ConfigurationEntry portEntry = _handler.getEntry(optionsPort); + ConfiguredObjectRecord portEntry = getEntry(optionsPort); assertCLIPortEntry(portEntry, optionsPort, Protocol.JMX_RMI); } @@ -156,9 +221,11 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeHttpPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + UUID optionsPort = getOptionsPortId(); - ConfigurationEntry portEntry = _handler.getEntry(optionsPort); + ConfiguredObjectRecord portEntry = getEntry(optionsPort); assertCLIPortEntry(portEntry, optionsPort, Protocol.HTTP); } @@ -169,8 +236,10 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase when(_portEntry.getAttributes()).thenReturn(attributes); _options.setManagementModeHttpPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); - ConfigurationEntry portEntry = _handler.getEntry(_portEntryId); + + ConfiguredObjectRecord portEntry = getEntry(_portEntryId); assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE)); } @@ -181,8 +250,10 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase when(_portEntry.getAttributes()).thenReturn(attributes); _options.setManagementModeRmiPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + - ConfigurationEntry portEntry = _handler.getEntry(_portEntryId); + ConfiguredObjectRecord portEntry = getEntry(_portEntryId); assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE)); } @@ -193,8 +264,10 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase when(_portEntry.getAttributes()).thenReturn(attributes); _options.setManagementModeRmiPortOverride(9090); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + - ConfigurationEntry portEntry = _handler.getEntry(_portEntryId); + ConfiguredObjectRecord portEntry = getEntry(_portEntryId); assertEquals("Unexpected state", State.QUIESCED, portEntry.getAttributes().get(Port.STATE)); } @@ -211,14 +284,25 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase private void virtualHostEntryQuiescedStatusTestImpl(boolean mmQuiesceVhosts) { UUID virtualHostId = UUID.randomUUID(); - ConfigurationEntry virtualHost = mock(ConfigurationEntry.class); - when(virtualHost.getId()).thenReturn(virtualHostId); - when(virtualHost.getType()).thenReturn(VirtualHost.class.getSimpleName()); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(VirtualHost.TYPE, "STANDARD"); - when(virtualHost.getAttributes()).thenReturn(attributes); - when(_store.getEntry(virtualHostId)).thenReturn(virtualHost); - when(_root.getChildrenIds()).thenReturn(new HashSet<UUID>(Arrays.asList(_portEntryId, virtualHostId))); + + final ConfiguredObjectRecord virtualHost = new ConfiguredObjectRecordImpl(virtualHostId, VirtualHost.class.getSimpleName(), attributes, Collections.singletonMap(Broker.class.getSimpleName(), _root)); + final ArgumentCaptor<ConfigurationRecoveryHandler> recovererArgumentCaptor = ArgumentCaptor.forClass(ConfigurationRecoveryHandler.class); + doAnswer( + new Answer() + { + @Override + public Object answer(final InvocationOnMock invocation) throws Throwable + { + ConfigurationRecoveryHandler recoverer = recovererArgumentCaptor.getValue(); + recoverer.configuredObject(_root); + recoverer.configuredObject(_portEntry); + recoverer.configuredObject(virtualHost); + return null; + } + } + ).when(_store).recoverConfigurationStore(recovererArgumentCaptor.capture()); State expectedState = mmQuiesceVhosts ? State.QUIESCED : null; if(mmQuiesceVhosts) @@ -227,19 +311,20 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase } _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); - ConfigurationEntry hostEntry = _handler.getEntry(virtualHostId); - Map<String, Object> hostAttributes = hostEntry.getAttributes(); + ConfiguredObjectRecord hostEntry = getEntry(virtualHostId); + Map<String, Object> hostAttributes = new HashMap<String, Object>(hostEntry.getAttributes()); assertEquals("Unexpected state", expectedState, hostAttributes.get(VirtualHost.STATE)); hostAttributes.remove(VirtualHost.STATE); assertEquals("Unexpected attributes", attributes, hostAttributes); } @SuppressWarnings("unchecked") - private void assertCLIPortEntry(ConfigurationEntry portEntry, UUID optionsPort, Protocol protocol) + private void assertCLIPortEntry(ConfiguredObjectRecord portEntry, UUID optionsPort, Protocol protocol) { assertEquals("Unexpected entry id", optionsPort, portEntry.getId()); - assertTrue("Unexpected children", portEntry.getChildrenIds().isEmpty()); + assertTrue("Unexpected children", getChildrenIds(portEntry).isEmpty()); Map<String, Object> attributes = portEntry.getAttributes(); assertEquals("Unexpected name", "MANAGEMENT-MODE-PORT-" + protocol.name(), attributes.get(Port.NAME)); assertEquals("Unexpected protocol", Collections.singleton(protocol), new HashSet<Protocol>( @@ -252,14 +337,15 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase _options.setManagementModeRmiPortOverride(2000); _options.setManagementModeJmxPortOverride(3000); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(Port.NAME, "TEST"); - ConfigurationEntry - configurationEntry = new ConfigurationEntryImpl(_portEntryId, Port.class.getSimpleName(), attributes, - Collections.<UUID> emptySet(), null); - _handler.save(configurationEntry); - verify(_store).save(any(ConfigurationEntry.class)); + ConfiguredObjectRecord + configurationEntry = new ConfiguredObjectRecordImpl(_portEntryId, Port.class.getSimpleName(), attributes, + Collections.singletonMap(Broker.class.getSimpleName(), getRootEntry())); + _handler.create(configurationEntry); + verify(_store).create(any(ConfiguredObjectRecord.class)); } public void testSaveRoot() @@ -268,31 +354,33 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase _options.setManagementModeRmiPortOverride(2000); _options.setManagementModeJmxPortOverride(3000); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); - ConfigurationEntry root = _handler.getRootEntry(); + ConfiguredObjectRecord root = getRootEntry(); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(Broker.NAME, "TEST"); - ConfigurationEntry - configurationEntry = new ConfigurationEntryImpl(_rootId, Broker.class.getSimpleName(), attributes, - root.getChildrenIds(), null); - _handler.save(configurationEntry); - verify(_store).save(any(ConfigurationEntry.class)); + ConfiguredObjectRecord + configurationEntry = new ConfiguredObjectRecordImpl(_rootId, Broker.class.getSimpleName(), attributes,root.getParents()); + _handler.update(false, configurationEntry); + verify(_store).update(anyBoolean(), any(ConfiguredObjectRecord.class)); } public void testSaveCLIHttpPort() { _options.setManagementModeHttpPortOverride(1000); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); UUID portId = getOptionsPortId(); Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put(Port.NAME, "TEST"); - ConfigurationEntry - configurationEntry = new ConfigurationEntryImpl(portId, Port.class.getSimpleName(), attributes, - Collections.<UUID> emptySet(), null); + ConfiguredObjectRecord + configurationEntry = new ConfiguredObjectRecordImpl(portId, Port.class.getSimpleName(), attributes, + Collections.singletonMap(Broker.class.getSimpleName(), + getRootEntry())); try { - _handler.save(configurationEntry); + _handler.update(false, configurationEntry); fail("Exception should be thrown on trying to save CLI port"); } catch (IllegalConfigurationException e) @@ -305,6 +393,8 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeHttpPortOverride(1000); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + ConfiguredObjectRecord record = new ConfiguredObjectRecord() { @Override @@ -339,6 +429,8 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase { _options.setManagementModeHttpPortOverride(1000); _handler = new ManagementModeStoreHandler(_store, _options); + _handler.openConfigurationStore(_systemContext,Collections.<String,Object>emptyMap()); + UUID portId = getOptionsPortId(); ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class); when(record.getId()).thenReturn(portId); @@ -355,13 +447,125 @@ public class ManagementModeStoreHandlerTest extends QpidTestCase private UUID getOptionsPortId() { - ConfigurationEntry root = _handler.getRootEntry(); + ConfiguredObjectRecord root = getRootEntry(); assertEquals("Unexpected root id", _rootId, root.getId()); - Collection<UUID> childrenIds = root.getChildrenIds(); + Collection<UUID> childrenIds = getChildrenIds(root); childrenIds.remove(_portEntryId); UUID optionsPort = childrenIds.iterator().next(); return optionsPort; } + + private class BrokerFinder implements ConfigurationRecoveryHandler + { + private ConfiguredObjectRecord _brokerRecord; + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) + { + + } + + @Override + public void configuredObject(final ConfiguredObjectRecord object) + { + if(object.getType().equals(Broker.class.getSimpleName())) + { + _brokerRecord = object; + } + } + + @Override + public int completeConfigurationRecovery() + { + return 0; + } + + public ConfiguredObjectRecord getBrokerRecord() + { + return _brokerRecord; + } + } + + private class RecordFinder implements ConfigurationRecoveryHandler + { + private final UUID _id; + private ConfiguredObjectRecord _foundRecord; + + private RecordFinder(final UUID id) + { + _id = id; + } + + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) + { + + } + + @Override + public void configuredObject(final ConfiguredObjectRecord object) + { + if(object.getId().equals(_id)) + { + _foundRecord = object; + } + } + + @Override + public int completeConfigurationRecovery() + { + return 0; + } + + public ConfiguredObjectRecord getFoundRecord() + { + return _foundRecord; + } + } + + private class ChildFinder implements ConfigurationRecoveryHandler + { + private final Collection<UUID> _childIds = new HashSet<UUID>(); + private final ConfiguredObjectRecord _parent; + + private ChildFinder(final ConfiguredObjectRecord parent) + { + _parent = parent; + } + + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) + { + + } + + @Override + public void configuredObject(final ConfiguredObjectRecord object) + { + + if(object.getParents() != null) + { + for(ConfiguredObjectRecord parent : object.getParents().values()) + { + if(parent.getId().equals(_parent.getId())) + { + _childIds.add(object.getId()); + } + } + + } + } + + @Override + public int completeConfigurationRecovery() + { + return 0; + } + + public Collection<UUID> getChildIds() + { + return _childIds; + } + } } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java index 47cf8b33ce..86098729d5 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java @@ -20,13 +20,7 @@ */ package org.apache.qpid.server.configuration.store; -import org.apache.qpid.server.BrokerOptions; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.model.Broker; -import org.codehaus.jackson.map.ObjectMapper; +import static org.mockito.Mockito.mock; import java.io.File; import java.util.Collections; @@ -36,10 +30,35 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import org.codehaus.jackson.map.ObjectMapper; + +import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.configuration.ConfigurationEntry; +import org.apache.qpid.server.configuration.ConfigurationEntryImpl; +import org.apache.qpid.server.configuration.IllegalConfigurationException; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.logging.EventLogger; +import org.apache.qpid.server.logging.LogRecorder; +import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.ConfiguredObjectFactory; +import org.apache.qpid.server.model.SystemContext; + public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTestCase { + private SystemContext _systemContext; + + @Override + public void setUp() throws Exception + { + super.setUp(); + _systemContext = new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(), + mock(EventLogger.class), mock(LogRecorder.class), + new BrokerOptions()); + + } + @Override - protected ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception + protected MemoryConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception { Map<String, Object> broker = new HashMap<String, Object>(); broker.put(Broker.ID, brokerId); @@ -52,7 +71,7 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe @Override protected void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId) { - ConfigurationEntryStore store = getStore(); + MemoryConfigurationEntryStore store = getStore(); ConfigurationEntry parentEntry = getStore().getEntry(parentId); Set<UUID> children = new HashSet<UUID>(parentEntry.getChildrenIds()); children.add(id); @@ -64,7 +83,7 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe { try { - new MemoryConfigurationEntryStore(null, null, Collections.<String,String>emptyMap()); + new MemoryConfigurationEntryStore(null, null, null, Collections.<String,String>emptyMap()); fail("Cannot create a memory store without either initial store or path to an initial store file"); } catch(IllegalConfigurationException e) @@ -86,8 +105,8 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe UUID brokerId = UUID.randomUUID(); Map<String, Object> brokerAttributes = new HashMap<String, Object>(); brokerAttributes.put(Broker.NAME, getTestName()); - MemoryConfigurationEntryStore initialStoreFile = (MemoryConfigurationEntryStore)createStore(brokerId, brokerAttributes); - MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(null, initialStoreFile, Collections.<String,String>emptyMap()); + MemoryConfigurationEntryStore initialStoreFile = createStore(brokerId, brokerAttributes); + MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(_systemContext, null, initialStoreFile, Collections.<String,String>emptyMap()); ConfigurationEntry root = store.getRootEntry(); assertNotNull("Root entry is not found", root); @@ -108,11 +127,11 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe setTestSystemProperty("QPID_HOME", TMP_FOLDER); setTestSystemProperty("QPID_WORK", TMP_FOLDER + File.separator + "work"); } - MemoryConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, null, new BrokerOptions().getConfigProperties()); + MemoryConfigurationEntryStore initialStore = new MemoryConfigurationEntryStore(_systemContext,BrokerOptions.DEFAULT_INITIAL_CONFIG_LOCATION, null, new BrokerOptions().getConfigProperties()); ConfigurationEntry initialStoreRoot = initialStore.getRootEntry(); assertNotNull("Initial store root entry is not found", initialStoreRoot); - MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(null, initialStore, Collections.<String,String>emptyMap()); + MemoryConfigurationEntryStore store = new MemoryConfigurationEntryStore(_systemContext, null, initialStore, Collections.<String,String>emptyMap()); ConfigurationEntry root = store.getRootEntry(); assertNotNull("Root entry is not found", root); diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java index dc58f61634..e72880e19a 100644 --- a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java @@ -36,7 +36,7 @@ import junit.framework.TestCase; import org.apache.qpid.server.configuration.ConfigurationEntry; import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.ConfigurationEntryStore; +import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.VirtualHost; @@ -45,7 +45,7 @@ public class ConfigurationEntryTest extends TestCase { public void testGetChildren() { - ConfigurationEntryStore store = mock(ConfigurationEntryStore.class); + MemoryConfigurationEntryStore store = mock(MemoryConfigurationEntryStore.class); ConfigurationEntry virtualHostEntry1 = new ConfigurationEntryImpl(UUID.randomUUID(), VirtualHost.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.<UUID> emptySet(), store); @@ -79,7 +79,7 @@ public class ConfigurationEntryTest extends TestCase public void testHashCode() { - ConfigurationEntryStore store = mock(ConfigurationEntryStore.class); + MemoryConfigurationEntryStore store = mock(MemoryConfigurationEntryStore.class); UUID id = UUID.randomUUID(); ConfigurationEntry entry1 = new ConfigurationEntryImpl(id, VirtualHost.class.getSimpleName(), @@ -95,7 +95,7 @@ public class ConfigurationEntryTest extends TestCase public void testEqualsObject() { - ConfigurationEntryStore store = mock(ConfigurationEntryStore.class); + MemoryConfigurationEntryStore store = mock(MemoryConfigurationEntryStore.class); UUID id = UUID.randomUUID(); Map<String, Object> attributes1 = new HashMap<String, Object>(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java index 7d5690b1bd..a7fd7d362d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/client/ssl/SSLTest.java @@ -415,7 +415,7 @@ public class SSLTest extends QpidBrokerTestCase sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); sslPortAttributes.put(Port.TRUST_STORES, Collections.singleton(TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE)); - getBrokerConfiguration().addPortConfiguration(sslPortAttributes); + getBrokerConfiguration().addObjectConfiguration(Port.class,sslPortAttributes); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java index d3d952ea8c..ead6a36c13 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/AlertingTest.java @@ -24,20 +24,21 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import javax.jms.Connection; +import javax.jms.Queue; +import javax.jms.Session; + import org.apache.qpid.client.AMQDestination; import org.apache.qpid.client.AMQSession; import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory; import org.apache.qpid.systest.rest.RestTestHelper; import org.apache.qpid.test.utils.TestBrokerConfiguration; -import javax.jms.Connection; -import javax.jms.Queue; -import javax.jms.Session; - public class AlertingTest extends AbstractTestLogging { @@ -154,19 +155,19 @@ public class AlertingTest extends AbstractTestLogging RestTestHelper restTestHelper = new RestTestHelper(findFreePort()); TestBrokerConfiguration config = getBrokerConfiguration(); config.addHttpManagementConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, restTestHelper.getHttpPort()); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, restTestHelper.getHttpPort()); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_RMI_PORT); Map<String, Object> anonymousProviderAttributes = new HashMap<String, Object>(); anonymousProviderAttributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE); anonymousProviderAttributes.put(AuthenticationProvider.NAME, "testAnonymous"); - config.addAuthenticationProviderConfiguration(anonymousProviderAttributes); + config.addObjectConfiguration(AuthenticationProvider.class, anonymousProviderAttributes); // set password authentication provider on http port for the tests - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); + config.setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); config.setSaved(false); restTestHelper.setUsernameAndPassword("webadmin", "webadmin"); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java index 6bd2b7569b..4952c4e10e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/logging/BrokerLoggingTest.java @@ -539,7 +539,7 @@ public class BrokerLoggingTest extends AbstractTestLogging sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - getBrokerConfiguration().addPortConfiguration(sslPortAttributes); + getBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); startBroker(); @@ -833,7 +833,7 @@ public class BrokerLoggingTest extends AbstractTestLogging sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - getBrokerConfiguration().addPortConfiguration(sslPortAttributes); + getBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); startBroker(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java index 7a1a6cd639..1baf998562 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/acl/ExternalACLJMXTest.java @@ -20,6 +20,7 @@ package org.apache.qpid.server.security.acl; import org.apache.qpid.management.common.mbeans.ServerInformation; import org.apache.qpid.server.security.access.ObjectType; +import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.test.utils.JMXTestUtils; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -45,7 +46,7 @@ public class ExternalACLJMXTest extends AbstractACLTestCase public void setUp() throws Exception { //remove the normal 'test' vhost, we will configure the vhosts below - getBrokerConfiguration(0).removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + getBrokerConfiguration(0).removeObjectConfiguration(org.apache.qpid.server.model.VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); createTestVirtualHost(0, TEST_VHOST); createTestVirtualHost(0, TEST2_VHOST); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java index 85d3fc0cdc..c3c8e58cc7 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/ExternalAuthenticationTest.java @@ -96,7 +96,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase public void testExternalAuthenticationManagerOnNonSslPort() throws Exception { setCommonBrokerSSLProperties(true); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); super.setUp(); setClientKeystoreProperties(); @@ -202,7 +202,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase sslTrustStoreAttributes.put(TrustStore.PATH, BROKER_PEERSTORE); sslTrustStoreAttributes.put(TrustStore.PASSWORD, BROKER_PEERSTORE_PASSWORD); sslTrustStoreAttributes.put(TrustStore.PEERS_ONLY, true); - getBrokerConfiguration().addTrustStoreConfiguration(sslTrustStoreAttributes); + getBrokerConfiguration().addObjectConfiguration(TrustStore.class, sslTrustStoreAttributes); super.setUp(); @@ -283,7 +283,7 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase JMXTestUtils jmxUtils = new JMXTestUtils(this); setCommonBrokerSSLProperties(true); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER, ExternalAuthenticationManagerFactory.ATTRIBUTE_USE_FULL_DN, "true"); + getBrokerConfiguration().setObjectAttribute(AuthenticationProvider.class, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER, ExternalAuthenticationManagerFactory.ATTRIBUTE_USE_FULL_DN, "true"); getBrokerConfiguration().addJmxManagementConfiguration(); super.setUp(); @@ -343,14 +343,14 @@ public class ExternalAuthenticationTest extends QpidBrokerTestCase sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); sslPortAttributes.put(Port.TRUST_STORES, trustStoreNames); - config.addPortConfiguration(sslPortAttributes); + config.addObjectConfiguration(Port.class, sslPortAttributes); Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>(); externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); externalAuthProviderAttributes.put(AuthenticationProvider.TYPE, ExternalAuthenticationManagerFactory.PROVIDER_TYPE); - config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes); + config.addObjectConfiguration(AuthenticationProvider.class, externalAuthProviderAttributes); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_SSL_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_EXTERNAL_PROVIDER); } private void setUntrustedClientKeystoreProperties() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java index e70897c68e..ae5785ba89 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/security/auth/manager/MultipleAuthenticationManagersTest.java @@ -31,6 +31,7 @@ import java.util.Map; import javax.jms.Connection; import javax.jms.JMSException; + import org.apache.qpid.AMQException; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.server.model.AuthenticationProvider; @@ -49,7 +50,7 @@ public class MultipleAuthenticationManagersTest extends QpidBrokerTestCase Map<String, Object> externalAuthProviderAttributes = new HashMap<String, Object>(); externalAuthProviderAttributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE); externalAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); - config.addAuthenticationProviderConfiguration(externalAuthProviderAttributes); + config.addObjectConfiguration(AuthenticationProvider.class, externalAuthProviderAttributes); Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); sslPortAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); @@ -58,7 +59,7 @@ public class MultipleAuthenticationManagersTest extends QpidBrokerTestCase sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); sslPortAttributes.put(Port.TRUST_STORES, Collections.singleton(TestBrokerConfiguration.ENTRY_NAME_SSL_TRUSTSTORE)); sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); - config.addPortConfiguration(sslPortAttributes); + config.addObjectConfiguration(Port.class, sslPortAttributes); // set the ssl system properties setSystemProperty("javax.net.ssl.keyStore", KEYSTORE); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java index 6d53896371..f2e72be447 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/stats/StatisticsReportingTest.java @@ -20,6 +20,16 @@ */ package org.apache.qpid.server.stats; +import java.util.List; +import java.util.Map; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + import org.apache.qpid.AMQException; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; @@ -28,20 +38,11 @@ import org.apache.qpid.client.AMQSession; import org.apache.qpid.exchange.ExchangeDefaults; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.util.LogMonitor; -import java.util.List; -import java.util.Map; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; - /** * Test generation of message/data statistics reporting and the ability * to control from the configuration file. @@ -72,7 +73,7 @@ public class StatisticsReportingTest extends QpidBrokerTestCase if (getName().equals("testEnabledStatisticsReporting")) { TestBrokerConfiguration config = getBrokerConfiguration(); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + config.removeObjectConfiguration(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); config.setBrokerAttribute(Broker.STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_PERIOD_IN_SECONDS); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java index 9f244e78a4..1b7f443705 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java @@ -82,8 +82,8 @@ public class SplitStoreTest extends QpidBrokerTestCase messageStoreSettings.put(MessageStore.STORE_PATH, _messageStorePath); TestBrokerConfiguration config = getBrokerConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.CONFIGURATION_STORE_SETTINGS, configurationStoreSettings); + config.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); + config.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.CONFIGURATION_STORE_SETTINGS, configurationStoreSettings); super.startBroker(); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java index 3dea6fd5bb..25a3571787 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/server/store/StoreOverfullTest.java @@ -70,7 +70,7 @@ public class StoreOverfullTest extends QpidBrokerTestCase messageStoreSettings.put(MessageStore.UNDERFULL_SIZE, UNDERFULL_SIZE); TestBrokerConfiguration config = getBrokerConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); + config.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java index f396c79351..cb6eae013e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/ManagementLoggingTest.java @@ -21,18 +21,16 @@ package org.apache.qpid.systest.management.jmx; -import org.apache.qpid.server.configuration.BrokerProperties; +import java.util.Collections; +import java.util.List; + import org.apache.qpid.server.logging.AbstractTestLogging; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Transport; import org.apache.qpid.test.utils.JMXTestUtils; import org.apache.qpid.test.utils.TestBrokerConfiguration; -import org.apache.qpid.test.utils.TestSSLConstants; import org.apache.qpid.util.LogMonitor; -import java.util.Collections; -import java.util.List; - /** * Management Console Test Suite * @@ -314,8 +312,8 @@ public class ManagementLoggingTest extends AbstractTestLogging if(useManagementSSL) { // This test requires we have ssl, change the transport and add they keystore to the port config - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); } startBroker(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java index db1e6f6617..922fb69845 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/management/jmx/UserManagementTest.java @@ -59,7 +59,7 @@ public class UserManagementTest extends QpidBrokerTestCase Map<String, Object> newAttributes = new HashMap<String, Object>(); newAttributes.put(AuthenticationProvider.TYPE, getAuthenticationManagerType()); newAttributes.put("path", _passwordFile.getAbsolutePath()); - getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); + getBrokerConfiguration().setObjectAttributes(AuthenticationProvider.class,TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); getBrokerConfiguration().addJmxManagementConfiguration(); _jmxUtils = new JMXTestUtils(this); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java index f87113465c..983b21da51 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AccessControlProviderRestTest.java @@ -30,6 +30,7 @@ import java.util.UUID; import org.apache.qpid.server.BrokerOptions; import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.AccessControlProvider; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.State; import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -58,7 +59,7 @@ public class AccessControlProviderRestTest extends QpidRestTestCase super.customizeConfiguration(); getRestTestHelper().configureTemporaryPasswordFile(this, ALLOWED_USER, DENIED_USER, OTHER_USER); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AnonymousAccessRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AnonymousAccessRestTest.java index 9bf815adf7..79406cc81e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AnonymousAccessRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AnonymousAccessRestTest.java @@ -27,6 +27,7 @@ import java.util.Map; import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -53,12 +54,12 @@ public class AnonymousAccessRestTest extends QpidRestTestCase Map<String, Object> anonymousAuthProviderAttributes = new HashMap<String, Object>(); anonymousAuthProviderAttributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE); anonymousAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); - config.addAuthenticationProviderConfiguration(anonymousAuthProviderAttributes); + config.addObjectConfiguration(AuthenticationProvider.class, anonymousAuthProviderAttributes); // set anonymous authentication provider on http port for the tests - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_ANONYMOUS_PROVIDER); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false); + config.setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false); // reset credentials getRestTestHelper().setUsernameAndPassword(null, null); @@ -91,7 +92,7 @@ public class AnonymousAccessRestTest extends QpidRestTestCase public void testGetWithPasswordAuthProvider() throws Exception { - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); startBrokerNow(); @@ -101,7 +102,7 @@ public class AnonymousAccessRestTest extends QpidRestTestCase public void testPutWithPasswordAuthProvider() throws Exception { - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); startBrokerNow(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java index e658cd5f20..7dd52d3aa3 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/AuthenticationProviderRestTest.java @@ -27,13 +27,13 @@ import java.util.Map; import java.util.UUID; import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.User; -import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory; import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -178,7 +178,7 @@ public class AuthenticationProviderRestTest extends QpidRestTestCase attributes.put(AuthenticationProvider.NAME, providerName); attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsoluteFile()); - UUID id = config.addAuthenticationProviderConfiguration(attributes); + UUID id = config.addObjectConfiguration(AuthenticationProvider.class, attributes); config.setSaved(false); startBroker(0, true); @@ -216,7 +216,7 @@ public class AuthenticationProviderRestTest extends QpidRestTestCase attributes.put(AuthenticationProvider.NAME, providerName); attributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, file.getAbsoluteFile()); - UUID id = config.addAuthenticationProviderConfiguration(attributes); + UUID id = config.addObjectConfiguration(AuthenticationProvider.class, attributes); config.setSaved(false); startBroker(0, true); @@ -260,9 +260,9 @@ public class AuthenticationProviderRestTest extends QpidRestTestCase { stopBroker(); getBrokerConfiguration().setSaved(false); - getBrokerConfiguration().removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.AUTHENTICATION_PROVIDER, ANONYMOUS_AUTHENTICATION_PROVIDER); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, ANONYMOUS_AUTHENTICATION_PROVIDER); + getBrokerConfiguration().removeObjectConfiguration(AuthenticationProvider.class, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.AUTHENTICATION_PROVIDER, ANONYMOUS_AUTHENTICATION_PROVIDER); + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, ANONYMOUS_AUTHENTICATION_PROVIDER); startBroker(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java index 81177b8c08..c9d5131b76 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BasicAuthRestTest.java @@ -30,6 +30,7 @@ import java.util.Collections; import javax.servlet.http.HttpServletResponse; import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Transport; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -57,8 +58,8 @@ public class BasicAuthRestTest extends QpidRestTestCase getRestTestHelper().setUseSsl(useSsl); if (useSsl) { - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL)); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.TRANSPORTS, Collections.singleton(Transport.SSL)); + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); } super.customizeConfiguration(); } @@ -85,7 +86,7 @@ public class BasicAuthRestTest extends QpidRestTestCase public void testBasicAuthWhenDisabledWithHttp() throws Exception { configure(false); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false); + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, false); super.setUp(); // Try the attempt with authentication, it should fail because @@ -98,7 +99,7 @@ public class BasicAuthRestTest extends QpidRestTestCase { configure(false); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); super.setUp(); // Try the attempt with authentication, it should succeed because @@ -110,7 +111,7 @@ public class BasicAuthRestTest extends QpidRestTestCase public void testDisablingForHttps() throws Exception { configure(true); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpsBasicAuthenticationEnabled", false); + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, "httpsBasicAuthenticationEnabled", false); super.setUp(); setSystemProperty("javax.net.ssl.trustStore", TRUSTSTORE); setSystemProperty("javax.net.ssl.trustStorePassword", TRUSTSTORE_PASSWORD); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsClientCertAuthTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsClientCertAuthTest.java index 3a85ad5431..6d6223048a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsClientCertAuthTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsClientCertAuthTest.java @@ -68,13 +68,13 @@ public class BrokerRestHttpsClientCertAuthTest extends QpidRestTestCase Map<String, Object> externalProviderAttributes = new HashMap<String, Object>(); externalProviderAttributes.put(AuthenticationProvider.TYPE, ExternalAuthenticationManagerFactory.PROVIDER_TYPE); externalProviderAttributes.put(AuthenticationProvider.NAME, EXTERNAL_AUTHENTICATION_PROVIDER); - getBrokerConfiguration().addAuthenticationProviderConfiguration(externalProviderAttributes); + getBrokerConfiguration().addObjectConfiguration(AuthenticationProvider.class, externalProviderAttributes); // set password authentication provider on http port for the tests - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + getBrokerConfiguration().setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, EXTERNAL_AUTHENTICATION_PROVIDER); - getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, newAttributes); + getBrokerConfiguration().setObjectAttributes(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, newAttributes); } public void testGetWithHttps() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java index 7400a4d425..4c8997bec5 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/BrokerRestHttpsTest.java @@ -28,12 +28,12 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.Transport; -import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.test.utils.TestBrokerConfiguration; public class BrokerRestHttpsTest extends QpidRestTestCase @@ -56,7 +56,7 @@ public class BrokerRestHttpsTest extends QpidRestTestCase newAttributes.put(Port.PROTOCOLS, Collections.singleton(Protocol.HTTP)); newAttributes.put(Port.TRANSPORTS, Collections.singleton(Transport.SSL)); newAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); - getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT,newAttributes); + getBrokerConfiguration().setObjectAttributes(Port.class,TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT,newAttributes); } public void testGetWithHttps() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java index 8c25706290..3ec8818c8d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/GroupProviderRestTest.java @@ -29,13 +29,13 @@ import java.util.Properties; import java.util.UUID; import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.Group; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.State; import org.apache.qpid.server.model.UUIDGenerator; -import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.security.group.FileGroupManagerFactory; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestFileUtils; @@ -301,7 +301,7 @@ public class GroupProviderRestTest extends QpidRestTestCase assertFalse("Group file should not exist", file.exists()); TestBrokerConfiguration config = getBrokerConfiguration(); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE); + config.removeObjectConfiguration(GroupProvider.class, TestBrokerConfiguration.ENTRY_NAME_GROUP_FILE); UUID id = config.addGroupFileConfiguration(file.getAbsolutePath()); config.setSaved(false); startBroker(0, true); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java index b6e60aec9d..680f807a9b 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/KeyStoreRestTest.java @@ -26,15 +26,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; + import org.apache.qpid.server.model.KeyStore; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.security.AbstractKeyStoreAdapter; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestSSLConstants; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; public class KeyStoreRestTest extends QpidRestTestCase { @@ -108,7 +109,7 @@ public class KeyStoreRestTest extends QpidRestTestCase sslKeyStoreAttributes.put(KeyStore.NAME, name); sslKeyStoreAttributes.put(KeyStore.PATH, TestSSLConstants.BROKER_KEYSTORE); sslKeyStoreAttributes.put(KeyStore.PASSWORD, TestSSLConstants.BROKER_KEYSTORE_PASSWORD); - getBrokerConfiguration().addKeyStoreConfiguration(sslKeyStoreAttributes); + getBrokerConfiguration().addObjectConfiguration(KeyStore.class,sslKeyStoreAttributes); //add the SSL port using it Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); @@ -117,7 +118,7 @@ public class KeyStoreRestTest extends QpidRestTestCase sslPortAttributes.put(Port.NAME, TestBrokerConfiguration.ENTRY_NAME_SSL_PORT); sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); sslPortAttributes.put(Port.KEY_STORE, name); - getBrokerConfiguration().addPortConfiguration(sslPortAttributes); + getBrokerConfiguration().addObjectConfiguration(Port.class,sslPortAttributes); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java index 2ded81f7a9..a06b41498c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/PreferencesProviderRestTest.java @@ -27,12 +27,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.ConfiguredObject; import org.apache.qpid.server.model.LifetimePolicy; import org.apache.qpid.server.model.PreferencesProvider; import org.apache.qpid.server.model.State; -import org.apache.qpid.server.model.AbstractConfiguredObject; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; import org.apache.qpid.server.security.auth.manager.PlainPasswordFileAuthenticationManagerFactory; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -77,7 +77,7 @@ public class PreferencesProviderRestTest extends QpidRestTestCase anonymousAuthProviderAttributes.put(AuthenticationProvider.TYPE, PlainPasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); anonymousAuthProviderAttributes.put(AuthenticationProvider.NAME, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER + "-2"); anonymousAuthProviderAttributes.put(PlainPasswordFileAuthenticationManagerFactory.ATTRIBUTE_PATH, _authenticationProviderFile.getAbsolutePath()); - getBrokerConfiguration().addAuthenticationProviderConfiguration(anonymousAuthProviderAttributes); + getBrokerConfiguration().addObjectConfiguration(AuthenticationProvider.class,anonymousAuthProviderAttributes); } public void testCreateAndGetProvider() throws Exception diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java index de5c2f561f..c0be10931c 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/QpidRestTestCase.java @@ -26,10 +26,12 @@ import java.util.Map; import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.AuthenticationProvider; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; +import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManagerFactory; -import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.QpidBrokerTestCase; +import org.apache.qpid.test.utils.TestBrokerConfiguration; public class QpidRestTestCase extends QpidBrokerTestCase { @@ -52,7 +54,7 @@ public class QpidRestTestCase extends QpidBrokerTestCase getRestTestHelper().setUsernameAndPassword("webadmin", "webadmin"); //remove the normal 'test' vhost, we will configure the vhosts below - getBrokerConfiguration(0).removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + getBrokerConfiguration(0).removeObjectConfiguration(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); // Set up virtualhost config with queues and bindings to the amq.direct for (String virtualhost : EXPECTED_VIRTUALHOSTS) @@ -81,19 +83,19 @@ public class QpidRestTestCase extends QpidBrokerTestCase { TestBrokerConfiguration config = getBrokerConfiguration(); config.addHttpManagementConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _restTestHelper.getHttpPort()); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT); - config.removeObjectConfiguration(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT); + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _restTestHelper.getHttpPort()); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT); + config.removeObjectConfiguration(Port.class, TestBrokerConfiguration.ENTRY_NAME_RMI_PORT); Map<String, Object> anonymousProviderAttributes = new HashMap<String, Object>(); anonymousProviderAttributes.put(AuthenticationProvider.TYPE, AnonymousAuthenticationManagerFactory.PROVIDER_TYPE); anonymousProviderAttributes.put(AuthenticationProvider.NAME, ANONYMOUS_AUTHENTICATION_PROVIDER); - config.addAuthenticationProviderConfiguration(anonymousProviderAttributes); + config.addObjectConfiguration(AuthenticationProvider.class, anonymousProviderAttributes); // set password authentication provider on http port for the tests - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, + config.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); + config.setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } public RestTestHelper getRestTestHelper() diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java index 7050dcfc33..89611ab727 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/RestTestHelper.java @@ -50,20 +50,21 @@ import javax.net.ssl.TrustManagerFactory; import javax.servlet.http.HttpServletResponse; import junit.framework.Assert; - import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; + import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Binding; import org.apache.qpid.server.model.Queue; import org.apache.qpid.ssl.SSLContextFactory; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; public class RestTestHelper { @@ -448,7 +449,7 @@ public class RestTestHelper { _passwdFile = createTemporaryPasswdFile(users); - testCase.getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, + testCase.getBrokerConfiguration().setObjectAttribute(AuthenticationProvider.class, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, "path", _passwdFile.getAbsolutePath()); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java index 6ec2a02ba1..6a910df04d 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/SaslRestTest.java @@ -35,12 +35,13 @@ import java.util.List; import java.util.Map; import org.apache.commons.codec.binary.Base64; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; + import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.security.auth.manager.Base64MD5PasswordFileAuthenticationManagerFactory; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.tools.security.Passwd; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; public class SaslRestTest extends QpidRestTestCase { @@ -378,6 +379,6 @@ public class SaslRestTest extends QpidRestTestCase Map<String, Object> newAttributes = new HashMap<String, Object>(); newAttributes.put("path", passwordFile.getAbsolutePath()); newAttributes.put(AuthenticationProvider.TYPE, Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE); - getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); + getBrokerConfiguration().setObjectAttributes(AuthenticationProvider.class,TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER, newAttributes); } } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java index 5a7bf71e67..3d1a0af9eb 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/TrustStoreRestTest.java @@ -26,15 +26,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; + import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Transport; import org.apache.qpid.server.model.TrustStore; import org.apache.qpid.server.security.AbstractKeyStoreAdapter; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestSSLConstants; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; public class TrustStoreRestTest extends QpidRestTestCase { @@ -106,7 +107,7 @@ public class TrustStoreRestTest extends QpidRestTestCase sslTrustStoreAttributes.put(TrustStore.NAME, name); sslTrustStoreAttributes.put(TrustStore.PATH, TestSSLConstants.TRUSTSTORE); sslTrustStoreAttributes.put(TrustStore.PASSWORD, TestSSLConstants.TRUSTSTORE_PASSWORD); - getBrokerConfiguration().addTrustStoreConfiguration(sslTrustStoreAttributes); + getBrokerConfiguration().addObjectConfiguration(TrustStore.class,sslTrustStoreAttributes); //add the SSL port using it Map<String, Object> sslPortAttributes = new HashMap<String, Object>(); @@ -116,7 +117,7 @@ public class TrustStoreRestTest extends QpidRestTestCase sslPortAttributes.put(Port.AUTHENTICATION_PROVIDER, TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER); sslPortAttributes.put(Port.KEY_STORE, TestBrokerConfiguration.ENTRY_NAME_SSL_KEYSTORE); sslPortAttributes.put(Port.TRUST_STORES, Collections.singleton(name)); - getBrokerConfiguration().addPortConfiguration(sslPortAttributes); + getBrokerConfiguration().addObjectConfiguration(Port.class, sslPortAttributes); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java index da9466e9a9..d98572807a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/BrokerACLTest.java @@ -27,12 +27,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.codehaus.jackson.JsonGenerationException; +import org.codehaus.jackson.map.JsonMappingException; + import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.AccessControlProvider; import org.apache.qpid.server.model.AuthenticationProvider; import org.apache.qpid.server.model.Broker; import org.apache.qpid.server.model.GroupProvider; import org.apache.qpid.server.model.KeyStore; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.Protocol; import org.apache.qpid.server.model.TrustStore; @@ -48,8 +52,6 @@ import org.apache.qpid.systest.rest.QpidRestTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.test.utils.TestFileUtils; import org.apache.qpid.test.utils.TestSSLConstants; -import org.codehaus.jackson.JsonGenerationException; -import org.codehaus.jackson.map.JsonMappingException; public class BrokerACLTest extends QpidRestTestCase { @@ -74,7 +76,7 @@ public class BrokerACLTest extends QpidRestTestCase "ACL DENY-LOG " + DENIED_USER + " CONFIGURE BROKER\n" + "ACL DENY-LOG ALL ALL"; - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/ExchangeRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/ExchangeRestACLTest.java index f20d9dfa47..2eaaf7d988 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/ExchangeRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/ExchangeRestACLTest.java @@ -20,14 +20,10 @@ */ package org.apache.qpid.systest.rest.acl; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import org.apache.qpid.server.management.plugin.HttpManagement; import org.apache.qpid.server.model.Binding; import org.apache.qpid.server.model.Exchange; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; @@ -35,6 +31,11 @@ import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + public class ExchangeRestACLTest extends QpidRestTestCase { private static final String ALLOWED_USER = "user1"; @@ -61,7 +62,7 @@ public class ExchangeRestACLTest extends QpidRestTestCase "ACL DENY-LOG " + DENIED_USER + " UNBIND EXCHANGE", "ACL DENY-LOG ALL ALL"); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java index e6d5f8b1e0..d2eba6a924 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/GroupRestACLTest.java @@ -29,6 +29,7 @@ import java.util.Properties; import javax.servlet.http.HttpServletResponse; import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -60,7 +61,7 @@ public class GroupRestACLTest extends QpidRestTestCase protected void customizeConfiguration() throws IOException { super.customizeConfiguration(); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } @Override diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/LogViewerACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/LogViewerACLTest.java index dd6c7d6a28..86dc1ea17a 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/LogViewerACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/LogViewerACLTest.java @@ -23,6 +23,7 @@ package org.apache.qpid.systest.rest.acl; import java.io.IOException; import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; @@ -43,7 +44,7 @@ public class LogViewerACLTest extends QpidRestTestCase "ACL DENY-LOG " + DENIED_USER + " ACCESS_LOGS BROKER", "ACL DENY-LOG ALL ALL"); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/QueueRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/QueueRestACLTest.java index b712327329..dced81277e 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/QueueRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/QueueRestACLTest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Map; import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Queue; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; @@ -51,7 +52,7 @@ public class QueueRestACLTest extends QpidRestTestCase "ACL DENY-LOG " + DENIED_USER + " DELETE QUEUE", "ACL DENY-LOG ALL ALL"); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java index 4b4854e4b3..1ec40cfc14 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserPreferencesRestACLTest.java @@ -29,6 +29,7 @@ import java.util.List; import java.util.Map; import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.PreferencesProvider; import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider; import org.apache.qpid.server.security.acl.AbstractACLTestCase; @@ -80,7 +81,7 @@ public class UserPreferencesRestACLTest extends QpidRestTestCase + " UPDATE USER", "ACL DENY-LOG " + DENIED_USER + " UPDATE USER", "ACL DENY-LOG ALL ALL"); TestBrokerConfiguration brokerConfiguration = getBrokerConfiguration(); - brokerConfiguration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, + brokerConfiguration.setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); Map<String, Object> attributes = new HashMap<String, Object>(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java index 7c5042c750..f792197369 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/systest/rest/acl/UserRestACLTest.java @@ -28,12 +28,14 @@ import java.util.Properties; import javax.servlet.http.HttpServletResponse; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; + import org.apache.qpid.server.management.plugin.HttpManagement; +import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.security.acl.AbstractACLTestCase; import org.apache.qpid.systest.rest.QpidRestTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; public class UserRestACLTest extends QpidRestTestCase { @@ -62,7 +64,7 @@ public class UserRestACLTest extends QpidRestTestCase protected void customizeConfiguration() throws IOException { super.customizeConfiguration(); - getBrokerConfiguration().setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); + getBrokerConfiguration().setObjectAttribute(Plugin.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_MANAGEMENT, HttpManagement.HTTP_BASIC_AUTHENTICATION_ENABLED, true); } @Override diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java index ee3a8c7260..e6e7484b28 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/destination/AddressBasedDestinationTest.java @@ -20,8 +20,34 @@ */ package org.apache.qpid.test.client.destination; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.QueueBrowser; +import javax.jms.QueueReceiver; +import javax.jms.QueueSession; +import javax.jms.Session; +import javax.jms.TextMessage; +import javax.jms.Topic; +import javax.jms.TopicSession; +import javax.jms.TopicSubscriber; +import javax.naming.Context; +import javax.naming.InitialContext; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.apache.qpid.client.AMQAnyDestination; import org.apache.qpid.client.AMQConnection; import org.apache.qpid.client.AMQDestination; @@ -35,17 +61,6 @@ import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; import org.apache.qpid.transport.ExecutionErrorCode; -import javax.jms.*; -import javax.naming.Context; -import javax.naming.InitialContext; - -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Properties; - public class AddressBasedDestinationTest extends QpidBrokerTestCase { private static final Logger _logger = LoggerFactory.getLogger(AddressBasedDestinationTest.class); @@ -55,7 +70,7 @@ public class AddressBasedDestinationTest extends QpidBrokerTestCase public void setUp() throws Exception { TestBrokerConfiguration config = getBrokerConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, 0); + config.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.QUEUE_MAXIMUM_DELIVERY_ATTEMPTS, 0); super.setUp(); _connection = getConnection() ; diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java index 4026b7a6cb..17485c5445 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java @@ -31,13 +31,14 @@ import javax.jms.MessageProducer; import javax.jms.Queue; import javax.jms.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.store.SlowMessageStore; import org.apache.qpid.test.utils.QpidBrokerTestCase; import org.apache.qpid.test.utils.TestBrokerConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * This tests that when the commit takes a long time(due to POST_COMMIT_DELAY) that the commit does not timeout @@ -66,7 +67,7 @@ public class SyncWaitDelayTest extends QpidBrokerTestCase messageStoreSettings.put(SlowMessageStore.DELAYS, slowMessageStoreDelays); TestBrokerConfiguration config = getBrokerConfiguration(); - config.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); + config.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings); super.setUp(); diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java index 2ffca48f56..6081dfeebf 100755 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java @@ -17,36 +17,6 @@ */ package org.apache.qpid.test.utils; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import javax.jms.BytesMessage; -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.JMSException; -import javax.jms.MapMessage; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.ObjectMessage; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.StreamMessage; -import javax.jms.TextMessage; -import javax.jms.Topic; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.qpid.AMQException; @@ -71,6 +41,23 @@ import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.util.FileUtils; import org.apache.qpid.util.SystemUtils; +import javax.jms.*; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.lang.IllegalStateException; + /** * Qpid base class for system testing test cases. */ @@ -232,17 +219,17 @@ public class QpidBrokerTestCase extends QpidTestCase } if (actualPort != DEFAULT_PORT) { - configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort); - configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort)); - configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET); + configuration.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_AMQP_PORT, Port.PORT, actualPort); + configuration.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_RMI_PORT, Port.PORT, getManagementPort(actualPort)); + configuration.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_JMX_PORT, Port.PORT, getManagementPort(actualPort) + JMXPORT_CONNECTORSERVER_OFFSET); String workDir = System.getProperty("QPID_WORK") + File.separator + TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST + File.separator + actualPort; - Map<String, Object> virtualHostSettings = configuration.getObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); + Map<String, Object> virtualHostSettings = configuration.getObjectAttributes(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST); @SuppressWarnings("unchecked") Map<String, Object> storeSettings = (Map<String, Object>)virtualHostSettings.get(VirtualHost.MESSAGE_STORE_SETTINGS); storeSettings.put(MessageStore.STORE_PATH, workDir); - configuration.setObjectAttribute(TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, storeSettings); + configuration.setObjectAttribute(VirtualHost.class, TestBrokerConfiguration.ENTRY_NAME_VIRTUAL_HOST, VirtualHost.MESSAGE_STORE_SETTINGS, storeSettings); } return configuration; @@ -851,7 +838,7 @@ public class QpidBrokerTestCase extends QpidTestCase messageStoreSettings.put(MessageStore.STORE_PATH, storeDir); attributes.put(VirtualHost.MESSAGE_STORE_SETTINGS, messageStoreSettings ); int port = getPort(brokerPort); - getBrokerConfiguration(port).addVirtualHostConfiguration(attributes); + getBrokerConfiguration(port).addObjectConfiguration(VirtualHost.class, attributes); } /** diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java index a51592dfaa..4c0e2b7ffc 100644 --- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java +++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/TestBrokerConfiguration.java @@ -20,24 +20,36 @@ */ package org.apache.qpid.test.utils; -import org.apache.qpid.server.configuration.ConfigurationEntry; -import org.apache.qpid.server.configuration.ConfigurationEntryImpl; -import org.apache.qpid.server.configuration.IllegalConfigurationException; -import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; -import org.apache.qpid.server.model.*; -import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; -import org.apache.qpid.server.security.group.FileGroupManagerFactory; -import org.apache.qpid.server.store.ConfiguredObjectRecord; +import static org.mockito.Mockito.mock; import java.io.File; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.UUID; +import org.apache.qpid.server.BrokerOptions; +import org.apache.qpid.server.configuration.store.MemoryConfigurationEntryStore; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.logging.EventLogger; +import org.apache.qpid.server.logging.LogRecorder; +import org.apache.qpid.server.model.AccessControlProvider; +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.ConfiguredObjectFactory; +import org.apache.qpid.server.model.GroupProvider; +import org.apache.qpid.server.model.Plugin; +import org.apache.qpid.server.model.PreferencesProvider; +import org.apache.qpid.server.model.SystemContext; +import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.security.access.FileAccessControlProviderConstants; +import org.apache.qpid.server.security.group.FileGroupManagerFactory; +import org.apache.qpid.server.store.ConfigurationRecoveryHandler; +import org.apache.qpid.server.store.ConfiguredObjectRecord; +import org.apache.qpid.server.store.ConfiguredObjectRecordImpl; +import org.apache.qpid.server.store.DurableConfigurationStore; + public class TestBrokerConfiguration { public static final String ENTRY_NAME_HTTP_PORT = "http"; @@ -63,17 +75,30 @@ public class TestBrokerConfiguration public TestBrokerConfiguration(String storeType, String intialStoreLocation) { - _store = new MemoryConfigurationEntryStore(intialStoreLocation, null, Collections.<String,String>emptyMap()); + _store = new MemoryConfigurationEntryStore(new SystemContext(new TaskExecutor(), new ConfiguredObjectFactory(), + mock(EventLogger.class), mock(LogRecorder.class), + mock(BrokerOptions.class)), + intialStoreLocation, + null, Collections.<String,String>emptyMap()); } public boolean setBrokerAttribute(String name, Object value) { - return setObjectAttribute(_store.getRootEntry(), name, value); + ConfiguredObjectRecord entry = findObject(Broker.class, null); + if (entry == null) + { + return false; + } + + return setObjectAttribute(entry, name, value); } - public boolean setObjectAttribute(String objectName, String attributeName, Object value) + public boolean setObjectAttribute(final Class<? extends ConfiguredObject> category, + String objectName, + String attributeName, + Object value) { - ConfigurationEntry entry = findObjectByName(objectName); + ConfiguredObjectRecord entry = findObject(category, objectName); if (entry == null) { return false; @@ -81,9 +106,11 @@ public class TestBrokerConfiguration return setObjectAttribute(entry, attributeName, value); } - public boolean setObjectAttributes(String objectName, Map<String, Object> attributes) + public boolean setObjectAttributes(final Class<? extends ConfiguredObject> category, + String objectName, + Map<String, Object> attributes) { - ConfigurationEntry entry = findObjectByName(objectName); + ConfiguredObjectRecord entry = findObject(category, objectName); if (entry == null) { return false; @@ -97,63 +124,38 @@ public class TestBrokerConfiguration return true; } - public UUID[] removeObjectConfiguration(String name) + public UUID[] removeObjectConfiguration(final Class<? extends ConfiguredObject> category, + String name) { - final ConfigurationEntry entry = findObjectByName(name); + final ConfiguredObjectRecord entry = findObject(category, name); if (entry != null) { - return _store.remove(new ConfiguredObjectRecord() - { - @Override - public UUID getId() - { - return entry.getId(); - } - - @Override - public String getType() - { - return entry.getType(); - } - - @Override - public Map<String, Object> getAttributes() - { - return entry.getAttributes(); - } - - @Override - public Map<String, ConfiguredObjectRecord> getParents() - { - // TODO RG : this should be rectified - return null; - } - }); + return _store.remove(entry); } return null; } - public UUID addObjectConfiguration(String name, String type, Map<String, Object> attributes) + public UUID addObjectConfiguration(Class<? extends ConfiguredObject> type, Map<String, Object> attributes) { UUID id = UUIDGenerator.generateRandomUUID(); - addObjectConfiguration(id, type, attributes); + addObjectConfiguration(id, type.getSimpleName(), attributes); return id; } public UUID addJmxManagementConfiguration() { Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(ConfiguredObject.TYPE, MANAGEMENT_JMX_PLUGIN_TYPE); + attributes.put(Plugin.TYPE, MANAGEMENT_JMX_PLUGIN_TYPE); attributes.put(Plugin.NAME, ENTRY_NAME_JMX_MANAGEMENT); - return addObjectConfiguration(ENTRY_NAME_JMX_MANAGEMENT, Plugin.class.getSimpleName(), attributes); + return addObjectConfiguration(Plugin.class, attributes); } public UUID addHttpManagementConfiguration() { Map<String, Object> attributes = new HashMap<String, Object>(); - attributes.put(ConfiguredObject.TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE); + attributes.put(Plugin.TYPE, MANAGEMENT_HTTP_PLUGIN_TYPE); attributes.put(Plugin.NAME, ENTRY_NAME_HTTP_MANAGEMENT); - return addObjectConfiguration(ENTRY_NAME_HTTP_MANAGEMENT, Plugin.class.getSimpleName(), attributes); + return addObjectConfiguration(Plugin.class, attributes); } public UUID addGroupFileConfiguration(String groupFilePath) @@ -163,7 +165,7 @@ public class TestBrokerConfiguration attributes.put(GroupProvider.TYPE, FileGroupManagerFactory.GROUP_FILE_PROVIDER_TYPE); attributes.put(FileGroupManagerFactory.PATH, groupFilePath); - return addGroupProviderConfiguration(attributes); + return addObjectConfiguration(GroupProvider.class, attributes); } public UUID addAclFileConfiguration(String aclFilePath) @@ -173,164 +175,104 @@ public class TestBrokerConfiguration attributes.put(AccessControlProvider.TYPE, FileAccessControlProviderConstants.ACL_FILE_PROVIDER_TYPE); attributes.put(FileAccessControlProviderConstants.PATH, aclFilePath); - return addAccessControlConfiguration(attributes); + return addObjectConfiguration(AccessControlProvider.class, attributes); } - public UUID addPortConfiguration(Map<String, Object> attributes) + private boolean setObjectAttributes(ConfiguredObjectRecord entry, Map<String, Object> attributes) { - String name = (String) attributes.get(Port.NAME); - return addObjectConfiguration(name, Port.class.getSimpleName(), attributes); + Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes()); + newAttributes.putAll(attributes); + ConfiguredObjectRecord newEntry = new ConfiguredObjectRecordImpl(entry.getId(), entry.getType(), newAttributes, + entry.getParents()); + _store.update(false, newEntry); + return true; } - public UUID addVirtualHostConfiguration(Map<String, Object> attributes) + private ConfiguredObjectRecord findObject(final Class<? extends ConfiguredObject> category, final String objectName) { - String name = (String) attributes.get(VirtualHost.NAME); - return addObjectConfiguration(name, VirtualHost.class.getSimpleName(), attributes); + final RecordFindingVisitor visitor = new RecordFindingVisitor(category, objectName); + _store.recoverConfigurationStore(visitor); + return visitor.getFoundRecord(); } - public UUID addAuthenticationProviderConfiguration(Map<String, Object> attributes) + private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes) { - String name = (String) attributes.get(AuthenticationProvider.NAME); - return addObjectConfiguration(name, AuthenticationProvider.class.getSimpleName(), attributes); - } + ConfiguredObjectRecord entry = new ConfiguredObjectRecordImpl(id, type, attributes, Collections.singletonMap(Broker.class.getSimpleName(), findObject(Broker.class,null))); - public UUID addGroupProviderConfiguration(Map<String, Object> attributes) - { - String name = (String) attributes.get(GroupProvider.NAME); - return addObjectConfiguration(name, GroupProvider.class.getSimpleName(), attributes); + _store.update(true, entry); } - public UUID addAccessControlConfiguration(Map<String, Object> attributes) + private boolean setObjectAttribute(ConfiguredObjectRecord entry, String attributeName, Object value) { - String name = (String) attributes.get(AccessControlProvider.NAME); - return addObjectConfiguration(name, AccessControlProvider.class.getSimpleName(), attributes); + Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); + attributes.put(attributeName, value); + ConfiguredObjectRecord newEntry = new ConfiguredObjectRecordImpl(entry.getId(), entry.getType(), attributes, entry.getParents()); + _store.update(false, newEntry); + return true; } - public UUID addTrustStoreConfiguration(Map<String, Object> attributes) + public boolean isSaved() { - String name = (String) attributes.get(TrustStore.NAME); - return addObjectConfiguration(name, TrustStore.class.getSimpleName(), attributes); + return _saved; } - public UUID addKeyStoreConfiguration(Map<String, Object> attributes) + public void setSaved(boolean saved) { - String name = (String) attributes.get(KeyStore.NAME); - return addObjectConfiguration(name, KeyStore.class.getSimpleName(), attributes); + _saved = saved; } - private boolean setObjectAttributes(ConfigurationEntry entry, Map<String, Object> attributes) + public void addPreferencesProviderConfiguration(String authenticationProvider, Map<String, Object> attributes) { - Map<String, Object> newAttributes = new HashMap<String, Object>(entry.getAttributes()); - newAttributes.putAll(attributes); - ConfigurationEntry newEntry = new ConfigurationEntryImpl(entry.getId(), entry.getType(), newAttributes, - entry.getChildrenIds(), _store); - _store.save(newEntry); - return true; - } + ConfiguredObjectRecord authProviderRecord = findObject(AuthenticationProvider.class, authenticationProvider); + ConfiguredObjectRecord pp = new ConfiguredObjectRecordImpl(UUIDGenerator.generateRandomUUID(), + PreferencesProvider.class.getSimpleName(), attributes, Collections.<String, ConfiguredObjectRecord>singletonMap(AuthenticationProvider.class.getSimpleName(),authProviderRecord)); - private ConfigurationEntry findObjectByName(String objectName) - { - ConfigurationEntry root = _store.getRootEntry(); - return findObjectByName(root, objectName); + _store.create(pp); } - private ConfigurationEntry findObjectByName(ConfigurationEntry entry, String objectName) + public Map<String,Object> getObjectAttributes(final Class<? extends ConfiguredObject> category, final String name) { - Map<String, Object> attributes = entry.getAttributes(); - if (attributes != null) - { - String name = (String) attributes.get("name"); - if (objectName.equals(name)) - { - return entry; - } - } - Set<UUID> childrenIds = entry.getChildrenIds(); - for (UUID uuid : childrenIds) - { - ConfigurationEntry child = _store.getEntry(uuid); - ConfigurationEntry result = findObjectByName(child, objectName); - if (result != null) - { - return result; - } - } - return null; + return findObject(category, name).getAttributes(); } - private void addObjectConfiguration(UUID id, String type, Map<String, Object> attributes) + private static class RecordFindingVisitor implements ConfigurationRecoveryHandler { - ConfigurationEntry entry = new ConfigurationEntryImpl(id, type, attributes, Collections.<UUID> emptySet(), _store); - ConfigurationEntry root = _store.getRootEntry(); - - Map<String, Collection<ConfigurationEntry>> children = root.getChildren(); + private final Class<? extends ConfiguredObject> _category; + private final String _objectName; + public ConfiguredObjectRecord _foundRecord; - verifyChildWithNameDoesNotExist(id, type, attributes, children); + public RecordFindingVisitor(final Class<? extends ConfiguredObject> category, final String objectName) + { + _category = category; + _objectName = objectName; + } - Set<UUID> childrenIds = new HashSet<UUID>(root.getChildrenIds()); - childrenIds.add(id); - ConfigurationEntry - newRoot = new ConfigurationEntryImpl(root.getId(), root.getType(), root.getAttributes(), childrenIds, - _store); - _store.save(newRoot, entry); - } + @Override + public void beginConfigurationRecovery(final DurableConfigurationStore store, final int configVersion) + { - private void verifyChildWithNameDoesNotExist(UUID id, String type, - Map<String, Object> attributes, - Map<String, Collection<ConfigurationEntry>> children) - { - Collection<ConfigurationEntry> childrenOfType = children.get(type); + } - if(childrenOfType != null) + @Override + public void configuredObject(final ConfiguredObjectRecord object) { - String name = (String) attributes.get("name"); - for(ConfigurationEntry ce : childrenOfType) + if (object.getType().equals(_category.getSimpleName()) + && (_objectName == null + || _objectName.equals(object.getAttributes().get(ConfiguredObject.NAME)))) { - Object ceName = ce.getAttributes().get("name"); - if(name.equals(ceName) && !id.equals(ce.getId())) - { - throw new IllegalConfigurationException("A " + type + " with name " + name + " already exists with a different ID"); - } + _foundRecord = object; } } - } - - private boolean setObjectAttribute(ConfigurationEntry entry, String attributeName, Object value) - { - Map<String, Object> attributes = new HashMap<String, Object>(entry.getAttributes()); - attributes.put(attributeName, value); - ConfigurationEntry - newEntry = new ConfigurationEntryImpl(entry.getId(), entry.getType(), attributes, entry.getChildrenIds(), - _store); - _store.save(newEntry); - return true; - } - - public boolean isSaved() - { - return _saved; - } - public void setSaved(boolean saved) - { - _saved = saved; - } - - public void addPreferencesProviderConfiguration(String authenticationProvider, Map<String, Object> attributes) - { - ConfigurationEntry pp = new ConfigurationEntryImpl(UUIDGenerator.generateRandomUUID(), - PreferencesProvider.class.getSimpleName(), attributes, Collections.<UUID> emptySet(), _store); - ConfigurationEntry ap = findObjectByName(authenticationProvider); - Set<UUID> children = new HashSet<UUID>(); - children.addAll(ap.getChildrenIds()); - children.add(pp.getId()); - ConfigurationEntry - newAp = new ConfigurationEntryImpl(ap.getId(), ap.getType(), ap.getAttributes(), children, _store); - _store.save(newAp, pp); - } + @Override + public int completeConfigurationRecovery() + { + return 0; + } - public Map<String, Object> getObjectAttributes(String name) - { - return findObjectByName(name).getAttributes(); + public ConfiguredObjectRecord getFoundRecord() + { + return _foundRecord; + } } } |