use of org.apache.nifi.processor.Processor in project nifi by apache.
the class InvokeScriptedProcessor method getRelationships.
/**
* 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);
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class InvokeScriptedProcessor method onPropertyModified.
/**
* Handles changes to this processor's properties. If changes are made to
* script- or engine-related properties, the script will be reloaded.
*
* @param descriptor of the modified property
* @param oldValue non-null property value (previous)
* @param newValue the new property value or if null indicates the property
*/
@Override
public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
validationResults.set(null);
final ComponentLog logger = getLogger();
final Processor instance = processor.get();
if (ScriptingComponentUtils.SCRIPT_FILE.equals(descriptor) || ScriptingComponentUtils.SCRIPT_BODY.equals(descriptor) || ScriptingComponentUtils.MODULES.equals(descriptor) || scriptingComponentHelper.SCRIPT_ENGINE.equals(descriptor)) {
scriptNeedsReload.set(true);
// reset engine. This happens only when a processor is stopped, so there won't be any performance impact in run-time.
scriptEngine = null;
} else if (instance != null) {
// If the script provides a Processor, call its onPropertyModified() method
try {
instance.onPropertyModified(descriptor, oldValue, newValue);
} catch (final Exception e) {
final String message = "Unable to invoke onPropertyModified from script Processor: " + e;
logger.error(message, e);
}
}
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestPutSyslog method testIOExceptionCreatingConnection.
@Test
public void testIOExceptionCreatingConnection() throws IOException {
final String pri = "34";
final String version = "1";
final String stamp = "2003-10-11T22:14:15.003Z";
final String host = "mymachine.example.com";
final String body = "su - ID47 - BOM'su root' failed for lonvick on /dev/pts/8";
Processor proc = new MockCreationErrorPutSyslog(new MockErrorSender(), 1);
runner = TestRunners.newTestRunner(proc);
runner.setProperty(PutSyslog.HOSTNAME, "localhost");
runner.setProperty(PutSyslog.PORT, "12345");
runner.setProperty(PutSyslog.BATCH_SIZE, "1");
runner.setProperty(PutSyslog.MSG_PRIORITY, pri);
runner.setProperty(PutSyslog.MSG_VERSION, version);
runner.setProperty(PutSyslog.MSG_TIMESTAMP, stamp);
runner.setProperty(PutSyslog.MSG_HOSTNAME, host);
runner.setProperty(PutSyslog.MSG_BODY, body);
// the first run will throw IOException when calling send so the connection won't be re-qeued
// the second run will try to create a new connection but throw an exception which should be caught and route files to failure
runner.enqueue("incoming data".getBytes(Charset.forName("UTF-8")));
runner.enqueue("incoming data".getBytes(Charset.forName("UTF-8")));
runner.run(2);
runner.assertAllFlowFilesTransferred(PutSyslog.REL_FAILURE, 2);
Assert.assertEquals(0, sender.messages.size());
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestMockProcessSession method testRejectTransferNewlyCreatedFileToSelf.
@Test(expected = IllegalArgumentException.class)
public void testRejectTransferNewlyCreatedFileToSelf() {
final Processor processor = new PoorlyBehavedProcessor();
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor);
final FlowFile ff1 = session.createFlowFile("hello, world".getBytes());
// this should throw an exception because we shouldn't allow a newly created flowfile to get routed back to self
session.transfer(ff1);
}
use of org.apache.nifi.processor.Processor in project nifi by apache.
the class TestMockProcessSession method testKeepPenalizedStatusAfterPuttingAttribute.
@Test
public void testKeepPenalizedStatusAfterPuttingAttribute() {
final Processor processor = new PoorlyBehavedProcessor();
final MockProcessSession session = new MockProcessSession(new SharedSessionState(processor, new AtomicLong(0L)), processor);
FlowFile ff1 = session.createFlowFile("hello, world".getBytes());
ff1 = session.penalize(ff1);
assertEquals(true, ff1.isPenalized());
ff1 = session.putAttribute(ff1, "hello", "world");
// adding attribute to flow file should not override the original penalized status
assertEquals(true, ff1.isPenalized());
}
Aggregations