org.apache.nifi.processor.Relationship Java Examples

The following examples show how to use org.apache.nifi.processor.Relationship. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsConsumer.java    From nifi with Apache License 2.0 6 votes vote down vote up
public JmsConsumer() {
    final Set<Relationship> rels = new HashSet<>();
    rels.add(REL_SUCCESS);
    this.relationships = Collections.unmodifiableSet(rels);

    final List<PropertyDescriptor> descriptors = new ArrayList<>();
    descriptors.add(JMS_PROVIDER);
    descriptors.add(URL);
    descriptors.add(DESTINATION_NAME);
    descriptors.add(TIMEOUT);
    descriptors.add(BATCH_SIZE);
    descriptors.add(USERNAME);
    descriptors.add(PASSWORD);
    descriptors.add(SSL_CONTEXT_SERVICE);
    descriptors.add(ACKNOWLEDGEMENT_MODE);
    descriptors.add(MESSAGE_SELECTOR);
    descriptors.add(JMS_PROPS_TO_ATTRIBUTES);
    descriptors.add(CLIENT_ID_PREFIX);
    this.propertyDescriptors = Collections.unmodifiableList(descriptors);
}
 
Example #2
Source File: TestFlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateMissingProcessor() throws ProcessorInstantiationException {
    final ProcessorNode procNode = controller.createProcessor("org.apache.nifi.NonExistingProcessor", "1234-Processor");
    assertNotNull(procNode);
    assertEquals("org.apache.nifi.NonExistingProcessor", procNode.getCanonicalClassName());
    assertEquals("(Missing) NonExistingProcessor", procNode.getComponentType());

    final PropertyDescriptor descriptor = procNode.getPropertyDescriptor("my descriptor");
    assertNotNull(descriptor);
    assertEquals("my descriptor", descriptor.getName());
    assertTrue(descriptor.isRequired());
    assertTrue(descriptor.isSensitive());

    final Relationship relationship = procNode.getRelationship("my relationship");
    assertEquals("my relationship", relationship.getName());
}
 
Example #3
Source File: GetHTTP.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    this.relationships = Collections.unmodifiableSet(relationships);

    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(URL);
    properties.add(FILENAME);
    properties.add(SSL_CONTEXT_SERVICE);
    properties.add(USERNAME);
    properties.add(PASSWORD);
    properties.add(CONNECTION_TIMEOUT);
    properties.add(DATA_TIMEOUT);
    properties.add(USER_AGENT);
    properties.add(ACCEPT_CONTENT_TYPE);
    properties.add(FOLLOW_REDIRECTS);
    properties.add(REDIRECT_COOKIE_POLICY);
    properties.add(HTTPUtils.PROXY_CONFIGURATION_SERVICE);
    properties.add(PROXY_HOST);
    properties.add(PROXY_PORT);
    this.properties = Collections.unmodifiableList(properties);
}
 
Example #4
Source File: TestLocalPort.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidLocalOutputPort() {
    final LocalPort port = getLocalOutputPort();

    // Add an incoming relationship.
    port.addConnection(new StandardConnection.Builder(null)
        .source(mock(Connectable.class))
        .destination(port)
        .relationships(Collections.singleton(Relationship.ANONYMOUS))
        .flowFileQueueFactory(mock(FlowFileQueueFactory.class))
        .build());

    // Add an outgoing relationship.
    port.addConnection(new StandardConnection.Builder(null)
        .source(port)
        .destination(mock(Connectable.class))
        .relationships(Collections.singleton(Relationship.ANONYMOUS))
        .flowFileQueueFactory(mock(FlowFileQueueFactory.class))
        .build());

    assertTrue(port.isValid());
}
 
Example #5
Source File: RouteText.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> set = new HashSet<>();
    set.add(REL_ORIGINAL);
    set.add(REL_NO_MATCH);
    relationships = new AtomicReference<>(set);

    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(ROUTE_STRATEGY);
    properties.add(MATCH_STRATEGY);
    properties.add(CHARACTER_SET);
    properties.add(TRIM_WHITESPACE);
    properties.add(IGNORE_CASE);
    properties.add(GROUPING_REGEX);
    this.properties = Collections.unmodifiableList(properties);
}
 
Example #6
Source File: UpdateRowsWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and transfers a new flow file whose contents are the JSON-serialized value of the specified event, and the sequence ID attribute set
 *
 * @param session   A reference to a ProcessSession from which the flow file(s) will be created and transferred
 * @param eventInfo An event whose value will become the contents of the flow file
 * @return The next available CDC sequence ID for use by the CDC processor
 */
@Override
public long writeEvent(final ProcessSession session, String transitUri, final UpdateRowsEventInfo eventInfo, final long currentSequenceId, Relationship relationship) {
    final AtomicLong seqId = new AtomicLong(currentSequenceId);
    for (Map.Entry<Serializable[], Serializable[]> row : eventInfo.getRows()) {

        FlowFile flowFile = session.create();
        flowFile = session.write(flowFile, outputStream -> {

            super.startJson(outputStream, eventInfo);
            super.writeJson(eventInfo);

            final BitSet bitSet = eventInfo.getIncludedColumns();
            writeRow(eventInfo, row, bitSet);

            super.endJson();
        });

        flowFile = session.putAllAttributes(flowFile, getCommonAttributes(seqId.get(), eventInfo));
        session.transfer(flowFile, relationship);
        session.getProvenanceReporter().receive(flowFile, transitUri);
        seqId.getAndIncrement();
    }
    return seqId.get();
}
 
Example #7
Source File: RouteText.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void appendLine(final ProcessSession session, final Map<Relationship, Map<Group, FlowFile>> flowFileMap, final Relationship relationship,
    final FlowFile original, final String line, final Charset charset, final Group group) {

    final Map<Group, FlowFile> groupToFlowFileMap = flowFileMap.computeIfAbsent(relationship, k -> new HashMap<>());

    FlowFile flowFile = groupToFlowFileMap.get(group);
    if (flowFile == null) {
        flowFile = session.create(original);
    }

    flowFile = session.append(flowFile, new OutputStreamCallback() {
        @Override
        public void process(final OutputStream out) throws IOException {
            out.write(line.getBytes(charset));
        }
    });

    groupToFlowFileMap.put(group, flowFile);
}
 
Example #8
Source File: ValidateCsv.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(SCHEMA);
    properties.add(HEADER);
    properties.add(DELIMITER_CHARACTER);
    properties.add(QUOTE_CHARACTER);
    properties.add(END_OF_LINE_CHARACTER);
    properties.add(VALIDATION_STRATEGY);
    this.properties = Collections.unmodifiableList(properties);

    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_VALID);
    relationships.add(REL_INVALID);
    this.relationships = Collections.unmodifiableSet(relationships);
}
 
Example #9
Source File: AbstractListenEventBatchingProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> descriptors = new ArrayList<>();
    descriptors.add(NETWORK_INTF_NAME);
    descriptors.add(PORT);
    descriptors.add(RECV_BUFFER_SIZE);
    descriptors.add(MAX_MESSAGE_QUEUE_SIZE);
    descriptors.add(MAX_SOCKET_BUFFER_SIZE);
    descriptors.add(CHARSET);
    descriptors.add(MAX_BATCH_SIZE);
    descriptors.add(MESSAGE_DELIMITER);
    descriptors.addAll(getAdditionalProperties());
    this.descriptors = Collections.unmodifiableList(descriptors);

    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    relationships.addAll(getAdditionalRelationships());
    this.relationships = Collections.unmodifiableSet(relationships);
}
 
Example #10
Source File: ProcessContext.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public boolean isAnyRelationshipAvailable() {
    for (final Relationship relationship : getConnectable().getRelationships()) {
        final Collection<Connection> connections = getConnections(relationship);

        boolean available = true;
        for (final Connection connection : connections) {
            if (connection.getFlowFileQueue().isFull()) {
                available = false;
                break;
            }
        }

        if (available) {
            return true;
        }
    }

    return false;
}
 
Example #11
Source File: RouteText.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> set = new HashSet<>();
    set.add(REL_ORIGINAL);
    set.add(REL_NO_MATCH);
    relationships = new AtomicReference<>(set);

    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(ROUTE_STRATEGY);
    properties.add(MATCH_STRATEGY);
    properties.add(CHARACTER_SET);
    properties.add(TRIM_WHITESPACE);
    properties.add(IGNORE_CASE);
    properties.add(GROUPING_REGEX);
    this.properties = Collections.unmodifiableList(properties);
}
 
Example #12
Source File: TestEvaluateJsonPath.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractPath_destinationAttributes_twoPaths_oneFound() throws Exception {
    final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
    testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_ATTRIBUTE);

    String jsonPathIdAttrKey = "evaluatejson.id";
    String jsonPathNameAttrKey = "evaluatejson.name";

    testRunner.setProperty(jsonPathIdAttrKey, "$[0]._id");
    testRunner.setProperty(jsonPathNameAttrKey, "$[0].name.nonexistent");

    testRunner.enqueue(JSON_SNIPPET);
    testRunner.run();

    Relationship expectedRel = EvaluateJsonPath.REL_MATCH;

    testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
    final MockFlowFile out = testRunner.getFlowFilesForRelationship(expectedRel).get(0);
    Assert.assertEquals("Transferred flow file did not have the correct result for id attribute", "54df94072d5dbf7dc6340cc5", out.getAttribute(jsonPathIdAttrKey));
    Assert.assertEquals("Transferred flow file did not have the correct result for name attribute", StringUtils.EMPTY, out.getAttribute(jsonPathNameAttrKey));
}
 
Example #13
Source File: TestEvaluateJsonPath.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testExtractPath_destinationContent_indefiniteResult_operators() throws Exception {
    String jsonPathAttrKey = "friends.indefinite.id.list";

    final TestRunner testRunner = TestRunners.newTestRunner(new EvaluateJsonPath());
    testRunner.setProperty(EvaluateJsonPath.DESTINATION, EvaluateJsonPath.DESTINATION_CONTENT);
    testRunner.setProperty(jsonPathAttrKey, "$[0].friends[?(@.id < 3)].id");

    testRunner.enqueue(JSON_SNIPPET);
    testRunner.run();

    Relationship expectedRel = EvaluateJsonPath.REL_MATCH;

    testRunner.assertAllFlowFilesTransferred(expectedRel, 1);
    testRunner.getFlowFilesForRelationship(expectedRel).get(0).assertContentEquals("[0,1,2]");
}
 
Example #14
Source File: WriteResourceToStream.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {

    final Set<Relationship> relationships = new HashSet<Relationship>();
    relationships.add(REL_SUCCESS);
    relationships.add(REL_FAILURE);
    this.relationships = Collections.unmodifiableSet(relationships);
    final InputStream resourceStream = Thread.currentThread()
            .getContextClassLoader().getResourceAsStream("file.txt");
    try {
        this.resourceData = IOUtils.toString(resourceStream);
    } catch (IOException e) {
        throw new RuntimeException("Unable to load resources", e);
    } finally {
        IOUtils.closeQuietly(resourceStream);
    }

}
 
Example #15
Source File: TestExtractText.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRelationShips() throws Exception {

    final ExtractText processor = new ExtractText();
    final TestRunner testRunner = TestRunners.newTestRunner(processor);

    testRunner.enqueue("foo".getBytes("UTF-8"));
    testRunner.run();

    Set<Relationship> relationships = processor.getRelationships();
    assertTrue(relationships.contains(ExtractText.REL_MATCH));
    assertTrue(relationships.contains(ExtractText.REL_NO_MATCH));
    assertEquals(2, relationships.size());
}
 
Example #16
Source File: DistributeLoad.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(createRelationship(1));
    relationshipsRef.set(Collections.unmodifiableSet(relationships));

    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(NUM_RELATIONSHIPS);
    properties.add(DISTRIBUTION_STRATEGY);
    this.properties = Collections.unmodifiableList(properties);
}
 
Example #17
Source File: CompressContent.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(MODE);
    properties.add(COMPRESSION_FORMAT);
    properties.add(COMPRESSION_LEVEL);
    properties.add(UPDATE_FILENAME);
    this.properties = Collections.unmodifiableList(properties);

    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    relationships.add(REL_FAILURE);
    this.relationships = Collections.unmodifiableSet(relationships);

    final Map<String, String> mimeTypeMap = new HashMap<>();
    mimeTypeMap.put("application/gzip", COMPRESSION_FORMAT_GZIP);
    mimeTypeMap.put("application/x-gzip", COMPRESSION_FORMAT_GZIP);
    mimeTypeMap.put("application/deflate", COMPRESSION_FORMAT_DEFLATE);
    mimeTypeMap.put("application/x-deflate", COMPRESSION_FORMAT_DEFLATE);
    mimeTypeMap.put("application/bzip2", COMPRESSION_FORMAT_BZIP2);
    mimeTypeMap.put("application/x-bzip2", COMPRESSION_FORMAT_BZIP2);
    mimeTypeMap.put("application/x-lzma", COMPRESSION_FORMAT_LZMA);
    mimeTypeMap.put("application/x-snappy", COMPRESSION_FORMAT_SNAPPY);
    mimeTypeMap.put("application/x-snappy-framed", COMPRESSION_FORMAT_SNAPPY_FRAMED);
    mimeTypeMap.put("application/x-lz4-framed", COMPRESSION_FORMAT_LZ4_FRAMED);
    this.compressionFormatMimeTypeMap = Collections.unmodifiableMap(mimeTypeMap);
}
 
Example #18
Source File: MockProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Relationship> getAvailableRelationships() {
    if (!(component instanceof Processor)) {
        return Collections.emptySet();
    }

    final Set<Relationship> relationships = new HashSet<>(((Processor) component).getRelationships());
    relationships.removeAll(unavailableRelationships);
    return relationships;
}
 
Example #19
Source File: DistributeLoad.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void updateWeightedRelationships(final Map<Integer, Integer> weightings) {
    final List<Relationship> relationshipList = new ArrayList<>();
    for (final Map.Entry<Integer, Integer> entry : weightings.entrySet()) {
        final String relationshipName = String.valueOf(entry.getKey());
        final Relationship relationship = new Relationship.Builder().name(relationshipName).build();
        for (int i = 0; i < entry.getValue(); i++) {
            relationshipList.add(relationship);
        }
    }

    this.weightedRelationshipListRef.set(Collections.unmodifiableList(relationshipList));
}
 
Example #20
Source File: MockProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public void setConnections(final Set<Relationship> connections) {
    if (connections == null) {
        this.connections = Collections.emptySet();
    } else {
        this.connections = Collections.unmodifiableSet(connections);
    }
}
 
Example #21
Source File: PutHBaseCell.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Relationship> getRelationships() {
    final Set<Relationship> rels = new HashSet<>();
    rels.add(REL_SUCCESS);
    rels.add(REL_FAILURE);
    return rels;
}
 
Example #22
Source File: PutEmail.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(SMTP_HOSTNAME);
    properties.add(SMTP_PORT);
    properties.add(SMTP_USERNAME);
    properties.add(SMTP_PASSWORD);
    properties.add(SMTP_AUTH);
    properties.add(SMTP_TLS);
    properties.add(SMTP_SOCKET_FACTORY);
    properties.add(HEADER_XMAILER);
    properties.add(CONTENT_TYPE);
    properties.add(FROM);
    properties.add(TO);
    properties.add(CC);
    properties.add(BCC);
    properties.add(SUBJECT);
    properties.add(MESSAGE);
    properties.add(ATTACH_FILE);
    properties.add(INCLUDE_ALL_ATTRIBUTES);
    this.properties = Collections.unmodifiableList(properties);

    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    relationships.add(REL_FAILURE);
    this.relationships = Collections.unmodifiableSet(relationships);
}
 
Example #23
Source File: ValidateXml.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(SCHEMA_FILE);
    this.properties = Collections.unmodifiableList(properties);

    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_VALID);
    relationships.add(REL_INVALID);
    this.relationships = Collections.unmodifiableSet(relationships);
}
 
Example #24
Source File: ConvertCharacterSet.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    this.relationships = Collections.unmodifiableSet(relationships);

    final List<PropertyDescriptor> properties = new ArrayList<>();
    properties.add(INPUT_CHARSET);
    properties.add(OUTPUT_CHARSET);
    this.properties = Collections.unmodifiableList(properties);
}
 
Example #25
Source File: ExtractEmailAttachments.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_ATTACHMENTS);
    relationships.add(REL_ORIGINAL);
    relationships.add(REL_FAILURE);
    this.relationships = Collections.unmodifiableSet(relationships);

    final List<PropertyDescriptor> descriptors = new ArrayList<>();

    this.descriptors = Collections.unmodifiableList(descriptors);
}
 
Example #26
Source File: ConnectableProcessContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Relationship> getAvailableRelationships() {
    for (final Connection connection : connectable.getConnections()) {
        if (connection.getFlowFileQueue().isFull()) {
            return Collections.emptySet();
        }
    }

    final Collection<Relationship> relationships = connectable.getRelationships();
    if (relationships instanceof Set) {
        return (Set<Relationship>) relationships;
    }
    return new HashSet<>(connectable.getRelationships());
}
 
Example #27
Source File: FetchDistributedMapCache.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public FetchDistributedMapCache() {
    final Set<Relationship> rels = new HashSet<>();
    rels.add(REL_SUCCESS);
    rels.add(REL_NOT_FOUND);
    rels.add(REL_FAILURE);
    relationships = Collections.unmodifiableSet(rels);
}
 
Example #28
Source File: ExtractHL7Attributes.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Relationship> getRelationships() {
    final Set<Relationship> relationships = new HashSet<>();
    relationships.add(REL_SUCCESS);
    relationships.add(REL_FAILURE);
    return relationships;
}
 
Example #29
Source File: StandardProcessorNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void setAutoTerminatedRelationships(final Set<Relationship> terminate) {
    if (isRunning()) {
        throw new IllegalStateException("Cannot modify Processor configuration while the Processor is running");
    }

    for (final Relationship rel : terminate) {
        if (!getConnections(rel).isEmpty()) {
            throw new IllegalStateException("Cannot mark relationship '" + rel.getName()
                    + "' as auto-terminated because Connection already exists with this relationship");
        }
    }
    undefinedRelationshipsToTerminate.set(new HashSet<>(terminate));
}
 
Example #30
Source File: RuleEngineProcessor.java    From NiFi-Rule-engine-processor with Apache License 2.0 5 votes vote down vote up
@Override
protected void init(final ProcessorInitializationContext context) {
	log = getLogger();
	log.debug("Init MatrixBI's RuleEngineProcesor");

	final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
     descriptors.add(DRL_PATH);
    this.descriptors = Collections.unmodifiableList(descriptors);

    final Set<Relationship> relationships = new HashSet<Relationship>();
     relationships.add(SUCCESS);
     relationships.add(FAILD);
    this.relationships = Collections.unmodifiableSet(relationships);
}