Search in sources :

Example 71 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class StandardProcessorNode method getRelationship.

/**
 * @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(processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }
    for (final Relationship rel : relationships) {
        if (rel.equals(specRel)) {
            returnRel = rel;
            break;
        }
    }
    return returnRel;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) Processor(org.apache.nifi.processor.Processor) Relationship(org.apache.nifi.processor.Relationship) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder)

Example 72 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class RepositoryContext method isAnyRelationshipAvailable.

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;
}
Also used : Relationship(org.apache.nifi.processor.Relationship) Connection(org.apache.nifi.connectable.Connection)

Example 73 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class AbstractBinlogEventWriter method writeEvent.

// Default implementation for binlog events
@Override
public long writeEvent(ProcessSession session, String transitUri, T eventInfo, long currentSequenceId, Relationship relationship) {
    FlowFile flowFile = session.create();
    flowFile = session.write(flowFile, (outputStream) -> {
        super.startJson(outputStream, eventInfo);
        writeJson(eventInfo);
        // Nothing in the body
        super.endJson();
    });
    flowFile = session.putAllAttributes(flowFile, getCommonAttributes(currentSequenceId, eventInfo));
    session.transfer(flowFile, relationship);
    session.getProvenanceReporter().receive(flowFile, transitUri);
    return currentSequenceId + 1;
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) AbstractEventWriter(org.apache.nifi.cdc.event.io.AbstractEventWriter) Relationship(org.apache.nifi.processor.Relationship) Map(java.util.Map) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) HashMap(java.util.HashMap) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) BinlogEventInfo(org.apache.nifi.cdc.mysql.event.BinlogEventInfo) FlowFile(org.apache.nifi.flowfile.FlowFile)

Example 74 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class AbstractBinlogTableEventWriter method writeEvent.

// Default implementation for table-related binlog events
@Override
public long writeEvent(ProcessSession session, String transitUri, T eventInfo, long currentSequenceId, Relationship relationship) {
    FlowFile flowFile = session.create();
    flowFile = session.write(flowFile, (outputStream) -> {
        super.startJson(outputStream, eventInfo);
        writeJson(eventInfo);
        // Nothing in the body
        super.endJson();
    });
    flowFile = session.putAllAttributes(flowFile, getCommonAttributes(currentSequenceId, eventInfo));
    session.transfer(flowFile, relationship);
    session.getProvenanceReporter().receive(flowFile, transitUri);
    return currentSequenceId + 1;
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) BinlogTableEventInfo(org.apache.nifi.cdc.mysql.event.BinlogTableEventInfo) Relationship(org.apache.nifi.processor.Relationship) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) FlowFile(org.apache.nifi.flowfile.FlowFile)

Example 75 with Relationship

use of org.apache.nifi.processor.Relationship in project nifi by apache.

the class DeleteRowsWriter method writeEvent.

/**
 * 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 DeleteRowsEventInfo eventInfo, final long currentSequenceId, Relationship relationship) {
    final AtomicLong seqId = new AtomicLong(currentSequenceId);
    for (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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) DeleteRowsEventInfo(org.apache.nifi.cdc.mysql.event.DeleteRowsEventInfo) FlowFile(org.apache.nifi.flowfile.FlowFile) Relationship(org.apache.nifi.processor.Relationship) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) BitSet(java.util.BitSet) ColumnDefinition(org.apache.nifi.cdc.event.ColumnDefinition) MySQLCDCUtils(org.apache.nifi.cdc.mysql.event.MySQLCDCUtils) Serializable(java.io.Serializable) FlowFile(org.apache.nifi.flowfile.FlowFile) AtomicLong(java.util.concurrent.atomic.AtomicLong) Serializable(java.io.Serializable) BitSet(java.util.BitSet)

Aggregations

Relationship (org.apache.nifi.processor.Relationship)106 ArrayList (java.util.ArrayList)41 HashSet (java.util.HashSet)40 HashMap (java.util.HashMap)32 FlowFile (org.apache.nifi.flowfile.FlowFile)32 Map (java.util.Map)31 IOException (java.io.IOException)26 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)26 Test (org.junit.Test)23 List (java.util.List)20 Set (java.util.Set)19 Connection (org.apache.nifi.connectable.Connection)18 TestRunner (org.apache.nifi.util.TestRunner)18 ProcessException (org.apache.nifi.processor.exception.ProcessException)17 ProcessSession (org.apache.nifi.processor.ProcessSession)15 InputStream (java.io.InputStream)14 DynamicRelationship (org.apache.nifi.annotation.behavior.DynamicRelationship)12 Processor (org.apache.nifi.processor.Processor)12 Collections (java.util.Collections)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)10