use of org.apache.nifi.cluster.protocol.StandardDataFlow 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.StandardDataFlow in project nifi by apache.
the class StandardFlowService method createDataFlow.
@Override
public StandardDataFlow createDataFlow() throws IOException {
// Load the flow from disk if the file exists.
if (dao.isFlowPresent()) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
dao.load(baos);
final byte[] bytes = baos.toByteArray();
final byte[] snippetBytes = controller.getSnippetManager().export();
final byte[] authorizerFingerprint = getAuthorizerFingerprint();
final StandardDataFlow fromDisk = new StandardDataFlow(bytes, snippetBytes, authorizerFingerprint, new HashSet<>());
return fromDisk;
}
// end up with the same ID for the root Process Group.
return createDataFlowFromController();
}
use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.
the class StandardFlowService method createDataFlowFromController.
@Override
public StandardDataFlow createDataFlowFromController() throws IOException {
final byte[] snippetBytes = controller.getSnippetManager().export();
final byte[] authorizerFingerprint = getAuthorizerFingerprint();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
dao.save(controller, baos);
final byte[] flowBytes = baos.toByteArray();
baos.reset();
final Set<String> missingComponents = new HashSet<>();
controller.getRootGroup().findAllProcessors().stream().filter(p -> p.isExtensionMissing()).forEach(p -> missingComponents.add(p.getIdentifier()));
controller.getAllControllerServices().stream().filter(cs -> cs.isExtensionMissing()).forEach(cs -> missingComponents.add(cs.getIdentifier()));
controller.getAllReportingTasks().stream().filter(r -> r.isExtensionMissing()).forEach(r -> missingComponents.add(r.getIdentifier()));
return new StandardDataFlow(flowBytes, snippetBytes, authorizerFingerprint, missingComponents);
}
use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.
the class StandardFlowServiceTest method testLoadWithFlow.
@Test
public void testLoadWithFlow() throws IOException {
byte[] flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
String expectedFlow = new String(flowBytes).trim();
String actualFlow = new String(baos.toByteArray()).trim();
Assert.assertEquals(expectedFlow, actualFlow);
}
use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.
the class StandardFlowServiceTest method testLoadExistingFlowWithUninheritableFlow.
@Test
public void testLoadExistingFlowWithUninheritableFlow() throws IOException {
byte[] originalBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
flowService.load(new StandardDataFlow(originalBytes, null, null, new HashSet<>()));
try {
byte[] updatedBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-uninheritable.xml"));
flowService.load(new StandardDataFlow(updatedBytes, null, null, new HashSet<>()));
fail("should have thrown " + UninheritableFlowException.class);
} catch (UninheritableFlowException ufe) {
FlowSerializer serializer = new StandardFlowSerializer(mockEncryptor);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(flowController, baos, ScheduledStateLookup.IDENTITY_LOOKUP);
String expectedFlow = new String(originalBytes).trim();
String actualFlow = new String(baos.toByteArray()).trim();
Assert.assertEquals(expectedFlow, actualFlow);
}
}
Aggregations