qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1612064 - in /qpid/trunk/qpid/java: bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/ bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/ broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/...
Date Sun, 20 Jul 2014 09:18:42 GMT
Author: kwall
Date: Sun Jul 20 09:18:41 2014
New Revision: 1612064

URL: http://svn.apache.org/r1612064
Log:
QPID-5867: [Java Broker] Allow the virtualhost's permitted node list to passed via the virtualhostnode's
virtualhost blueprint context variable.

Work completed by Andrew MacBean <macbean@apache.org> and me.

Modified:
    qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
    qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
    qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java
    qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java

Modified: qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
Sun Jul 20 09:18:41 2014
@@ -66,6 +66,8 @@ import org.apache.qpid.server.store.berk
 import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacadeFactory;
 import org.apache.qpid.server.store.berkeleydb.replication.ReplicationGroupListener;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
+import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost;
+import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHostImpl;
 import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
 
 @ManagedObject( category = false, type = BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE
)
@@ -414,14 +416,43 @@ public class BDBHAVirtualHostNodeImpl ex
             {
                 if (LOGGER.isDebugEnabled())
                 {
-                    LOGGER.debug("Creating new virtualhost with name : " +  getGroupName());
+                    LOGGER.debug("Creating new virtualhost with name : " + getGroupName());
+                }
+
+                boolean hasBlueprint = getContext().containsKey(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
+                boolean blueprintUtilised = getContext().containsKey(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)
+                                            && Boolean.parseBoolean(String.valueOf(getContext().get(
+                        VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)));
+
+                Map<String, Object> hostAttributes = new HashMap<>();
+                if (hasBlueprint && !blueprintUtilised)
+                {
+                    Map<String, Object> virtualhostBlueprint =
+                            getContextValue(Map.class, VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
+
+                    if (LOGGER.isDebugEnabled())
+                    {
+                        LOGGER.debug("Using virtualhost blueprint " + virtualhostBlueprint);
+                    }
+
+                    hostAttributes.putAll(virtualhostBlueprint);
+
+
                 }
 
-                Map<String, Object> hostAttributes = new HashMap<String, Object>();
                 hostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
                 hostAttributes.put(VirtualHost.NAME, getGroupName());
-                hostAttributes.put(VirtualHost.TYPE, "BDB_HA");
+                hostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
                 host = createChild(VirtualHost.class, hostAttributes);
+
+                if (hasBlueprint && !blueprintUtilised)
+                {
+                    // Update the context with the utilised flag
+                    Map<String, String> actualContext = (Map<String, String>)
getActualAttributes().get(CONTEXT);
+                    Map<String, String> context = new HashMap<>(actualContext);
+                    context.put(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR, Boolean.TRUE.toString());
+                    setAttribute(CONTEXT, getContext(), context);
+                }
             }
             else
             {

Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
(original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeTest.java
Sun Jul 20 09:18:41 2014
@@ -20,6 +20,7 @@
  */
 package org.apache.qpid.server.store.berkeleydb;
 
+import static java.util.Collections.*;
 import static org.mockito.Mockito.when;
 
 import java.io.File;
@@ -45,6 +46,7 @@ import org.apache.qpid.server.model.Virt
 import org.apache.qpid.server.store.DurableConfigurationStore;
 import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost;
 import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHostImpl;
+import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
 import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode;
 import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNodeImpl;
 import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode;
@@ -95,7 +97,7 @@ public class BDBHAVirtualHostNodeTest ex
         attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperHostPort);
         attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath);
         attributes.put(BDBHAVirtualHostNode.CONTEXT,
-                Collections.singletonMap(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout));
+                singletonMap(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout));
 
         BDBHAVirtualHostNode<?> node = _helper.createHaVHN(attributes);
 
@@ -467,10 +469,18 @@ public class BDBHAVirtualHostNodeTest ex
     {
         String messageStorePath = _helper.getMessageStorePath();
         int node1PortNumber = findFreePort();
+        int node2PortNumber = getNextAvailable(node1PortNumber+1);
         String helperAddress = "localhost:" + node1PortNumber;
         String groupName = "group";
 
-        Map<String, Object> node1Attributes = new HashMap<String, Object>();
+        List<String> permittedNodes = new ArrayList<>();
+        permittedNodes.add(helperAddress);
+        String node2Address = "localhost:" + node2PortNumber;
+        permittedNodes.add(node2Address);
+
+        String blueprint = String.format("{ \"%s\" : [ \"%s\", \"%s\" ] } ", BDBHAVirtualHost.PERMITTED_NODES,
helperAddress, node2Address);
+
+        Map<String, Object> node1Attributes = new HashMap<>();
         node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
         node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
         node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
@@ -478,22 +488,17 @@ public class BDBHAVirtualHostNodeTest ex
         node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
         node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
         node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator
+ "1");
+        Map<String, String> contextMap = singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
blueprint);
+        node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, contextMap);
 
         BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
-        BDBHAVirtualHost<?> host = (BDBHAVirtualHost<?>)node1.getVirtualHost();
-
-        List<String> permittedNodes = new ArrayList<String>();
-        int node2PortNumber = getNextAvailable(node1PortNumber+1);
-        permittedNodes.add(helperAddress);
-        permittedNodes.add("localhost:" + node2PortNumber);
-        host.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHost.PERMITTED_NODES,
permittedNodes));
 
         Map<String, Object> node2Attributes = new HashMap<String, Object>();
         node2Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
         node2Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
         node2Attributes.put(BDBHAVirtualHostNode.NAME, "node2");
         node2Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
-        node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node2PortNumber);
+        node2Attributes.put(BDBHAVirtualHostNode.ADDRESS, node2Address);
         node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
         node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator
+ "2");
         node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1");

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
Sun Jul 20 09:18:41 2014
@@ -44,8 +44,6 @@ public abstract class AbstractStandardVi
                 implements VirtualHostNode<X>
 {
     private static final Logger LOGGER = Logger.getLogger(AbstractStandardVirtualHostNode.class);
-    public static final String VIRTUALHOST_BLUEPRINT_CONTEXT_VAR = "virtualhostBlueprint";
-    public static final String VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR = "virtualhostBlueprintUtilised";
 
     public AbstractStandardVirtualHostNode(Map<String, Object> attributes,
                                            Broker<?> parent)

Modified: qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractVirtualHostNode.java
Sun Jul 20 09:18:41 2014
@@ -47,6 +47,8 @@ import java.util.concurrent.atomic.Atomi
 public abstract class AbstractVirtualHostNode<X extends AbstractVirtualHostNode<X>>
extends AbstractConfiguredObject<X> implements VirtualHostNode<X>
 {
 
+    public static final String VIRTUALHOST_BLUEPRINT_CONTEXT_VAR = "virtualhostBlueprint";
+    public static final String VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR = "virtualhostBlueprintUtilised";
     private static final Logger LOGGER = Logger.getLogger(AbstractVirtualHostNode.class);
 
     private final Broker<?> _broker;

Modified: qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
(original)
+++ qpid/trunk/qpid/java/broker-core/src/test/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNodeTest.java
Sun Jul 20 09:18:41 2014
@@ -20,7 +20,6 @@
  */
 package org.apache.qpid.server.virtualhostnode;
 
-import static org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode.*;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -145,7 +144,7 @@ public class AbstractStandardVirtualHost
         String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}",
                                            TestMemoryVirtualHost.VIRTUAL_HOST_TYPE,
                                            TEST_VIRTUAL_HOST_NAME);
-        Map<String, String> context = Collections.singletonMap(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
vhBlueprint);
+        Map<String, String> context = Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
vhBlueprint);
 
         Map<String, Object> nodeAttributes = new HashMap<>();
         nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
@@ -166,10 +165,10 @@ public class AbstractStandardVirtualHost
         Map<String, String> updatedContext = node.getContext();
 
         assertTrue("Context should now have utilised flag", updatedContext.containsKey(
-                VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR));
+                AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR));
         assertEquals("Utilised flag should be true",
                      Boolean.TRUE.toString(),
-                     updatedContext.get(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR));
+                     updatedContext.get(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR));
     }
 
     /**
@@ -185,8 +184,8 @@ public class AbstractStandardVirtualHost
                                            TestMemoryVirtualHost.VIRTUAL_HOST_TYPE,
                                            TEST_VIRTUAL_HOST_NAME);
         Map<String, String> context = new HashMap<>();
-        context.put(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
-        context.put(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR, Boolean.TRUE.toString());
+        context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, vhBlueprint);
+        context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR, Boolean.TRUE.toString());
 
         Map<String, Object> nodeAttributes = new HashMap<>();
         nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);
@@ -217,7 +216,7 @@ public class AbstractStandardVirtualHost
         String vhBlueprint = String.format("{ \"type\" : \"%s\", \"name\" : \"%s\"}",
                                            TestMemoryVirtualHost.VIRTUAL_HOST_TYPE,
                                            "vhFromBlueprint");
-        Map<String, String> context = Collections.singletonMap(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
vhBlueprint);
+        Map<String, String> context = Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
vhBlueprint);
 
         Map<String, Object> nodeAttributes = new HashMap<>();
         nodeAttributes.put(VirtualHostNode.NAME, TEST_VIRTUAL_HOST_NODE_NAME);

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/store/SplitStoreTest.java
Sun Jul 20 09:18:41 2014
@@ -32,7 +32,7 @@ import javax.jms.Session;
 
 import org.apache.qpid.configuration.ClientProperties;
 import org.apache.qpid.server.model.VirtualHostNode;
-import org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode;
+import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
 import org.apache.qpid.server.virtualhostnode.JsonVirtualHostNode;
 import org.apache.qpid.server.virtualhostnode.JsonVirtualHostNodeImpl;
 import org.apache.qpid.test.utils.QpidBrokerTestCase;
@@ -88,7 +88,7 @@ public class SplitStoreTest extends Qpid
     {
         final String blueprint = String.format(
            "{ \"type\" : \"%s\",  \"storePath\" : \"%s\" }", virtualHostType, _messageStorePath);
-        final Map<String, String> contextMap = Collections.singletonMap(AbstractStandardVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
+        final Map<String, String> contextMap = Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
                                                                         blueprint);
 
         TestBrokerConfiguration config = getBrokerConfiguration();

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java?rev=1612064&r1=1612063&r2=1612064&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidBrokerTestCase.java
Sun Jul 20 09:18:41 2014
@@ -69,7 +69,7 @@ import org.apache.qpid.server.model.Port
 import org.apache.qpid.server.model.Protocol;
 import org.apache.qpid.server.model.VirtualHostNode;
 import org.apache.qpid.server.store.MemoryConfigurationStore;
-import org.apache.qpid.server.virtualhostnode.AbstractStandardVirtualHostNode;
+import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
 import org.apache.qpid.server.virtualhostnode.JsonVirtualHostNode;
 import org.apache.qpid.url.URLSyntaxException;
 import org.apache.qpid.util.FileUtils;
@@ -873,7 +873,7 @@ public class QpidBrokerTestCase extends 
 
         final String blueprint = getTestProfileVirtualHostNodeBlueprint();
 
-        attributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap(AbstractStandardVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
+        attributes.put(ConfiguredObject.CONTEXT, Collections.singletonMap(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR,
                                                                           blueprint));
 
         int port = getPort(brokerPort);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message