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());
}
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()));
}
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;
}
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());
}
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);
}
Aggregations