Search in sources :

Example 1 with ClusterCoordinationProtocolSenderListener

use of org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener in project nifi by apache.

the class HeartbeatMonitorFactoryBean method getObject.

@Override
public HeartbeatMonitor getObject() throws Exception {
    if (heartbeatMonitor == null && properties.isNode()) {
        final ClusterCoordinationProtocolSenderListener protocolSenderListener = applicationContext.getBean("clusterCoordinationProtocolSenderListener", ClusterCoordinationProtocolSenderListener.class);
        final ClusterCoordinator clusterCoordinator = applicationContext.getBean("clusterCoordinator", ClusterCoordinator.class);
        heartbeatMonitor = new ClusterProtocolHeartbeatMonitor(clusterCoordinator, protocolSenderListener, properties);
    }
    return heartbeatMonitor;
}
Also used : ClusterProtocolHeartbeatMonitor(org.apache.nifi.cluster.coordination.heartbeat.ClusterProtocolHeartbeatMonitor) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener)

Example 2 with ClusterCoordinationProtocolSenderListener

use of org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener 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 3 with ClusterCoordinationProtocolSenderListener

use of org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener 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 4 with ClusterCoordinationProtocolSenderListener

use of org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener 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 5 with ClusterCoordinationProtocolSenderListener

use of org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener in project nifi by apache.

the class Node method createClusterCoordinator.

@SuppressWarnings("unchecked")
private NodeClusterCoordinator createClusterCoordinator() {
    final EventReporter eventReporter = new EventReporter() {

        @Override
        public void reportEvent(Severity severity, String category, String message) {
            reportedEvents.add(new ReportedEvent(nodeId, severity, message));
        }
    };
    final ServerSocketConfiguration serverSocketConfiguration = new ServerSocketConfiguration();
    serverSocketConfiguration.setSocketTimeout(5000);
    final ProtocolContext<ProtocolMessage> protocolContext = new JaxbProtocolContext<>(JaxbProtocolUtils.JAXB_CONTEXT);
    protocolListener = new SocketProtocolListener(3, Integer.parseInt(nodeProperties.getProperty(NiFiProperties.CLUSTER_NODE_PROTOCOL_PORT)), serverSocketConfiguration, protocolContext);
    try {
        protocolListener.start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    final ClusterCoordinationProtocolSenderListener protocolSenderListener = new ClusterCoordinationProtocolSenderListener(createCoordinatorProtocolSender(), protocolListener);
    return new NodeClusterCoordinator(protocolSenderListener, eventReporter, electionManager, flowElection, null, revisionManager, nodeProperties, protocolSender);
}
Also used : SocketProtocolListener(org.apache.nifi.cluster.protocol.impl.SocketProtocolListener) NodeClusterCoordinator(org.apache.nifi.cluster.coordination.node.NodeClusterCoordinator) Severity(org.apache.nifi.reporting.Severity) IOException(java.io.IOException) ProtocolMessage(org.apache.nifi.cluster.protocol.message.ProtocolMessage) ReportedEvent(org.apache.nifi.cluster.ReportedEvent) ServerSocketConfiguration(org.apache.nifi.io.socket.ServerSocketConfiguration) JaxbProtocolContext(org.apache.nifi.cluster.protocol.jaxb.JaxbProtocolContext) ClusterCoordinationProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener) EventReporter(org.apache.nifi.events.EventReporter)

Aggregations

ClusterCoordinationProtocolSenderListener (org.apache.nifi.cluster.protocol.impl.ClusterCoordinationProtocolSenderListener)5 EventReporter (org.apache.nifi.events.EventReporter)4 RevisionManager (org.apache.nifi.web.revision.RevisionManager)3 NodeClusterCoordinator (org.apache.nifi.cluster.coordination.node.NodeClusterCoordinator)2 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)2 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)2 ProtocolMessage (org.apache.nifi.cluster.protocol.message.ProtocolMessage)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ReportedEvent (org.apache.nifi.cluster.ReportedEvent)1 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)1 FlowElection (org.apache.nifi.cluster.coordination.flow.FlowElection)1 ClusterProtocolHeartbeatMonitor (org.apache.nifi.cluster.coordination.heartbeat.ClusterProtocolHeartbeatMonitor)1 ClusterNodeFirewall (org.apache.nifi.cluster.firewall.ClusterNodeFirewall)1 ConnectionRequest (org.apache.nifi.cluster.protocol.ConnectionRequest)1 ConnectionResponse (org.apache.nifi.cluster.protocol.ConnectionResponse)1 NodeProtocolSender (org.apache.nifi.cluster.protocol.NodeProtocolSender)1 SocketProtocolListener (org.apache.nifi.cluster.protocol.impl.SocketProtocolListener)1