Search in sources :

Example 11 with State

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

the class BDBHAVirtualHostNodeImpl method shutdownOnIntruder.

protected void shutdownOnIntruder(String intruderHostAndPort) {
    LOGGER.info("Intruder detected (" + intruderHostAndPort + "), stopping and setting state to ERRORED");
    final State initialState = getState();
    ListenableFuture<Void> future = doAfterAlways(stopAndSetStateTo(State.ERRORED), new Runnable() {

        @Override
        public void run() {
            _lastRole.set(NodeRole.DETACHED);
            attributeSet(ROLE, _role, NodeRole.DETACHED);
            notifyStateChanged(initialState, State.ERRORED);
        }
    });
    addFutureCallback(future, new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
        }

        @Override
        public void onFailure(final Throwable t) {
            LOGGER.error("Failed to close children when handling intruder", t);
        }
    }, getTaskExecutor());
}
Also used : State(org.apache.qpid.server.model.State) NodeState(com.sleepycat.je.rep.NodeState)

Example 12 with State

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

the class BDBHAVirtualHostNodeTest method testNodeCannotStartWithIntruder.

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)

Example 13 with State

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

the class AbstractConfiguredObjectTest method testSuccessfulDeletion.

public void testSuccessfulDeletion() throws Exception {
    TestConfiguredObject configuredObject = new TestConfiguredObject("configuredObject");
    configuredObject.create();
    final List<ChangeEvent> events = new ArrayList<>();
    configuredObject.addChangeListener(new AbstractConfigurationChangeListener() {

        @Override
        public void attributeSet(ConfiguredObject<?> object, String attributeName, Object oldAttributeValue, Object newAttributeValue) {
            events.add(new ChangeEvent(EventType.ATTRIBUTE_SET, object, attributeName, oldAttributeValue, newAttributeValue));
        }

        @Override
        public void stateChanged(ConfiguredObject<?> object, State oldState, State newState) {
            events.add(new ChangeEvent(EventType.STATE_CHANGED, object, ConfiguredObject.DESIRED_STATE, oldState, newState));
        }
    });
    configuredObject.delete();
    assertEquals(2, events.size());
    assertEquals(State.DELETED, configuredObject.getDesiredState());
    assertEquals(State.DELETED, configuredObject.getState());
    assertEquals("Unexpected events number", 2, events.size());
    ChangeEvent event0 = events.get(0);
    ChangeEvent event1 = events.get(1);
    assertEquals("Unexpected first event: " + event0, new ChangeEvent(EventType.STATE_CHANGED, configuredObject, Exchange.DESIRED_STATE, State.ACTIVE, State.DELETED), event0);
    assertEquals("Unexpected second event: " + event1, new ChangeEvent(EventType.ATTRIBUTE_SET, configuredObject, Exchange.DESIRED_STATE, State.ACTIVE, State.DELETED), event1);
}
Also used : State(org.apache.qpid.server.model.State) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Aggregations

State (org.apache.qpid.server.model.State)13 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)9 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 Durability (com.sleepycat.je.Durability)3 File (java.io.File)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ConfigurationChangeListener (org.apache.qpid.server.model.ConfigurationChangeListener)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 NodeState (com.sleepycat.je.rep.NodeState)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)1 IllegalStateTransitionException (org.apache.qpid.server.model.IllegalStateTransitionException)1 VirtualHost (org.apache.qpid.server.model.VirtualHost)1 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)1 ConfiguredObjectRecordImpl (org.apache.qpid.server.store.ConfiguredObjectRecordImpl)1 ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)1