summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader1_3.java389
1 files changed, 216 insertions, 173 deletions
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader1_3.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader1_3.java
index 913ed4d773..9d30ce754e 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader1_3.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/startup/StoreUpgrader1_3.java
@@ -23,10 +23,11 @@ package org.apache.qpid.server.configuration.startup;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.apache.qpid.server.configuration.ConfigurationEntry;
@@ -37,6 +38,7 @@ import org.apache.qpid.server.model.Broker;
@SuppressWarnings("serial")
public final class StoreUpgrader1_3 extends StoreUpgrader
{
+
public static final String VERSION = "1.3";
private Map<String, VirtualHostEntryUpgrader> _vhostUpgraderMap = new HashMap<String, VirtualHostEntryUpgrader>()
@@ -83,263 +85,304 @@ public final class StoreUpgrader1_3 extends StoreUpgrader
store.save(changed.toArray(new ConfigurationEntry[changed.size()]));
}
- public interface VirtualHostEntryUpgrader
+ private interface VirtualHostEntryUpgrader
{
ConfigurationEntry upgrade(ConfigurationEntryStore store, ConfigurationEntry vhost);
}
- public class BdbHaVirtualHostUpgrader implements VirtualHostEntryUpgrader
+ private class StandardVirtualHostUpgrader implements VirtualHostEntryUpgrader
{
- private final String[] HA_ATTRIBUTES =
- { "storePath", "haNodeName", "haGroupName", "haHelperAddress", "haCoalescingSync", "haNodeAddress", "haDurability",
- "haDesignatedPrimary", "haReplicationConfig", "bdbEnvironmentConfig" };
+ Map<String, AttributesTransformer> _messageStoreAttributeTransformers = new HashMap<String, AttributesTransformer>()
+ {{
+ put("DERBY", new AttributesTransformer().
+ addAttributeTransformer("storePath", copyAttribute()).
+ addAttributeTransformer("storeUnderfullSize", copyAttribute()).
+ addAttributeTransformer("storeOverfullSize", copyAttribute()).
+ addAttributeTransformer("storeType", mutateAttributeValue("DERBY")));
+ put("MEMORY", new AttributesTransformer().
+ addAttributeTransformer("storeType", mutateAttributeValue("Memory")));
+ put("BDB", new AttributesTransformer().
+ addAttributeTransformer("storePath", copyAttribute()).
+ addAttributeTransformer("storeUnderfullSize", copyAttribute()).
+ addAttributeTransformer("storeOverfullSize", copyAttribute()).
+ addAttributeTransformer("bdbEnvironmentConfig", copyAttribute()).
+ addAttributeTransformer("storeType", mutateAttributeValue("BDB")));
+ put("JDBC", new AttributesTransformer().
+ addAttributeTransformer("storePath", mutateAttributeName("connectionURL")).
+ addAttributeTransformer("connectionURL", copyAttribute()).
+ addAttributeTransformer("connectionPool", copyAttribute()).
+ addAttributeTransformer("jdbcBigIntType", copyAttribute()).
+ addAttributeTransformer("jdbcBytesForBlob", copyAttribute()).
+ addAttributeTransformer("jdbcBlobType", copyAttribute()).
+ addAttributeTransformer("jdbcVarbinaryType", copyAttribute()).
+ addAttributeTransformer("partitionCount", copyAttribute()).
+ addAttributeTransformer("maxConnectionsPerPartition", copyAttribute()).
+ addAttributeTransformer("minConnectionsPerPartition", copyAttribute()).
+ addAttributeTransformer("storeType", mutateAttributeValue("JDBC")));
+ }};
+
+ Map<String, AttributesTransformer> _configurationStoreAttributeTransformers = new HashMap<String, AttributesTransformer>()
+ {{
+ put("DERBY", new AttributesTransformer().
+ addAttributeTransformer("configStorePath", mutateAttributeName("storePath")).
+ addAttributeTransformer("configStoreType", mutateAttributeName("storeType"), mutateAttributeValue("DERBY")));
+ put("MEMORY", new AttributesTransformer().
+ addAttributeTransformer("configStoreType", mutateAttributeValue("Memory")));
+ put("JSON", new AttributesTransformer().
+ addAttributeTransformer("configStorePath", mutateAttributeName("storePath")).
+ addAttributeTransformer("configStoreType", mutateAttributeName("storeType"), mutateAttributeValue("JSON")));
+ put("BDB", new AttributesTransformer().
+ addAttributeTransformer("configStorePath", mutateAttributeName("storePath")).
+ addAttributeTransformer("bdbEnvironmentConfig", copyAttribute()).
+ addAttributeTransformer("configStoreType", mutateAttributeName("storeType"), mutateAttributeValue("BDB")));
+ put("JDBC", new AttributesTransformer().
+ addAttributeTransformer("configStorePath", mutateAttributeName("connectionURL")).
+ addAttributeTransformer("configConnectionURL", mutateAttributeName("connectionURL")).
+ addAttributeTransformer("connectionPool", copyAttribute()).
+ addAttributeTransformer("jdbcBigIntType", copyAttribute()).
+ addAttributeTransformer("jdbcBytesForBlob", copyAttribute()).
+ addAttributeTransformer("jdbcBlobType", copyAttribute()).
+ addAttributeTransformer("jdbcVarbinaryType", copyAttribute()).
+ addAttributeTransformer("partitionCount", copyAttribute()).
+ addAttributeTransformer("maxConnectionsPerPartition", copyAttribute()).
+ addAttributeTransformer("minConnectionsPerPartition", copyAttribute()).
+ addAttributeTransformer("configStoreType", mutateAttributeName("storeType"), mutateAttributeValue("JDBC")));
+ }};
@Override
public ConfigurationEntry upgrade(ConfigurationEntryStore store, ConfigurationEntry vhost)
{
Map<String, Object> attributes = vhost.getAttributes();
Map<String, Object> newAttributes = new HashMap<String, Object>(attributes);
- Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
- for (String haAttribute : HA_ATTRIBUTES)
+ String capitalisedStoreType = String.valueOf(attributes.get("storeType")).toUpperCase();
+ AttributesTransformer vhAttrsToMessageStoreSettings = _messageStoreAttributeTransformers.get(capitalisedStoreType);
+ Map<String, Object> messageStoreSettings = null;
+ if (vhAttrsToMessageStoreSettings != null)
{
- if (attributes.containsKey(haAttribute))
- {
- messageStoreSettings.put(haAttribute, newAttributes.remove(haAttribute));
- }
+ messageStoreSettings = vhAttrsToMessageStoreSettings.upgrade(attributes);
}
- if (attributes.containsKey("storeUnderfullSize"))
+ if (attributes.containsKey("configStoreType"))
{
- messageStoreSettings.put("storeUnderfullSize", newAttributes.remove("storeUnderfullSize"));
+ String capitaliseConfigStoreType = ((String) attributes.get("configStoreType")).toUpperCase();
+ AttributesTransformer vhAttrsToConfigurationStoreSettings = _configurationStoreAttributeTransformers
+ .get(capitaliseConfigStoreType);
+ Map<String, Object> configurationStoreSettings = vhAttrsToConfigurationStoreSettings.upgrade(attributes);
+ newAttributes.keySet().removeAll(vhAttrsToConfigurationStoreSettings.getNamesToBeDeleted());
+ newAttributes.put("configurationStoreSettings", configurationStoreSettings);
}
- if (attributes.containsKey("storeOverfullSize"))
+
+ if (vhAttrsToMessageStoreSettings != null)
{
- messageStoreSettings.put("storeOverfullSize", newAttributes.remove("storeOverfullSize"));
+ newAttributes.keySet().removeAll(vhAttrsToMessageStoreSettings.getNamesToBeDeleted());
+ newAttributes.put("messageStoreSettings", messageStoreSettings);
}
- newAttributes.remove("storeType");
- newAttributes.put("messageStoreSettings", messageStoreSettings);
+
return new ConfigurationEntry(vhost.getId(), vhost.getType(), newAttributes, vhost.getChildrenIds(), store);
}
-
}
- public interface StoreEntryUpgrader
+ private class BdbHaVirtualHostUpgrader implements VirtualHostEntryUpgrader
{
- Map<String, Object> upgrade(Map<String, Object> attributes);
- Set<String> getNamesToBeDeleted();
+ private final AttributesTransformer haAttributesTransformer = new AttributesTransformer().
+ addAttributeTransformer("storePath", copyAttribute()).
+ addAttributeTransformer("storeUnderfullSize", copyAttribute()).
+ addAttributeTransformer("storeOverfullSize", copyAttribute()).
+ addAttributeTransformer("haNodeName", copyAttribute()).
+ addAttributeTransformer("haGroupName", copyAttribute()).
+ addAttributeTransformer("haHelperAddress", copyAttribute()).
+ addAttributeTransformer("haCoalescingSync", copyAttribute()).
+ addAttributeTransformer("haNodeAddress", copyAttribute()).
+ addAttributeTransformer("haDurability", copyAttribute()).
+ addAttributeTransformer("haDesignatedPrimary", copyAttribute()).
+ addAttributeTransformer("haReplicationConfig", copyAttribute()).
+ addAttributeTransformer("bdbEnvironmentConfig", copyAttribute()).
+ addAttributeTransformer("storeType", removeAttribute());
+
+ @Override
+ public ConfigurationEntry upgrade(ConfigurationEntryStore store, ConfigurationEntry vhost)
+ {
+ Map<String, Object> attributes = vhost.getAttributes();
+
+ Map<String, Object> messageStoreSettings = haAttributesTransformer.upgrade(attributes);
+
+ Map<String, Object> newAttributes = new HashMap<String, Object>(attributes);
+ newAttributes.keySet().removeAll(haAttributesTransformer.getNamesToBeDeleted());
+ newAttributes.put("messageStoreSettings", messageStoreSettings);
+
+ return new ConfigurationEntry(vhost.getId(), vhost.getType(), newAttributes, vhost.getChildrenIds(), store);
+ }
}
- public class GenericMessageStoreEntryUpgrader implements StoreEntryUpgrader
+ private class AttributesTransformer
{
- private Map<String, String> _oldToNewNamesMap;
- private String _storeType;
+ private final Map<String, List<AttributeTransformer>> _transformers = new HashMap<String, List<AttributeTransformer>>();
+ private Set<String> _namesToBeDeleted = new HashSet<String>();
- public GenericMessageStoreEntryUpgrader(String storeType, Map<String, String> oldToNewNamesMap)
+ public AttributesTransformer addAttributeTransformer(String string, AttributeTransformer... attributeTransformers)
{
- _oldToNewNamesMap = oldToNewNamesMap;
- _storeType = storeType;
+ _transformers.put(string, Arrays.asList(attributeTransformers));
+ return this;
}
- @Override
public Map<String, Object> upgrade(Map<String, Object> attributes)
{
- Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
- for (Map.Entry<String, String> nameMapEntry : _oldToNewNamesMap.entrySet())
+ Map<String, Object> settings = new HashMap<String, Object>();
+ for (Entry<String, List<AttributeTransformer>> entry : _transformers.entrySet())
{
- String attributeName = nameMapEntry.getKey();
+ String attributeName = entry.getKey();
if (attributes.containsKey(attributeName))
{
- messageStoreSettings.put(nameMapEntry.getValue(), attributes.get(attributeName));
+ Object attributeValue = attributes.get(attributeName);
+ MutatableEntry newEntry = new MutatableEntry(attributeName, attributeValue);
+
+ List<AttributeTransformer> transformers = entry.getValue();
+ for (AttributeTransformer attributeTransformer : transformers)
+ {
+ newEntry = attributeTransformer.transform(newEntry);
+ if (newEntry == null)
+ {
+ break;
+ }
+ }
+ if (newEntry != null)
+ {
+ settings.put(newEntry.getKey(), newEntry.getValue());
+ }
+
+ _namesToBeDeleted.add(attributeName);
}
}
- messageStoreSettings.put("storeType", _storeType);
- return messageStoreSettings;
+ return settings;
}
- @Override
public Set<String> getNamesToBeDeleted()
{
- Set<String> names = new HashSet<String>(_oldToNewNamesMap.keySet());
- names.add("storeType");
- return names;
+ return _namesToBeDeleted;
}
+ }
+ private AttributeTransformer copyAttribute()
+ {
+ return CopyAttribute.INSTANCE;
}
- public class JDBCMessageStoreEntryUpgrader implements StoreEntryUpgrader
+ private AttributeTransformer removeAttribute()
{
- private final String[] JDBC_ATTRIBUTES =
- { "connectionURL", "connectionPool", "jdbcBigIntType", "jdbcBytesForBlob", "jdbcVarbinaryType", "jdbcBlobType",
- "partitionCount", "maxConnectionsPerPartition", "minConnectionsPerPartition" };
+ return RemoveAttribute.INSTANCE;
+ }
- @Override
- public Map<String, Object> upgrade(Map<String, Object> attributes)
- {
- Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
+ private AttributeTransformer mutateAttributeValue(Object newValue)
+ {
+ return new MutateAttributeValue(newValue);
+ }
- if (attributes.containsKey("storePath"))
- {
- messageStoreSettings.put("connectionURL", attributes.get("storePath"));
- }
+ private AttributeTransformer mutateAttributeName(String newName)
+ {
+ return new MutateAttributeName(newName);
+ }
- copyJdbcStoreSettings(attributes, messageStoreSettings);
+ private interface AttributeTransformer
+ {
+ MutatableEntry transform(MutatableEntry entry);
+ }
- messageStoreSettings.put("storeType", "JDBC");
- return messageStoreSettings;
- }
+ private static class CopyAttribute implements AttributeTransformer
+ {
+ private static final CopyAttribute INSTANCE = new CopyAttribute();
- @Override
- public Set<String> getNamesToBeDeleted()
+ private CopyAttribute()
{
- Set<String> names = new HashSet<String>();
- names.addAll(Arrays.asList(JDBC_ATTRIBUTES));
- names.add("storePath");
- names.add("storeType");
- return names;
}
- private void copyJdbcStoreSettings(Map<String, Object> attributes, Map<String, Object> messageStoreSettings)
+ @Override
+ public MutatableEntry transform(MutatableEntry entry)
{
- for (String jdbcAttribute : JDBC_ATTRIBUTES)
- {
- if (attributes.containsKey(jdbcAttribute))
- {
- messageStoreSettings.put(jdbcAttribute, attributes.get(jdbcAttribute));
- }
- }
+ return entry;
}
-
}
- public class JDBCConfigurationStoreEntryUpgrader implements StoreEntryUpgrader
+ private static class RemoveAttribute implements AttributeTransformer
{
+ private static final RemoveAttribute INSTANCE = new RemoveAttribute();
- private final String[] JDBC_ATTRIBUTES =
- { "connectionPool", "jdbcBigIntType", "jdbcBytesForBlob", "jdbcVarbinaryType", "jdbcBlobType", "partitionCount",
- "maxConnectionsPerPartition", "minConnectionsPerPartition" };
+ private RemoveAttribute()
+ {
+ }
@Override
- public Map<String, Object> upgrade(Map<String, Object> attributes)
+ public MutatableEntry transform(MutatableEntry entry)
{
- Map<String, Object> messageStoreSettings = new HashMap<String, Object>();
-
- if (attributes.containsKey("configStorePath"))
- {
- messageStoreSettings.put("connectionURL", attributes.get("configStorePath"));
- }
-
- if (attributes.containsKey("configConnectionURL"))
- {
- messageStoreSettings.put("connectionURL", attributes.get("configConnectionURL"));
- }
+ return null;
+ }
+ }
- copyJdbcStoreSettings(attributes, messageStoreSettings);
+ private class MutateAttributeName implements AttributeTransformer
+ {
+ private final String _newName;
- messageStoreSettings.put("storeType", "JDBC");
- return messageStoreSettings;
+ public MutateAttributeName(String newName)
+ {
+ _newName = newName;
}
@Override
- public Set<String> getNamesToBeDeleted()
+ public MutatableEntry transform(MutatableEntry entry)
{
- Set<String> names = new HashSet<String>();
- names.addAll(Arrays.asList(JDBC_ATTRIBUTES));
- names.add("configStorePath");
- names.add("configStoreType");
- names.add("configConnectionURL");
- return names;
+ entry.setKey(_newName);
+ return entry;
}
+ }
+
+ private static class MutateAttributeValue implements AttributeTransformer
+ {
+ private final Object _newValue;
- private void copyJdbcStoreSettings(Map<String, Object> attributes, Map<String, Object> messageStoreSettings)
+ public MutateAttributeValue(Object newValue)
{
- for (String jdbcAttribute : JDBC_ATTRIBUTES)
- {
- if (attributes.containsKey(jdbcAttribute))
- {
- messageStoreSettings.put(jdbcAttribute, attributes.get(jdbcAttribute));
- }
- }
+ _newValue = newValue;
+ }
+
+ @Override
+ public MutatableEntry transform(MutatableEntry entry)
+ {
+ entry.setValue(_newValue);
+ return entry;
}
}
- public class StandardVirtualHostUpgrader implements VirtualHostEntryUpgrader
+ private static class MutatableEntry
{
- Map<String, StoreEntryUpgrader> _messageStoreEntryUpgrader = new HashMap<String, StoreEntryUpgrader>()
- {{
- put("JDBC", new JDBCMessageStoreEntryUpgrader());
- put("BDB", new GenericMessageStoreEntryUpgrader("BDB", new HashMap<String, String>()
- {{
- put("storePath", "storePath");
- put("bdbEnvironmentConfig", "bdbEnvironmentConfig");
- put("storeUnderfullSize", "storeUnderfullSize");
- put("storeOverfullSize", "storeOverfullSize");
- }}));
- put("DERBY", new GenericMessageStoreEntryUpgrader("DERBY", new HashMap<String, String>()
- {{
- put("storePath", "storePath");
- put("storeUnderfullSize", "storeUnderfullSize");
- put("storeOverfullSize", "storeOverfullSize");
- }}));
- put("MEMORY", new GenericMessageStoreEntryUpgrader("Memory", Collections.<String, String> emptyMap()));
- }};
- Map<String, StoreEntryUpgrader> _configurationStoreEntryUpgrader = new HashMap<String, StoreEntryUpgrader>()
- {{
- put("JDBC", new JDBCConfigurationStoreEntryUpgrader());
- put("DERBY", new GenericMessageStoreEntryUpgrader("DERBY", new HashMap<String, String>()
- {{
- put("configStorePath", "storePath");
- put("configStoreType", "storeType");
- }}));
- put("BDB", new GenericMessageStoreEntryUpgrader("BDB", new HashMap<String, String>()
- {{
- put("configStoreType", "storeType");
- put("configStorePath", "storePath");
- put("bdbEnvironmentConfig", "bdbEnvironmentConfig");
- }}));
- put("MEMORY", new GenericMessageStoreEntryUpgrader("Memory",
- Collections.<String, String> singletonMap("configStoreType", "storeType")));
- put("JSON", new GenericMessageStoreEntryUpgrader("JSON", new HashMap<String, String>()
- {{
- put("configStorePath", "storePath");
- put("configStoreType", "storeType");
- }}));
- }};
+ private String _key;
+ private Object _value;
- @Override
- public ConfigurationEntry upgrade(ConfigurationEntryStore store, ConfigurationEntry vhost)
+ public MutatableEntry(String key, Object value)
{
- Map<String, Object> attributes = vhost.getAttributes();
- Map<String, Object> newAttributes = new HashMap<String, Object>(attributes);
-
- String capitalisedStoreType = String.valueOf(attributes.get("storeType")).toUpperCase();
- StoreEntryUpgrader messageStoreSettingsUpgrader = _messageStoreEntryUpgrader.get(capitalisedStoreType);
- Map<String, Object> messageStoreSettings = null;
- if (messageStoreSettingsUpgrader != null)
- {
- messageStoreSettings = messageStoreSettingsUpgrader.upgrade(attributes);
- }
+ _key = key;
+ _value = value;
+ }
- if (attributes.containsKey("configStoreType"))
- {
- String capitaliseConfigStoreType = ((String) attributes.get("configStoreType")).toUpperCase();
- StoreEntryUpgrader configurationStoreSettingsUpgrader = _configurationStoreEntryUpgrader
- .get(capitaliseConfigStoreType);
- Map<String, Object> configurationStoreSettings = configurationStoreSettingsUpgrader.upgrade(attributes);
- newAttributes.keySet().removeAll(configurationStoreSettingsUpgrader.getNamesToBeDeleted());
- newAttributes.put("configurationStoreSettings", configurationStoreSettings);
- }
+ public String getKey()
+ {
+ return _key;
+ }
- if (messageStoreSettingsUpgrader != null)
- {
- newAttributes.keySet().removeAll(messageStoreSettingsUpgrader.getNamesToBeDeleted());
- newAttributes.put("messageStoreSettings", messageStoreSettings);
- }
+ public void setKey(String key)
+ {
+ _key = key;
+ }
- return new ConfigurationEntry(vhost.getId(), vhost.getType(), newAttributes, vhost.getChildrenIds(), store);
+ public Object getValue()
+ {
+ return _value;
}
+ public void setValue(Object value)
+ {
+ _value = value;
+ }
}
} \ No newline at end of file