[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2018-01-24 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2201#discussion_r163573373
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/resources/groovy/test_implementingabstractProcessor.groovy
 ---
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+import org.apache.nifi.components.PropertyDescriptor
+import org.apache.nifi.components.ValidationContext
+import org.apache.nifi.components.ValidationResult
+import org.apache.nifi.logging.ComponentLog
+import org.apache.nifi.processor.AbstractProcessor
+import org.apache.nifi.processor.ProcessContext
+import org.apache.nifi.processor.ProcessSession
+import org.apache.nifi.processor.ProcessSessionFactory
+import org.apache.nifi.processor.ProcessorInitializationContext
+import org.apache.nifi.processor.Relationship
+import org.apache.nifi.processor.exception.ProcessException
+
+class testImplementingAbstractProcessor extends AbstractProcessor {
--- End diff --

This should probably exercise more of the updated logic, such as having its 
own properties with validators, etc.


---


[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2018-01-24 Thread mattyb149
Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2201#discussion_r163567699
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/impl/ValidationContextAdapter.java
 ---
@@ -0,0 +1,97 @@
+/*
+ * 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.script.impl;
+
+import java.util.Map;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyValue;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.controller.ControllerService;
+import org.apache.nifi.controller.ControllerServiceLookup;
+import org.apache.nifi.expression.ExpressionLanguageCompiler;
+
+public abstract class ValidationContextAdapter implements 
ValidationContext {
--- End diff --

I wonder if we should add a method here to retrieve the 
innerValidationContext. It's not part of the ValidationContext interface of 
course, but currently scripts that are expecting a StandardValidationContext 
(and use methods on that class that are not on the interface) would break. If 
we expose the underlying context, then the scripts could be updated by checking 
to see if the context is a ValidationContextAdapter, then getting the 
underlying context adapter if they want it. Thoughts?


---


[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2018-01-24 Thread mgaido91
Github user mgaido91 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2201#discussion_r163571877
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/resources/groovy/test_implementingabstractProcessor.groovy
 ---
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+import org.apache.nifi.components.PropertyDescriptor
+import org.apache.nifi.components.ValidationContext
+import org.apache.nifi.components.ValidationResult
+import org.apache.nifi.logging.ComponentLog
+import org.apache.nifi.processor.AbstractProcessor
+import org.apache.nifi.processor.ProcessContext
+import org.apache.nifi.processor.ProcessSession
+import org.apache.nifi.processor.ProcessSessionFactory
+import org.apache.nifi.processor.ProcessorInitializationContext
+import org.apache.nifi.processor.Relationship
+import org.apache.nifi.processor.exception.ProcessException
+
+class testImplementingAbstractProcessor extends AbstractProcessor {
+   
+   def ComponentLog log
--- End diff --

I think indentation is a bit strange in this file...


---


[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2018-01-24 Thread mgaido91
Github user mgaido91 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2201#discussion_r163569718
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java
 ---
@@ -461,8 +463,13 @@ public File getKerberosConfigurationFile() {
 // if there was existing validation errors and the processor 
loaded successfully
 if (currentValidationResults.isEmpty() && instance != null) {
 try {
-// defer to the underlying processor for validation
-final Collection instanceResults = 
instance.validate(context);
+// defer to the underlying processor for validation, 
without the
+// invokescriptedprocessor properties
+final Set innerPropertyDescriptor = 
new HashSet(scriptingComponentHelper.getDescriptors());
+
+ValidationContext innerValidationContext = new 
FilteredPropertiesValidationContextAdapter(context, innerPropertyDescriptor);
+final Collection instanceResults = 
instance.validate(innerValidationContext);
--- End diff --

I think we should do the same in the `onTrigger` method too


---


[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2018-01-24 Thread mgaido91
Github user mgaido91 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2201#discussion_r163568827
  
--- Diff: 
nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/impl/FilteredPropertiesValidationContextAdapter.java
 ---
@@ -0,0 +1,92 @@
+/*
+ * 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.script.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.PropertyValue;
+import org.apache.nifi.components.ValidationContext;
+
+/**
+ * filter properties in the ValidationContext, proxy approach, for 
removing unwanted properties
+ *
+ * @author pfreydiere
+ *
+ */
+public class FilteredPropertiesValidationContextAdapter extends 
ValidationContextAdapter {
+
+private Set removedProperties;
+private Set removedPropertyNames;
+
+public FilteredPropertiesValidationContextAdapter(ValidationContext 
validationContext, Set removedProperties) {
+super(validationContext);
+this.removedProperties = removedProperties;
+Set keys = new HashSet<>();
+for (PropertyDescriptor p : removedProperties) {
+keys.add(p.getName());
+}
+this.removedPropertyNames = keys;
+}
+
+@Override
+public Map getAllProperties() {
+HashMap returnedProperties = new 
HashMap<>(super.getAllProperties());
--- End diff --

I think that the `returnedProperties` can be computed once in the 
constructor and reused, instead of being recreated anytime


---


[GitHub] nifi pull request #2201: NIFI-4367 Fix on processor for permit deriving scri...

2017-10-08 Thread frett27
GitHub user frett27 opened a pull request:

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

NIFI-4367 Fix on processor for permit deriving script classes from Ab…

…stractProcessor or other Records based base classes

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced 
 in the commit message?

- [x] Does your PR title start with NIFI- where  is the JIRA number 
you are trying to resolve? Pay particular attention to the hyphen "-" character.

- [x] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

- [ ] Is your initial contribution a single, squashed commit?

### For code changes:
- [x] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi folder?
- [x] Have you written or updated unit tests to verify your changes?
- [x] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
- [x] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under nifi-assembly?
- [x] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under nifi-assembly?
- [x] If adding new Properties, have you added .displayName in addition to 
.name (programmatic access) for each of the new properties?

### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


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

$ git pull https://github.com/frett27/nifi nifi-4367

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

https://github.com/apache/nifi/pull/2201.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 #2201


commit 3eec6c7a022a2424accc5d84f425b8746719c2d0
Author: Patrice Freydiere 
Date:   2017-09-09T14:43:14Z

NIFI-4367 Fix on processor for permit deriving script classes from 
AbstractProcessor or other Records based base classes




---