You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2012/12/27 18:40:49 UTC
svn commit: r1426268 - in
/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src:
main/java/org/apache/qpid/server/configuration/
main/java/org/apache/qpid/server/configuration/store/
main/java/org/apache/qpid/server/model/adapter/ main/java/...
Author: orudyy
Date: Thu Dec 27 17:40:48 2012
New Revision: 1426268
URL: http://svn.apache.org/viewvc?rev=1426268&view=rev
Log:
QPID-4390: Add default configuration and functionality to copy the default configuration into user store
Added:
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/resources/default.json
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java
Modified:
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/ConfigurationEntry.java Thu Dec 27 17:40:48 2012
@@ -30,6 +30,8 @@ import java.util.UUID;
public class ConfigurationEntry
{
+ public static final String ATTRIBUTE_NAME = "name";
+
private final UUID _id;
private final String _type;
private final Map<String, Object> _attributes;
@@ -139,6 +141,50 @@ public class ConfigurationEntry
{
return false;
}
+ if (_type == null)
+ {
+ if (other._type != null)
+ {
+ return false;
+ }
+ }
+ else if (!_type.equals(other._type))
+ {
+ return false;
+ }
+ if (_store == null)
+ {
+ if (other._store != null)
+ {
+ return false;
+ }
+ }
+ else if (!_store.equals(other._store))
+ {
+ return false;
+ }
+ if (_childrenIds == null)
+ {
+ if (other._childrenIds != null)
+ {
+ return false;
+ }
+ }
+ else if (!_childrenIds.equals(other._childrenIds))
+ {
+ return false;
+ }
+ if (_attributes == null)
+ {
+ if (other._attributes != null)
+ {
+ return false;
+ }
+ }
+ else if (!_attributes.equals(other._attributes))
+ {
+ return false;
+ }
return true;
}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStore.java Thu Dec 27 17:40:48 2012
@@ -1,8 +1,13 @@
package org.apache.qpid.server.configuration.store;
+import static org.apache.qpid.server.configuration.ConfigurationEntry.ATTRIBUTE_NAME;
+
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -18,8 +23,10 @@ import org.apache.qpid.server.configurat
import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.UUIDGenerator;
+import org.apache.qpid.util.Strings;
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;
@@ -28,55 +35,55 @@ import org.codehaus.jackson.node.ArrayNo
public class JsonConfigurationEntryStore implements ConfigurationEntryStore
{
+ private static final String DEFAULT_BROKER_TYPE = Broker.class.getSimpleName();
+ private static final String DEFAULT_BROKER_NAME = "Broker";
static final String ATTRIBUTES = "attributes";
private static final String ID = "id";
private static final String TYPE = "type";
- private static final String NAME = "name";
private ObjectMapper _objectMapper;
private Map<UUID, ConfigurationEntry> _entries;
private File _storeFile;
private UUID _rootId;
- public JsonConfigurationEntryStore(String filePath)
+ private JsonConfigurationEntryStore()
{
- _storeFile = new File(filePath);
_objectMapper = new ObjectMapper();
_objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
+ _entries = new HashMap<UUID, ConfigurationEntry>();
+ }
- if (_storeFile.exists())
- {
- JsonNode node = load(_storeFile, _objectMapper);
+ public JsonConfigurationEntryStore(URL storeURL)
+ {
+ this();
+ JsonNode node = load(storeURL, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, true, _entries);
+ _rootId = brokerEntry.getId();
+ }
- Map<UUID, ConfigurationEntry> entries = new HashMap<UUID, ConfigurationEntry>();
- ConfigurationEntry brokerEntry = toEntry(node, true, entries);
- _rootId = brokerEntry.getId();
- _entries = entries;
- }
- else
+ public JsonConfigurationEntryStore(File storeFile)
+ {
+ this();
+ _storeFile = storeFile;
+ if (storeFile.exists())
{
- _entries = new HashMap<UUID, ConfigurationEntry>();
- File parent = _storeFile.getParentFile();
- if (!parent.exists())
+ if (storeFile.length() > 0)
{
- if (!parent.mkdirs())
- {
- throw new IllegalConfigurationException("Cannot create folder(s) for the store at " + _storeFile);
- }
- }
- try
- {
- if (!_storeFile.createNewFile())
- {
- throw new IllegalConfigurationException("Cannot create store file at " + _storeFile);
- }
+ URL storeURL = fileToURL(storeFile);
+ JsonNode node = load(storeURL, _objectMapper);
+ ConfigurationEntry brokerEntry = toEntry(node, true, _entries);
+ _rootId = brokerEntry.getId();
}
- catch (IOException e)
- {
- throw new IllegalConfigurationException("Cannot write into file at " + _storeFile, e);
- }
- ConfigurationEntry brokerEntry = new ConfigurationEntry(UUID.randomUUID(), Broker.class.getSimpleName(), null, null, null);
- _rootId = brokerEntry.getId();
+ }
+ else
+ {
+ createStoreFile(storeFile);
+ }
+ if (_rootId == null)
+ {
+ _rootId = createUUID(DEFAULT_BROKER_TYPE, DEFAULT_BROKER_NAME);
+ ConfigurationEntry brokerEntry = new ConfigurationEntry(_rootId, DEFAULT_BROKER_TYPE, null, null, null);
save(brokerEntry);
}
}
@@ -99,7 +106,8 @@ public class JsonConfigurationEntryStore
{
Set<UUID> children = new HashSet<UUID>(entry.getChildrenIds());
children.remove(uuid);
- ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(), entry.getAttributes(), children, this);
+ ConfigurationEntry referal = new ConfigurationEntry(entry.getId(), entry.getType(),
+ entry.getAttributes(), children, this);
_entries.put(entry.getId(), referal);
}
}
@@ -143,6 +151,43 @@ public class JsonConfigurationEntryStore
return _entries.get(id);
}
+ private void createStoreFile(File storeFile)
+ {
+ File parent = storeFile.getParentFile();
+ if (!parent.exists())
+ {
+ if (!parent.mkdirs())
+ {
+ throw new IllegalConfigurationException("Cannot create folder(s) for the store at " + _storeFile);
+ }
+ }
+ try
+ {
+ if (!storeFile.createNewFile())
+ {
+ throw new IllegalConfigurationException("Cannot create store file at " + _storeFile);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException("Cannot write into file at " + _storeFile, e);
+ }
+ }
+
+ private URL fileToURL(File storeFile)
+ {
+ URL storeURL = null;
+ try
+ {
+ storeURL = storeFile.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalConfigurationException("Cannot create URL for file " + storeFile, e);
+ }
+ return storeURL;
+ }
+
private boolean removeInternal(UUID entryId)
{
ConfigurationEntry oldEntry = _entries.remove(entryId);
@@ -163,7 +208,10 @@ public class JsonConfigurationEntryStore
private void saveAsTree()
{
- saveAsTree(_rootId, _entries, _objectMapper, _storeFile);
+ if (_storeFile != null)
+ {
+ saveAsTree(_rootId, _entries, _objectMapper, _storeFile);
+ }
}
private void saveAsTree(UUID rootId, Map<UUID, ConfigurationEntry> entries, ObjectMapper mapper, File file)
@@ -211,11 +259,12 @@ public class JsonConfigurationEntryStore
if (child != null)
{
String relationshipName = child.getType().toLowerCase() + "s";
+
@SuppressWarnings("unchecked")
- Set<Map<String, Object>> children = (Set<Map<String, Object>>) tree.get(relationshipName);
+ Collection<Map<String, Object>> children = (Collection<Map<String, Object>>) tree.get(relationshipName);
if (children == null)
{
- children = new TreeSet<Map<String, Object>>();
+ children = new ArrayList<Map<String, Object>>();
tree.put(relationshipName, children);
}
Map<String, Object> childAsMap = toTree(relationship, entries);
@@ -226,27 +275,27 @@ public class JsonConfigurationEntryStore
return tree;
}
- private JsonNode load(File file, ObjectMapper mapper)
+ private JsonNode load(URL url, ObjectMapper mapper)
{
JsonNode root = null;
try
{
- root = mapper.readTree(file);
+ root = mapper.readTree(url);
}
catch (JsonProcessingException e)
{
- throw new IllegalConfigurationException("Cannot parse file '" + file + "'!", e);
+ throw new IllegalConfigurationException("Cannot parse json from '" + url + "'", e);
}
catch (IOException e)
{
- throw new IllegalConfigurationException("Cannot read file '" + file + "'!", e);
+ throw new IllegalConfigurationException("Cannot read from '" + url + "'", e);
}
return root;
}
private ConfigurationEntry toEntry(JsonNode parent, boolean isRoot, Map<UUID, ConfigurationEntry> entries)
{
- Map<String, Object> attributes = new HashMap<String, Object>();
+ Map<String, Object> attributes = null;
Set<UUID> childrenIds = new TreeSet<UUID>();
Iterator<String> fieldNames = parent.getFieldNames();
String type = null;
@@ -263,13 +312,7 @@ public class JsonConfigurationEntryStore
{
throw new IllegalConfigurationException("Object attributes are set incorrectly for " + parent);
}
- Iterator<String> attributeNamesNames = fieldNode.getFieldNames();
- while (attributeNamesNames.hasNext())
- {
- String name = attributeNamesNames.next();
- JsonNode node = fieldNode.get(name);
- attributes.put(name, toObject(node));
- }
+ attributes = toMap(fieldNode);
}
}
else if (fieldName.equals(ID))
@@ -300,19 +343,19 @@ public class JsonConfigurationEntryStore
{
if (isRoot)
{
- type = Broker.class.getName();
+ type = DEFAULT_BROKER_TYPE;
}
else
{
throw new IllegalConfigurationException("Type attribute is not provided for configuration entry " + parent);
}
}
- String name = (String) attributes.get(NAME);
+ String name = (String) attributes.get(ATTRIBUTE_NAME);
if ((name == null || "".equals(name)))
{
if (isRoot)
{
- name = "Broker";
+ name = DEFAULT_BROKER_NAME;
}
else
{
@@ -320,10 +363,9 @@ public class JsonConfigurationEntryStore
}
}
UUID id = null;
-
if (idAsString == null)
{
- id = UUIDGenerator.generateBrokerChildUUID(type, name);
+ id = createUUID(type, name);
}
else
{
@@ -333,19 +375,25 @@ public class JsonConfigurationEntryStore
}
catch (Exception e)
{
- throw new IllegalConfigurationException("ID attribute value does not conform to UUID format for configuration entry " + parent);
+ throw new IllegalConfigurationException(
+ "ID attribute value does not conform to UUID format for configuration entry " + parent);
}
}
ConfigurationEntry entry = new ConfigurationEntry(id, type, attributes, childrenIds, this);
if (entries.containsKey(id))
{
- throw new IllegalConfigurationException("Duplicate id is found: " + id + "! The following configuration entries have the same id: "
- + entries.get(id) + ", " + entry);
+ throw new IllegalConfigurationException("Duplicate id is found: " + id
+ + "! The following configuration entries have the same id: " + entries.get(id) + ", " + entry);
}
entries.put(id, entry);
return entry;
}
+ private UUID createUUID(String type, String name)
+ {
+ return UUIDGenerator.generateBrokerChildUUID(type, name);
+ }
+
private Object toObject(JsonNode node)
{
if (node.isValueNode())
@@ -372,7 +420,7 @@ public class JsonConfigurationEntryStore
}
else
{
- return node.asText();
+ return Strings.expand(node.asText());
}
}
else if (node.isArray())
@@ -381,15 +429,7 @@ public class JsonConfigurationEntryStore
}
else if (node.isObject())
{
- Map<String, Object> object = new HashMap<String, Object>();
- Iterator<String> fieldNames = node.getFieldNames();
- while (fieldNames.hasNext())
- {
- String name = fieldNames.next();
- Object value = toObject(node.get(name));
- object.put(name, value);
- }
- return object;
+ return toMap(node);
}
else
{
@@ -397,6 +437,19 @@ public class JsonConfigurationEntryStore
}
}
+ private Map<String, Object> toMap(JsonNode node)
+ {
+ Map<String, Object> object = new TreeMap<String, Object>();
+ Iterator<String> fieldNames = node.getFieldNames();
+ while (fieldNames.hasNext())
+ {
+ String name = fieldNames.next();
+ Object value = toObject(node.get(name));
+ object.put(name, value);
+ }
+ return object;
+ }
+
private Object toArray(JsonNode node)
{
ArrayNode arrayNode = (ArrayNode) node;
Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java?rev=1426268&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java (added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/MergingStore.java Thu Dec 27 17:40:48 2012
@@ -0,0 +1,127 @@
+/*
+ *
+ * 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.configuration.store;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+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.ConfigurationEntryStore;
+
+/**
+ * A store implementation which is responsible for copying the configuration
+ * from the master store into a user store if the configuration entries with the
+ * same name do not exist in the user store.
+ */
+public class MergingStore implements ConfigurationEntryStore
+{
+ private final ConfigurationEntryStore _userStore;
+
+ public MergingStore(ConfigurationEntryStore userStore, ConfigurationEntryStore masterStore)
+ {
+ mergeAndSave(userStore, masterStore);
+ _userStore = userStore;
+ }
+
+ @Override
+ public ConfigurationEntry getRootEntry()
+ {
+ return _userStore.getRootEntry();
+ }
+
+ @Override
+ public ConfigurationEntry getEntry(UUID id)
+ {
+ return _userStore.getEntry(id);
+ }
+
+ @Override
+ public void save(ConfigurationEntry... entries)
+ {
+ _userStore.save(entries);
+ }
+
+ @Override
+ public UUID[] remove(UUID... entryIds)
+ {
+ return _userStore.remove(entryIds);
+ }
+
+ private void mergeAndSave(ConfigurationEntryStore userStore, ConfigurationEntryStore masterStore)
+ {
+ ConfigurationEntry masterRoot = masterStore.getRootEntry();
+ Set<UUID> masterRootChildren = masterRoot.getChildrenIds();
+
+ ConfigurationEntry userRoot = userStore.getRootEntry();
+ Map<String, Collection<ConfigurationEntry>> userRootChildren = userRoot.getChildren();
+
+ List<ConfigurationEntry> entriesToSave = new ArrayList<ConfigurationEntry>();
+ Set<UUID> userRootNewChildren = new HashSet<UUID>();
+ for (UUID uuid : masterRootChildren)
+ {
+ ConfigurationEntry masterEntry = masterStore.getEntry(uuid);
+ String masterEntryName = (String) masterEntry.getAttributes().get(ConfigurationEntry.ATTRIBUTE_NAME);
+ Collection<ConfigurationEntry> userEntriesOfTheSameType = userRootChildren.get(masterEntry.getType().toString());
+ boolean found = false;
+ if (userEntriesOfTheSameType != null && !userEntriesOfTheSameType.isEmpty())
+ {
+ for (ConfigurationEntry entry : userEntriesOfTheSameType)
+ {
+ Map<String, Object> attributes = entry.getAttributes();
+ if (attributes != null && masterEntryName.equals(attributes.get(ConfigurationEntry.ATTRIBUTE_NAME)))
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+ if (!found)
+ {
+ entriesToSave.add(masterEntry);
+ userRootNewChildren.add(masterEntry.getId());
+ }
+ }
+
+ Map<String, Object> userRootAttributes = userRoot.getAttributes();
+ boolean noUserStoreRootAttributes = userRootAttributes == null || userRootAttributes.isEmpty();
+ if (noUserStoreRootAttributes || !userRootNewChildren.isEmpty())
+ {
+ Set<UUID> currentUserStoreRootChildrenIds = userRoot.getChildrenIds();
+ if (currentUserStoreRootChildrenIds != null)
+ {
+ userRootNewChildren.addAll(currentUserStoreRootChildrenIds);
+ }
+ Map<String, Object> newAttributes = noUserStoreRootAttributes ? masterRoot.getAttributes() : userRootAttributes;
+ entriesToSave.add(new ConfigurationEntry(userRoot.getId(), userRoot.getType(), newAttributes, userRootNewChildren,
+ userStore));
+ }
+ if (!entriesToSave.isEmpty())
+ {
+ userStore.save(entriesToSave.toArray(new ConfigurationEntry[entriesToSave.size()]));
+ }
+ }
+
+}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/store/XMLConfigurationEntryStore.java Thu Dec 27 17:40:48 2012
@@ -81,6 +81,11 @@ public class XMLConfigurationEntryStore
this(new ServerConfiguration(configFile), new BrokerOptions());
}
+ public XMLConfigurationEntryStore(String configFile, BrokerOptions options) throws ConfigurationException
+ {
+ this(new ServerConfiguration(new File(configFile)), options);
+ }
+
public XMLConfigurationEntryStore(File configFile, BrokerOptions options) throws ConfigurationException
{
this(new ServerConfiguration(configFile), options);
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/model/adapter/PortAttributeDestringifier.java Thu Dec 27 17:40:48 2012
@@ -21,7 +21,6 @@
package org.apache.qpid.server.model.adapter;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -42,22 +41,10 @@ public class PortAttributeDestringifier
{
Map<String, Object> destringifiedAttributes = new HashMap<String, Object>(attributes);
- final Set<Object> protocolObjectSet = MapValueConverter.getSetAttribute(Port.PROTOCOLS, attributes);
- final Set<Protocol> protocolSet = new HashSet<Protocol>();
- for (Object object : protocolObjectSet)
- {
- Protocol protocol = Protocol.valueOfObject(object);
- protocolSet.add(protocol);
- }
+ final Set<Protocol> protocolSet = MapValueConverter.getEnumSetAttribute(Port.PROTOCOLS, attributes, Protocol.class);
destringifiedAttributes.put(Port.PROTOCOLS, protocolSet);
- final Set<Object> transportObjectSet = MapValueConverter.getSetAttribute(Port.TRANSPORTS, attributes);
- final Set<Transport> transportSet = new HashSet<Transport>();
- for (Object transportObject : transportObjectSet)
- {
- Transport transport = Transport.valueOfObject(transportObject);
- transportSet.add(transport);
- }
+ final Set<Transport> transportSet = MapValueConverter.getEnumSetAttribute(Port.TRANSPORTS, attributes, Transport.class);
destringifiedAttributes.put(Port.TRANSPORTS, transportSet);
Integer port = MapValueConverter.getIntegerAttribute(Port.PORT, attributes);
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/java/org/apache/qpid/server/util/MapValueConverter.java Thu Dec 27 17:40:48 2012
@@ -21,6 +21,7 @@
package org.apache.qpid.server.util;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -195,4 +196,61 @@ public class MapValueConverter
}
}
+ @SuppressWarnings("unchecked")
+ public static <T extends Enum<T>> Set<T> getEnumSetAttribute(String name, Map<String,Object> attributes, Class<T> clazz)
+ {
+ Object obj = attributes.get(name);
+ String[] items= null;
+ if(obj == null)
+ {
+ return null;
+ }
+ else if(obj instanceof Set)
+ {
+ Set<?> data= (Set<?>) obj;
+ items = new String[data.size()];
+ int i = 0;
+ boolean sameType = true;
+ for (Object object : data)
+ {
+ items[i++] = String.valueOf(object);
+ if (clazz != object.getClass())
+ {
+ sameType = false;
+ }
+ }
+ if (sameType)
+ {
+ return (Set<T>)data;
+ }
+ }
+ else if (obj instanceof String)
+ {
+ items = ((String)obj).split(",");
+ }
+ else if (obj instanceof String[])
+ {
+ items = (String[])obj;
+ }
+ else if (obj instanceof Object[])
+ {
+ Object[] objects = (Object[])obj;
+ items = new String[objects.length];
+ for (int i = 0; i < objects.length; i++)
+ {
+ items[i] = String.valueOf(objects[i]);
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("Value for attribute " + name + "["+ obj + "] cannot be converted into set of enum of " + clazz);
+ }
+ Set<T> set = new HashSet<T>();
+ for (int i = 0; i < items.length; i++)
+ {
+ T item = (T)Enum.valueOf(clazz, items[i]);
+ set.add(item);
+ }
+ return set;
+ }
}
Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/resources/default.json
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/resources/default.json?rev=1426268&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/resources/default.json (added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/main/resources/default.json Thu Dec 27 17:40:48 2012
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.
+ *
+ */
+{
+ "type" : "Broker",
+ "attributes" : {
+ "name": "Broker",
+ "defaultAuthenticationProvider" : "defaultAuthenticationProvider",
+ "defaultVirtualHost" : "default",
+ "aclFile" : null,
+ "alertThresholdQueueDepth" : 0,
+ "alertThresholdMessageCount" : 0,
+ "alertThresholdMessageSize" : 0,
+ "alertThresholdMessageAge" : 0,
+ "alertRepeatGap" : 30000,
+ "heartBeatDelay" : 0,
+ "sessionCountLimit" : 256,
+ "deadLetterQueueEnabled" : false,
+ "maximumDeliveryAttempts" : 0,
+ "housekeepingCheckPeriod" : 30000,
+ "queueFlowControlSizeBytes" : 0,
+ "queueFlowResumeSizeBytes" : 0,
+ "statisticsReportingPeriod" : 0,
+ "statisticsReportingResetEnabled" : false
+ },
+ "authenticationproviders" : [ {
+ "type" : "AuthenticationProvider",
+ "attributes" : {
+ "name" : "defaultAuthenticationProvider",
+ "authenticationProviderType" : "PlainPasswordFileAuthenticationProvider",
+ "path" : "${QPID_HOME}/etc/passwd"
+ }
+ } ],
+ "ports" : [ {
+ "type" : "Port",
+ "attributes" : {
+ "name" : "defaultHttpPort",
+ "port" : 8080,
+ "transports" : [ "TCP" ],
+ "protocols" : [ "HTTP" ]
+ }
+ }, {
+ "type" : "Port",
+ "attributes" : {
+ "name" : "defaultAmqpPort",
+ "port" : 5672,
+ "tcpNoDelay" : true,
+ "transports" : [ "TCP" ],
+ "protocols" : [ "AMQP_0_8", "AMQP_0_9", "AMQP_0_9_1", "AMQP_0_10", "AMQP_1_0" ],
+ "wantClientAuth" : false,
+ "needClientAuth" : false,
+ "receiveBufferSize" : 262144,
+ "sendBufferSize" : 262144
+ }
+ }, {
+ "type" : "Port",
+ "attributes" : {
+ "name" : "defaultJmxRmiPort",
+ "port" : 9099,
+ "transports" : [ "TCP" ],
+ "protocols" : [ "JMX_RMI" ]
+ }
+ }, {
+ "type" : "Port",
+ "attributes" : {
+ "name" : "defaultRmiPort",
+ "port" : 8999,
+ "transports" : [ "TCP" ],
+ "protocols" : [ "RMI" ]
+ }
+ } ],
+ "virtualhosts" : [ {
+ "type" : "VirtualHost",
+ "attributes" : {
+ "name" : "default",
+ "configuration" : "${QPID_HOME}/etc/virtualhosts.xml"
+ }
+ } ],
+ "plugins" : [ {
+ "type" : "Plugin",
+ "attributes" : {
+ "pluginType" : "MANAGEMENT-HTTP",
+ "name" : "httpManagement",
+ "httpSaslAuthenticationEnabled" : true,
+ "httpsSaslAuthenticationEnabled" : false,
+ "httpBasicAuthenticationEnabled" : false,
+ "httpsBasicAuthenticationEnabled" : false
+ }
+ }, {
+ "type" : "Plugin",
+ "attributes" : {
+ "pluginType" : "MANAGEMENT-JMX",
+ "name" : "jmxManagement",
+ "usePlatformMBeanServer" : true,
+ "managementRightsInferAllAccess" : true
+ }
+ } ]
+}
\ No newline at end of file
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java Thu Dec 27 17:40:48 2012
@@ -28,7 +28,6 @@ import java.util.UUID;
import org.apache.qpid.server.configuration.ConfigurationEntry;
import org.apache.qpid.server.configuration.ConfigurationEntryStore;
-import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.model.AuthenticationProvider;
import org.apache.qpid.server.model.Broker;
import org.apache.qpid.server.model.GroupProvider;
@@ -89,8 +88,8 @@ public abstract class ConfigurationEntry
_authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, AnonymousAuthenticationManager.class.getSimpleName());
_store = createStore(_brokerId, _brokerAttributes);
- addConfiguration(_virtualHostId, VirtualHost.class.getName(), _virtualHostAttributes);
- addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getName(), _authenticationProviderAttributes);
+ addConfiguration(_virtualHostId, VirtualHost.class.getSimpleName(), _virtualHostAttributes);
+ addConfiguration(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(), _authenticationProviderAttributes);
}
// ??? perhaps it should not be abstract
@@ -108,7 +107,7 @@ public abstract class ConfigurationEntry
ConfigurationEntry brokerConfigEntry = _store.getRootEntry();
assertNotNull("Root entry does not exist", brokerConfigEntry);
assertEquals("Unexpected id", _brokerId, brokerConfigEntry.getId());
- assertEquals("Unexpected type ", Broker.class.getName(), brokerConfigEntry.getType());
+ 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);
@@ -119,7 +118,7 @@ public abstract class ConfigurationEntry
ConfigurationEntry authenticationProviderConfigEntry = _store.getEntry(_authenticationProviderId);
assertNotNull("Provider with id " + _authenticationProviderId + " should exist", authenticationProviderConfigEntry);
assertEquals("Unexpected id", _authenticationProviderId, authenticationProviderConfigEntry.getId());
- assertEquals("Unexpected type ", AuthenticationProvider.class.getName(), authenticationProviderConfigEntry.getType());
+ assertEquals("Unexpected type ", AuthenticationProvider.class.getSimpleName(), authenticationProviderConfigEntry.getType());
Map<String, Object> attributes = authenticationProviderConfigEntry.getAttributes();
assertNotNull("Attributes cannot be null", attributes);
assertEquals("Unexpected attributes", _authenticationProviderAttributes, attributes);
@@ -131,7 +130,7 @@ public abstract class ConfigurationEntry
virtualHostAttributes.put(VirtualHost.NAME, getName());
virtualHostAttributes.put(VirtualHost.CONFIGURATION, "/path/to/phantom/virtualhost/config");
UUID virtualHostId = UUID.randomUUID();
- addConfiguration(virtualHostId, VirtualHost.class.getName(), virtualHostAttributes);
+ addConfiguration(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes);
assertNotNull("Virtual host with id " + virtualHostId + " should exist", _store.getEntry(virtualHostId));
@@ -145,13 +144,13 @@ public abstract class ConfigurationEntry
virtualHost1Attributes.put(VirtualHost.NAME, "test1");
virtualHost1Attributes.put(VirtualHost.CONFIGURATION, "/path/to/phantom/virtualhost/config1");
UUID virtualHost1Id = UUID.randomUUID();
- addConfiguration(virtualHost1Id, VirtualHost.class.getName(), virtualHost1Attributes);
+ addConfiguration(virtualHost1Id, VirtualHost.class.getSimpleName(), virtualHost1Attributes);
Map<String, Object> virtualHost2Attributes = new HashMap<String, Object>();
virtualHost2Attributes.put(VirtualHost.NAME, "test1");
virtualHost2Attributes.put(VirtualHost.CONFIGURATION, "/path/to/phantom/virtualhost/config2");
UUID virtualHost2Id = UUID.randomUUID();
- addConfiguration(virtualHost2Id, VirtualHost.class.getName(), virtualHost2Attributes);
+ addConfiguration(virtualHost2Id, VirtualHost.class.getSimpleName(), virtualHost2Attributes);
assertNotNull("Virtual host with id " + virtualHost1Id + " should exist", _store.getEntry(virtualHost1Id));
assertNotNull("Virtual host with id " + virtualHost2Id + " should exist", _store.getEntry(virtualHost2Id));
@@ -185,7 +184,7 @@ public abstract class ConfigurationEntry
attributes.put(Broker.HEART_BEAT_DELAY, 12000);
attributes.put(Broker.STATISTICS_REPORTING_PERIOD, 14000);
attributes.put(Broker.STATISTICS_REPORTING_RESET_ENABLED, false);
- ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(_brokerId, Broker.class.getName(), attributes,
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(_brokerId, Broker.class.getSimpleName(), attributes,
brokerConfigEntry.getChildrenIds(), _store);
_store.save(updatedBrokerEntry);
@@ -193,7 +192,7 @@ public abstract class ConfigurationEntry
ConfigurationEntry newBrokerConfigEntry = _store.getRootEntry();
assertNotNull("Root entry does not exist", newBrokerConfigEntry);
assertEquals("Unexpected id", _brokerId, newBrokerConfigEntry.getId());
- assertEquals("Unexpected type ", Broker.class.getName(), newBrokerConfigEntry.getType());
+ assertEquals("Unexpected type ", Broker.class.getSimpleName(), newBrokerConfigEntry.getType());
Map<String, Object> newBrokerattributes = newBrokerConfigEntry.getAttributes();
assertNotNull("Attributes cannot be null", newBrokerattributes);
assertEquals("Unexpected attributes", attributes, newBrokerattributes);
@@ -205,14 +204,14 @@ public abstract class ConfigurationEntry
virtualHostAttributes.put(VirtualHost.NAME, "test1");
virtualHostAttributes.put(VirtualHost.CONFIGURATION, "/path/to/phantom/virtualhost/config1");
UUID virtualHostId = UUID.randomUUID();
- ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getName(), virtualHostAttributes,
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
Collections.<UUID> emptySet(), _store);
_store.save(hostEntry);
ConfigurationEntry configurationEntry = _store.getEntry(virtualHostId);
assertEquals("Unexpected virtual host configuration", hostEntry, configurationEntry);
- assertEquals("Unexpected type", VirtualHost.class.getName(), configurationEntry.getType());
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), configurationEntry.getType());
assertEquals("Unexpected virtual host attributes", hostEntry.getAttributes(), configurationEntry.getAttributes());
assertTrue("Unexpected virtual host children found", hostEntry.getChildrenIds().isEmpty());
}
@@ -226,13 +225,13 @@ public abstract class ConfigurationEntry
virtualHostAttributes.put(VirtualHost.NAME, "test");
virtualHostAttributes.put(VirtualHost.CONFIGURATION, "/path/to/new/phantom/test/configuration");
- ConfigurationEntry updatedEntry = new ConfigurationEntry(_virtualHostId, VirtualHost.class.getName(), virtualHostAttributes,
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
hostEntry.getChildrenIds(), _store);
_store.save(updatedEntry);
ConfigurationEntry newHostEntry = _store.getEntry(_virtualHostId);
assertEquals("Unexpected virtual host configuration", updatedEntry, newHostEntry);
- assertEquals("Unexpected type", VirtualHost.class.getName(), newHostEntry.getType());
+ assertEquals("Unexpected type", VirtualHost.class.getSimpleName(), newHostEntry.getType());
assertEquals("Unexpected virtual host attributes", updatedEntry.getAttributes(), newHostEntry.getAttributes());
assertEquals("Unexpected virtual host children found", updatedEntry.getChildrenIds(), newHostEntry.getChildrenIds());
}
@@ -243,14 +242,14 @@ public abstract class ConfigurationEntry
Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
- ConfigurationEntry providerEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getName(),
+ ConfigurationEntry providerEntry = new ConfigurationEntry(authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
_store.save(providerEntry);
ConfigurationEntry storeEntry = _store.getEntry(authenticationProviderId);
assertEquals("Unexpected provider configuration", providerEntry, storeEntry);
- assertEquals("Unexpected type", AuthenticationProvider.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected provider attributes", providerEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -263,13 +262,13 @@ public abstract class ConfigurationEntry
Map<String, Object> authenticationProviderAttributes = new HashMap<String, Object>();
authenticationProviderAttributes.put(AuthenticationProvider.NAME, "authenticationProvider1");
authenticationProviderAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE, ExternalAuthenticationManager.class.getSimpleName());
- ConfigurationEntry updatedEntry = new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getName(),
+ ConfigurationEntry updatedEntry = new ConfigurationEntry(_authenticationProviderId, AuthenticationProvider.class.getSimpleName(),
authenticationProviderAttributes, Collections.<UUID> emptySet(), _store);
_store.save(updatedEntry);
ConfigurationEntry storeEntry = _store.getEntry(_authenticationProviderId);
assertEquals("Unexpected provider configuration", updatedEntry, storeEntry);
- assertEquals("Unexpected type", AuthenticationProvider.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", AuthenticationProvider.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected provider attributes", updatedEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -285,14 +284,14 @@ public abstract class ConfigurationEntry
attributes.put(TrustStore.KEY_MANAGER_FACTORY_ALGORITHM, "NON-STANDARD");
attributes.put(TrustStore.DESCRIPTION, "Description");
- ConfigurationEntry trustStoreEntry = new ConfigurationEntry(trustStoreId, TrustStore.class.getName(), attributes,
+ ConfigurationEntry trustStoreEntry = new ConfigurationEntry(trustStoreId, TrustStore.class.getSimpleName(), attributes,
Collections.<UUID> emptySet(), _store);
_store.save(trustStoreEntry);
ConfigurationEntry storeEntry = _store.getEntry(trustStoreId);
assertEquals("Unexpected trust store configuration", trustStoreEntry, storeEntry);
- assertEquals("Unexpected type", TrustStore.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", TrustStore.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected provider attributes", trustStoreEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -309,14 +308,14 @@ public abstract class ConfigurationEntry
attributes.put(KeyStore.DESCRIPTION, "Description");
attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
- ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getName(), attributes, Collections.<UUID> emptySet(),
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
_store);
_store.save(keyStoreEntry);
ConfigurationEntry storeEntry = _store.getEntry(keyStoreId);
assertEquals("Unexpected key store configuration", keyStoreEntry, storeEntry);
- assertEquals("Unexpected type", KeyStore.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", KeyStore.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected provider attributes", keyStoreEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -327,14 +326,14 @@ public abstract class ConfigurationEntry
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(GroupProvider.NAME, getName());
- ConfigurationEntry groupProviderEntry = new ConfigurationEntry(groupProviderId, GroupProvider.class.getName(), attributes,
+ ConfigurationEntry groupProviderEntry = new ConfigurationEntry(groupProviderId, GroupProvider.class.getSimpleName(), attributes,
Collections.<UUID> emptySet(), _store);
_store.save(groupProviderEntry);
ConfigurationEntry storeEntry = _store.getEntry(groupProviderId);
assertEquals("Unexpected group provider configuration", groupProviderEntry, storeEntry);
- assertEquals("Unexpected type", GroupProvider.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", GroupProvider.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected group provider attributes", groupProviderEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected provider children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -352,13 +351,13 @@ public abstract class ConfigurationEntry
attributes.put(Port.NEED_CLIENT_AUTH, true);
attributes.put(Port.WANT_CLIENT_AUTH, true);
- ConfigurationEntry portEntry = new ConfigurationEntry(portId, Port.class.getName(), attributes, Collections.<UUID> emptySet(), _store);
+ ConfigurationEntry portEntry = new ConfigurationEntry(portId, Port.class.getSimpleName(), attributes, Collections.<UUID> emptySet(), _store);
_store.save(portEntry);
ConfigurationEntry storeEntry = _store.getEntry(portId);
assertEquals("Unexpected port configuration", portEntry, storeEntry);
- assertEquals("Unexpected type", Port.class.getName(), storeEntry.getType());
+ assertEquals("Unexpected type", Port.class.getSimpleName(), storeEntry.getType());
assertEquals("Unexpected port attributes", portEntry.getAttributes(), storeEntry.getAttributes());
assertTrue("Unexpected port children found", storeEntry.getChildrenIds().isEmpty());
}
@@ -369,7 +368,7 @@ public abstract class ConfigurationEntry
Map<String, Object> virtualHostAttributes = new HashMap<String, Object>();
virtualHostAttributes.put(VirtualHost.NAME, "test1");
virtualHostAttributes.put(VirtualHost.CONFIGURATION, "/path/to/phantom/virtualhost/config1");
- ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getName(), virtualHostAttributes,
+ ConfigurationEntry hostEntry = new ConfigurationEntry(virtualHostId, VirtualHost.class.getSimpleName(), virtualHostAttributes,
Collections.<UUID> emptySet(), _store);
UUID keyStoreId = UUID.randomUUID();
@@ -382,7 +381,7 @@ public abstract class ConfigurationEntry
attributes.put(KeyStore.DESCRIPTION, "Description");
attributes.put(KeyStore.CERTIFICATE_ALIAS, "Alias");
- ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getName(), attributes, Collections.<UUID> emptySet(),
+ ConfigurationEntry keyStoreEntry = new ConfigurationEntry(keyStoreId, KeyStore.class.getSimpleName(), attributes, Collections.<UUID> emptySet(),
_store);
_store.save(hostEntry, keyStoreEntry);
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java Thu Dec 27 17:40:48 2012
@@ -33,7 +33,7 @@ public class JsonConfigurationEntryStore
Map<String, Object> brokerObjectMap = new HashMap<String, Object>();
brokerObjectMap.put(Broker.ID, brokerId);
- brokerObjectMap.put("type", Broker.class.getName());
+ brokerObjectMap.put("type", Broker.class.getSimpleName());
brokerObjectMap.put(JsonConfigurationEntryStore.ATTRIBUTES, brokerAttributes);
StringWriter sw = new StringWriter();
@@ -43,7 +43,7 @@ public class JsonConfigurationEntryStore
_storeFile = TestFileUtils.createTempFile(this, ".json", brokerJson);
- JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(_storeFile.getAbsolutePath());
+ JsonConfigurationEntryStore store = new JsonConfigurationEntryStore(_storeFile);
return store;
}
@@ -51,7 +51,25 @@ public class JsonConfigurationEntryStore
protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
{
ConfigurationEntryStore store = getStore();
- store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID>emptySet(), store));
+ store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+ }
+
+ public void testAttributeIsResolvedFromSystemProperties()
+ {
+ String aclLocation = "path/to/acl/" + getTestName();
+ setTestSystemProperty("my.test.property", aclLocation);
+
+ ConfigurationEntryStore store = getStore();
+ ConfigurationEntry brokerConfigEntry = store.getRootEntry();
+ Map<String, Object> attributes = new HashMap<String, Object>(brokerConfigEntry.getAttributes());
+ attributes.put(Broker.ACL_FILE, "${my.test.property}");
+ ConfigurationEntry updatedBrokerEntry = new ConfigurationEntry(brokerConfigEntry.getId(), Broker.class.getSimpleName(),
+ attributes, brokerConfigEntry.getChildrenIds(), store);
+ store.save(updatedBrokerEntry);
+
+ JsonConfigurationEntryStore store2 = new JsonConfigurationEntryStore(_storeFile);
+
+ assertEquals("Unresolved ACL value", aclLocation, store2.getRootEntry().getAttributes().get(Broker.ACL_FILE));
}
}
Added: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java?rev=1426268&view=auto
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java (added)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/store/MergingStoreTest.java Thu Dec 27 17:40:48 2012
@@ -0,0 +1,239 @@
+/*
+ *
+ * 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.configuration.store;
+
+import static org.apache.qpid.server.configuration.ConfigurationEntryStoreFactory.DEFAULT_STORE;
+
+import java.io.File;
+import java.util.Collection;
+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.configuration.ConfigurationEntry;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
+import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.util.BrokerTestHelper;
+import org.apache.qpid.test.utils.QpidTestCase;
+import org.apache.qpid.util.FileUtils;
+
+public class MergingStoreTest extends QpidTestCase
+{
+ private ConfigurationEntryStore _masterStore;
+ private ConfigurationEntryStore _userStore;
+
+ private File _userStoreFile;
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ setTestSystemProperty("QPID_HOME", TMP_FOLDER);
+ _masterStore = new JsonConfigurationEntryStore(getClass().getClassLoader().getResource(DEFAULT_STORE));
+ _userStoreFile = new File(TMP_FOLDER, "_store_" + System.currentTimeMillis() + "_" + getTestName());
+ _userStore = createStore(_userStoreFile);
+ }
+
+ public void tearDown() throws Exception
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (_userStoreFile != null)
+ {
+ FileUtils.delete(_userStoreFile, true);
+ }
+ }
+ }
+
+ private ConfigurationEntryStore createStore(File userStoreFile) throws Exception
+ {
+ return BrokerTestHelper.createTestProfileBrokerConfigurationStore(userStoreFile.getAbsolutePath());
+ }
+
+ public void testAllMasterEntriesAreCopiedForEmptyUserStore()
+ {
+ MergingStore store = new MergingStore(_userStore, _masterStore);
+
+ assertStoreEntries(store, _userStore, _masterStore);
+ }
+
+ private void assertStoreEntries(ConfigurationEntryStore mergedStore, ConfigurationEntryStore userStore,
+ ConfigurationEntryStore masterStore)
+ {
+ ConfigurationEntry masterRootEntry = masterStore.getRootEntry();
+ ConfigurationEntry userRootEntry = userStore.getRootEntry();
+ ConfigurationEntry mergedRootEntry = mergedStore.getRootEntry();
+
+ Map<String, Object> masterStoreAttributes = masterRootEntry.getAttributes();
+ assertFalse("Master store has no attributes defined for broker", masterStoreAttributes.isEmpty());
+
+ Map<String, Object> userStoreAttributes = userRootEntry.getAttributes();
+ Map<String, Object> mergedStoreAttributes = mergedRootEntry.getAttributes();
+ for (Map.Entry<String, Object> attributeEntry : masterStoreAttributes.entrySet())
+ {
+ assertEquals("Unexpected attribute " + attributeEntry.getKey() + " in user store", attributeEntry.getValue(),
+ userStoreAttributes.get(attributeEntry.getKey()));
+ assertEquals("Unexpected attribute " + attributeEntry.getKey() + " in merged store", attributeEntry.getValue(),
+ mergedStoreAttributes.get(attributeEntry.getKey()));
+ }
+
+ Set<UUID> childrenIds = masterRootEntry.getChildrenIds();
+ assertFalse("Master store has no chldren", childrenIds.isEmpty());
+
+ for (UUID id : childrenIds)
+ {
+ ConfigurationEntry masterEntry = masterStore.getEntry(id);
+ ConfigurationEntry userEntry = userStore.getEntry(id);
+ ConfigurationEntry mergedEntry = mergedStore.getEntry(id);
+
+ assertEquals("Unexpected entry in user store", masterEntry, userEntry);
+ assertEquals("Unexpected entry in merged store", masterEntry, mergedEntry);
+ }
+ }
+
+ public void testMasterEntriesAreCopiedIntoUserStoreWhenTheyAreMissedInUserStore()
+ {
+ // merge all entries
+ MergingStore store = new MergingStore(_userStore, _masterStore);
+
+ Map<String, Collection<ConfigurationEntry>> userChildren = _userStore.getRootEntry().getChildren();
+ Collection<ConfigurationEntry> ports = userChildren.get(Port.class.getSimpleName());
+ assertFalse("Ports are missed in master store", ports.isEmpty());
+
+ // remove ports
+ for (ConfigurationEntry portEntry : ports)
+ {
+ _userStore.remove(portEntry.getId());
+ }
+
+ // merge again
+ store = new MergingStore(_userStore, _masterStore);
+
+ assertStoreEntries(store, _userStore, _masterStore);
+ }
+
+ public void testMasterEntriesAreCopiedIntoUserStoreWhenTheyAreReplacedWithEntriesWithDifferentNames()
+ {
+ // merge all entries
+ MergingStore store = new MergingStore(_userStore, _masterStore);
+
+ Map<String, Collection<ConfigurationEntry>> userChildren = _userStore.getRootEntry().getChildren();
+ Collection<ConfigurationEntry> ports = userChildren.get(Port.class.getSimpleName());
+ assertFalse("Ports are missed in master store", ports.isEmpty());
+
+ // remove ports
+ for (ConfigurationEntry portEntry : ports)
+ {
+ _userStore.remove(portEntry.getId());
+ }
+
+ Map<String, Object> attributes = new HashMap<String, Object>();
+ attributes.put(Port.NAME, getTestName());
+ ConfigurationEntry port = new ConfigurationEntry(UUID.randomUUID(), Port.class.getSimpleName(), attributes, null,
+ _userStore);
+ _userStore.save(port);
+
+ // merge again
+ store = new MergingStore(_userStore, _masterStore);
+
+ assertStoreEntries(store, _userStore, _masterStore);
+
+ // previously added custom entry still should be in store
+ ConfigurationEntry storedPortEntry = store.getEntry(port.getId());
+ assertEquals("User port entry was removed", port, storedPortEntry);
+ }
+
+ public void testStoreEntriesAreNotReplacedIfAttributesAreModified() throws Exception
+ {
+ // merge all entries
+ MergingStore store = new MergingStore(_userStore, _masterStore);
+
+ ConfigurationEntry root = store.getRootEntry();
+ Set<UUID> childrenIds = root.getChildrenIds();
+ assertFalse("Cannot find chldren", childrenIds.isEmpty());
+
+ Set<UUID> all = new HashSet<UUID>(childrenIds);
+ all.add(root.getId());
+
+ // store new attributes in map for verification
+ Map<UUID, Map<String, Object>> modifiedAttributes = new HashMap<UUID, Map<String, Object>>();
+ Set<ConfigurationEntry> entriesToStore = new HashSet<ConfigurationEntry>();
+
+ // modify primitive attributes in all entries
+ for (UUID uuid : all)
+ {
+ ConfigurationEntry entry = store.getEntry(uuid);
+ Map<String, Object> newAttributes = new HashMap<String, Object>();
+ modifiedAttributes.put(entry.getId(), newAttributes);
+ ConfigurationEntry modifiedEntry = new ConfigurationEntry(entry.getId(), entry.getType(), newAttributes,
+ entry.getChildrenIds(), entry.getStore());
+ entriesToStore.add(modifiedEntry);
+ for (Map.Entry<String, Object> attributeEntry : entry.getAttributes().entrySet())
+ {
+ Object value = attributeEntry.getValue();
+ String key = attributeEntry.getKey();
+ if (!key.equals("name"))
+ {
+ if (value instanceof String)
+ {
+ value = (String) value + "_Modified";
+ }
+ else if (value instanceof Number)
+ {
+ value = ((Number) value).intValue() + 10000;
+ }
+ else if (value instanceof Boolean)
+ {
+ value = !((Boolean) value).booleanValue();
+ }
+ }
+ newAttributes.put(key, value);
+ }
+ }
+
+ // save modified entries
+ store.save(entriesToStore.toArray(new ConfigurationEntry[entriesToStore.size()]));
+
+ // merge again
+ store = new MergingStore(_userStore, _masterStore);
+
+ for (Map.Entry<UUID, Map<String, Object>> entryAttributes : modifiedAttributes.entrySet())
+ {
+ ConfigurationEntry entry = store.getEntry(entryAttributes.getKey());
+ assertEquals("Unexpected attributes", entryAttributes.getValue(), entry.getAttributes());
+ }
+
+ // assert that all values have been saved, re-create user store
+ _userStore = createStore(_userStoreFile);
+
+ for (Map.Entry<UUID, Map<String, Object>> entryAttributes : modifiedAttributes.entrySet())
+ {
+ ConfigurationEntry entry = store.getEntry(entryAttributes.getKey());
+ assertEquals("Unexpected attributes in user store", entryAttributes.getValue(), entry.getAttributes());
+ }
+
+ }
+}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/model/configuration/ConfigurationEntryTest.java Thu Dec 27 17:40:48 2012
@@ -86,7 +86,7 @@ public class ConfigurationEntryTest exte
ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(),
Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
- VirtualHost.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
+ VirtualHost.class.getSimpleName(), Collections.<String, Object> emptyMap(), Collections.singleton(UUID.randomUUID()), store);
assertTrue(entry1.hashCode() == entry2.hashCode());
assertFalse(entry1.hashCode() == entryWithDifferentId.hashCode());
@@ -99,18 +99,31 @@ public class ConfigurationEntryTest exte
UUID id = UUID.randomUUID();
Map<String, Object> attributes1 = new HashMap<String, Object>();
attributes1.put(VirtualHost.NAME, "name1");
+ Set<UUID> childrenIds = Collections.singleton(UUID.randomUUID());
ConfigurationEntry entry1 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
- Collections.singleton(UUID.randomUUID()), store);
+ childrenIds, store);
Map<String, Object> attributes2 = new HashMap<String, Object>();
attributes2.put(VirtualHost.NAME, "name2");
- ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes2,
- Collections.singleton(UUID.randomUUID()), store);
+ ConfigurationEntry entry2 = new ConfigurationEntry(id, VirtualHost.class.getSimpleName(), attributes1,
+ childrenIds, store);
ConfigurationEntry entryWithDifferentId = new ConfigurationEntry(UUID.randomUUID(),
- VirtualHost.class.getSimpleName(), attributes1, Collections.singleton(UUID.randomUUID()), store);
+ VirtualHost.class.getSimpleName(), attributes1, childrenIds, store);
assertTrue(entry1.equals(entry2));
- assertFalse(entry1.equals(entryWithDifferentId));
+ assertFalse("Entries should be dirrent because of diferrent IDs", entry1.equals(entryWithDifferentId));
+
+ ConfigurationEntry entryWithDifferentChildId = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes1, Collections.singleton(UUID.randomUUID()), store);
+ assertFalse("Entries should be dirrent because of diferrent children", entry1.equals(entryWithDifferentChildId));
+
+ ConfigurationEntry entryWithDifferentName = new ConfigurationEntry(id,
+ VirtualHost.class.getSimpleName(), attributes2, childrenIds, store);
+ assertFalse("Entries should be dirrent because of diferrent attributes", entry1.equals(entryWithDifferentName));
+
+ ConfigurationEntry entryWithDifferentType = new ConfigurationEntry(id,
+ Broker.class.getSimpleName(), attributes1, childrenIds, store);
+ assertFalse("Entries should be dirrent because of diferrent types", entry1.equals(entryWithDifferentType));
}
}
Modified: qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java?rev=1426268&r1=1426267&r2=1426268&view=diff
==============================================================================
--- qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java (original)
+++ qpid/branches/java-broker-config-qpid-4390/qpid/java/broker/src/test/java/org/apache/qpid/server/util/BrokerTestHelper.java Thu Dec 27 17:40:48 2012
@@ -24,6 +24,8 @@ import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import java.io.File;
+import java.lang.reflect.Constructor;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.UUID;
@@ -36,6 +38,7 @@ import org.apache.qpid.framing.BasicCont
import org.apache.qpid.framing.ContentHeaderBody;
import org.apache.qpid.framing.abstraction.MessagePublishInfo;
import org.apache.qpid.server.AMQChannel;
+import org.apache.qpid.server.configuration.ConfigurationEntryStore;
import org.apache.qpid.server.configuration.VirtualHostConfiguration;
import org.apache.qpid.server.exchange.DefaultExchangeFactory;
import org.apache.qpid.server.exchange.Exchange;
@@ -61,6 +64,10 @@ import org.apache.qpid.server.virtualhos
public class BrokerTestHelper
{
+ protected static final String BROKER_STORE_CLASS_NAME_KEY = "brokerstore.class.name";
+ protected static final String JSON_BROKER_STORE_CLASS_NAME = "org.apache.qpid.server.configuration.store.JsonConfigurationEntryStore";
+
+
public static Broker createBrokerMock()
{
setCurrentActorIfNecessary();
@@ -205,4 +212,39 @@ public class BrokerTestHelper
return queue;
}
+ public static String getTestProfileBrokerConfigurationStoreClassName()
+ {
+ final String storeClass = System.getProperty(BROKER_STORE_CLASS_NAME_KEY);
+ return storeClass != null ? storeClass : JSON_BROKER_STORE_CLASS_NAME;
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static ConfigurationEntryStore createTestProfileBrokerConfigurationStore(String storeLocation) throws Exception
+ {
+ String className = getTestProfileBrokerConfigurationStoreClassName();
+ Class classObject = Class.forName(className);
+ Constructor[] constructors = classObject.getConstructors();
+ for (int i = 0; i < constructors.length; i++)
+ {
+ Constructor constructor = constructors[i];
+ Class[] parameterTypes = constructor.getParameterTypes();
+ if (parameterTypes == null || parameterTypes.length == 0)
+ {
+ return (ConfigurationEntryStore) classObject.newInstance();
+ }
+ else if (parameterTypes.length == 1)
+ {
+ if (parameterTypes[0] == String.class)
+ {
+ return (ConfigurationEntryStore) constructor.newInstance(storeLocation);
+ }
+ else if (parameterTypes[0] == File.class)
+ {
+ return (ConfigurationEntryStore) constructor.newInstance(new File(storeLocation));
+ }
+ }
+ }
+ throw new RuntimeException("Cannot instantiate broker configuration store. Try to override getTestProfileBrokerConfigurationStore");
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org