diff options
author | Alex Rudyy <orudyy@apache.org> | 2013-03-21 13:43:40 +0000 |
---|---|---|
committer | Alex Rudyy <orudyy@apache.org> | 2013-03-21 13:43:40 +0000 |
commit | a7f267df53b4b9bad41dc4a1a75be00bbc79fc52 (patch) | |
tree | 090b8fa2a47b800509ae47a6f0c9637103ba90d1 | |
parent | e60947dfba845a5b3067f58de7a341ab8ac15b35 (diff) | |
download | qpid-python-a7f267df53b4b9bad41dc4a1a75be00bbc79fc52.tar.gz |
QPID-4390: Add ability to save java broker store version with existing broker configuration stores. Add broker attributes for the store version, store type, store location and version of management interfaces.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1459307 13f79535-47bb-0310-9956-ffa450edef68
12 files changed, 123 insertions, 12 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java index d514bf25ce..5f3589c7ef 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntryStore.java @@ -62,12 +62,26 @@ public interface ConfigurationEntryStore * @param target location to copy store into * @throws IllegalConfigurationException if store cannot be copied into given location */ - public void copyTo(String copyLocation); + void copyTo(String copyLocation); /** * Return the store location for the opened store or null if store has not been opened. * * @return store location for the opened store or null if store has not been opened */ - public String getStoreLocation(); + String getStoreLocation(); + + /** + * Returns the version of the store + * + * @return store version + */ + int getVersion(); + + /** + * Returns the type of the store + * + * @return store type + */ + String getType(); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java index c9c8fc3688..b76717802c 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/startup/BrokerRecoverer.java @@ -50,7 +50,7 @@ public class BrokerRecoverer implements ConfiguredObjectRecoverer<Broker> { StoreConfigurationChangeListener storeChangeListener = new StoreConfigurationChangeListener(entry.getStore()); BrokerAdapter broker = new BrokerAdapter(entry.getId(), entry.getAttributes(), _statisticsGatherer, _virtualHostRegistry, - _logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor); + _logRecorder, _rootMessageLogger, _authenticationProviderFactory, _portFactory, _taskExecutor, entry.getStore()); broker.addChangeListener(storeChangeListener); Map<String, Collection<ConfigurationEntry>> childEntries = entry.getChildren(); diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java index 2ee072e5ff..413e9d2563 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java @@ -57,6 +57,12 @@ public class JsonConfigurationEntryStore extends MemoryConfigurationEntryStore } @Override + public String getType() + { + return STORE_TYPE; + } + + @Override public String toString() { return "JsonConfigurationEntryStore [_storeFile=" + _storeFile + ", _rootId=" + getRootEntry().getId() + "]"; @@ -81,7 +87,7 @@ public class JsonConfigurationEntryStore extends MemoryConfigurationEntryStore ConfigurationEntry rootEntry = initialStore.getRootEntry(); Map<UUID, ConfigurationEntry> entries = new HashMap<UUID, ConfigurationEntry>(); copyEntry(rootEntry.getId(), initialStore, entries); - saveAsTree(rootEntry.getId(), entries, getObjectMapper(), storeFile); + saveAsTree(rootEntry.getId(), entries, getObjectMapper(), storeFile, getVersion()); } } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java index 59247df25a..385d2f7327 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/ManagementModeStoreHandler.java @@ -149,6 +149,18 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore return _store.getStoreLocation(); } + @Override + public int getVersion() + { + return _store.getVersion(); + } + + @Override + public String getType() + { + return _store.getType(); + } + private Map<UUID, ConfigurationEntry> createPortsFromCommadLineOptions(BrokerOptions options) { int managementModeRmiPort = options.getManagementModeRmiPort(); @@ -312,4 +324,5 @@ public class ManagementModeStoreHandler implements ConfigurationEntryStore } return new ConfigurationEntry(entry.getId(), entry.getType(), attributes, children, entry.getStore()); } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java index 48ca01c312..5944adaa99 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java @@ -66,6 +66,8 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore private static final String ID = "id"; private static final String TYPE = "@type"; + private static final int STORE_VERSION = 1; + private final ObjectMapper _objectMapper; private final Map<UUID, ConfigurationEntry> _entries; private final Map<String, Class<? extends ConfiguredObject>> _relationshipClasses; @@ -189,6 +191,18 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore } @Override + public int getVersion() + { + return STORE_VERSION; + } + + @Override + public String getType() + { + return STORE_TYPE; + } + + @Override public String toString() { return "MemoryConfigurationEntryStore [_rootId=" + _rootId + "]"; @@ -215,12 +229,13 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore protected void saveAsTree(File file) { - saveAsTree(_rootId, _entries, _objectMapper, file); + saveAsTree(_rootId, _entries, _objectMapper, file, STORE_VERSION); } - protected void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file) + protected void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file, int version) { Map<String, Object> tree = toTree(rootId, entries); + tree.put(Broker.STORE_VERSION, version); try { mapper.writeValue(file, tree); @@ -317,8 +332,11 @@ public class MemoryConfigurationEntryStore implements ConfigurationEntryStore throw new IllegalConfigurationException("Duplicate id is found: " + entryId + "! The following configuration entries have the same id: " + entries.get(entryId) + ", " + entry); } - entries.put(entryId, entry); + Set<UUID> children = entry.getChildrenIds(); + Set<UUID> childrenCopy = children == null? null : new HashSet<UUID>(children); + ConfigurationEntry copy = new ConfigurationEntry(entryId, entry.getType(), new HashMap<String, Object>(entry.getAttributes()), childrenCopy, this); + entries.put(entryId, copy); if (children != null) { for (UUID uuid : children) diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java index 1d2fdd0452..21a22d032d 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Broker.java @@ -71,6 +71,10 @@ public interface Broker extends ConfiguredObject String HEART_BEAT_DELAY = "heartBeatDelay"; String STATISTICS_REPORTING_PERIOD = "statisticsReportingPeriod"; String STATISTICS_REPORTING_RESET_ENABLED = "statisticsReportingResetEnabled"; + String STORE_TYPE = "storeType"; + String STORE_VERSION = "storeVersion"; + String STORE_PATH = "storePath"; + String MANAGEMENT_VERSION = "managementVersion"; /* * A temporary attribute to pass the path to ACL file. @@ -131,6 +135,10 @@ public interface Broker extends ConfiguredObject HEART_BEAT_DELAY, STATISTICS_REPORTING_PERIOD, STATISTICS_REPORTING_RESET_ENABLED, + STORE_TYPE, + STORE_VERSION, + STORE_PATH, + MANAGEMENT_VERSION, ACL_FILE, KEY_STORE_PATH, diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java index 2c05dce9cb..3244d55fe2 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/Model.java @@ -29,6 +29,12 @@ import java.util.Map; public class Model { + /* + * API version for the broker management interfaces + */ + public static final int MANAGEMENT_API_MAJOR_VERSION = 1; + public static final int MANAGEMENT_API_MINOR_VERSION = 0; + private static final Model MODEL_INSTANCE = new Model(); private final Map<Class<? extends ConfiguredObject>, Collection<Class<? extends ConfiguredObject>>> diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java index 2d90bb4fc2..fd275b23bd 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java @@ -37,6 +37,7 @@ import java.security.cert.Certificate; import org.apache.log4j.Logger; import org.apache.qpid.common.QpidProperties; +import org.apache.qpid.server.configuration.ConfigurationEntryStore; import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.logging.LogRecorder; import org.apache.qpid.server.logging.RootMessageLogger; @@ -49,6 +50,7 @@ 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.LifetimePolicy; +import org.apache.qpid.server.model.Model; import org.apache.qpid.server.model.Plugin; import org.apache.qpid.server.model.Port; import org.apache.qpid.server.model.State; @@ -178,11 +180,12 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat private final UUID _defaultKeyStoreId; private final UUID _defaultTrustStoreId; - private Collection<String> _supportedStoreTypes; + private final Collection<String> _supportedStoreTypes; + private final ConfigurationEntryStore _brokerStore; public BrokerAdapter(UUID id, Map<String, Object> attributes, StatisticsGatherer statisticsGatherer, VirtualHostRegistry virtualHostRegistry, LogRecorder logRecorder, RootMessageLogger rootMessageLogger, AuthenticationProviderFactory authenticationProviderFactory, - PortFactory portFactory, TaskExecutor taskExecutor) + PortFactory portFactory, TaskExecutor taskExecutor, ConfigurationEntryStore brokerStore) { super(id, DEFAULTS, MapValueConverter.convert(attributes, ATTRIBUTE_TYPES), taskExecutor); _statisticsGatherer = statisticsGatherer; @@ -198,6 +201,7 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat _defaultTrustStoreId = UUIDGenerator.generateBrokerChildUUID(TrustStore.class.getSimpleName(), DEFAULT_TRUST_STORE_NAME); createBrokerChildrenFromAttributes(); _supportedStoreTypes = new MessageStoreCreator().getStoreTypes(); + _brokerStore = brokerStore; } /* @@ -705,6 +709,22 @@ public class BrokerAdapter extends AbstractAdapter implements Broker, Configurat } return null; } + else if (MANAGEMENT_VERSION.equals(name)) + { + return Model.MANAGEMENT_API_MAJOR_VERSION + "." + Model.MANAGEMENT_API_MINOR_VERSION; + } + else if (STORE_VERSION.equals(name)) + { + return _brokerStore.getVersion(); + } + else if (STORE_TYPE.equals(name)) + { + return _brokerStore.getType(); + } + else if (STORE_PATH.equals(name)) + { + return _brokerStore.getStoreLocation(); + } return super.getAttribute(name); } diff --git a/qpid/java/broker/src/main/resources/initial-store.json b/qpid/java/broker/src/main/resources/initial-store.json index 9fe72b3601..7e73772d6d 100644 --- a/qpid/java/broker/src/main/resources/initial-store.json +++ b/qpid/java/broker/src/main/resources/initial-store.json @@ -20,6 +20,7 @@ */ { "name": "QpidBroker", + "storeVersion": 1, "defaultAuthenticationProvider" : "passwordFile", "defaultVirtualHost" : "default", "authenticationproviders" : [ { diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java index b357c0b8e9..9d7f6a9cc1 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java @@ -110,7 +110,10 @@ public abstract class ConfigurationEntryStoreTestCase extends QpidTestCase assertEquals("Unexpected type ", Broker.class.getSimpleName(), brokerConfigEntry.getType()); Map<String, Object> attributes = brokerConfigEntry.getAttributes(); assertNotNull("Attributes cannot be null", attributes); - assertEquals("Unexpected attributes", _brokerAttributes, attributes); + for (Map.Entry<String, Object> attribute : _brokerAttributes.entrySet()) + { + assertEquals("Unexpected attribute " + attribute.getKey(), attribute.getValue(), attributes.get(attribute.getKey())); + } } public void testGetEntry() diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java index 92e304ab86..1cb760f611 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java @@ -52,6 +52,7 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest Map<String, Object> brokerObjectMap = new HashMap<String, Object>(); brokerObjectMap.put(Broker.ID, brokerId); brokerObjectMap.put("@type", Broker.class.getSimpleName()); + brokerObjectMap.put("storeVersion", 1); brokerObjectMap.putAll(brokerAttributes); StringWriter sw = new StringWriter(); @@ -114,8 +115,9 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest assertEquals("Unexpected root entry", brokerId, root.getId()); Map<String, Object> attributes = root.getAttributes(); assertNotNull("Attributes not found", attributes); - assertEquals("Unexpected number of attriburtes", 1, attributes.size()); + assertEquals("Unexpected number of attriburtes", 2, attributes.size()); assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); + assertEquals("Unexpected version attribute", 1, attributes.get(Broker.STORE_VERSION)); } public void testCreateFromInitialStore() throws Exception @@ -135,8 +137,18 @@ public class JsonConfigurationEntryStoreTest extends ConfigurationEntryStoreTest assertEquals("Unexpected root entry", brokerId, root.getId()); Map<String, Object> attributes = root.getAttributes(); assertNotNull("Attributes not found", attributes); - assertEquals("Unexpected number of attriburtes", 1, attributes.size()); + assertEquals("Unexpected number of attriburtes", 2, attributes.size()); assertEquals("Unexpected name attribute", getTestName(), attributes.get(Broker.NAME)); + assertEquals("Unexpected version attribute", 1, attributes.get(Broker.STORE_VERSION)); } + public void testGetVersion() + { + assertEquals("Unexpected version", 1, getStore().getVersion()); + } + + public void testGetType() + { + assertEquals("Unexpected type", "json", getStore().getType()); + } } diff --git a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java index 65ced69915..314e673c08 100644 --- a/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java +++ b/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java @@ -94,4 +94,14 @@ public class MemoryConfigurationEntryStoreTest extends ConfigurationEntryStoreTe assertEquals("Unexpected broker attributes", initialStoreRoot.getAttributes(), root.getAttributes()); assertEquals("Unexpected broker children", initialStoreRoot.getChildrenIds(), root.getChildrenIds()); } + + public void testGetVersion() + { + assertEquals("Unexpected version", 1, getStore().getVersion()); + } + + public void testGetType() + { + assertEquals("Unexpected type", "memory", getStore().getType()); + } } |