[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2017-01-06 Thread ASF subversion and git services (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15805561#comment-15805561
 ] 

ASF subversion and git services commented on NIFI-1458:
---

Commit 675f4f544cb87bef0ec51b8dee5023088ad224ad in nifi's branch 
refs/heads/master from [~mattyb149]
[ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=675f4f5 ]

NIFI-1458: Added ScriptedReportingTask

This closes #1045.

Signed-off-by: Andy LoPresto 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15805380#comment-15805380
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on the issue:

https://github.com/apache/nifi/pull/1045
  
Also I noticed the DynamicProperty annotation is missing, will add that too.



> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15805336#comment-15805336
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on the issue:

https://github.com/apache/nifi/pull/1045
  
Absolutely will add Restricted, good catch thanks!


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2017-01-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15805312#comment-15805312
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on the issue:

https://github.com/apache/nifi/pull/1045
  
@mattyb149 everything looks great; I tried it out and was able to write a 
simple Groovy script and run it as a reporting task. One thing is that since 
you submitted this, we've added the `Restricted` designator for "dangerous" 
processors/controller services/reporting tasks, and I feel this counts. If you 
add that, I'll merge this in. Thanks. 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-11-08 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15649294#comment-15649294
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on the issue:

https://github.com/apache/nifi/pull/1045
  
I think most everything was hashed out sufficiently. If you make the 
changes you indicated above, I'll run locally, verify `contrib-check`, and 
test, and provide the +1. 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
> Fix For: 1.1.0
>
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-11-08 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15649292#comment-15649292
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r87113621
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java
 ---
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.reporting.script;
+
+import com.yammer.metrics.core.VirtualMachineMetrics;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.script.ScriptEngineConfigurator;
+import org.apache.nifi.processors.script.ScriptUtils;
+import org.apache.nifi.reporting.AbstractReportingTask;
+import org.apache.nifi.reporting.ReportingContext;
+import org.apache.nifi.util.StringUtils;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A Reporting task whose body is provided by a script (via supported 
JSR-223 script engines)
+ */
+@Tags({"reporting", "script", "execute", "groovy", "python", "jython", 
"jruby", "ruby", "javascript", "js", "lua", "luaj"})
+@CapabilityDescription("Provides reporting and status information to a 
script. ReportingContext, ComponentLog, and VirtualMachineMetrics objects are 
made available "
++ "as variables (context, log, and vmMetrics, respectively) to the 
script for further processing. The context makes various information available 
such "
++ "as events, provenance, bulletins, controller services, process 
groups, Java Virtual Machine metrics, etc.")
+public class ScriptedReportingTask extends AbstractReportingTask {
+
+protected volatile ScriptUtils scriptUtils = new ScriptUtils();
+protected volatile String scriptToRun = null;
+protected volatile VirtualMachineMetrics vmMetrics;
+
+/**
+ * Returns a list of property descriptors supported by this processor. 
The list always includes properties such as
+ * script engine name, script file name, script body name, script 
arguments, and an external module path. If the
+ * scripted processor also defines supported properties, those are 
added to the list as well.
+ *
+ * @return a List of PropertyDescriptor objects supported by this 
processor
+ */
+@Override
+protected List getSupportedPropertyDescriptors() {
+synchronized (scriptUtils.isInitialized) {
+if (!scriptUtils.isInitialized.get()) {
+scriptUtils.createResources();
+}
+}
+
+return Collections.unmodifiableList(scriptUtils.descriptors);
+}
+
+/**
+ * Returns a PropertyDescriptor for the given name. This is for the 
user to be able to define their own properties
+ * which will be available as variables in the script
+ *
+ * 

[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15608471#comment-15608471
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r85123335
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptUtils.java
 ---
@@ -46,23 +44,19 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
-import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationContext;
 import org.apache.nifi.components.ValidationResult;
 import org.apache.nifi.components.Validator;
-import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
 import org.apache.nifi.processor.Relationship;
 import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.util.StringUtils;
 
 /**
- * This class contains variables and methods common to scripting processors
+ * This class contains variables and methods common to scripting 
processors, reporting tasks, etc.
  */
-@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
-description = "Scripts can store and retrieve state using the 
State Management APIs. Consult the State Manager section of the Developer's 
Guide for more details.")
-public abstract class AbstractScriptProcessor extends 
AbstractSessionFactoryProcessor {
+public class ScriptUtils {
--- End diff --

I can also change the public members to private and change the rest of the 
classes to use the accessors. I chose not to only to make the changes easier to 
see (and probably a bit of laziness)


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15608439#comment-15608439
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r85119526
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java
 ---
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.reporting.script;
+
+import com.yammer.metrics.core.VirtualMachineMetrics;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.script.ScriptEngineConfigurator;
+import org.apache.nifi.processors.script.ScriptUtils;
+import org.apache.nifi.reporting.AbstractReportingTask;
+import org.apache.nifi.reporting.ReportingContext;
+import org.apache.nifi.util.StringUtils;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A Reporting task whose body is provided by a script (via supported 
JSR-223 script engines)
+ */
+@Tags({"reporting", "script", "execute", "groovy", "python", "jython", 
"jruby", "ruby", "javascript", "js", "lua", "luaj"})
+@CapabilityDescription("Provides reporting and status information to a 
script. ReportingContext, ComponentLog, and VirtualMachineMetrics objects are 
made available "
++ "as variables (context, log, and vmMetrics, respectively) to the 
script for further processing. The context makes various information available 
such "
++ "as events, provenance, bulletins, controller services, process 
groups, Java Virtual Machine metrics, etc.")
+public class ScriptedReportingTask extends AbstractReportingTask {
+
+protected volatile ScriptUtils scriptUtils = new ScriptUtils();
+protected volatile String scriptToRun = null;
+protected volatile VirtualMachineMetrics vmMetrics;
+
+/**
+ * Returns a list of property descriptors supported by this processor. 
The list always includes properties such as
+ * script engine name, script file name, script body name, script 
arguments, and an external module path. If the
+ * scripted processor also defines supported properties, those are 
added to the list as well.
+ *
+ * @return a List of PropertyDescriptor objects supported by this 
processor
+ */
+@Override
+protected List getSupportedPropertyDescriptors() {
+synchronized (scriptUtils.isInitialized) {
+if (!scriptUtils.isInitialized.get()) {
+scriptUtils.createResources();
+}
+}
+
+return Collections.unmodifiableList(scriptUtils.descriptors);
+}
+
+/**
+ * Returns a PropertyDescriptor for the given name. This is for the 
user to be able to define their own properties
+ * which will be available as variables in the script
+ *
+ * 

[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15608434#comment-15608434
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r85119222
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptUtils.java
 ---
@@ -46,23 +44,19 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
-import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationContext;
 import org.apache.nifi.components.ValidationResult;
 import org.apache.nifi.components.Validator;
-import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
 import org.apache.nifi.processor.Relationship;
 import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.util.StringUtils;
 
 /**
- * This class contains variables and methods common to scripting processors
+ * This class contains variables and methods common to scripting 
processors, reporting tasks, etc.
  */
-@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
-description = "Scripts can store and retrieve state using the 
State Management APIs. Consult the State Manager section of the Developer's 
Guide for more details.")
-public abstract class AbstractScriptProcessor extends 
AbstractSessionFactoryProcessor {
+public class ScriptUtils {
--- End diff --

How do you picture the split? If I move the PropertyDescriptors and 
Relationships out, then I possibly should update all the state container logic 
such that those are passed in vs. used from the static constants class. I took 
quite a few liberties with the OO on this because it would involve a large 
amount of refactor and I didn't want to risk introducing more bugs. If you've 
got a good proposal for this though, I'd be happy to make the change


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15608414#comment-15608414
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r85117619
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ExecuteScript.java
 ---
@@ -116,30 +139,29 @@ protected PropertyDescriptor 
getSupportedDynamicPropertyDescriptor(final String
  */
 @OnScheduled
 public void setup(final ProcessContext context) {
-scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue();
-scriptPath = 
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue();
-scriptBody = context.getProperty(SCRIPT_BODY).getValue();
-String modulePath = context.getProperty(MODULES).getValue();
+scriptUtils.scriptEngineName = 
context.getProperty(ScriptUtils.SCRIPT_ENGINE).getValue();
--- End diff --

Will do


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-26 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15608393#comment-15608393
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r85116446
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ExecuteScript.java
 ---
@@ -66,8 +85,8 @@
 @Override
 public Set getRelationships() {
 final Set relationships = new HashSet<>();
-relationships.add(REL_SUCCESS);
-relationships.add(REL_FAILURE);
+relationships.add(ScriptUtils.REL_SUCCESS);
--- End diff --

Yes, I only changed them because I kept the class-level versions of them 
for backwards compatibility


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582853#comment-15582853
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83522047
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ExecuteScript.java
 ---
@@ -116,30 +139,29 @@ protected PropertyDescriptor 
getSupportedDynamicPropertyDescriptor(final String
  */
 @OnScheduled
 public void setup(final ProcessContext context) {
-scriptEngineName = context.getProperty(SCRIPT_ENGINE).getValue();
-scriptPath = 
context.getProperty(SCRIPT_FILE).evaluateAttributeExpressions().getValue();
-scriptBody = context.getProperty(SCRIPT_BODY).getValue();
-String modulePath = context.getProperty(MODULES).getValue();
+scriptUtils.scriptEngineName = 
context.getProperty(ScriptUtils.SCRIPT_ENGINE).getValue();
--- End diff --

Could this initialization process be encapsulated in a method (either here 
or within `ScriptUtils`) that accepts the `context` as a parameter? Seems like 
a minor logic leak to iterate over the constants here. 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582854#comment-15582854
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83524883
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptUtils.java
 ---
@@ -46,23 +44,19 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
-import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationContext;
 import org.apache.nifi.components.ValidationResult;
 import org.apache.nifi.components.Validator;
-import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
 import org.apache.nifi.processor.Relationship;
 import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.util.StringUtils;
 
 /**
- * This class contains variables and methods common to scripting processors
+ * This class contains variables and methods common to scripting 
processors, reporting tasks, etc.
  */
-@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
-description = "Scripts can store and retrieve state using the 
State Management APIs. Consult the State Manager section of the Developer's 
Guide for more details.")
-public abstract class AbstractScriptProcessor extends 
AbstractSessionFactoryProcessor {
+public class ScriptUtils {
--- End diff --

Sorry to spam; I think splitting them would also help mitigate your 
concerns about exposing public members, as they would be fields of a POJO with 
accessors. 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582852#comment-15582852
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83522194
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptUtils.java
 ---
@@ -46,23 +44,19 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
-import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationContext;
 import org.apache.nifi.components.ValidationResult;
 import org.apache.nifi.components.Validator;
-import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
 import org.apache.nifi.processor.Relationship;
 import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.util.StringUtils;
 
 /**
- * This class contains variables and methods common to scripting processors
+ * This class contains variables and methods common to scripting 
processors, reporting tasks, etc.
  */
-@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
-description = "Scripts can store and retrieve state using the 
State Management APIs. Consult the State Manager section of the Developer's 
Guide for more details.")
-public abstract class AbstractScriptProcessor extends 
AbstractSessionFactoryProcessor {
+public class ScriptUtils {
--- End diff --

I'm a little confused -- it seems like this class both contains static 
constants and utility methods (which I would expect to be together) as well 
acting as a state container for dynamic values necessary for the 
`ExecuteScript` or `InvokeScriptedProcessor` components. Am I missing something?


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582849#comment-15582849
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83518147
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ExecuteScript.java
 ---
@@ -66,8 +85,8 @@
 @Override
 public Set getRelationships() {
 final Set relationships = new HashSet<>();
-relationships.add(REL_SUCCESS);
-relationships.add(REL_FAILURE);
+relationships.add(ScriptUtils.REL_SUCCESS);
--- End diff --

Can these two lines just reference the local `REL_SUCCESS` and 
`REL_FAILURE` rather than the external static variables?


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582855#comment-15582855
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83525123
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/reporting/script/ScriptedReportingTask.java
 ---
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nifi.reporting.script;
+
+import com.yammer.metrics.core.VirtualMachineMetrics;
+import org.apache.commons.io.IOUtils;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.annotation.lifecycle.OnScheduled;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.logging.ComponentLog;
+import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.processors.script.ScriptEngineConfigurator;
+import org.apache.nifi.processors.script.ScriptUtils;
+import org.apache.nifi.reporting.AbstractReportingTask;
+import org.apache.nifi.reporting.ReportingContext;
+import org.apache.nifi.util.StringUtils;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A Reporting task whose body is provided by a script (via supported 
JSR-223 script engines)
+ */
+@Tags({"reporting", "script", "execute", "groovy", "python", "jython", 
"jruby", "ruby", "javascript", "js", "lua", "luaj"})
+@CapabilityDescription("Provides reporting and status information to a 
script. ReportingContext, ComponentLog, and VirtualMachineMetrics objects are 
made available "
++ "as variables (context, log, and vmMetrics, respectively) to the 
script for further processing. The context makes various information available 
such "
++ "as events, provenance, bulletins, controller services, process 
groups, Java Virtual Machine metrics, etc.")
+public class ScriptedReportingTask extends AbstractReportingTask {
+
+protected volatile ScriptUtils scriptUtils = new ScriptUtils();
+protected volatile String scriptToRun = null;
+protected volatile VirtualMachineMetrics vmMetrics;
+
+/**
+ * Returns a list of property descriptors supported by this processor. 
The list always includes properties such as
+ * script engine name, script file name, script body name, script 
arguments, and an external module path. If the
+ * scripted processor also defines supported properties, those are 
added to the list as well.
+ *
+ * @return a List of PropertyDescriptor objects supported by this 
processor
+ */
+@Override
+protected List getSupportedPropertyDescriptors() {
+synchronized (scriptUtils.isInitialized) {
+if (!scriptUtils.isInitialized.get()) {
+scriptUtils.createResources();
+}
+}
+
+return Collections.unmodifiableList(scriptUtils.descriptors);
+}
+
+/**
+ * Returns a PropertyDescriptor for the given name. This is for the 
user to be able to define their own properties
+ * which will be available as variables in the script
+ *
+ * 

[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15582851#comment-15582851
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on a diff in the pull request:

https://github.com/apache/nifi/pull/1045#discussion_r83524685
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/ScriptUtils.java
 ---
@@ -46,23 +44,19 @@
 import javax.script.ScriptEngineManager;
 import javax.script.ScriptException;
 
-import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.AllowableValue;
 import org.apache.nifi.components.PropertyDescriptor;
 import org.apache.nifi.components.ValidationContext;
 import org.apache.nifi.components.ValidationResult;
 import org.apache.nifi.components.Validator;
-import org.apache.nifi.processor.AbstractSessionFactoryProcessor;
 import org.apache.nifi.processor.Relationship;
 import org.apache.nifi.processor.util.StandardValidators;
 import org.apache.nifi.util.StringUtils;
 
 /**
- * This class contains variables and methods common to scripting processors
+ * This class contains variables and methods common to scripting 
processors, reporting tasks, etc.
  */
-@Stateful(scopes = {Scope.LOCAL, Scope.CLUSTER},
-description = "Scripts can store and retrieve state using the 
State Management APIs. Consult the State Manager section of the Developer's 
Guide for more details.")
-public abstract class AbstractScriptProcessor extends 
AbstractSessionFactoryProcessor {
+public class ScriptUtils {
--- End diff --

I'm now realizing this is because it was previously the parent class for 
the processors. As much as it pains me to ask, I think the mental benefit of 
separating state container logic from the util methods & static constants 
outweighs the complexity of introducing a second class. Interested to hear from 
other people though; this may just be a personal preference. 


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-10-14 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15576898#comment-15576898
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

Github user alopresto commented on the issue:

https://github.com/apache/nifi/pull/1045
  
Reviewing...


> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask

2016-09-22 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15513404#comment-15513404
 ] 

ASF GitHub Bot commented on NIFI-1458:
--

GitHub user mattyb149 opened a pull request:

https://github.com/apache/nifi/pull/1045

NIFI-1458: Added ScriptedReportingTask

I refactored AbstractScriptProcessor into ScriptUtils, so the functionality 
could be shared between scripting processors and scripting reporting tasks. I 
admit the use of ScriptUtils is not pure OO (public members, e.g.) but I wanted 
to keep the spirit of what the processors did when this was part of its parent 
class (since we don't have traits or multiple inheritance).

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/mattyb149/nifi NIFI-1458

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi/pull/1045.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #1045


commit cd5a523b41cbe81a602e4d0f10df38b6a58a6779
Author: Matt Burgess 
Date:   2016-09-22T14:13:40Z

NIFI-1458: Added ScriptedReportingTask




> Add scriptable ReportingTask
> 
>
> Key: NIFI-1458
> URL: https://issues.apache.org/jira/browse/NIFI-1458
> Project: Apache NiFi
>  Issue Type: Improvement
>Reporter: Matt Burgess
>Assignee: Matt Burgess
>
> Now that NIFI-210 adds scriptable Processors (and scripted onTrigger bodies), 
> a great extension would be to add a scriptable ReportingTask. This would 
> enable users to script their own ReportingTasks using the various supported 
> scripting languages.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)