Search in sources :

Example 11 with DataFlow

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

the class TestFlowController method testSynchronizeFlowWhenCurrentAuthorizationsAreEmptyAndProposedAreNot.

@Test
public void testSynchronizeFlowWhenCurrentAuthorizationsAreEmptyAndProposedAreNot() {
    final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
    // create a mock proposed data flow with the same auth fingerprint as the current authorizer
    final String authFingerprint = authorizer.getFingerprint();
    final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
    when(proposedDataFlow.getAuthorizerFingerprint()).thenReturn(authFingerprint.getBytes(StandardCharsets.UTF_8));
    authorizer = new MockPolicyBasedAuthorizer();
    assertNotEquals(authFingerprint, authorizer.getFingerprint());
    controller.shutdown(true);
    controller = FlowController.createStandaloneInstance(flowFileEventRepo, nifiProperties, authorizer, auditService, encryptor, bulletinRepo, variableRegistry, Mockito.mock(FlowRegistryClient.class));
    controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
    assertEquals(authFingerprint, authorizer.getFingerprint());
}
Also used : FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) MockPolicyBasedAuthorizer(org.apache.nifi.authorization.MockPolicyBasedAuthorizer) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) Test(org.junit.Test)

Example 12 with DataFlow

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

the class TestFlowController method testSynchronizeFlowWhenProposedMissingComponentsAreDifferent.

@Test
public void testSynchronizeFlowWhenProposedMissingComponentsAreDifferent() {
    final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
    final Set<String> missingComponents = new HashSet<>();
    missingComponents.add("1");
    missingComponents.add("2");
    final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
    when(proposedDataFlow.getMissingComponents()).thenReturn(missingComponents);
    try {
        controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
        Assert.fail("Should have thrown exception");
    } catch (UninheritableFlowException e) {
        assertTrue(e.getMessage().contains("Proposed flow has missing components that are not considered missing in the current flow (1,2)"));
    }
}
Also used : FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 13 with DataFlow

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

the class TestFlowController method testSynchronizeFlowWhenAuthorizationsAreEqual.

@Test
public void testSynchronizeFlowWhenAuthorizationsAreEqual() {
    final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(StringEncryptor.createEncryptor(nifiProperties), nifiProperties);
    // create a mock proposed data flow with the same auth fingerprint as the current authorizer
    final String authFingerprint = authorizer.getFingerprint();
    final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
    when(proposedDataFlow.getAuthorizerFingerprint()).thenReturn(authFingerprint.getBytes(StandardCharsets.UTF_8));
    controller.synchronize(standardFlowSynchronizer, proposedDataFlow);
    assertEquals(authFingerprint, authorizer.getFingerprint());
}
Also used : FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) Test(org.junit.Test)

Example 14 with DataFlow

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

the class TestPopularVoteFlowElection method testAutoGeneratedVsPopulatedFlowElection.

@Test
public void testAutoGeneratedVsPopulatedFlowElection() throws IOException {
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(getNiFiProperties()));
    final PopularVoteFlowElection election = new PopularVoteFlowElection(1, TimeUnit.MINUTES, 4, fingerprintFactory);
    final byte[] emptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/auto-generated-empty-flow.xml"));
    final byte[] nonEmptyFlow = Files.readAllBytes(Paths.get("src/test/resources/conf/reporting-task-flow.xml"));
    for (int i = 0; i < 4; i++) {
        assertFalse(election.isElectionComplete());
        assertNull(election.getElectedDataFlow());
        final DataFlow dataFlow;
        if (i % 2 == 0) {
            dataFlow = createDataFlow(emptyFlow);
        } else {
            dataFlow = createDataFlow(nonEmptyFlow);
        }
        final DataFlow electedDataFlow = election.castVote(dataFlow, createNodeId(i));
        if (i == 3) {
            assertNotNull(electedDataFlow);
            assertEquals(new String(nonEmptyFlow), new String(electedDataFlow.getFlow()));
        } else {
            assertNull(electedDataFlow);
        }
    }
}
Also used : FingerprintFactory(org.apache.nifi.fingerprint.FingerprintFactory) Matchers.anyString(org.mockito.Matchers.anyString) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) Test(org.junit.Test)

Example 15 with DataFlow

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

the class TestPopularVoteFlowElection method testDifferentPopulatedFlowsElection.

@Test
public void testDifferentPopulatedFlowsElection() throws IOException {
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(getNiFiProperties()));
    final PopularVoteFlowElection election = new PopularVoteFlowElection(1, TimeUnit.MINUTES, 4, fingerprintFactory);
    final byte[] nonEmptyCandidateA = Files.readAllBytes(Paths.get("src/test/resources/conf/controller-service-flow.xml"));
    final byte[] nonEmptyCandidateB = Files.readAllBytes(Paths.get("src/test/resources/conf/reporting-task-flow.xml"));
    for (int i = 0; i < 4; i++) {
        assertFalse(election.isElectionComplete());
        assertNull(election.getElectedDataFlow());
        final DataFlow dataFlow;
        if (i % 2 == 0) {
            dataFlow = createDataFlow(nonEmptyCandidateA);
        } else {
            dataFlow = createDataFlow(nonEmptyCandidateB);
        }
        final DataFlow electedDataFlow = election.castVote(dataFlow, createNodeId(i));
        if (i == 3) {
            assertNotNull(electedDataFlow);
            assertEquals(new String(nonEmptyCandidateA), new String(electedDataFlow.getFlow()));
        } else {
            assertNull(electedDataFlow);
        }
    }
}
Also used : FingerprintFactory(org.apache.nifi.fingerprint.FingerprintFactory) Matchers.anyString(org.mockito.Matchers.anyString) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) StandardDataFlow(org.apache.nifi.cluster.protocol.StandardDataFlow) Test(org.junit.Test)

Aggregations

DataFlow (org.apache.nifi.cluster.protocol.DataFlow)20 Test (org.junit.Test)14 StandardDataFlow (org.apache.nifi.cluster.protocol.StandardDataFlow)11 FlowSynchronizer (org.apache.nifi.controller.serialization.FlowSynchronizer)9 FingerprintFactory (org.apache.nifi.fingerprint.FingerprintFactory)6 IOException (java.io.IOException)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 FlowSynchronizationException (org.apache.nifi.controller.serialization.FlowSynchronizationException)4 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)4 StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 URL (java.net.URL)3 StandardCharsets (java.nio.charset.StandardCharsets)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3