Search in sources :

Example 6 with AbstractConfigurationChangeListener

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

the class TrustStoreMessageSourceCreator method register.

@Override
public void register(final SystemNodeRegistry registry) {
    final VirtualHost<?> vhost = registry.getVirtualHost();
    VirtualHostNode<?> virtualHostNode = (VirtualHostNode<?>) vhost.getParent();
    final Broker<?> broker = (Broker<?>) virtualHostNode.getParent();
    final Collection<TrustStore> trustStores = broker.getChildren(TrustStore.class);
    final TrustStoreChangeListener trustStoreChangeListener = new TrustStoreChangeListener(registry);
    for (final TrustStore trustStore : trustStores) {
        updateTrustStoreSourceRegistration(registry, trustStore);
        trustStore.addChangeListener(trustStoreChangeListener);
    }
    broker.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
            if (child instanceof TrustStore) {
                TrustStore<?> trustStore = (TrustStore<?>) child;
                updateTrustStoreSourceRegistration(registry, trustStore);
                trustStore.addChangeListener(trustStoreChangeListener);
            }
        }

        @Override
        public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?> child) {
            if (child instanceof TrustStore) {
                TrustStore<?> trustStore = (TrustStore<?>) child;
                trustStore.removeChangeListener(trustStoreChangeListener);
                registry.removeSystemNode(TrustStoreMessageSource.getSourceNameFromTrustStore(trustStore));
            }
        }
    });
}
Also used : Broker(org.apache.qpid.server.model.Broker) TrustStore(org.apache.qpid.server.model.TrustStore) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 7 with AbstractConfigurationChangeListener

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

the class BDBHAVirtualHostNodeTest method testIntruderProtectionInManagementMode.

public void testIntruderProtectionInManagementMode() throws Exception {
    int nodePortNumber = _portHelper.getNextAvailable();
    int intruderPortNumber = _portHelper.getNextAvailable();
    String helperAddress = "localhost:" + nodePortNumber;
    String groupName = "group";
    String nodeName = "node";
    Map<String, Object> nodeAttributes = _helper.createNodeAttributes(nodeName, groupName, helperAddress, helperAddress, nodeName, nodePortNumber);
    BDBHAVirtualHostNode<?> node = _helper.createAndStartHaVHN(nodeAttributes);
    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) nodeAttributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(intruderPortNumber, "intruder", groupName, helperAddress, durability, environmentPathFile);
    LOGGER.debug("Permitted and intruder nodes are created");
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(10, TimeUnit.SECONDS));
    LOGGER.debug("Master node transited into ERRORED state due to intruder protection");
    when(_helper.getBroker().isManagementMode()).thenReturn(true);
    LOGGER.debug("Starting node in management mode");
    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();
            }
        }
    });
    node.start();
    LOGGER.debug("Node is started");
    // 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)

Example 8 with AbstractConfigurationChangeListener

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

the class BDBHAVirtualHostNodeTest method testIntruderConnected.

public void testIntruderConnected() 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);
    BDBHAVirtualHostNode<?> node1 = _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();
            }
        }
    };
    node1.addChangeListener(listener);
    String node2Name = "node2";
    File environmentPathFile = new File(_helper.getMessageStorePath() + File.separator + node2Name);
    Durability durability = Durability.parse((String) node1Attributes.get(BDBHAVirtualHostNode.DURABILITY));
    joinIntruder(node2PortNumber, node2Name, groupName, helperAddress, durability, environmentPathFile);
    assertTrue("Intruder protection was not triggered during expected timeout", stopLatch.await(20, TimeUnit.SECONDS));
}
Also used : ConfigurationChangeListener(org.apache.qpid.server.model.ConfigurationChangeListener) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) State(org.apache.qpid.server.model.State) Durability(com.sleepycat.je.Durability) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Example 9 with AbstractConfigurationChangeListener

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

the class BDBHAVirtualHostNodeOperationalLoggingTest method testRemoteNodeDetached.

public void testRemoteNodeDetached() 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);
    node1Attributes.put(BDBHAVirtualHostNode.DESIGNATED_PRIMARY, true);
    BDBHAVirtualHostNodeImpl node1 = (BDBHAVirtualHostNodeImpl) _helper.createHaVHN(node1Attributes);
    final CountDownLatch remoteNodeAdded = new CountDownLatch(1);
    node1.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void childAdded(ConfiguredObject<?> object, ConfiguredObject<?> child) {
            if (child instanceof BDBHARemoteReplicationNode) {
                remoteNodeAdded.countDown();
            }
        }
    });
    Map<String, Object> node2Attributes = _helper.createNodeAttributes("node2", groupName, "localhost:" + node2PortNumber, helperAddress, nodeName);
    BDBHAVirtualHostNodeImpl node2 = (BDBHAVirtualHostNodeImpl) _helper.createHaVHN(node2Attributes);
    assertTrue("Remote node was not added during expected period of time", remoteNodeAdded.await(10, TimeUnit.SECONDS));
    BDBHARemoteReplicationNodeImpl remoteNode = (BDBHARemoteReplicationNodeImpl) node1.getRemoteReplicationNodes().iterator().next();
    waitForRemoteNodeToAttainRole(remoteNode, EnumSet.of(NodeRole.REPLICA));
    reset(_eventLogger);
    // close remote node
    node2.close();
    waitForRemoteNodeToAttainRole(remoteNode, EnumSet.of(NodeRole.UNREACHABLE));
    // make sure that task executor thread finishes all scheduled tasks
    node1.stop();
    // verify that remaining node issues the DETACHED operational logging for remote node
    String expectedMessage = HighAvailabilityMessages.LEFT(node2.getName(), node2.getAddress()).toString();
    verify(_eventLogger).message(argThat(new LogSubjectMatcher(node1.getGroupLogSubject())), argThat(new LogMessageMatcher(expectedMessage, HighAvailabilityMessages.LEFT_LOG_HIERARCHY)));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 10 with AbstractConfigurationChangeListener

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

the class BDBHAVirtualHostNodeTest method testTransferMasterToRemoteReplica.

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)

Aggregations

AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)16 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)12 State (org.apache.qpid.server.model.State)9 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Durability (com.sleepycat.je.Durability)3 File (java.io.File)3 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)3 ConfigurationChangeListener (org.apache.qpid.server.model.ConfigurationChangeListener)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)2 StoreConfigurationChangeListener (org.apache.qpid.server.configuration.store.StoreConfigurationChangeListener)1 Broker (org.apache.qpid.server.model.Broker)1 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)1 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)1 RemoteReplicationNode (org.apache.qpid.server.model.RemoteReplicationNode)1 TrustStore (org.apache.qpid.server.model.TrustStore)1