Search in sources :

Example 1 with StandardDataFlow

use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.

the class StandardFlowServiceTest method testLoadExistingFlow.

@Test
public void testLoadExistingFlow() throws IOException {
    byte[] flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow.xml"));
    flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
    flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-inheritable.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);
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializer(org.apache.nifi.controller.serialization.FlowSerializer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with StandardDataFlow

use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.

the class StandardFlowServiceTest method testLoadExistingFlowWithCorruptFlow.

@Test
public void testLoadExistingFlowWithCorruptFlow() 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-corrupt.xml"));
        flowService.load(new StandardDataFlow(updatedBytes, null, null, new HashSet<>()));
        fail("should have thrown " + FlowSerializationException.class);
    } catch (FlowSerializationException 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);
    }
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandardFlowSerializer(org.apache.nifi.controller.serialization.StandardFlowSerializer) FlowSerializer(org.apache.nifi.controller.serialization.FlowSerializer) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with StandardDataFlow

use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.

the class StandardFlowServiceTest method testLoadWithCorruptFlow.

@Test(expected = FlowSerializationException.class)
public void testLoadWithCorruptFlow() throws IOException {
    byte[] flowBytes = IOUtils.toByteArray(StandardFlowServiceTest.class.getResourceAsStream("/conf/all-flow-corrupt.xml"));
    flowService.load(new StandardDataFlow(flowBytes, null, null, new HashSet<>()));
}
Also used : StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with StandardDataFlow

use of org.apache.nifi.cluster.protocol.StandardDataFlow in project nifi by apache.

the class TestNodeClusterCoordinator method requestConnection.

private ProtocolMessage requestConnection(final NodeIdentifier requestedNodeId, final NodeClusterCoordinator coordinator) {
    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);
    return coordinator.handle(requestMsg);
}
Also used : ConnectionRequest(org.apache.nifi.cluster.protocol.ConnectionRequest) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) ConnectionRequestMessage(org.apache.nifi.cluster.protocol.message.ConnectionRequestMessage) HashSet(java.util.HashSet)

Example 5 with StandardDataFlow

use of org.apache.nifi.cluster.protocol.StandardDataFlow 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)

Aggregations

StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)15 HashSet (java.util.HashSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 Test (org.junit.Test)9 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)5 StandardFlowSerializer (org.apache.nifi.controller.serialization.StandardFlowSerializer)5 FlowSerializer (org.apache.nifi.controller.serialization.FlowSerializer)4 ArrayList (java.util.ArrayList)3 ConnectionRequest (org.apache.nifi.cluster.protocol.ConnectionRequest)3 DataFlow (org.apache.nifi.cluster.protocol.DataFlow)3 ConnectionRequestMessage (org.apache.nifi.cluster.protocol.message.ConnectionRequestMessage)3 RevisionManager (org.apache.nifi.web.revision.RevisionManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 StandardOpenOption (java.nio.file.StandardOpenOption)2 Collections (java.util.Collections)2