Search in sources :

Example 11 with Relationship

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

the class RelationshipAuditor method createConnectDetails.

/**
 * Creates action details for connect/disconnect actions.
 *
 * @param connection connection
 * @param source source
 * @param relationships relationships
 * @param destination destinations
 * @return details
 */
public ConnectDetails createConnectDetails(final Connection connection, final Connectable source, final Collection<Relationship> relationships, final Connectable destination) {
    final Component sourceType = determineConnectableType(source);
    final Component destiantionType = determineConnectableType(destination);
    // format the relationship names
    Collection<String> relationshipNames = new HashSet<>(connection.getRelationships().size());
    for (final Relationship relationship : relationships) {
        relationshipNames.add(relationship.getName());
    }
    final String formattedRelationships = relationshipNames.isEmpty() ? StringUtils.EMPTY : StringUtils.join(relationshipNames, ", ");
    // create the connect details
    final FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
    connectDetails.setSourceId(source.getIdentifier());
    connectDetails.setSourceName(source.getName());
    connectDetails.setSourceType(sourceType);
    connectDetails.setRelationship(formattedRelationships);
    connectDetails.setDestinationId(destination.getIdentifier());
    connectDetails.setDestinationName(destination.getName());
    connectDetails.setDestinationType(destiantionType);
    return connectDetails;
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Relationship(org.apache.nifi.processor.Relationship) Component(org.apache.nifi.action.Component) HashSet(java.util.HashSet)

Example 12 with Relationship

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

the class TestFlowController method testCreateMissingProcessor.

@Test
public void testCreateMissingProcessor() throws ProcessorInstantiationException {
    final ProcessorNode procNode = controller.createProcessor("org.apache.nifi.NonExistingProcessor", "1234-Processor", systemBundle.getBundleDetails().getCoordinate());
    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());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

Example 13 with Relationship

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

the class DDLEventWriter method writeEvent.

@Override
public long writeEvent(ProcessSession session, String transitUri, DDLEventInfo eventInfo, long currentSequenceId, Relationship relationship) {
    FlowFile flowFile = session.create();
    flowFile = session.write(flowFile, (outputStream) -> {
        super.startJson(outputStream, eventInfo);
        super.writeJson(eventInfo);
        jsonGenerator.writeStringField("query", eventInfo.getQuery());
        super.endJson();
    });
    flowFile = session.putAllAttributes(flowFile, getCommonAttributes(currentSequenceId, eventInfo));
    session.transfer(flowFile, relationship);
    session.getProvenanceReporter().receive(flowFile, transitUri);
    return currentSequenceId + 1;
}
Also used : DDLEventInfo(org.apache.nifi.cdc.mysql.event.DDLEventInfo) FlowFile(org.apache.nifi.flowfile.FlowFile) Relationship(org.apache.nifi.processor.Relationship) ProcessSession(org.apache.nifi.processor.ProcessSession) FlowFile(org.apache.nifi.flowfile.FlowFile)

Example 14 with Relationship

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

the class UpdateRowsWriter 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 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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FlowFile(org.apache.nifi.flowfile.FlowFile) Relationship(org.apache.nifi.processor.Relationship) Map(java.util.Map) ProcessSession(org.apache.nifi.processor.ProcessSession) IOException(java.io.IOException) BitSet(java.util.BitSet) ColumnDefinition(org.apache.nifi.cdc.event.ColumnDefinition) UpdateRowsEventInfo(org.apache.nifi.cdc.mysql.event.UpdateRowsEventInfo) MySQLCDCUtils(org.apache.nifi.cdc.mysql.event.MySQLCDCUtils) Serializable(java.io.Serializable) FlowFile(org.apache.nifi.flowfile.FlowFile) AtomicLong(java.util.concurrent.atomic.AtomicLong) BitSet(java.util.BitSet) Map(java.util.Map)

Example 15 with Relationship

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

the class TestMockProcessSession method testTransferUnknownRelationship.

@Test
public void testTransferUnknownRelationship() {
    final Processor processor = new PoorlyBehavedProcessor();
    final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor);
    FlowFile ff1 = session.createFlowFile("hello, world".getBytes());
    final Relationship fakeRel = new Relationship.Builder().name("FAKE").build();
    try {
        session.transfer(ff1, fakeRel);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (final IllegalArgumentException ie) {
    }
    try {
        session.transfer(Collections.singleton(ff1), fakeRel);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (final IllegalArgumentException ie) {
    }
}
Also used : FlowFile(org.apache.nifi.flowfile.FlowFile) AtomicLong(java.util.concurrent.atomic.AtomicLong) Processor(org.apache.nifi.processor.Processor) AbstractProcessor(org.apache.nifi.processor.AbstractProcessor) Relationship(org.apache.nifi.processor.Relationship) Test(org.junit.Test)

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