use of org.apache.nifi.fingerprint.FingerprintFactory 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);
}
}
}
use of org.apache.nifi.fingerprint.FingerprintFactory in project nifi by apache.
the class Cluster method createNode.
public Node createNode() {
final Map<String, String> addProps = new HashMap<>();
addProps.put(NiFiProperties.ZOOKEEPER_CONNECT_STRING, getZooKeeperConnectString());
addProps.put(NiFiProperties.CLUSTER_IS_NODE, "true");
final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties("src/test/resources/conf/nifi.properties", addProps);
final FingerprintFactory fingerprintFactory = new FingerprintFactory(StringEncryptor.createEncryptor(nifiProperties));
final FlowElection flowElection = new PopularVoteFlowElection(flowElectionTimeoutMillis, TimeUnit.MILLISECONDS, flowElectionMaxNodes, fingerprintFactory);
final Node node = new Node(nifiProperties, flowElection);
node.start();
nodes.add(node);
return node;
}
use of org.apache.nifi.fingerprint.FingerprintFactory in project nifi by apache.
the class StandardFlowSynchronizer method checkFlowInheritability.
private String checkFlowInheritability(final byte[] existingFlow, final byte[] proposedFlow, final FlowController controller) {
if (existingFlow == null) {
// no existing flow, so equivalent to proposed flow
return null;
}
// check if the Flow is inheritable
final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor);
final String existingFlowFingerprintBeforeHash = fingerprintFactory.createFingerprint(existingFlow, controller);
if (existingFlowFingerprintBeforeHash.trim().isEmpty()) {
// no existing flow, so equivalent to proposed flow
return null;
}
if (proposedFlow == null || proposedFlow.length == 0) {
// existing flow is not empty and proposed flow is empty (we could orphan flowfiles)
return "Proposed Flow was empty but Current Flow is not";
}
final String proposedFlowFingerprintBeforeHash = fingerprintFactory.createFingerprint(proposedFlow, controller);
if (proposedFlowFingerprintBeforeHash.trim().isEmpty()) {
// existing flow is not empty and proposed flow is empty (we could orphan flowfiles)
return "Proposed Flow was empty but Current Flow is not";
}
if (logger.isTraceEnabled()) {
logger.trace("Local Fingerprint Before Hash = {}", new Object[] { existingFlowFingerprintBeforeHash });
logger.trace("Proposed Fingerprint Before Hash = {}", new Object[] { proposedFlowFingerprintBeforeHash });
}
final boolean inheritable = existingFlowFingerprintBeforeHash.equals(proposedFlowFingerprintBeforeHash);
if (!inheritable) {
return findFirstDiscrepancy(existingFlowFingerprintBeforeHash, proposedFlowFingerprintBeforeHash, "Flows");
}
return null;
}
Aggregations