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;
}
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());
}
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;
}
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();
}
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) {
}
}
Aggregations