<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: nifi custom processor - onTrigger in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214215#M60137</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/17476/gugur.html" nodeid="17476"&gt;@Gu Gur&lt;/A&gt; Since your processor has INPUT_FORBIDDEN, you can never have flow files coming in to your processor, so you should remove the beginning of onTrigger where you have:&lt;/P&gt;&lt;PRE&gt;FlowFile flowFile = aSession.get();
if(flowFile ==null){
return;
}&lt;/PRE&gt;&lt;P&gt;That will always return and exit your onTrigger because there are no flow files.&lt;/P&gt;&lt;P&gt;Instead you will want to create a new flow file like:&lt;/P&gt;&lt;PRE&gt;FlowFile flowFile = session.create();&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Apr 2017 04:04:30 GMT</pubDate>
    <dc:creator>bbende</dc:creator>
    <dc:date>2017-04-28T04:04:30Z</dc:date>
    <item>
      <title>nifi custom processor - onTrigger</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214214#M60136</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I created custom processor, added loging for onTrigger, init, onScheduled methods.&lt;/P&gt;&lt;P&gt;But onTrigger never called. When I press Run in Nifi GUI, I see onScheduled method called, but not onTrigger.&lt;/P&gt;&lt;P&gt;Thank you for your help.&lt;/P&gt;&lt;P&gt;My code example:&lt;/P&gt;&lt;PRE&gt;@TriggerSerially
@InputRequirement(Requirement.INPUT_FORBIDDEN)



	public static final PropertyDescriptor SCAN_PORT = new PropertyDescriptor.Builder().name("Port")
			.description("Scan port").defaultValue("8080").required(true)
			.addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();


	public static final Relationship REL_FOUND = new Relationship.Builder().name("found")
			.description("Found host with given port").build();


	private List&amp;lt;PropertyDescriptor&amp;gt; descriptors;


	private Set&amp;lt;Relationship&amp;gt; relationships;


	private static HostScanner hostScanner;


	@Override
	protected void init(final ProcessorInitializationContext context) {
		final List&amp;lt;PropertyDescriptor&amp;gt; descriptors = new ArrayList&amp;lt;PropertyDescriptor&amp;gt;();
		descriptors.add(SCAN_PORT);
		this.descriptors = Collections.unmodifiableList(descriptors);


		final Set&amp;lt;Relationship&amp;gt; relationships = new HashSet&amp;lt;Relationship&amp;gt;();
		relationships.add(REL_FOUND);
		this.relationships = Collections.unmodifiableSet(relationships);
		this.getLogger().info("[INFO] HostDiscoveryProcessor init");


		hostScanner = new HostScanner();
		hostScanner.setLogger(getLogger());
	}


	@Override
	public Set&amp;lt;Relationship&amp;gt; getRelationships() {
		return this.relationships;
	}


	@Override
	public final List&amp;lt;PropertyDescriptor&amp;gt; getSupportedPropertyDescriptors() {
		return descriptors;
	}


	@OnScheduled
	public void onScheduled(final ProcessContext context) {
		this.getLogger().info("[INFO] HostDiscoveryProcessor onScheduled");
		final String scanPort = context.getProperty(SCAN_PORT).getValue();
		hostScanner.setPort(Integer.parseInt(scanPort));


	}


	@Override
	public void onTrigger(final ProcessContext context, final ProcessSession aSession) throws ProcessException {
		FlowFile flowFile = aSession.get();
		if (flowFile == null) {
			return;
		}
		// Logger logger = Logger.getLogger(MyClass.class.getName());
		this.getLogger().info("[INFO] HostDiscoveryProcessor onTrigger - start scan");
		List&amp;lt;String&amp;gt; ips = hostScanner.scan();
		this.getLogger().info("[INFO] Scan completed");
		
		flowFile = aSession.write(flowFile, new OutputStreamCallback() {			
			@Override
			public void process(OutputStream aStream) throws IOException {
				 aStream.write(listToBytes(ips));
				
			}
		});
		aSession.transfer(flowFile, REL_FOUND);
		aSession.commit();
	}
&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 02:40:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214214#M60136</guid>
      <dc:creator>gugur</dc:creator>
      <dc:date>2017-04-28T02:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: nifi custom processor - onTrigger</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214215#M60137</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/17476/gugur.html" nodeid="17476"&gt;@Gu Gur&lt;/A&gt; Since your processor has INPUT_FORBIDDEN, you can never have flow files coming in to your processor, so you should remove the beginning of onTrigger where you have:&lt;/P&gt;&lt;PRE&gt;FlowFile flowFile = aSession.get();
if(flowFile ==null){
return;
}&lt;/PRE&gt;&lt;P&gt;That will always return and exit your onTrigger because there are no flow files.&lt;/P&gt;&lt;P&gt;Instead you will want to create a new flow file like:&lt;/P&gt;&lt;PRE&gt;FlowFile flowFile = session.create();&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Apr 2017 04:04:30 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214215#M60137</guid>
      <dc:creator>bbende</dc:creator>
      <dc:date>2017-04-28T04:04:30Z</dc:date>
    </item>
    <item>
      <title>Re: nifi custom processor - onTrigger</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214216#M60138</link>
      <description>&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2017 14:55:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/nifi-custom-processor-onTrigger/m-p/214216#M60138</guid>
      <dc:creator>gugur</dc:creator>
      <dc:date>2017-04-28T14:55:50Z</dc:date>
    </item>
  </channel>
</rss>

