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 2014/08/06 14:21:59 UTC
svn commit: r1616186 - in /qpid/trunk/qpid/java/bdbstore:
src/main/java/org/apache/qpid/server/store/berkeleydb/replication/
src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/
src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/ s...
Author: orudyy
Date: Wed Aug 6 12:21:59 2014
New Revision: 1616186
URL: http://svn.apache.org/r1616186
Log:
QPID-5967: Intruder node detection must be mandatory and should validate all necessary arguments
Modified:
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHost.java
qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHostImpl.java
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/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java
qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostRestTest.java
qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
Modified: qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacade.java Wed Aug 6 12:21:59 2014
@@ -105,7 +105,7 @@ public class ReplicatedEnvironmentFacade
private static final int DEFAULT_REMOTE_NODE_MONITOR_INTERVAL = 1000;
private static final int MASTER_TRANSFER_TIMEOUT = Integer.getInteger(MASTER_TRANSFER_TIMEOUT_PROPERTY_NAME, DEFAULT_MASTER_TRANSFER_TIMEOUT);
- private static final int DB_PING_SOCKET_TIMEOUT = Integer.getInteger(DB_PING_SOCKET_TIMEOUT_PROPERTY_NAME, DEFAULT_DB_PING_SOCKET_TIMEOUT);
+ public static final int DB_PING_SOCKET_TIMEOUT = Integer.getInteger(DB_PING_SOCKET_TIMEOUT_PROPERTY_NAME, DEFAULT_DB_PING_SOCKET_TIMEOUT);
private static final int REMOTE_NODE_MONITOR_INTERVAL = Integer.getInteger(REMOTE_NODE_MONITOR_INTERVAL_PROPERTY_NAME, DEFAULT_REMOTE_NODE_MONITOR_INTERVAL);
private static final int RESTART_TRY_LIMIT = 3;
@@ -149,7 +149,7 @@ public class ReplicatedEnvironmentFacade
put(ReplicationConfig.LOG_FLUSH_TASK_INTERVAL, "1 min");
}});
- private static final String PERMITTED_NODE_LIST = "permittedNodes";
+ public static final String PERMITTED_NODE_LIST = "permittedNodes";
private final ReplicatedEnvironmentConfiguration _configuration;
private final String _prettyGroupNodeName;
@@ -978,7 +978,7 @@ public class ReplicatedEnvironmentFacade
LOGGER.info("Node name " + nodeName);
LOGGER.info("Node host port " + hostPort);
LOGGER.info("Helper host port " + helperHostPort);
- LOGGER.info("Helper host name " + helperNodeName);
+ LOGGER.info("Helper node name " + helperNodeName);
LOGGER.info("Durability " + _defaultDurability);
LOGGER.info("Designated primary (applicable to 2 node case only) " + designatedPrimary);
LOGGER.info("Node priority " + priority);
@@ -986,10 +986,6 @@ public class ReplicatedEnvironmentFacade
LOGGER.info("Permitted node list " + _permittedNodes);
}
- if (helperNodeName != null && _permittedNodes.isEmpty() && !helperHostPort.equals(hostPort))
- {
- connectToHelperNodeAndCheckPermittedHosts(helperNodeName, helperHostPort, hostPort);
- }
Map<String, String> replicationEnvironmentParameters = new HashMap<>(ReplicatedEnvironmentFacade.REPCONFIG_DEFAULTS);
replicationEnvironmentParameters.putAll(_configuration.getReplicationParameters());
@@ -1241,64 +1237,6 @@ public class ReplicatedEnvironmentFacade
return baos.toByteArray();
}
- Collection<String> bytesToPermittedNodeList(byte[] applicationState)
- {
- if (applicationState == null || applicationState.length == 0)
- {
- return Collections.emptySet();
- }
-
- ObjectMapper objectMapper = new ObjectMapper();
- try
- {
- Map<String, Object> settings = objectMapper.readValue(applicationState, Map.class);
- return (Collection<String>)settings.get(PERMITTED_NODE_LIST);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unexpected exception on de-serializing of application state", e);
- }
- }
-
- private void connectToHelperNodeAndCheckPermittedHosts(String helperNodeName, String helperHostPort, String hostPort)
- {
- if (LOGGER.isDebugEnabled())
- {
- LOGGER.debug(String.format("Requesting state of the node '%s' at '%s'", helperNodeName, helperHostPort));
- }
-
- Collection<String> permittedNodes = null;
- try
- {
- NodeState state = getRemoteNodeState(new ReplicationNodeImpl(helperNodeName, helperHostPort));
- byte[] applicationState = state.getAppState();
- permittedNodes = bytesToPermittedNodeList(applicationState);
- }
- catch (IOException e)
- {
- throw new IllegalConfigurationException(String.format("Cannot connect to '%s'", helperHostPort), e);
- }
- catch (ServiceConnectFailedException e)
- {
- throw new IllegalConfigurationException(String.format("Failure to connect to '%s'", helperHostPort), e);
- }
- catch (Exception e)
- {
- throw new RuntimeException(String.format("Unexpected exception on attempt to retrieve state from '%s' at '%s'",
- helperNodeName, helperHostPort), e);
- }
-
- if (LOGGER.isDebugEnabled())
- {
- LOGGER.debug(String.format("Attribute 'permittedNodes' on node '%s' is set to '%s'", helperNodeName, String.valueOf(permittedNodes)));
- }
-
- if (permittedNodes != null && !permittedNodes.isEmpty() && !permittedNodes.contains(hostPort))
- {
- throw new IllegalConfigurationException(String.format("Node from '%s' is not permitted!", hostPort));
- }
- }
-
private void populateExistingRemoteReplicationNodes()
{
ReplicationGroup group = _environment.getGroup();
@@ -1542,7 +1480,7 @@ public class ReplicatedEnvironmentFacade
}
}
- static class ReplicationNodeImpl implements ReplicationNode
+ public static class ReplicationNodeImpl implements ReplicationNode
{
private final InetSocketAddress _address;
Modified: qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHost.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHost.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHost.java Wed Aug 6 12:21:59 2014
@@ -56,6 +56,6 @@ public interface BDBHAVirtualHost<X exte
@ManagedAttribute(mandatory = true, defaultValue = "0")
Long getStoreOverfullSize();
- @ManagedAttribute
+ @ManagedAttribute(mandatory = true)
List<String> getPermittedNodes();
}
Modified: qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHostImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHostImpl.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHostImpl.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhost/berkeleydb/BDBHAVirtualHostImpl.java Wed Aug 6 12:21:59 2014
@@ -134,26 +134,30 @@ public class BDBHAVirtualHostImpl extend
if(changedAttributes.contains(PERMITTED_NODES))
{
+ validatePermittedNodes(((BDBHAVirtualHost<?>)proxyForValidation).getPermittedNodes());
+ }
+ }
- List<String> permittedNodes = ((BDBHAVirtualHost<?>)proxyForValidation).getPermittedNodes();
- if (permittedNodes != null)
+ private void validatePermittedNodes(List<String> permittedNodes)
+ {
+ if (permittedNodes == null || permittedNodes.isEmpty())
+ {
+ throw new IllegalArgumentException(String.format("Attribute '%s' is mandatory and must be set", PERMITTED_NODES));
+ }
+ for (String permittedNode: permittedNodes)
+ {
+ String[] tokens = permittedNode.split(":");
+ if (tokens.length != 2)
+ {
+ throw new IllegalArgumentException(String.format("Invalid permitted node specified '%s'. ", permittedNode));
+ }
+ try
{
- for (String permittedNode: permittedNodes)
- {
- String[] tokens = permittedNode.split(":");
- if (tokens.length != 2)
- {
- throw new IllegalArgumentException(String.format("Invalid permitted node specified '%s'. ", permittedNode));
- }
- try
- {
- Integer.parseInt(tokens[1]);
- }
- catch(Exception e)
- {
- throw new IllegalArgumentException(String.format("Invalid port is specified in permitted node '%s'. ", permittedNode));
- }
- }
+ Integer.parseInt(tokens[1]);
+ }
+ catch(Exception e)
+ {
+ throw new IllegalArgumentException(String.format("Invalid port is specified in permitted node '%s'. ", permittedNode));
}
}
}
@@ -193,6 +197,16 @@ public class BDBHAVirtualHostImpl extend
return _permittedNodes;
}
+ @Override
+ public void onValidate()
+ {
+ super.onValidate();
+
+ validatePermittedNodes(this.getPermittedNodes());
+ validateTransactionSynchronizationPolicy(this.getLocalTransactionSynchronizationPolicy());
+ validateTransactionSynchronizationPolicy(this.getRemoteTransactionSynchronizationPolicy());
+ }
+
protected void applyPermittedNodes()
{
ReplicatedEnvironmentFacade facade = getReplicatedEnvironmentFacade();
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=1616186&r1=1616185&r2=1616186&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 Wed Aug 6 12:21:59 2014
@@ -20,9 +20,11 @@
*/
package org.apache.qpid.server.virtualhostnode.berkeleydb;
+import java.io.IOException;
import java.net.InetSocketAddress;
import java.security.PrivilegedAction;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -41,10 +43,13 @@ import com.sleepycat.je.rep.ReplicatedEn
import com.sleepycat.je.rep.ReplicationNode;
import com.sleepycat.je.rep.StateChangeEvent;
import com.sleepycat.je.rep.StateChangeListener;
+import com.sleepycat.je.rep.util.DbPing;
import com.sleepycat.je.rep.util.ReplicationGroupAdmin;
import com.sleepycat.je.rep.utilint.HostPortPair;
+import com.sleepycat.je.rep.utilint.ServiceDispatcher;
import org.apache.log4j.Logger;
+import org.apache.qpid.server.configuration.IllegalConfigurationException;
import org.apache.qpid.server.configuration.updater.Task;
import org.apache.qpid.server.logging.messages.ConfigStoreMessages;
import org.apache.qpid.server.logging.messages.HighAvailabilityMessages;
@@ -66,8 +71,10 @@ 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;
+import org.codehaus.jackson.map.ObjectMapper;
@ManagedObject( category = false, type = BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE )
public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtualHostNodeImpl> implements
@@ -253,6 +260,19 @@ public class BDBHAVirtualHostNodeImpl ex
public void onCreate()
{
super.onCreate();
+ if (!isFirstNodeInAGroup())
+ {
+ try
+ {
+ connectToHelperNodeAndCheckPermittedHosts(getHelperNodeName(), getHelperAddress(), getAddress());
+ }
+ catch(IllegalConfigurationException e)
+ {
+ deleted();
+ throw e;
+ }
+ }
+
getEventLogger().message(getVirtualHostNodeLogSubject(), HighAvailabilityMessages.ADDED(getName(), getGroupName()));
}
@@ -383,6 +403,7 @@ public class BDBHAVirtualHostNodeImpl ex
return helpers;
}
+ @Override
protected void onClose()
{
try
@@ -675,6 +696,76 @@ public class BDBHAVirtualHostNodeImpl ex
}
}
+ private boolean isFirstNodeInAGroup()
+ {
+ return getAddress().equals(getHelperAddress());
+ }
+
+ private void connectToHelperNodeAndCheckPermittedHosts(String helperNodeName, String helperHostPort, String hostPort)
+ {
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug(String.format("Requesting state of the node '%s' at '%s'", helperNodeName, helperHostPort));
+ }
+
+ if (_helperNodeName == null || "".equals(_helperNodeName))
+ {
+ throw new IllegalConfigurationException(String.format("An attribute '%s' is not set in node '%s'"
+ + " on joining the group '%s'", HELPER_NODE_NAME, getName(), getGroupName()));
+ }
+
+ Collection<String> permittedNodes = null;
+ try
+ {
+ ReplicatedEnvironmentFacade.ReplicationNodeImpl node = new ReplicatedEnvironmentFacade.ReplicationNodeImpl(helperNodeName, helperHostPort);
+ NodeState state = new DbPing(node, getGroupName(), ReplicatedEnvironmentFacade.DB_PING_SOCKET_TIMEOUT).getNodeState();
+ byte[] applicationState = state.getAppState();
+ permittedNodes = bytesToPermittedNodeList(applicationState);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalConfigurationException(String.format("Cannot connect to '%s'", helperHostPort), e);
+ }
+ catch (ServiceDispatcher.ServiceConnectFailedException e)
+ {
+ throw new IllegalConfigurationException(String.format("Failure to connect to '%s'", helperHostPort), e);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(String.format("Unexpected exception on attempt to retrieve state from '%s' at '%s'",
+ helperNodeName, helperHostPort), e);
+ }
+
+ if (LOGGER.isDebugEnabled())
+ {
+ LOGGER.debug(String.format("Attribute 'permittedNodes' on node '%s' is set to '%s'", helperNodeName, String.valueOf(permittedNodes)));
+ }
+
+ if (permittedNodes != null && !permittedNodes.isEmpty() && !permittedNodes.contains(hostPort))
+ {
+ throw new IllegalConfigurationException(String.format("Node from '%s' is not permitted!", hostPort));
+ }
+ }
+
+ private Collection<String> bytesToPermittedNodeList(byte[] applicationState)
+ {
+ if (applicationState == null || applicationState.length == 0)
+ {
+ return Collections.emptySet();
+ }
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ try
+ {
+ Map<String, Object> settings = objectMapper.readValue(applicationState, Map.class);
+ return (Collection<String>)settings.get(ReplicatedEnvironmentFacade.PERMITTED_NODE_LIST);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected exception on de-serializing of application state", e);
+ }
+ }
+
private class RemoteNodesDiscoverer implements ReplicationGroupListener
{
@Override
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=1616186&r1=1616185&r2=1616186&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 Wed Aug 6 12:21:59 2014
@@ -34,6 +34,8 @@ import java.util.concurrent.CountDownLat
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
+import com.sleepycat.je.Durability;
+import com.sleepycat.je.EnvironmentConfig;
import com.sleepycat.je.rep.ReplicatedEnvironment;
import com.sleepycat.je.rep.ReplicationConfig;
@@ -80,25 +82,16 @@ public class BDBHAVirtualHostNodeTest ex
public void testCreateAndActivateVirtualHostNode() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
- String repStreamTimeout = "2 h";
- String nodeName = "node";
+ int node1PortNumber = findFreePort();
+ String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
- String nodeHostPort = "localhost:" + findFreePort();
- String helperHostPort = nodeHostPort;
- UUID id = UUID.randomUUID();
-
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(BDBHAVirtualHostNode.TYPE, BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
- attributes.put(BDBHAVirtualHostNode.ID, id);
- attributes.put(BDBHAVirtualHostNode.NAME, nodeName);
- attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- attributes.put(BDBHAVirtualHostNode.ADDRESS, nodeHostPort);
- attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperHostPort);
- attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath);
- attributes.put(BDBHAVirtualHostNode.CONTEXT,
- singletonMap(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout));
+ String nodeName = "node1";
+ Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
+ String messageStorePath = (String)attributes.get(BDBHAVirtualHostNode.STORE_PATH);
+ String repStreamTimeout = "2 h";
+ Map<String,String> context = (Map<String,String>)attributes.get(BDBHAVirtualHostNode.CONTEXT);
+ context.put(ReplicationConfig.REP_STREAM_TIMEOUT, repStreamTimeout);
BDBHAVirtualHostNode<?> node = _helper.createHaVHN(attributes);
final CountDownLatch virtualHostAddedLatch = new CountDownLatch(1);
@@ -117,6 +110,7 @@ public class BDBHAVirtualHostNodeTest ex
node.start();
_helper.assertNodeRole(node, "MASTER", "REPLICA");
+
assertEquals("Unexpected node state", State.ACTIVE, node.getState());
DurableConfigurationStore store = node.getConfigurationStore();
@@ -128,8 +122,8 @@ public class BDBHAVirtualHostNodeTest ex
assertEquals(nodeName, environment.getNodeName());
assertEquals(groupName, environment.getGroup().getName());
- assertEquals(nodeHostPort, replicationConfig.getNodeHostPort());
- assertEquals(helperHostPort, replicationConfig.getHelperHosts());
+ assertEquals(helperAddress, replicationConfig.getNodeHostPort());
+ assertEquals(helperAddress, replicationConfig.getHelperHosts());
assertEquals("SYNC,NO_SYNC,SIMPLE_MAJORITY", environment.getConfig().getDurability().toString());
assertEquals("Unexpected JE replication stream timeout", repStreamTimeout, replicationConfig.getConfigParam(ReplicationConfig.REP_STREAM_TIMEOUT));
@@ -155,18 +149,12 @@ public class BDBHAVirtualHostNodeTest ex
public void testMutableAttributes() throws Exception
{
- UUID id = UUID.randomUUID();
- String address = "localhost:" + findFreePort();
-
- Map<String, Object> attributes = new HashMap<String, Object>();
- attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- attributes.put(BDBHAVirtualHostNode.ID, id);
- attributes.put(BDBHAVirtualHostNode.NAME, "node");
- attributes.put(BDBHAVirtualHostNode.GROUP_NAME, "group");
- attributes.put(BDBHAVirtualHostNode.ADDRESS, address);
- attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, address);
- attributes.put(BDBHAVirtualHostNode.STORE_PATH, _helper.getMessageStorePath());
+ int node1PortNumber = findFreePort();
+ String helperAddress = "localhost:" + node1PortNumber;
+ String groupName = "group";
+ String nodeName = "node1";
+ Map<String, Object> attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(attributes);
BDBConfigurationStore bdbConfigurationStore = (BDBConfigurationStore) node.getConfigurationStore();
@@ -190,42 +178,21 @@ public class BDBHAVirtualHostNodeTest ex
public void testTransferMasterToSelf() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+ int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
_helper.createAndStartHaVHN(node1Attributes);
- int node2PortNumber = getNextAvailable(node1PortNumber+1);
-
- 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.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
_helper.createAndStartHaVHN(node2Attributes);
- int node3PortNumber = getNextAvailable(node2PortNumber+1);
- Map<String, Object> node3Attributes = new HashMap<String, Object>();
- node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3");
- node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber);
- node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3");
+ Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
_helper.createAndStartHaVHN(node3Attributes);
BDBHAVirtualHostNode<?> replica = _helper.awaitAndFindNodeInRole("REPLICA");
@@ -238,19 +205,15 @@ public class BDBHAVirtualHostNodeTest ex
public void testTransferMasterToRemoteReplica() throws Exception
{
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+ int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
- String messageStorePath = _helper.getMessageStorePath();
-
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
+ String nodeName = "node1";
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress,
+ helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
final AtomicReference<RemoteReplicationNode<?>> lastSeenReplica = new AtomicReference<>();
@@ -268,28 +231,10 @@ public class BDBHAVirtualHostNodeTest ex
}
});
- int node2PortNumber = getNextAvailable(node1PortNumber+1);
-
- 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.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
-
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
- int node3PortNumber = getNextAvailable(node2PortNumber+1);
- Map<String, Object> node3Attributes = new HashMap<String, Object>();
- node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3");
- node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber);
- node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3");
+ Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNode<?> node3 = _helper.createAndStartHaVHN(node3Attributes);
assertTrue("Replication nodes have not been seen during 5s", remoteNodeLatch.await(5, TimeUnit.SECONDS));
@@ -308,17 +253,9 @@ public class BDBHAVirtualHostNodeTest ex
int nodePortNumber = findFreePort();
String helperAddress = "localhost:" + nodePortNumber;
String groupName = "group";
- String messageStorePath = _helper.getMessageStorePath();
-
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
+ String nodeName = "node1";
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(node1Attributes);
_helper.assertNodeRole(node, "MASTER");
@@ -336,42 +273,21 @@ public class BDBHAVirtualHostNodeTest ex
public void testRemoveReplicaNode() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+ int node3PortNumber = getNextAvailable(node2PortNumber + 1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber, node3PortNumber);
_helper.createAndStartHaVHN(node1Attributes);
- int node2PortNumber = getNextAvailable(node1PortNumber+1);
-
- 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.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
_helper.createAndStartHaVHN(node2Attributes);
- int node3PortNumber = getNextAvailable(node2PortNumber+1);
- Map<String, Object> node3Attributes = new HashMap<String, Object>();
- node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3");
- node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber);
- node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3");
+ Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
_helper.createAndStartHaVHN(node3Attributes);
BDBHAVirtualHostNode<?> master = _helper.awaitAndFindNodeInRole("MASTER");
@@ -393,15 +309,9 @@ public class BDBHAVirtualHostNodeTest ex
int node1PortNumber = findFreePort();
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- Map<String, Object> nodeAttributes = new HashMap<String, Object>();
- nodeAttributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- nodeAttributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- nodeAttributes.put(BDBHAVirtualHostNode.NAME, "node1");
- nodeAttributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- nodeAttributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- nodeAttributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- nodeAttributes.put(BDBHAVirtualHostNode.STORE_PATH, _helper.getMessageStorePath() + File.separator + "1");
+ Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNode<?> node = _helper.createHaVHN(nodeAttributes);
final CountDownLatch virtualHostAddedLatch = new CountDownLatch(1);
@@ -465,59 +375,23 @@ public class BDBHAVirtualHostNodeTest ex
}
- public void testIntruderProtection() throws Exception
+ public void testNotPermittedNodeIsNotAllowedToConnect() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
int node1PortNumber = findFreePort();
int node2PortNumber = getNextAvailable(node1PortNumber+1);
+ int node3PortNumber = getNextAvailable(node2PortNumber+1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- 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");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- 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);
-
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
- 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, node2Address);
- node2Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
- node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1");
- node2Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0);
-
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
- int node3PortNumber = getNextAvailable(node2PortNumber+1);
- Map<String, Object> node3Attributes = new HashMap<String, Object>();
- node3Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node3Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node3Attributes.put(BDBHAVirtualHostNode.NAME, "node3");
- node3Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node3Attributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + node3PortNumber);
- node3Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node3Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "3");
- node3Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1");
- node3Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0);
-
+ Map<String, Object> node3Attributes = _helper.createNodeAttributes("node3", groupName, "localhost:" + node3PortNumber, helperAddress, nodeName);
try
{
_helper.createHaVHN(node3Attributes);
@@ -527,59 +401,22 @@ public class BDBHAVirtualHostNodeTest ex
{
assertEquals("Unexpected exception message", String.format("Node from '%s' is not permitted!", "localhost:" + node3PortNumber), e.getMessage());
}
-
- // join node by skipping a step retrieving node state and checking the permitted hosts
- node3Attributes.remove(BDBHAVirtualHostNode.HELPER_NODE_NAME);
-
- final CountDownLatch stopLatch = new CountDownLatch(1);
- ConfigurationChangeListener listener = new NoopConfigurationChangeListener()
- {
- @Override
- public void stateChanged(ConfiguredObject<?> object, State oldState, State newState)
- {
- if (newState == State.ERRORED)
- {
- stopLatch.countDown();
- }
- }
- };
- node1.addChangeListener(listener);
-
- _helper.createHaVHN(node3Attributes);
-
- assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
}
public void testIntruderProtectionInManagementMode() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
-
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
- int node2PortNumber = getNextAvailable(node1PortNumber+1);
- 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.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
- node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1");
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
node2Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0);
-
BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
final CountDownLatch stopLatch = new CountDownLatch(1);
@@ -613,37 +450,18 @@ public class BDBHAVirtualHostNodeTest ex
remote.delete();
}
- public void testIntruderConnectedBeforePermittedNodesAreSet() throws Exception
+ public void testIntruderConnected() throws Exception
{
- String messageStorePath = _helper.getMessageStorePath();
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
+
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
+ String nodeName = "node1";
- Map<String, Object> node1Attributes = new HashMap<String, Object>();
- node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
- node1Attributes.put(BDBHAVirtualHostNode.TYPE, "BDB_HA");
- node1Attributes.put(BDBHAVirtualHostNode.NAME, "node1");
- node1Attributes.put(BDBHAVirtualHostNode.GROUP_NAME, groupName);
- node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
- node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "1");
-
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
- int node2PortNumber = getNextAvailable(node1PortNumber+1);
- 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.HELPER_ADDRESS, helperAddress);
- node2Attributes.put(BDBHAVirtualHostNode.STORE_PATH, messageStorePath + File.separator + "2");
- node2Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, "node1");
-
- _helper.createAndStartHaVHN(node2Attributes);
-
final CountDownLatch stopLatch = new CountDownLatch(1);
ConfigurationChangeListener listener = new NoopConfigurationChangeListener()
{
@@ -658,14 +476,28 @@ public class BDBHAVirtualHostNodeTest ex
};
node1.addChangeListener(listener);
- BDBHAVirtualHost<?> host = (BDBHAVirtualHost<?>)node1.getVirtualHost();
- List<String> permittedNodes = new ArrayList<String>();
- permittedNodes.add(helperAddress);
- host.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHost.PERMITTED_NODES, permittedNodes));
+ String node2Name = "node2";
+ File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name);
+ environmentPathFile.mkdirs();
+
+ ReplicationConfig replicationConfig = new ReplicationConfig(groupName, node2Name, "localhost:" + node2PortNumber );
+ replicationConfig.setHelperHosts(helperAddress);
+ EnvironmentConfig envConfig = new EnvironmentConfig();
+ envConfig.setAllowCreate(true);
+ envConfig.setTransactional(true);
+ envConfig.setDurability(Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY)));
+
+ ReplicatedEnvironment intruder = null;
+ try
+ {
+ intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
+ }
+ finally
+ {
+ intruder.close();
+ }
assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
}
-}
-
-
+}
\ No newline at end of file
Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeTest.java Wed Aug 6 12:21:59 2014
@@ -24,11 +24,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
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.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@@ -55,6 +51,7 @@ import com.sleepycat.je.rep.ReplicationC
import com.sleepycat.je.rep.ReplicationNode;
import com.sleepycat.je.rep.StateChangeEvent;
import com.sleepycat.je.rep.StateChangeListener;
+import org.codehaus.jackson.map.ObjectMapper;
public class ReplicatedEnvironmentFacadeTest extends QpidTestCase
{
@@ -267,6 +264,7 @@ public class ReplicatedEnvironmentFacade
String node2Name = TEST_NODE_NAME + "_2";
String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1);
+ replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort));
createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
assertTrue("Listener not fired within timeout", nodeAddedLatch.await(LISTENER_TIMEOUT, TimeUnit.SECONDS));
@@ -309,6 +307,7 @@ public class ReplicatedEnvironmentFacade
String node2Name = TEST_NODE_NAME + "_2";
String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1);
+ replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort));
createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
assertEquals("Unexpected number of nodes at start of test", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
@@ -358,6 +357,7 @@ public class ReplicatedEnvironmentFacade
assertTrue("Master was not started", stateChangeListener.awaitForStateChange(LISTENER_TIMEOUT, TimeUnit.SECONDS));
String node2NodeHostPort = "localhost" + ":" + getNextAvailable(TEST_NODE_PORT + 1);
+ replicatedEnvironmentFacade.setPermittedNodes(Arrays.asList(replicatedEnvironmentFacade.getHostPort(), node2NodeHostPort));
createReplica(node2Name, node2NodeHostPort, new NoopReplicationGroupListener());
assertEquals("Unexpected number of nodes at start of test", 2, replicatedEnvironmentFacade.getNumberOfElectableGroupMembers());
@@ -434,7 +434,7 @@ public class ReplicatedEnvironmentFacade
int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
String node1NodeHostPort = "localhost:" + replica1Port;
-
+ masterEnvironment.setPermittedNodes(Arrays.asList(masterEnvironment.getHostPort(), node1NodeHostPort));
ReplicatedEnvironmentFacade replica = createReplica(replicaName, node1NodeHostPort, new NoopReplicationGroupListener());
assertTrue("Node should be added", nodeAddedLatch.await(WAIT_STATE_CHANGE_TIMEOUT, TimeUnit.SECONDS));
@@ -658,7 +658,10 @@ public class ReplicatedEnvironmentFacade
NodeState nodeState = firstNode.getRemoteNodeState(new ReplicatedEnvironmentFacade.ReplicationNodeImpl(TEST_NODE_NAME, TEST_NODE_HOST_PORT));
- Collection<String> appStatePermittedNodes = firstNode.bytesToPermittedNodeList(nodeState.getAppState());
+ ObjectMapper objectMapper = new ObjectMapper();
+
+ Map<String, Object> settings = objectMapper.readValue(nodeState.getAppState(), Map.class);
+ Collection<String> appStatePermittedNodes = (Collection<String>)settings.get(ReplicatedEnvironmentFacade.PERMITTED_NODE_LIST);
assertEquals("Unexpected permitted nodes", permittedNodes, new HashSet<String>(appStatePermittedNodes));
}
@@ -684,33 +687,6 @@ public class ReplicatedEnvironmentFacade
assertEquals("Unexpected state", State.REPLICA.name(), secondNode.getNodeState());
}
- public void testNotPermittedNodeIsNotAllowedToConnect() throws Exception
- {
- ReplicatedEnvironmentFacade firstNode = createMaster();
-
- int replica1Port = getNextAvailable(TEST_NODE_PORT + 1);
- String node1NodeHostPort = "localhost:" + replica1Port;
-
- Set<String> permittedNodes = new HashSet<String>();
- permittedNodes.add("localhost:" + TEST_NODE_PORT);
-
- firstNode.setPermittedNodes(permittedNodes);
-
- ReplicatedEnvironmentConfiguration configuration = createReplicatedEnvironmentConfiguration(TEST_NODE_NAME + "_1", node1NodeHostPort, false);
- when(configuration.getHelperNodeName()).thenReturn(TEST_NODE_NAME);
-
- try
- {
- createReplicatedEnvironmentFacade(TEST_NODE_NAME + "_1", new TestStateChangeListener(State.REPLICA), new NoopReplicationGroupListener(), configuration);
- fail("Node is not allowed to connect from " + node1NodeHostPort + " but environment was successfully created");
- }
- catch (IllegalConfigurationException e)
- {
- assertEquals("Unexpected exception message", String.format("Node from '%s' is not permitted!",
- node1NodeHostPort), e.getMessage());
- }
- }
-
public void testIntruderNodeIsDetected() throws Exception
{
final CountDownLatch intruderLatch = new CountDownLatch(1);
@@ -820,6 +796,7 @@ public class ReplicatedEnvironmentFacade
when(node.getPriority()).thenReturn(TEST_PRIORITY);
when(node.getGroupName()).thenReturn(TEST_GROUP_NAME);
when(node.getHelperHostPort()).thenReturn(TEST_NODE_HELPER_HOST_PORT);
+ when(node.getHelperNodeName()).thenReturn(TEST_NODE_NAME);
Map<String, String> repConfig = new HashMap<String, String>();
repConfig.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s");
Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeOperationalLoggingTest.java Wed Aug 6 12:21:59 2014
@@ -75,7 +75,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -105,7 +105,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
reset(_eventLogger);
@@ -128,7 +128,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -148,7 +148,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -172,7 +172,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -195,7 +195,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -218,7 +218,7 @@ public class BDBHAVirtualHostNodeOperati
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
@@ -237,18 +237,19 @@ public class BDBHAVirtualHostNodeOperati
public void testRemoteNodeAdded() throws Exception
{
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
reset(_eventLogger);
- int node2PortNumber = getNextAvailable(node1PortNumber + 1);
- Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress);
+
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes);
_helper.awaitRemoteNodes(node1, 1);
@@ -269,19 +270,19 @@ public class BDBHAVirtualHostNodeOperati
public void testRemoteNodeRemoved() throws Exception
{
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
resetEventLogger();
- int node2PortNumber = getNextAvailable(node1PortNumber + 1);
- Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress);
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes);
_helper.awaitRemoteNodes(node1, 1);
@@ -301,17 +302,17 @@ public class BDBHAVirtualHostNodeOperati
public void testRemoteNodeDetached() throws Exception
{
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
- int node2PortNumber = getNextAvailable(node1PortNumber + 1);
- Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress);
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes);
_helper.awaitRemoteNodes(node1, 1);
@@ -334,18 +335,19 @@ public class BDBHAVirtualHostNodeOperati
public void testRemoteNodeReAttached() throws Exception
{
int node1PortNumber = findFreePort();
+ int node2PortNumber = getNextAvailable(node1PortNumber + 1);
String helperAddress = "localhost:" + node1PortNumber;
String groupName = "group";
String nodeName = "node1";
- Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress);
+ Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node1Attributes);
_helper.assertNodeRole(node1, "MASTER");
resetEventLogger();
- int node2PortNumber = getNextAvailable(node1PortNumber + 1);
- Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress);
+
+ Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl)_helper.createHaVHN(node2Attributes);
_helper.awaitRemoteNodes(node1, 1);
Modified: qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java (original)
+++ qpid/trunk/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeTestHelper.java Wed Aug 6 12:21:59 2014
@@ -26,10 +26,13 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import java.io.File;
+import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@@ -38,18 +41,17 @@ import com.sleepycat.je.rep.ReplicationC
import org.apache.qpid.server.configuration.updater.TaskExecutor;
import org.apache.qpid.server.configuration.updater.TaskExecutorImpl;
-import org.apache.qpid.server.model.Broker;
-import org.apache.qpid.server.model.BrokerModel;
-import org.apache.qpid.server.model.ConfiguredObject;
-import org.apache.qpid.server.model.ConfiguredObjectFactory;
-import org.apache.qpid.server.model.RemoteReplicationNode;
-import org.apache.qpid.server.model.State;
-import org.apache.qpid.server.model.VirtualHostNode;
+import org.apache.qpid.server.model.*;
import org.apache.qpid.server.store.ConfiguredObjectRecordImpl;
import org.apache.qpid.server.store.UnresolvedConfiguredObject;
import org.apache.qpid.server.util.BrokerTestHelper;
+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.test.utils.QpidTestCase;
import org.apache.qpid.util.FileUtils;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
/**
* Helper class to make the tests of BDB HA Virtual Host Nodes simpler and more concise.
@@ -258,7 +260,9 @@ public class BDBHAVirtualHostNodeTestHel
return _broker;
}
- Map<String, Object> createNodeAttributes(String nodeName, String groupName, String address, String helperAddress)
+ public Map<String, Object> createNodeAttributes(String nodeName, String groupName, String address,
+ String helperAddress, String helperNodeNode, int... ports)
+ throws Exception
{
Map<String, Object> node1Attributes = new HashMap<String, Object>();
node1Attributes.put(BDBHAVirtualHostNode.ID, UUID.randomUUID());
@@ -268,13 +272,39 @@ public class BDBHAVirtualHostNodeTestHel
node1Attributes.put(BDBHAVirtualHostNode.ADDRESS, address);
node1Attributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, helperAddress);
node1Attributes.put(BDBHAVirtualHostNode.STORE_PATH, getMessageStorePath() + File.separator + nodeName);
+ node1Attributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, helperNodeNode);
- Map<String, String> repConfig = new HashMap<String, String>();
- repConfig.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s");
- repConfig.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s");
+ Map<String, String> context = new HashMap<String, String>();
+ context.put(ReplicationConfig.REPLICA_ACK_TIMEOUT, "2 s");
+ context.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s");
- node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, repConfig);
+ if (ports != null)
+ {
+ String bluePrint = getBlueprint(ports);
+ context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, bluePrint);
+ }
+
+ node1Attributes.put(BDBHAVirtualHostNode.CONTEXT, context);
return node1Attributes;
}
+
+ public static String getBlueprint(int... ports) throws Exception
+ {
+ List<String> permittedNodes = new ArrayList<String>();
+ for (int port:ports)
+ {
+ permittedNodes.add("localhost:" + port);
+ }
+ Map<String,Object> bluePrint = new HashMap<>();
+ bluePrint.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
+ bluePrint.put(BDBHAVirtualHost.PERMITTED_NODES, permittedNodes);
+
+ StringWriter writer = new StringWriter();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ mapper.writeValue(writer, bluePrint);
+ return writer.toString();
+ }
+
}
Modified: qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java (original)
+++ qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostNodeRestTest.java Wed Aug 6 12:21:59 2014
@@ -41,6 +41,7 @@ import org.apache.qpid.server.model.Virt
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade;
import org.apache.qpid.server.virtualhost.berkeleydb.BDBHAVirtualHost;
+import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode;
import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode;
import org.apache.qpid.systest.rest.Asserts;
@@ -77,6 +78,7 @@ public class BDBHAVirtualHostNodeRestTes
_node2HaPort = getNextAvailable(_node1HaPort + 1);
_node3HaPort = getNextAvailable(_node2HaPort + 1);
+
}
@Override
@@ -302,7 +304,7 @@ public class BDBHAVirtualHostNodeRestTes
assertEquals("Unexpected response code for virtual host node " + nodeName + " creation request", 201, responseCode);
}
- private Map<String, Object> createNodeAttributeMap(String nodeName, int nodePort, int helperPort)
+ private Map<String, Object> createNodeAttributeMap(String nodeName, int nodePort, int helperPort) throws Exception
{
Map<String, Object> nodeData = new HashMap<String, Object>();
nodeData.put(BDBHAVirtualHostNode.NAME, nodeName);
@@ -311,6 +313,11 @@ public class BDBHAVirtualHostNodeRestTes
nodeData.put(BDBHAVirtualHostNode.GROUP_NAME, _hostName);
nodeData.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + nodePort);
nodeData.put(BDBHAVirtualHostNode.HELPER_ADDRESS, "localhost:" + helperPort);
+ nodeData.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, NODE1);
+ Map<String,String> context = new HashMap<>();
+ nodeData.put(BDBHAVirtualHostNode.CONTEXT, context);
+ String bluePrint = HATestClusterCreator.getBlueprint("localhost", _node1HaPort, _node2HaPort, _node3HaPort);
+ context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, bluePrint);
return nodeData;
}
@@ -431,4 +438,6 @@ public class BDBHAVirtualHostNodeRestTes
assertNotNull("Could not find new master", newMasterData);
return newMasterData;
}
+
+
}
Modified: qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostRestTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostRestTest.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostRestTest.java (original)
+++ qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/BDBHAVirtualHostRestTest.java Wed Aug 6 12:21:59 2014
@@ -35,6 +35,7 @@ import org.apache.qpid.server.model.Stat
import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
import org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade;
+import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode;
import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNode;
import org.apache.qpid.systest.rest.Asserts;
import org.apache.qpid.systest.rest.QpidRestTestCase;
@@ -48,6 +49,7 @@ public class BDBHAVirtualHostRestTest ex
private int _nodeHaPort;
private Object _nodeName;
private String _virtualhostUrl;
+ private String _bluePrint;
@Override
public void setUp() throws Exception
@@ -58,6 +60,7 @@ public class BDBHAVirtualHostRestTest ex
_storeBaseDir = new File(TMP_FOLDER, "store-" + _hostName + "-" + System.currentTimeMillis());
_nodeHaPort = getNextAvailable(getRestTestHelper().getHttpPort() + 1);
_virtualhostUrl = "virtualhost/" + _nodeName + "/" + _hostName;
+ _bluePrint = HATestClusterCreator.getBlueprint("localhost", _nodeHaPort);
super.setUp();
}
@@ -93,6 +96,11 @@ public class BDBHAVirtualHostRestTest ex
nodeAttributes.put(BDBHAVirtualHostNode.GROUP_NAME, _hostName);
nodeAttributes.put(BDBHAVirtualHostNode.ADDRESS, "localhost:" + _nodeHaPort);
nodeAttributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, "localhost:" + _nodeHaPort);
+ nodeAttributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, _nodeName);
+ Map<String, String> context = new HashMap<String,String>();
+ context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, _bluePrint);
+
+ nodeAttributes.put(BDBHAVirtualHostNode.CONTEXT, context);
config.addObjectConfiguration(VirtualHostNode.class, nodeAttributes);
}
Modified: qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java?rev=1616186&r1=1616185&r2=1616186&view=diff
==============================================================================
--- qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java (original)
+++ qpid/trunk/qpid/java/bdbstore/systests/src/main/java/org/apache/qpid/server/store/berkeleydb/HATestClusterCreator.java Wed Aug 6 12:21:59 2014
@@ -21,8 +21,10 @@ package org.apache.qpid.server.store.ber
import java.io.File;
import java.io.IOException;
+import java.io.StringWriter;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -47,8 +49,11 @@ import org.apache.qpid.client.AMQConnect
import org.apache.qpid.server.management.plugin.HttpManagement;
import org.apache.qpid.server.model.Plugin;
import org.apache.qpid.server.model.Port;
+import org.apache.qpid.server.model.VirtualHost;
import org.apache.qpid.server.model.VirtualHostNode;
-import org.apache.qpid.server.virtualhostnode.JsonVirtualHostNode;
+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.BDBHAVirtualHostNode;
import org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHAVirtualHostNodeImpl;
@@ -56,6 +61,8 @@ import org.apache.qpid.systest.rest.Rest
import org.apache.qpid.test.utils.QpidBrokerTestCase;
import org.apache.qpid.test.utils.TestBrokerConfiguration;
import org.apache.qpid.url.URLSyntaxException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
import org.junit.Assert;
import com.sleepycat.je.rep.ReplicationConfig;
@@ -101,11 +108,22 @@ public class HATestClusterCreator
{
int brokerPort = _testcase.findFreePort();
+ int[] bdbPorts = new int[_numberOfNodes];
for (int i = 0; i < _numberOfNodes; i++)
{
int bdbPort = _testcase.getNextAvailable(brokerPort + 1);
+ bdbPorts[i] = bdbPort;
_brokerPortToBdbPortMap.put(brokerPort, bdbPort);
+ brokerPort = _testcase.getNextAvailable(bdbPort + 1);
+ }
+
+ String bluePrintJson = getBlueprint(_ipAddressOfBroker, bdbPorts);
+ String helperName = null;
+ for (Map.Entry<Integer,Integer> entry: _brokerPortToBdbPortMap.entrySet())
+ {
+ brokerPort = entry.getKey();
+ int bdbPort = entry.getValue();
LOGGER.debug("Cluster broker port " + brokerPort + ", bdb replication port " + bdbPort);
if (_bdbHelperPort == 0)
{
@@ -113,6 +131,10 @@ public class HATestClusterCreator
}
String nodeName = getNodeNameForNodeAt(bdbPort);
+ if (helperName == null)
+ {
+ helperName = nodeName;
+ }
Map<String, Object> virtualHostNodeAttributes = new HashMap<String, Object>();
virtualHostNodeAttributes.put(BDBHAVirtualHostNode.STORE_PATH, System.getProperty("QPID_WORK") + File.separator + brokerPort);
@@ -121,11 +143,13 @@ public class HATestClusterCreator
virtualHostNodeAttributes.put(BDBHAVirtualHostNode.ADDRESS, getNodeHostPortForNodeAt(bdbPort));
virtualHostNodeAttributes.put(BDBHAVirtualHostNode.HELPER_ADDRESS, getHelperHostPort());
virtualHostNodeAttributes.put(BDBHAVirtualHostNode.TYPE, BDBHAVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
+ virtualHostNodeAttributes.put(BDBHAVirtualHostNode.HELPER_NODE_NAME, helperName);
- Map<String, String> repSettings = new HashMap<>();
- repSettings.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s");
- repSettings.put(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES, "0");
- virtualHostNodeAttributes.put(BDBHAVirtualHostNode.CONTEXT, repSettings);
+ Map<String, String> context = new HashMap<>();
+ context.put(ReplicationConfig.INSUFFICIENT_REPLICAS_TIMEOUT, "2 s");
+ context.put(ReplicationConfig.ELECTIONS_PRIMARY_RETRIES, "0");
+ context.put(AbstractVirtualHostNode.VIRTUALHOST_BLUEPRINT_CONTEXT_VAR, bluePrintJson);
+ virtualHostNodeAttributes.put(BDBHAVirtualHostNode.CONTEXT, context);
TestBrokerConfiguration brokerConfiguration = _testcase.getBrokerConfiguration(brokerPort);
brokerConfiguration.addJmxManagementConfiguration();
@@ -134,7 +158,6 @@ public class HATestClusterCreator
brokerConfiguration.setObjectAttribute(Port.class, TestBrokerConfiguration.ENTRY_NAME_HTTP_PORT, Port.PORT, _testcase.getHttpManagementPort(brokerPort));
brokerConfiguration.setObjectAttributes(VirtualHostNode.class, _virtualHostName, virtualHostNodeAttributes);
- brokerPort = _testcase.getNextAvailable(bdbPort + 1);
}
_primaryBrokerPort = getPrimaryBrokerPort();
}
@@ -485,4 +508,22 @@ public class HATestClusterCreator
helper.setUsernameAndPassword("webadmin", "webadmin");
return helper;
}
+
+ public static String getBlueprint(String hostName, int... ports) throws Exception
+ {
+ List<String> permittedNodes = new ArrayList<String>();
+ for (int port:ports)
+ {
+ permittedNodes.add(hostName + ":" + port);
+ }
+ Map<String,Object> bluePrint = new HashMap<>();
+ bluePrint.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
+ bluePrint.put(BDBHAVirtualHost.PERMITTED_NODES, permittedNodes);
+
+ StringWriter writer = new StringWriter();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+ mapper.writeValue(writer, bluePrint);
+ return writer.toString();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org