You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/11/09 00:17:58 UTC
[jira] [Commented] (NIFI-1458) Add scriptable ReportingTask
[ https://issues.apache.org/jira/browse/NIFI-1458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=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<PropertyDescriptor> 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
+ *
+ * @param propertyDescriptorName used to lookup if any property descriptors exist for that name
+ * @return a PropertyDescriptor object corresponding to the specified dynamic property name
+ */
+ @Override
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return new PropertyDescriptor.Builder()
+ .name(propertyDescriptorName)
--- End diff --
I filed [NIFI-3006](https://issues.apache.org/jira/browse/NIFI-3006) to capture this. We can ignore it in this case until that Jira is worked on.
> 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)