diff options
| author | Keith Wall <kwall@apache.org = kwall = Keith Wall kwall@apache.org@apache.org> | 2014-04-14 08:54:19 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org = kwall = Keith Wall kwall@apache.org@apache.org> | 2014-04-14 08:54:19 +0000 |
| commit | cde1072e86b57286594eb4fdb494576689aa8bca (patch) | |
| tree | 8e0f378d16d5cf564f8ab0d2f93e5ec6f338621f /qpid/java/bdbstore | |
| parent | 981b8f5357355f842a523e4b50a1d5c711095a68 (diff) | |
| download | qpid-python-cde1072e86b57286594eb4fdb494576689aa8bca.tar.gz | |
QPID-5685: Store configuration version as an attribute of virtualhost within configuration store rather than within separate database/table
* ConfiguredObjectRecordHandler begin/end methods no longer take/return config version
* DefaultUpgraderProvider uses the virtualhost record for the config version only and uses this to trigger
the correct upgrade. Note this record is *not* recovered (yet).
* BDB/SQL Upgraders migrate the config version from database/table to be the modelVersion attribute of a virtualhost entry.
* BDB Upgrader tests (7 to 8).
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1587165 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java/bdbstore')
5 files changed, 455 insertions, 109 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java index 652e4c135d..722a3a090d 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStore.java @@ -70,7 +70,6 @@ import org.apache.qpid.server.util.MapValueConverter; import org.apache.qpid.util.FileUtils; import com.sleepycat.bind.tuple.ByteBinding; -import com.sleepycat.bind.tuple.IntegerBinding; import com.sleepycat.bind.tuple.LongBinding; import com.sleepycat.je.CheckpointConfig; import com.sleepycat.je.Cursor; @@ -109,8 +108,7 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore private static String BRIDGEDB_NAME = "BRIDGES"; private static String LINKDB_NAME = "LINKS"; private static String XID_DB_NAME = "XIDS"; - private static String CONFIG_VERSION_DB_NAME = "CONFIG_VERSION"; - private static final String[] CONFIGURATION_STORE_DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIG_VERSION_DB_NAME , CONFIGURED_OBJECT_HIERARCHY_DB_NAME}; + private static final String[] CONFIGURATION_STORE_DATABASE_NAMES = new String[] { CONFIGURED_OBJECTS_DB_NAME, CONFIGURED_OBJECT_HIERARCHY_DB_NAME}; private static final String[] MESSAGE_STORE_DATABASE_NAMES = new String[] { MESSAGE_META_DATA_DB_NAME, MESSAGE_CONTENT_DB_NAME, DELIVERY_DB_NAME, BRIDGEDB_NAME, LINKDB_NAME, XID_DB_NAME }; private EnvironmentFacade _environmentFacade; @@ -182,16 +180,9 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore try { - int configVersion = getConfigVersion(); - - handler.begin(configVersion); + handler.begin(); doVisitAllConfiguredObjectRecords(handler); - - int newConfigVersion = handler.end(); - if(newConfigVersion != configVersion) - { - updateConfigVersion(newConfigVersion); - } + handler.end(); } catch (DatabaseException e) { @@ -372,70 +363,6 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore } } - @SuppressWarnings("resource") - private void updateConfigVersion(int newConfigVersion) throws StoreException - { - Transaction txn = null; - Cursor cursor = null; - try - { - txn = _environmentFacade.getEnvironment().beginTransaction(null, null); - cursor = getConfigVersionDb().openCursor(txn, null); - DatabaseEntry key = new DatabaseEntry(); - ByteBinding.byteToEntry((byte) 0,key); - DatabaseEntry value = new DatabaseEntry(); - - while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) - { - IntegerBinding.intToEntry(newConfigVersion, value); - OperationStatus status = cursor.put(key, value); - if (status != OperationStatus.SUCCESS) - { - throw new StoreException("Error setting config version: " + status); - } - } - cursor.close(); - cursor = null; - txn.commit(); - txn = null; - } - finally - { - closeCursorSafely(cursor); - abortTransactionIgnoringException("Error setting config version", txn);; - } - - } - - private int getConfigVersion() throws StoreException - { - Cursor cursor = null; - try - { - cursor = getConfigVersionDb().openCursor(null, null); - DatabaseEntry key = new DatabaseEntry(); - DatabaseEntry value = new DatabaseEntry(); - while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) - { - return IntegerBinding.entryToInt(value); - } - - // Insert 0 as the default config version - IntegerBinding.intToEntry(0,value); - ByteBinding.byteToEntry((byte) 0,key); - OperationStatus status = getConfigVersionDb().put(null, key, value); - if (status != OperationStatus.SUCCESS) - { - throw new StoreException("Error initialising config version: " + status); - } - return 0; - } - finally - { - closeCursorSafely(cursor); - } - } - private void closeCursorSafely(Cursor cursor) throws StoreException { if (cursor != null) @@ -1622,11 +1549,6 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore return _environmentFacade.getOpenDatabase(MESSAGE_CONTENT_DB_NAME); } - private Database getConfigVersionDb() - { - return _environmentFacade.getOpenDatabase(CONFIG_VERSION_DB_NAME); - } - private Database getMessageMetaDataDb() { return _environmentFacade.getOpenDatabase(MESSAGE_META_DATA_DB_NAME); @@ -1644,8 +1566,7 @@ public class BDBMessageStore implements MessageStore, DurableConfigurationStore class UpgradeTask implements EnvironmentFacadeTask { - - private ConfiguredObject<?> _parent; + private final ConfiguredObject<?> _parent; public UpgradeTask(ConfiguredObject<?> parent) { diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java index e5e1201c6a..8f3cf73275 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8.java @@ -20,32 +20,38 @@ */ package org.apache.qpid.server.store.berkeleydb.upgrade; -import com.sleepycat.bind.tuple.ByteBinding; -import com.sleepycat.bind.tuple.IntegerBinding; -import com.sleepycat.bind.tuple.TupleBinding; -import com.sleepycat.bind.tuple.TupleInput; -import com.sleepycat.bind.tuple.TupleOutput; -import com.sleepycat.je.*; +import java.io.IOException; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import org.apache.qpid.server.model.ConfiguredObject; - +import org.apache.qpid.server.model.Model; +import org.apache.qpid.server.model.UUIDGenerator; import org.apache.qpid.server.store.ConfiguredObjectRecord; import org.apache.qpid.server.store.StoreException; -import org.apache.qpid.server.store.berkeleydb.BDBConfiguredObjectRecord; -import org.apache.qpid.server.store.berkeleydb.entry.HierarchyKey; import org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding; -import org.apache.qpid.server.store.berkeleydb.tuple.HierarchyKeyBinding; import org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding; import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; -import java.io.IOException; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import com.sleepycat.bind.tuple.IntegerBinding; +import com.sleepycat.bind.tuple.TupleBinding; +import com.sleepycat.bind.tuple.TupleInput; +import com.sleepycat.bind.tuple.TupleOutput; +import com.sleepycat.je.Cursor; +import com.sleepycat.je.Database; +import com.sleepycat.je.DatabaseConfig; +import com.sleepycat.je.DatabaseEntry; +import com.sleepycat.je.Environment; +import com.sleepycat.je.LockMode; +import com.sleepycat.je.OperationStatus; +import com.sleepycat.je.Transaction; public class UpgradeFrom7To8 extends AbstractStoreUpgrade { + private static final TypeReference<HashMap<String, Object>> MAP_TYPE_REFERENCE = new TypeReference<HashMap<String,Object>>(){}; @Override public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) @@ -58,9 +64,25 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade Database hierarchyDb = environment.openDatabase(null, "CONFIGURED_OBJECT_HIERARCHY", dbConfig); Database configuredObjectsDb = environment.openDatabase(null, "CONFIGURED_OBJECTS", dbConfig); + Database configVersionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig); Cursor objectsCursor = null; + String stringifiedConfigVersion = Model.MODEL_VERSION; + int configVersion = getConfigVersion(configVersionDb); + if (configVersion > -1) + { + stringifiedConfigVersion = "0." + configVersion; + } + configVersionDb.close(); + + Map<String, Object> virtualHostAttributes = new HashMap<String, Object>(); + virtualHostAttributes.put("modelVersion", stringifiedConfigVersion); + + String virtualHostName = parent.getName(); + UUID virtualHostId = UUIDGenerator.generateVhostUUID(virtualHostName); + ConfiguredObjectRecord virtualHostRecord = new org.apache.qpid.server.store.ConfiguredObjectRecordImpl(virtualHostId, "VirtualHost", virtualHostAttributes); + Transaction txn = environment.beginTransaction(null, null); try @@ -69,9 +91,6 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade DatabaseEntry key = new DatabaseEntry(); DatabaseEntry value = new DatabaseEntry(); - Map<UUID, BDBConfiguredObjectRecord> configuredObjects = - new HashMap<UUID, BDBConfiguredObjectRecord>(); - while (objectsCursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) { UUID id = UUIDTupleBinding.getInstance().entryToObject(key); @@ -80,7 +99,7 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade if(!type.endsWith("Binding")) { - UUIDTupleBinding.getInstance().objectToEntry(parent.getId(),value); + UUIDTupleBinding.getInstance().objectToEntry(virtualHostId, value); TupleOutput tupleOutput = new TupleOutput(); tupleOutput.writeLong(id.getMostSignificantBits()); tupleOutput.writeLong(id.getLeastSignificantBits()); @@ -97,7 +116,7 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade DatabaseEntry hierarchyKey = new DatabaseEntry(); DatabaseEntry hierarchyValue = new DatabaseEntry(); - Map<String,Object> attributes = mapper.readValue(json, Map.class); + Map<String,Object> attributes = mapper.readValue(json, MAP_TYPE_REFERENCE); Object queueIdString = attributes.remove("queue"); if(queueIdString instanceof String) { @@ -134,13 +153,8 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade { throw new StoreException(e); } - } - - } - - } finally { @@ -149,13 +163,51 @@ public class UpgradeFrom7To8 extends AbstractStoreUpgrade objectsCursor.close(); } } + + storeConfiguredObjectEntry(configuredObjectsDb, txn, virtualHostRecord); txn.commit(); hierarchyDb.close(); configuredObjectsDb.close(); + reportFinished(environment, 8); + } + private int getConfigVersion(Database configVersionDb) + { + Cursor cursor = null; + try + { + cursor = configVersionDb.openCursor(null, null); + DatabaseEntry key = new DatabaseEntry(); + DatabaseEntry value = new DatabaseEntry(); + while (cursor.getNext(key, value, LockMode.RMW) == OperationStatus.SUCCESS) + { + return IntegerBinding.entryToInt(value); + } + return -1; + } + finally + { + cursor.close(); + } + } - reportFinished(environment, 8); + private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject) + { + DatabaseEntry key = new DatabaseEntry(); + UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance(); + uuidBinding.objectToEntry(configuredObject.getId(), key); + + DatabaseEntry value = new DatabaseEntry(); + ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance(); + + configuredObjectBinding.objectToEntry(configuredObject, value); + OperationStatus status = configuredObjectsDb.put(txn, key, value); + if (status != OperationStatus.SUCCESS) + { + throw new StoreException("Error writing configured object " + configuredObject + " to database: " + + status); + } } } diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8Test.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8Test.java new file mode 100644 index 0000000000..57adc5afe4 --- /dev/null +++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/upgrade/UpgradeFrom7To8Test.java @@ -0,0 +1,367 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.apache.qpid.server.store.berkeleydb.upgrade; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; + +import org.apache.qpid.server.model.Binding; +import org.apache.qpid.server.model.Exchange; +import org.apache.qpid.server.model.LifetimePolicy; +import org.apache.qpid.server.model.Queue; +import org.apache.qpid.server.model.UUIDGenerator; +import org.apache.qpid.server.model.VirtualHost; +import org.apache.qpid.server.util.MapJsonSerializer; + +import com.sleepycat.bind.tuple.TupleBinding; +import com.sleepycat.bind.tuple.TupleInput; +import com.sleepycat.bind.tuple.TupleOutput; +import com.sleepycat.je.Database; +import com.sleepycat.je.DatabaseEntry; +import com.sleepycat.je.Transaction; + +public class UpgradeFrom7To8Test extends AbstractUpgradeTestCase +{ + private static final String ARGUMENTS = "arguments"; + + private static final String CONFIGURED_OBJECTS_DB_NAME = "CONFIGURED_OBJECTS"; + private static final String CONFIGURED_OBJECT_HIERARCHY_DB_NAME = "CONFIGURED_OBJECT_HIERARCHY"; + + @Override + public VirtualHost<?,?,?> getVirtualHost() + { + VirtualHost<?,?,?> virtualHost = mock(VirtualHost.class); + when(virtualHost.getName()).thenReturn("test"); + return virtualHost; + } + + @Override + protected String getStoreDirectoryName() + { + return "bdbstore-v7"; + } + + public void testPerformUpgrade() throws Exception + { + UpgradeFrom7To8 upgrade = new UpgradeFrom7To8(); + upgrade.performUpgrade(_environment, UpgradeInteractionHandler.DEFAULT_HANDLER, getVirtualHost()); + + assertDatabaseRecordCount(CONFIGURED_OBJECTS_DB_NAME, 7); + assertDatabaseRecordCount(CONFIGURED_OBJECT_HIERARCHY_DB_NAME, 9); + + assertConfiguredObjects(); + assertConfiguredObjectHierarchy(); + } + + + private void assertConfiguredObjectHierarchy() + { + Map<UpgradeHierarchyKey, UUID> hierarchy = loadConfiguredObjectHierarchy(); + assertEquals("Unexpected number of configured objects", 9, hierarchy.size()); + + UUID vhUuid = UUIDGenerator.generateVhostUUID(getVirtualHost().getName()); + UUID myExchUuid = UUIDGenerator.generateExchangeUUID("myexch", getVirtualHost().getName()); + UUID amqDirectUuid = UUIDGenerator.generateExchangeUUID("amq.direct", getVirtualHost().getName()); + UUID queue1Uuid = UUIDGenerator.generateQueueUUID("queue1", getVirtualHost().getName()); + UUID queue1ToAmqDirectBindingUuid = UUIDGenerator.generateBindingUUID("amq.direct", "queue1", "queue1", getVirtualHost().getName()); + + // myexch -> virtualhost + UpgradeHierarchyKey myExchToVhParent = new UpgradeHierarchyKey(myExchUuid, VirtualHost.class.getSimpleName()); + assertExpectedHierarchyEntry(hierarchy, myExchToVhParent, vhUuid); + + // queue1 -> virtualhost + UpgradeHierarchyKey queue1ToVhParent = new UpgradeHierarchyKey(queue1Uuid, VirtualHost.class.getSimpleName()); + assertExpectedHierarchyEntry(hierarchy, queue1ToVhParent, vhUuid); + + // ! amq.direct -> virtualhost (This will change when the upgrader is changed to create the default exchanges) + UpgradeHierarchyKey amqDirectToVhParent = new UpgradeHierarchyKey(amqDirectUuid, VirtualHost.class.getSimpleName()); + assertFalse("amq.direct should not have a binding to virtualhost", hierarchy.containsKey(amqDirectToVhParent)); + + // queue1binding -> amq.direct + // queue1binding -> queue1 + UpgradeHierarchyKey queue1BindingToAmqDirect = new UpgradeHierarchyKey(queue1ToAmqDirectBindingUuid, Exchange.class.getSimpleName()); + UpgradeHierarchyKey queue1BindingToQueue1 = new UpgradeHierarchyKey(queue1ToAmqDirectBindingUuid, Queue.class.getSimpleName()); + assertExpectedHierarchyEntry(hierarchy, queue1BindingToAmqDirect, amqDirectUuid); + assertExpectedHierarchyEntry(hierarchy, queue1BindingToQueue1, queue1Uuid); + } + + private void assertExpectedHierarchyEntry( + Map<UpgradeHierarchyKey, UUID> hierarchy, + UpgradeHierarchyKey childHierarchyKey, UUID parentUUID) + { + assertTrue("Expected hierarchy entry does not exist", hierarchy.containsKey(childHierarchyKey)); + assertEquals("Expected hierarchy entry does not exist", parentUUID, hierarchy.get(childHierarchyKey)); + } + + + private void assertConfiguredObjects() + { + Map<UUID, UpgradeConfiguredObjectRecord> configuredObjects = loadConfiguredObjects(); + assertEquals("Unexpected number of configured objects", 7, configuredObjects.size()); + + Map<UUID, Map<String, Object>> expected = new HashMap<UUID, Map<String, Object>>(); + + String configVersion = "0.3"; + expected.putAll(createExpectedVirtualHost(configVersion)); + + expected.putAll(createExpectedQueue("queue1", Boolean.FALSE, null, null)); + expected.putAll(createExpectedQueue("queue2", Boolean.FALSE, null, null)); + + expected.putAll(createExpectedExchangeMap("myexch", "direct")); + + expected.putAll(createExpectedBindingMap("queue1", "queue1", "amq.direct", null)); + expected.putAll(createExpectedBindingMap("queue1", "queue1", "myexch", null)); + expected.putAll(createExpectedBindingMap("queue2", "queue2", "amq.fanout", null)); + + MapJsonSerializer jsonSerializer = new MapJsonSerializer(); + for (Entry<UUID, UpgradeConfiguredObjectRecord> entry : configuredObjects.entrySet()) + { + UpgradeConfiguredObjectRecord object = entry.getValue(); + + UUID actualKey = entry.getKey(); + String actualType = object.getType(); + String actualJson = object.getAttributes(); + Map<String, Object> actualDeserializedAttributes = jsonSerializer.deserialize(actualJson); + + assertTrue("Entry UUID " + actualKey + " of type " + actualType + " is unexpected", expected.containsKey(actualKey)); + + Map<String, Object> expectedDeserializedAttributes = expected.get(actualKey); + + assertEquals("Entry UUID " + actualKey + " of type " + actualType + " has uenxpected deserialised value, json was: " + actualJson, + expectedDeserializedAttributes, actualDeserializedAttributes); + } + } + + private Map<UUID, Map<String, Object>> createExpectedVirtualHost(String modelVersion) + { + Map<String, Object> expectedVirtualHostEntry = new HashMap<String, Object>(); + expectedVirtualHostEntry.put("modelVersion", modelVersion); + + UUID expectedUUID = UUIDGenerator.generateVhostUUID(getVirtualHost().getName()); + return Collections.singletonMap(expectedUUID, expectedVirtualHostEntry); + } + + private Map<UUID, Map<String, Object>> createExpectedQueue(String queueName, boolean exclusiveFlag, String owner, Map<String, Object> argumentMap) + { + Map<String, Object> expectedQueueEntry = new HashMap<String, Object>(); + expectedQueueEntry.put(Queue.NAME, queueName); + expectedQueueEntry.put(Queue.EXCLUSIVE, exclusiveFlag); + expectedQueueEntry.put(Queue.OWNER, owner); + expectedQueueEntry.put(Queue.TYPE, "standard"); + + if (argumentMap != null) + { + expectedQueueEntry.put(ARGUMENTS, argumentMap); + } + UUID expectedUUID = UUIDGenerator.generateQueueUUID(queueName, getVirtualHost().getName()); + return Collections.singletonMap(expectedUUID, expectedQueueEntry); + } + + private Map<UUID, Map<String, Object>> createExpectedExchangeMap(String exchangeName, String type) + { + Map<String, Object> expectedExchangeMap = new HashMap<String, Object>(); + expectedExchangeMap.put(Exchange.NAME, exchangeName); + expectedExchangeMap.put(Exchange.TYPE, type); + expectedExchangeMap.put(Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT.name()); + UUID expectedUUID = UUIDGenerator.generateExchangeUUID(exchangeName, getVirtualHost().getName()); + return Collections.singletonMap(expectedUUID, expectedExchangeMap); + } + + private Map<UUID, Map<String, Object>> createExpectedBindingMap(String queueName, String bindingName, String exchangeName, Map<String, String> argumentMap) + { + Map<String, Object> expectedBinding = new HashMap<String, Object>(); + expectedBinding.put(Binding.NAME, bindingName); + expectedBinding.put(Binding.ARGUMENTS, argumentMap == null ? Collections.emptyMap() : argumentMap); + + UUID expectedUUID = UUIDGenerator.generateBindingUUID(exchangeName, queueName, bindingName, getVirtualHost().getName()); + return Collections.singletonMap(expectedUUID, expectedBinding); + } + + private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() + { + final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>(); + final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding(); + final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding(); + CursorOperation configuredObjectsCursor = new CursorOperation() + { + @Override + public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, + DatabaseEntry key, DatabaseEntry value) + { + UUID id = uuidBinding.entryToObject(key); + UpgradeConfiguredObjectRecord object = binding.entryToObject(value); + configuredObjectsRecords.put(id, object); + } + }; + new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor); + return configuredObjectsRecords; + } + + + private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy() + { + final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>(); + final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding(); + final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding(); + CursorOperation hierarchyCursor = new CursorOperation() + { + @Override + public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, + DatabaseEntry key, DatabaseEntry value) + { + UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key); + UUID parentId = uuidParentBinding.entryToObject(value); + hierarchyRecords.put(hierarchyKey, parentId); + } + }; + new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor); + return hierarchyRecords; + } + + private static class UpgradeConfiguredObjectBinding extends TupleBinding<UpgradeConfiguredObjectRecord> + { + @Override + public UpgradeConfiguredObjectRecord entryToObject(TupleInput tupleInput) + { + String type = tupleInput.readString(); + String json = tupleInput.readString(); + UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(type, json); + return configuredObject; + } + + @Override + public void objectToEntry(UpgradeConfiguredObjectRecord object, TupleOutput tupleOutput) + { + throw new UnsupportedOperationException(); + } + } + + private static class UpgradeConfiguredObjectRecord + { + private final String _attributes; + private final String _type; + + public UpgradeConfiguredObjectRecord(String type, String attributes) + { + super(); + _attributes = attributes; + _type = type; + } + + public String getAttributes() + { + return _attributes; + } + + public String getType() + { + return _type; + } + + } + + private static class UpgradeUUIDBinding extends TupleBinding<UUID> + { + @Override + public UUID entryToObject(final TupleInput tupleInput) + { + return new UUID(tupleInput.readLong(), tupleInput.readLong()); + } + + @Override + public void objectToEntry(final UUID uuid, final TupleOutput tupleOutput) + { + throw new UnsupportedOperationException(); + } + } + + private static class UpgradeHierarchyKeyBinding extends TupleBinding<UpgradeHierarchyKey> + { + @Override + public UpgradeHierarchyKey entryToObject(TupleInput tupleInput) + { + UUID childId = new UUID(tupleInput.readLong(), tupleInput.readLong()); + String parentType = tupleInput.readString(); + + return new UpgradeHierarchyKey(childId, parentType); + } + + @Override + public void objectToEntry(UpgradeHierarchyKey hk, TupleOutput tupleOutput) + { + throw new UnsupportedOperationException(); + } + } + + private static class UpgradeHierarchyKey + { + private final UUID _childId; + private final String _parentType; + + public UpgradeHierarchyKey(final UUID childId, final String parentType) + { + _childId = childId; + _parentType = parentType; + } + + @Override + public boolean equals(final Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + final UpgradeHierarchyKey that = (UpgradeHierarchyKey) o; + + if (!_childId.equals(that._childId)) + { + return false; + } + if (!_parentType.equals(that._parentType)) + { + return false; + } + + return true; + } + + @Override + public int hashCode() + { + int result = _childId.hashCode(); + result = 31 * result + _parentType.hashCode(); + return result; + } + + } + +} diff --git a/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/readme.txt b/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/readme.txt new file mode 100644 index 0000000000..efb929c944 --- /dev/null +++ b/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/readme.txt @@ -0,0 +1,6 @@ +The bdbstore v7 data was obtained by running 0.26 and: + +* creating an exchange 'myexch' of type direct +* creating queues 'queue1' and 'queue2' +* binding 'queue1' to 'myexch' and 'amq.direct' using binding key 'queue1' +* binding 'queue2' to amq.fanout only using binding key 'queue2'
\ No newline at end of file diff --git a/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/test-store/00000000.jdb b/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/test-store/00000000.jdb Binary files differnew file mode 100644 index 0000000000..4957f86e1a --- /dev/null +++ b/qpid/java/bdbstore/src/test/resources/upgrade/bdbstore-v7/test-store/00000000.jdb |
