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<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 -- Obviously the name is provided by the user at runtime, but should we still try to define a `displayName` for the `PropertyDescriptor`? I could see three possibilities: * `name` and `displayName` are identical -- not much value * `name` is as provided, `displayName` is the parameter passed through a `humanize()`-type method (see below) * `displayName` is as provided, `name` is the parameter passed through a `symbolize()`-type method (see below) The transform methods `humanize()`/`symbolize()` could be as simple as title-casing and adding/removing spaces at word boundary guesses. I'm not sure how much energy this is worth investing, as these property names are not constants which will be retained across instances of the processor, but I think they still would lose the state persisted in the `flow.xml.gz` if it was somehow modified.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---