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 2013/10/05 02:26:00 UTC
svn commit: r1529359 - in /qpid/trunk/qpid/java/broker-core/src:
main/java/org/apache/qpid/server/configuration/store/
test/java/org/apache/qpid/server/configuration/store/
Author: orudyy
Date: Sat Oct 5 00:26:00 2013
New Revision: 1529359
URL: http://svn.apache.org/r1529359
Log:
QPID-5138: Simplify the evaluation of child configured object class in configuration store and add tests
Modified:
qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java
Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java?rev=1529359&r1=1529358&r2=1529359&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStore.java Sat Oct 5 00:26:00 2013
@@ -70,7 +70,7 @@ public class MemoryConfigurationEntrySto
private final ObjectMapper _objectMapper;
private final Map<UUID, ConfigurationEntry> _entries;
- private final Map<String, Class<? extends ConfiguredObject>> _relationshipClasses;
+ private final Map<String, Class<? extends ConfiguredObject>> _brokerChildrenRelationshipMap;
private final ConfigurationEntryStoreUtil _util = new ConfigurationEntryStoreUtil();
private String _storeLocation;
@@ -86,7 +86,7 @@ public class MemoryConfigurationEntrySto
_objectMapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
_objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
_entries = new HashMap<UUID, ConfigurationEntry>();
- _relationshipClasses = buildRelationshipClassMap();
+ _brokerChildrenRelationshipMap = buildRelationshipClassMap();
_resolver = new Strings.ChainedResolver(Strings.SYSTEM_RESOLVER,
new Strings.MapResolver(configProperties));
}
@@ -291,7 +291,7 @@ public class MemoryConfigurationEntrySto
+ " can not be loaded by store of version " + STORE_VERSION);
}
- ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries, null);
+ ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
_rootId = brokerEntry.getId();
}
catch (IOException e)
@@ -370,7 +370,7 @@ public class MemoryConfigurationEntrySto
byte[] bytes = json.getBytes("UTF-8");
bais = new ByteArrayInputStream(bytes);
JsonNode node = loadJsonNodes(bais, _objectMapper);
- ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries, null);
+ ConfigurationEntry brokerEntry = toEntry(node, Broker.class, _entries);
_rootId = brokerEntry.getId();
}
catch(Exception e)
@@ -490,7 +490,7 @@ public class MemoryConfigurationEntrySto
return root;
}
- private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries, Class<? extends ConfiguredObject> parentClass)
+ private ConfigurationEntry toEntry(JsonNode parent, Class<? extends ConfiguredObject> expectedConfiguredObjectClass, Map<UUID, ConfigurationEntry> entries)
{
Map<String, Object> attributes = null;
Set<UUID> childrenIds = new TreeSet<UUID>();
@@ -519,23 +519,11 @@ public class MemoryConfigurationEntrySto
JsonNode element = elements.next();
if (element.isObject())
{
- Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = _relationshipClasses.get(fieldName);
- if (expectedChildConfiguredObjectClass == null && expectedConfiguredObjectClass != null)
- {
- Collection<Class<? extends ConfiguredObject>> childTypes = Model.getInstance().getChildTypes(expectedConfiguredObjectClass);
- for (Class<? extends ConfiguredObject> childType : childTypes)
- {
- String relationship = childType.getSimpleName().toLowerCase();
- relationship += relationship.endsWith("s") ? "es": "s";
- if (fieldName.equals(relationship))
- {
- expectedChildConfiguredObjectClass = childType;
- break;
- }
- }
- }
+ Class<? extends ConfiguredObject> expectedChildConfiguredObjectClass = findExpectedChildConfiguredObjectClass(
+ fieldName, expectedConfiguredObjectClass);
+
// assuming it is a child node
- ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries, expectedConfiguredObjectClass);
+ ConfigurationEntry entry = toEntry(element, expectedChildConfiguredObjectClass, entries);
childrenIds.add(entry.getId());
}
else
@@ -629,6 +617,34 @@ public class MemoryConfigurationEntrySto
return entry;
}
+ private Class<? extends ConfiguredObject> findExpectedChildConfiguredObjectClass(String parentFieldName,
+ Class<? extends ConfiguredObject> parentConfiguredObjectClass)
+ {
+ if (parentConfiguredObjectClass == Broker.class)
+ {
+ return _brokerChildrenRelationshipMap.get(parentFieldName);
+ }
+
+ // for non-broker parent classes
+ // try to determine the child class from the model by iterating through the children classes
+ // for the parent configured object class
+ if (parentConfiguredObjectClass != null)
+ {
+ Collection<Class<? extends ConfiguredObject>> childTypes = Model.getInstance().getChildTypes(parentConfiguredObjectClass);
+ for (Class<? extends ConfiguredObject> childType : childTypes)
+ {
+ String relationship = childType.getSimpleName().toLowerCase();
+ relationship += relationship.endsWith("s") ? "es": "s";
+ if (parentFieldName.equals(relationship))
+ {
+ return childType;
+ }
+ }
+ }
+
+ return null;
+ }
+
private Object toObject(JsonNode node)
{
if (node.isValueNode())
Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java?rev=1529359&r1=1529358&r2=1529359&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/ConfigurationEntryStoreTestCase.java Sat Oct 5 00:26:00 2013
@@ -33,9 +33,11 @@ import org.apache.qpid.server.model.Brok
import org.apache.qpid.server.model.GroupProvider;
import org.apache.qpid.server.model.KeyStore;
import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.PreferencesProvider;
import org.apache.qpid.server.model.Transport;
import org.apache.qpid.server.model.TrustStore;
import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider;
import org.apache.qpid.server.plugin.AuthenticationManagerFactory;
import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
import org.apache.qpid.server.security.auth.manager.ExternalAuthenticationManager;
@@ -47,7 +49,7 @@ public abstract class ConfigurationEntry
private UUID _brokerId;
private UUID _virtualHostId;
- private UUID _authenticationProviderId;
+ protected UUID _authenticationProviderId;
private Map<String, Object> _brokerAttributes;
private Map<String, Object> _virtualHostAttributes;
@@ -93,7 +95,12 @@ public abstract class ConfigurationEntry
// ??? perhaps it should not be abstract
protected abstract ConfigurationEntryStore createStore(UUID brokerId, Map<String, Object> brokerAttributes) throws Exception;
- protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes);
+ protected abstract void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId);
+
+ protected final void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+ {
+ addConfiguration(id, type, attributes, _brokerId);
+ }
protected ConfigurationEntryStore getStore()
{
@@ -388,4 +395,43 @@ public abstract class ConfigurationEntry
assertNotNull("Virtual host is not found", _store.getEntry(virtualHostId));
assertNotNull("Key store is not found", _store.getEntry(keyStoreId));
}
+
+ public void testAddPreferencesProvider()
+ {
+ UUID preferencesProviderId = UUID.randomUUID();
+ String path = TMP_FOLDER;
+ String name = getTestName();
+
+ addPreferencesProvider(preferencesProviderId, name, path);
+
+ assertEquals("Unexpected preference provider ID in authentication provider children set", preferencesProviderId, _store
+ .getEntry(_authenticationProviderId).getChildrenIds().iterator().next());
+ ConfigurationEntry preferencesProviderEntry = _store.getEntry(preferencesProviderId);
+ assertNotNull("Preferences providert is not found", preferencesProviderEntry);
+ assertEquals("Unexpected preferences providert id", preferencesProviderId, preferencesProviderEntry.getId());
+ Map<String, Object> attributes = preferencesProviderEntry.getAttributes();
+ assertEquals("Unexpected preferences provider name", name, attributes.get(PreferencesProvider.NAME));
+ assertEquals("Unexpected preferences provider path", path, attributes.get(FileSystemPreferencesProvider.PATH));
+ assertEquals("Unexpected preferences provider type", FileSystemPreferencesProvider.PROVIDER_TYPE,
+ attributes.get(PreferencesProvider.TYPE));
+ }
+
+ protected void addPreferencesProvider(UUID preferencesProviderId, String name, String path)
+ {
+ ConfigurationEntry authenticationProviderEntry = _store.getEntry(_authenticationProviderId);
+ ConfigurationEntry newAuthenticationProviderConfigEntry = new ConfigurationEntry(authenticationProviderEntry.getId(),
+ authenticationProviderEntry.getType(), authenticationProviderEntry.getAttributes(),
+ Collections.<UUID>singleton(preferencesProviderId), _store);
+
+ Map<String, Object> preferencesProviderAttributes = new HashMap<String, Object>();
+ preferencesProviderAttributes.put(PreferencesProvider.TYPE, FileSystemPreferencesProvider.PROVIDER_TYPE);
+ preferencesProviderAttributes.put(FileSystemPreferencesProvider.PATH, path);
+ preferencesProviderAttributes.put(PreferencesProvider.NAME, name);
+
+ ConfigurationEntry preferencesProviderEntry = new ConfigurationEntry(preferencesProviderId, PreferencesProvider.class.getSimpleName(),
+ preferencesProviderAttributes, Collections.<UUID> emptySet(), _store);
+
+ _store.save(newAuthenticationProviderConfigEntry, preferencesProviderEntry);
+ }
+
}
Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java?rev=1529359&r1=1529358&r2=1529359&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/JsonConfigurationEntryStoreTest.java Sat Oct 5 00:26:00 2013
@@ -25,13 +25,17 @@ import java.io.IOException;
import java.io.StringWriter;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import org.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.Broker;
+import org.apache.qpid.server.model.PreferencesProvider;
+import org.apache.qpid.server.model.adapter.FileSystemPreferencesProvider;
import org.apache.qpid.test.utils.TestFileUtils;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
@@ -43,6 +47,7 @@ public class JsonConfigurationEntryStore
private File _storeFile;
private ObjectMapper _objectMapper;
+
@Override
public void setUp() throws Exception
{
@@ -93,10 +98,14 @@ public class JsonConfigurationEntryStore
}
@Override
- protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+ protected void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId)
{
ConfigurationEntryStore store = getStore();
- store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+ ConfigurationEntry parentEntry = getStore().getEntry(parentId);
+ Set<UUID> children = new HashSet<UUID>(parentEntry.getChildrenIds());
+ children.add(id);
+ ConfigurationEntry newParentEntry = new ConfigurationEntry(parentEntry.getId(), parentEntry.getType(), parentEntry.getAttributes(), children, store);
+ store.save(newParentEntry, new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
}
public void testAttributeIsResolvedFromSystemProperties()
@@ -233,4 +242,27 @@ public class JsonConfigurationEntryStore
}
}
}
+
+ public void testGetPreferencesProvider() throws Exception
+ {
+ UUID preferencesProviderId = UUID.randomUUID();
+ String path = TMP_FOLDER;
+ String name = getTestName();
+
+ addPreferencesProvider(preferencesProviderId, name, path);
+
+ // verify that store can deserialise child of a child
+ JsonConfigurationEntryStore newStore = new JsonConfigurationEntryStore(_storeFile.getAbsolutePath(), null, false, Collections.<String, String>emptyMap());
+
+ ConfigurationEntry authenticationProviderEntry = newStore.getEntry(_authenticationProviderId);
+ assertEquals("Unexpected preference provider ID in authentication provider children set", preferencesProviderId, authenticationProviderEntry.getChildrenIds().iterator().next());
+ ConfigurationEntry preferencesProviderEntry = newStore.getEntry(preferencesProviderId);
+ assertNotNull("Preferences providert is not found", preferencesProviderEntry);
+ assertEquals("Unexpected preferences providert id", preferencesProviderId, preferencesProviderEntry.getId());
+ Map<String, Object> attributes = preferencesProviderEntry.getAttributes();
+ assertEquals("Unexpected preferences provider name", name, attributes.get(PreferencesProvider.NAME));
+ assertEquals("Unexpected preferences provider path", path, attributes.get(FileSystemPreferencesProvider.PATH));
+ assertEquals("Unexpected preferences provider type", FileSystemPreferencesProvider.PROVIDER_TYPE,
+ attributes.get(PreferencesProvider.TYPE));
+ }
}
Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java?rev=1529359&r1=1529358&r2=1529359&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java (original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/configuration/store/MemoryConfigurationEntryStoreTest.java Sat Oct 5 00:26:00 2013
@@ -23,7 +23,9 @@ package org.apache.qpid.server.configura
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.UUID;
import org.apache.qpid.server.BrokerOptions;
@@ -48,10 +50,14 @@ public class MemoryConfigurationEntrySto
}
@Override
- protected void addConfiguration(UUID id, String type, Map<String, Object> attributes)
+ protected void addConfiguration(UUID id, String type, Map<String, Object> attributes, UUID parentId)
{
ConfigurationEntryStore store = getStore();
- store.save(new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
+ ConfigurationEntry parentEntry = getStore().getEntry(parentId);
+ Set<UUID> children = new HashSet<UUID>(parentEntry.getChildrenIds());
+ children.add(id);
+ ConfigurationEntry newParentEntry = new ConfigurationEntry(parentEntry.getId(), parentEntry.getType(), parentEntry.getAttributes(), children, store);
+ store.save(newParentEntry, new ConfigurationEntry(id, type, attributes, Collections.<UUID> emptySet(), store));
}
public void testCreateWithNullLocationAndNullInitialStore()
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org