Search in sources :

Example 6 with RevisionManager

use of org.apache.nifi.web.revision.RevisionManager in project nifi by apache.

the class TestNodeClusterCoordinator method testTryAgainIfNoFlowServiceSet.

@Test
public void testTryAgainIfNoFlowServiceSet() {
    final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
    final EventReporter eventReporter = Mockito.mock(EventReporter.class);
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {

        @Override
        void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
        }
    };
    final NodeIdentifier requestedNodeId = createNodeId(6);
    final ConnectionRequest request = new ConnectionRequest(requestedNodeId, new StandardDataFlow(new byte[0], new byte[0], new byte[0], new HashSet<>()));
    final ConnectionRequestMessage requestMsg = new ConnectionRequestMessage();
    requestMsg.setConnectionRequest(request);
    coordinator.setConnected(true);
    final ProtocolMessage protocolResponse = coordinator.handle(requestMsg);
    assertNotNull(protocolResponse);
    assertTrue(protocolResponse instanceof ConnectionResponseMessage);
    final ConnectionResponse response = ((ConnectionResponseMessage) protocolResponse).getConnectionResponse();
    assertNotNull(response);
    assertEquals(5, response.getTryLaterSeconds());
}
Also used : ConnectionRequestMessage(org.apache.nifi.cluster.protocol.message.ConnectionRequestMessage) RevisionManager(org.apache.nifi.web.revision.RevisionManager) ConnectionResponse(org.apache.nifi.cluster.protocol.ConnectionResponse) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) ConnectionRequest(org.apache.nifi.cluster.protocol.ConnectionRequest) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ConnectionResponseMessage(org.apache.nifi.cluster.protocol.message.ConnectionResponseMessage) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with RevisionManager

use of org.apache.nifi.web.revision.RevisionManager in project nifi by apache.

the class TestNodeClusterCoordinator method testUnknownNodeAskedToConnectOnAttemptedConnectionComplete.

@Test(timeout = 5000)
public void testUnknownNodeAskedToConnectOnAttemptedConnectionComplete() throws IOException, InterruptedException {
    final ClusterCoordinationProtocolSenderListener senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
    final AtomicReference<ReconnectionRequestMessage> requestRef = new AtomicReference<>();
    Mockito.when(senderListener.requestReconnection(Mockito.any(ReconnectionRequestMessage.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final ReconnectionRequestMessage msg = invocation.getArgumentAt(0, ReconnectionRequestMessage.class);
            requestRef.set(msg);
            return null;
        }
    });
    final EventReporter eventReporter = Mockito.mock(EventReporter.class);
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    final NodeClusterCoordinator coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {

        @Override
        void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
        }
    };
    final FlowService flowService = Mockito.mock(FlowService.class);
    final StandardDataFlow dataFlow = new StandardDataFlow(new byte[50], new byte[50], new byte[50], new HashSet<>());
    Mockito.when(flowService.createDataFlowFromController()).thenReturn(dataFlow);
    coordinator.setFlowService(flowService);
    coordinator.setConnected(true);
    final NodeIdentifier nodeId = createNodeId(1);
    coordinator.finishNodeConnection(nodeId);
    while (requestRef.get() == null) {
        Thread.sleep(10L);
    }
    final ReconnectionRequestMessage msg = requestRef.get();
    assertEquals(nodeId, msg.getNodeId());
    final StandardDataFlow df = msg.getDataFlow();
    assertNotNull(df);
    assertTrue(Arrays.equals(dataFlow.getFlow(), df.getFlow()));
    assertTrue(Arrays.equals(dataFlow.getSnippets(), df.getSnippets()));
}
Also used : RevisionManager(org.apache.nifi.web.revision.RevisionManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ReconnectionRequestMessage(org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter) FlowService(org.apache.nifi.services.FlowService) Test(org.junit.Test)

Example 8 with RevisionManager

use of org.apache.nifi.web.revision.RevisionManager in project nifi by apache.

the class NodeClusterCoordinatorFactoryBean method getObject.

@Override
public NodeClusterCoordinator getObject() throws Exception {
    if (nodeClusterCoordinator == null && properties.isNode()) {
        final ClusterCoordinationProtocolSenderListener protocolSenderListener = applicationContext.getBean("clusterCoordinationProtocolSenderListener", ClusterCoordinationProtocolSenderListener.class);
        final EventReporter eventReporter = applicationContext.getBean("eventReporter", EventReporter.class);
        final ClusterNodeFirewall clusterFirewall = applicationContext.getBean("clusterFirewall", ClusterNodeFirewall.class);
        final RevisionManager revisionManager = applicationContext.getBean("revisionManager", RevisionManager.class);
        final LeaderElectionManager electionManager = applicationContext.getBean("leaderElectionManager", LeaderElectionManager.class);
        final FlowElection flowElection = applicationContext.getBean("flowElection", FlowElection.class);
        final NodeProtocolSender nodeProtocolSender = applicationContext.getBean("nodeProtocolSender", NodeProtocolSender.class);
        nodeClusterCoordinator = new NodeClusterCoordinator(protocolSenderListener, eventReporter, electionManager, flowElection, clusterFirewall, revisionManager, properties, nodeProtocolSender);
    }
    return nodeClusterCoordinator;
}
Also used : NodeProtocolSender(org.apache.nifi.cluster.protocol.NodeProtocolSender) LeaderElectionManager(org.apache.nifi.controller.leader.election.LeaderElectionManager) NodeClusterCoordinator(org.apache.nifi.cluster.coordination.node.NodeClusterCoordinator) ClusterNodeFirewall(org.apache.nifi.cluster.firewall.ClusterNodeFirewall) RevisionManager(org.apache.nifi.web.revision.RevisionManager) FlowElection(org.apache.nifi.cluster.coordination.flow.FlowElection) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter)

Example 9 with RevisionManager

use of org.apache.nifi.web.revision.RevisionManager in project nifi by apache.

the class TestNodeClusterCoordinator method testStatusChangesReplicated.

@Test(timeout = 5000)
public void testStatusChangesReplicated() throws InterruptedException, IOException {
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    // Create a connection request message and send to the coordinator
    final NodeIdentifier requestedNodeId = createNodeId(1);
    requestConnection(requestedNodeId, coordinator);
    // The above connection request should trigger a 'CONNECTING' state transition to be replicated
    while (nodeStatuses.isEmpty()) {
        Thread.sleep(20L);
    }
    final NodeConnectionStatus connectingStatus = nodeStatuses.get(0);
    assertEquals(NodeConnectionState.CONNECTING, connectingStatus.getState());
    assertEquals(requestedNodeId, connectingStatus.getNodeIdentifier());
    // set node status to connected
    coordinator.finishNodeConnection(requestedNodeId);
    // the above method will result in the node identifier becoming 'CONNECTED'. Wait for this to happen and clear the map
    while (nodeStatuses.isEmpty()) {
        Thread.sleep(20L);
    }
    nodeStatuses.clear();
    coordinator.disconnectionRequestedByNode(requestedNodeId, DisconnectionCode.NODE_SHUTDOWN, "Unit Test");
    while (nodeStatuses.isEmpty()) {
        Thread.sleep(20L);
    }
    assertEquals(1, nodeStatuses.size());
    final NodeConnectionStatus statusChange = nodeStatuses.get(0);
    assertNotNull(statusChange);
    assertEquals(createNodeId(1), statusChange.getNodeIdentifier());
    assertEquals(DisconnectionCode.NODE_SHUTDOWN, statusChange.getDisconnectCode());
    assertEquals("Unit Test", statusChange.getDisconnectReason());
}
Also used : RevisionManager(org.apache.nifi.web.revision.RevisionManager) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Test(org.junit.Test)

Example 10 with RevisionManager

use of org.apache.nifi.web.revision.RevisionManager in project nifi by apache.

the class TestNodeClusterCoordinator method setup.

@Before
public void setup() throws IOException {
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/conf/nifi.properties");
    senderListener = Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
    nodeStatuses = Collections.synchronizedList(new ArrayList<>());
    final EventReporter eventReporter = Mockito.mock(EventReporter.class);
    final RevisionManager revisionManager = Mockito.mock(RevisionManager.class);
    Mockito.when(revisionManager.getAllRevisions()).thenReturn(Collections.emptyList());
    coordinator = new NodeClusterCoordinator(senderListener, eventReporter, null, new FirstVoteWinsFlowElection(), null, revisionManager, createProperties(), null) {

        @Override
        void notifyOthersOfNodeStatusChange(NodeConnectionStatus updatedStatus, boolean notifyAllNodes, boolean waitForCoordinator) {
            nodeStatuses.add(updatedStatus);
        }
    };
    final FlowService flowService = Mockito.mock(FlowService.class);
    final StandardDataFlow dataFlow = new StandardDataFlow(new byte[50], new byte[50], new byte[50], new HashSet<>());
    Mockito.when(flowService.createDataFlow()).thenReturn(dataFlow);
    coordinator.setFlowService(flowService);
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) RevisionManager(org.apache.nifi.web.revision.RevisionManager) ArrayList(java.util.ArrayList) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter) FlowService(org.apache.nifi.services.FlowService) Before(org.junit.Before)

Aggregations

RevisionManager (org.apache.nifi.web.revision.RevisionManager)12 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Arrays (java.util.Arrays)5 Collection (java.util.Collection)5 Collections (java.util.Collections)5 Comparator (java.util.Comparator)5 Date (java.util.Date)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 LinkedHashSet (java.util.LinkedHashSet)5 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 Function (java.util.function.Function)5 Supplier (java.util.function.Supplier)5 Collectors (java.util.stream.Collectors)5 WebApplicationException (javax.ws.rs.WebApplicationException)5 Action (org.apache.nifi.action.Action)5