use of org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage 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()));
}
use of org.apache.nifi.cluster.protocol.message.ReconnectionRequestMessage in project nifi by apache.
the class NodeClusterCoordinator method requestNodeConnect.
@Override
public void requestNodeConnect(final NodeIdentifier nodeId, final String userDn) {
if (requireElection && !flowElection.isElectionComplete() && flowElection.isVoteCounted(nodeId)) {
// If we receive a heartbeat from a node that we already know, we don't want to request that it reconnect
// to the cluster because no flow has yet been elected. However, if the node has not yet voted, we want to send
// a reconnect request because we want this node to cast its vote for the flow, and this happens on connection
logger.debug("Received heartbeat for {} and node is not connected. Will not request node connect to cluster, " + "though, because the Flow Election is still in progress", nodeId);
return;
}
if (userDn == null) {
reportEvent(nodeId, Severity.INFO, "Requesting that node connect to cluster");
} else {
reportEvent(nodeId, Severity.INFO, "Requesting that node connect to cluster on behalf of " + userDn);
}
updateNodeStatus(new NodeConnectionStatus(nodeId, NodeConnectionState.CONNECTING, null, null, System.currentTimeMillis()));
// create the request
final ReconnectionRequestMessage request = new ReconnectionRequestMessage();
request.setNodeId(nodeId);
request.setInstanceId(instanceId);
// If we still are requiring that an election take place, we do not want to include our local dataflow, because we don't
// yet know what the cluster's dataflow looks like. However, if we don't require election, then we've connected to the
// cluster, which means that our flow is correct.
final boolean includeDataFlow = !requireElection;
requestReconnectionAsynchronously(request, 10, 5, includeDataFlow);
}
Aggregations