Java Code Examples for org.apache.nifi.processor.Processor#getRelationships()

The following examples show how to use org.apache.nifi.processor.Processor#getRelationships() . 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: InvokeScriptedProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the valid relationships for this processor as supplied by the
 * script itself.
 *
 * @return a Set of Relationships supported by this processor
 */
@Override
public Set<Relationship> getRelationships() {
    final Set<Relationship> relationships = new HashSet<>();
    final Processor instance = processor.get();
    if (instance != null) {
        try {
            final Set<Relationship> rels = instance.getRelationships();
            if (rels != null && !rels.isEmpty()) {
                relationships.addAll(rels);
            }
        } catch (final Throwable t) {
            final ComponentLog logger = getLogger();
            final String message = "Unable to get relationships from scripted Processor: " + t;

            logger.error(message);
            if (logger.isDebugEnabled()) {
                logger.error(message, t);
            }
        }
    }
    return Collections.unmodifiableSet(relationships);
}
 
Example 2
Source File: HtmlProcessorDocumentationWriter.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a table describing the relations a processor has.
 *
 * @param processor the processor to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the xml
 */
private void writeRelationships(final Processor processor, final XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {

    writeSimpleElement(xmlStreamWriter, "h3", "Relationships: ");

    if (processor.getRelationships().size() > 0) {
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "relationships");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        for (Relationship relationship : processor.getRelationships()) {
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "td", relationship.getName());
            writeSimpleElement(xmlStreamWriter, "td", relationship.getDescription());
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
    } else {
        xmlStreamWriter.writeCharacters("This processor has no relationships.");
    }
}
 
Example 3
Source File: InvokeScriptedProcessor.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the valid relationships for this processor as supplied by the
 * script itself.
 *
 * @return a Set of Relationships supported by this processor
 */
@Override
public Set<Relationship> getRelationships() {
    final Set<Relationship> relationships = new HashSet<>();
    final Processor instance = processor.get();
    if (instance != null) {
        try {
            final Set<Relationship> rels = instance.getRelationships();
            if (rels != null && !rels.isEmpty()) {
                relationships.addAll(rels);
            }
        } catch (final Throwable t) {
            final ComponentLog logger = getLogger();
            final String message = "Unable to get relationships from scripted Processor: " + t;

            logger.error(message);
            if (logger.isDebugEnabled()) {
                logger.error(message, t);
            }
        }
    }
    return Collections.unmodifiableSet(relationships);
}
 
Example 4
Source File: HtmlProcessorDocumentationWriter.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Writes a table describing the relations a processor has.
 *
 * @param processor the processor to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the xml
 */
private void writeRelationships(final Processor processor, final XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {

    writeSimpleElement(xmlStreamWriter, "h3", "Relationships: ");

    if (processor.getRelationships().size() > 0) {
        xmlStreamWriter.writeStartElement("table");
        xmlStreamWriter.writeAttribute("id", "relationships");
        xmlStreamWriter.writeStartElement("tr");
        writeSimpleElement(xmlStreamWriter, "th", "Name");
        writeSimpleElement(xmlStreamWriter, "th", "Description");
        xmlStreamWriter.writeEndElement();

        for (Relationship relationship : processor.getRelationships()) {
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "td", relationship.getName());
            writeSimpleElement(xmlStreamWriter, "td", relationship.getDescription());
            xmlStreamWriter.writeEndElement();
        }
        xmlStreamWriter.writeEndElement();
    } else {
        xmlStreamWriter.writeCharacters("This processor has no relationships.");
    }
}
 
Example 5
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * @param relationshipName
 *            name
 * @return the relationship for this nodes processor for the given name or
 *         creates a new relationship for the given name
 */
@Override
public Relationship getRelationship(final String relationshipName) {
    final Relationship specRel = new Relationship.Builder().name(relationshipName).build();
    Relationship returnRel = specRel;

    final Set<Relationship> relationships;
    final Processor processor = processorRef.get().getProcessor();
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getExtensionManager(), processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }

    for (final Relationship rel : relationships) {
        if (rel.equals(specRel)) {
            returnRel = rel;
            break;
        }
    }
    return returnRel;
}
 
Example 6
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
public Set<Relationship> getUndefinedRelationships() {
    final Set<Relationship> undefined = new HashSet<>();
    final Set<Relationship> relationships;
    final Processor processor = processorRef.get().getProcessor();
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getExtensionManager(), processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }

    if (relationships == null) {
        return undefined;
    }
    for (final Relationship relation : relationships) {
        final Set<Connection> connectionSet = this.connections.get(relation);
        if (connectionSet == null || connectionSet.isEmpty()) {
            undefined.add(relation);
        }
    }
    return undefined;
}
 
Example 7
Source File: TestJoltTransformJSON.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelationshipsCreated() throws IOException{
    Processor processor= new JoltTransformJSON();
    final TestRunner runner = TestRunners.newTestRunner(processor);
    final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
    runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
    runner.enqueue(JSON_INPUT);
    Set<Relationship> relationships = processor.getRelationships();
    assertTrue(relationships.contains(JoltTransformJSON.REL_FAILURE));
    assertTrue(relationships.contains(JoltTransformJSON.REL_SUCCESS));
    assertTrue(relationships.size() == 2);
}
 
Example 8
Source File: TestJoltTransformJSON.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelationshipsCreated() throws IOException{
    Processor processor= new JoltTransformJSON();
    final TestRunner runner = TestRunners.newTestRunner(processor);
    final String spec = new String(Files.readAllBytes(Paths.get("src/test/resources/TestJoltTransformJson/chainrSpec.json")));
    runner.setProperty(JoltTransformJSON.JOLT_SPEC, spec);
    runner.enqueue(JSON_INPUT);
    Set<Relationship> relationships = processor.getRelationships();
    assertTrue(relationships.contains(JoltTransformJSON.REL_FAILURE));
    assertTrue(relationships.contains(JoltTransformJSON.REL_SUCCESS));
    assertTrue(relationships.size() == 2);
}