Search in sources :

Example 56 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testNodeCannotStartWithIntruder.

@Test
public void testNodeCannotStartWithIntruder() throws Exception {
    int nodePortNumber = _portHelper.getNextAvailable();
    int intruderPortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + nodePortNumber;
    String groupName = "group";
    String nodeName = "node";
    Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
    BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(node1Attributes);
    final CountDownLatch stopLatch = new CountDownLatch(1);
    ConfigurationChangeListener listener = new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            if (newState == State.ERRORED) {
                stopLatch.countDown();
            }
        }
    };
    node.addChangeListener(listener);
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + "intruder");
    Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
    final CountDownLatch stateChangeLatch = new CountDownLatch(1);
    final CountDownLatch roleChangeLatch = new CountDownLatch(1);
    node.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
            if (newState == State.ERRORED) {
                stateChangeLatch.countDown();
            }
        }

        @Override
        public void attributeSet(final ConfiguredObject<?> object, final String attributeName, final Object oldAttributeValue, final Object newAttributeValue) {
            if (BDBHAVirtualHostNode.ROLE.equals(attributeName) && NodeRole.DETACHED.equals(NodeRole.DETACHED)) {
                roleChangeLatch.countDown();
            }
        }
    });
    // Try top re start the ERRORED node and ensure exception is thrown
    try {
        node.start();
        fail("Restart of node should have thrown exception");
    } catch (IllegalStateException ise) {
        assertEquals("Unexpected exception when restarting node post intruder detection", "Intruder node detected: " + "localhost:" + intruderPortNumber, ise.getMessage());
    }
    // verify that intruder detection is triggered after restart and environment is closed
    assertTrue("Node state was not set to ERRORED", stateChangeLatch.await(10, TimeUnit.SECONDS));
    assertTrue("Node role was not set to DETACHED", roleChangeLatch.await(10, TimeUnit.SECONDS));
}
Also used : Durability(com.sleepycat.je.Durability) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File) Test(org.junit.Test)

Example 57 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testTransferMasterToRemoteReplica.

@Test
public void testTransferMasterToRemoteReplica() throws Exception {
    int node1PortNumber = _portHelper.getNextAvailable();
    int node2PortNumber = _portHelper.getNextAvailable();
    int node3PortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + node1PortNumber;
    String groupName = "group";
    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<>();
    final CountDownLatch remoteNodeLatch = new CountDownLatch(2);
    node1.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void childAdded(ConfiguredObject<?> object, ConfiguredObject<?> child) {
            if (child instanceof RemoteReplicationNode) {
                remoteNodeLatch.countDown();
                lastSeenReplica.set((RemoteReplicationNode<?>) child);
            }
        }
    });
    Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
    BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
    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));
    BDBHARemoteReplicationNodeImpl replicaRemoteNode = (BDBHARemoteReplicationNodeImpl) lastSeenReplica.get();
    _helper.awaitForAttributeChange(replicaRemoteNode, BDBHARemoteReplicationNodeImpl.ROLE, NodeRole.REPLICA);
    replicaRemoteNode.setAttributes(Collections.<String, Object>singletonMap(BDBHARemoteReplicationNode.ROLE, NodeRole.MASTER));
    BDBHAVirtualHostNode<?> replica = replicaRemoteNode.getName().equals(node2.getName()) ? node2 : node3;
    _helper.assertNodeRole(replica, NodeRole.MASTER);
}
Also used : BDBHARemoteReplicationNodeImpl(org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNodeImpl) RemoteReplicationNode(org.apache.qpid.server.model.RemoteReplicationNode) BDBHARemoteReplicationNode(org.apache.qpid.server.virtualhostnode.berkeleydb.BDBHARemoteReplicationNode) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 58 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class BDBHAVirtualHostNodeTest method testPermittedNodesChangedOnReplicaNodeOnlyOnceAfterBeingChangedOnMaster.

@Test
public void testPermittedNodesChangedOnReplicaNodeOnlyOnceAfterBeingChangedOnMaster() throws Exception {
    int node1PortNumber = _portHelper.getNextAvailable();
    int node2PortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + node1PortNumber;
    String groupName = "group";
    String nodeName = "node1";
    Map<String, Object> node1Attributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, node1PortNumber, node2PortNumber);
    BDBHAVirtualHostNode<?> node1 = _helper.createAndStartHaVHN(node1Attributes);
    Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
    node2Attributes.put(BDBHAVirtualHostNode.PRIORITY, 0);
    BDBHAVirtualHostNode<?> node2 = _helper.createAndStartHaVHN(node2Attributes);
    assertEquals("Unexpected role", NodeRole.REPLICA, node2.getRole());
    _helper.awaitRemoteNodes(node2, 1);
    BDBHARemoteReplicationNode<?> remote = _helper.findRemoteNode(node2, node1.getName());
    final AtomicInteger permittedNodesChangeCounter = new AtomicInteger();
    final CountDownLatch _permittedNodesLatch = new CountDownLatch(1);
    node2.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void attributeSet(ConfiguredObject<?> object, String attributeName, Object oldAttributeValue, Object newAttributeValue) {
            if (attributeName.equals(BDBHAVirtualHostNode.PERMITTED_NODES)) {
                permittedNodesChangeCounter.incrementAndGet();
                _permittedNodesLatch.countDown();
            }
        }
    });
    List<String> permittedNodes = new ArrayList<>(node1.getPermittedNodes());
    permittedNodes.add("localhost:5000");
    node1.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHostNode.PERMITTED_NODES, permittedNodes));
    assertTrue("Permitted nodes were not changed on Replica", _permittedNodesLatch.await(10, TimeUnit.SECONDS));
    assertEquals("Not the same permitted nodes", new HashSet<>(node1.getPermittedNodes()), new HashSet<>(node2.getPermittedNodes()));
    assertEquals("Unexpected counter of changes permitted nodes", (long) 1, (long) permittedNodesChangeCounter.get());
    // change the order of permitted nodes
    Collections.swap(permittedNodes, 0, 2);
    node1.setAttributes(Collections.<String, Object>singletonMap(BDBHAVirtualHostNode.PERMITTED_NODES, permittedNodes));
    // make sure that node2 onNodeState was invoked by performing transaction on master and making sure that it was replicated
    performTransactionAndAwaitForRemoteNodeToGetAware(node1, remote);
    // perform transaction second time because permitted nodes are changed after last transaction id
    performTransactionAndAwaitForRemoteNodeToGetAware(node1, remote);
    assertEquals("Unexpected counter of changes permitted nodes", (long) 1, (long) permittedNodesChangeCounter.get());
}
Also used : ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 59 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method createExchangeConfiguredObjectRecord.

private UpgradeConfiguredObjectRecord createExchangeConfiguredObjectRecord(String exchangeName, String exchangeType, boolean autoDelete) {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    attributesMap.put(Exchange.NAME, exchangeName);
    attributesMap.put(Exchange.TYPE, exchangeType);
    attributesMap.put(Exchange.LIFETIME_POLICY, autoDelete ? "AUTO_DELETE" : LifetimePolicy.PERMANENT.name());
    String json = serialiseMap(attributesMap);
    UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(Exchange.class.getName(), json);
    return configuredObject;
}
Also used : Exchange(org.apache.qpid.server.model.Exchange) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Example 60 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class UpgradeFrom5To6 method createBindingConfiguredObjectRecord.

private UpgradeConfiguredObjectRecord createBindingConfiguredObjectRecord(String exchangeName, String queueName, String routingKey, FieldTable arguments, String virtualHostName) {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    attributesMap.put("name", routingKey);
    attributesMap.put("exchange", UUIDGenerator.generateExchangeUUID(exchangeName, virtualHostName));
    attributesMap.put("queue", UUIDGenerator.generateQueueUUID(queueName, virtualHostName));
    if (arguments != null) {
        attributesMap.put("arguments", FieldTable.convertToMap(arguments));
    }
    String json = serialiseMap(attributesMap);
    UpgradeConfiguredObjectRecord configuredObject = new UpgradeConfiguredObjectRecord(Binding.class.getName(), json);
    return configuredObject;
}
Also used : TupleBinding(com.sleepycat.bind.tuple.TupleBinding) LongBinding(com.sleepycat.bind.tuple.LongBinding) Binding(org.apache.qpid.server.model.Binding) HashMap(java.util.HashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)117 ArrayList (java.util.ArrayList)43 HashMap (java.util.HashMap)35 Test (org.junit.Test)33 Map (java.util.Map)29 List (java.util.List)27 LinkedHashMap (java.util.LinkedHashMap)25 UUID (java.util.UUID)21 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)21 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)15 Collection (java.util.Collection)12 LegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.LegacyConfiguredObject)12 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 State (org.apache.qpid.server.model.State)10 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 GenericLegacyConfiguredObject (org.apache.qpid.server.management.plugin.controller.GenericLegacyConfiguredObject)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6