exceptionfactory commented on code in PR #9837:
URL: https://github.com/apache/nifi/pull/9837#discussion_r2031379976


##########
nifi-framework-api/src/main/java/org/apache/nifi/action/FlowActionReporterConfigurationContext.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.action;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.X509TrustManager;
+import java.util.Optional;
+
+/**
+ * A context that will be passed to the reporter in order to obtain 
configuration.
+ */
+public interface FlowActionReporterConfigurationContext {
+    /**
+     * Retrieves SSLContext if set

Review Comment:
   ```suggestion
        * Retrieves SSLContext if configured in application properties
   ```



##########
nifi-framework-api/src/main/java/org/apache/nifi/action/FlowActionAttributes.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.action;
+
+/**
+ * Flow Action attributes for consistent naming
+ */
+public interface FlowActionAttributes {

Review Comment:
   This interface should be removed since it is just a simple wrapper right 
now. The `FlowActionAttribute` does not seem to provide much value, so I 
recommend removing it and naming the top-level `enum` as `FlowActionAttribute`.



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/framework/configuration/FlowControllerConfiguration.java:
##########
@@ -83,6 +88,9 @@
 @Configuration
 public class FlowControllerConfiguration {
 
+    public static final String FLOW_ACTION_REPORTER_IMPLEMENTATION = 
"nifi.flow.action.reporter.implementation";
+    public static final String DEFAULT_FLOW_ACTION_REPORTER_IMPLEMENTATION = 
"org.apache.nifi.action.HeadlessFlowActionReporter";

Review Comment:
   It looks like the visibility of these properties can be reduced to `private`.



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/framework/configuration/FlowControllerConfiguration.java:
##########
@@ -83,6 +88,9 @@
 @Configuration
 public class FlowControllerConfiguration {
 
+    public static final String FLOW_ACTION_REPORTER_IMPLEMENTATION = 
"nifi.flow.action.reporter.implementation";
+    public static final String DEFAULT_FLOW_ACTION_REPORTER_IMPLEMENTATION = 
"org.apache.nifi.action.HeadlessFlowActionReporter";

Review Comment:
   The default implementation is gone, so this should be removed.



##########
nifi-framework-api/src/main/java/org/apache/nifi/action/FlowActionReporter.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.action;
+
+import java.util.Collection;
+
+/**
+ * A {@link FlowActionReporter} is responsible for reporting {@link 
FlowAction}s.
+ * Provides {@link FlowActionReporterConfigurationContext} to allow for 
configuration and initialization.
+ * Uses {@link #preDestruction()} to allow for cleanup. The default 
implementation does nothing.

Review Comment:
   The `reportFlowActions()` method is required to be implemented, so this 
portion of the comment should be removed.
   ```suggestion
    * Uses {@link #preDestruction()} to allow for cleanup.
   ```



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/framework/configuration/FlowControllerConfiguration.java:
##########
@@ -471,4 +479,38 @@ public AssetSynchronizer assetSynchronizer() throws 
Exception {
     public AssetComponentManager affectedComponentManager() throws Exception {
         return new StandardAssetComponentManager(flowController());
     }
+
+    /**
+     * Flow Action Reporter configured from NiFi Application Properties
+     *
+     * @return Flow Action Reporter
+     * @throws Exception Thrown on failures to create Flow Action Reporter
+     */
+    @Bean(destroyMethod = "preDestruction")
+    public FlowActionReporter flowActionReporter() throws Exception {
+        final String configuredClassName = 
properties.getProperty(FLOW_ACTION_REPORTER_IMPLEMENTATION, 
DEFAULT_FLOW_ACTION_REPORTER_IMPLEMENTATION);
+        if (StringUtils.isBlank(configuredClassName)) {
+            throw new RuntimeException("Cannot create FlowActionReporter 
because the configuration is missing the following property: "

Review Comment:
   Recommend a more specific exception:
   ```suggestion
               throw new IllegalStateException("Cannot create 
FlowActionReporter because the configuration is missing the following property: 
"
   ```



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/framework/configuration/FlowControllerConfiguration.java:
##########
@@ -471,4 +479,38 @@ public AssetSynchronizer assetSynchronizer() throws 
Exception {
     public AssetComponentManager affectedComponentManager() throws Exception {
         return new StandardAssetComponentManager(flowController());
     }
+
+    /**
+     * Flow Action Reporter configured from NiFi Application Properties
+     *
+     * @return Flow Action Reporter
+     * @throws Exception Thrown on failures to create Flow Action Reporter
+     */
+    @Bean(destroyMethod = "preDestruction")
+    public FlowActionReporter flowActionReporter() throws Exception {
+        final String configuredClassName = 
properties.getProperty(FLOW_ACTION_REPORTER_IMPLEMENTATION, 
DEFAULT_FLOW_ACTION_REPORTER_IMPLEMENTATION);
+        if (StringUtils.isBlank(configuredClassName)) {
+            throw new RuntimeException("Cannot create FlowActionReporter 
because the configuration is missing the following property: "
+                + FLOW_ACTION_REPORTER_IMPLEMENTATION);
+        }
+        try {
+            FlowActionReporter reporter = 
NarThreadContextClassLoader.createInstance(extensionManager, 
configuredClassName, FlowActionReporter.class, properties);
+            reporter.onConfigured(new 
StandardFlowActionReporterConfigurationContext(sslContext, trustManager));
+            return reporter;
+        } catch (final Exception e) {
+            throw new RuntimeException("Failed to create FlowActionReporter 
with class " + configuredClassName, e);
+        }
+
+    }
+
+    /**
+     * Action Converter for converting actions to flow actions
+     *
+     * @return Action Converter
+     * @throws Exception Thrown on failures to create Action Converter
+     */
+    @Bean
+    public ActionConverter flowActionConverter() throws Exception {

Review Comment:
   It seems unnecessary to define this as a Bean, I recommend instantiating the 
implementation directly in the `auditService()` method.



##########
nifi-framework-api/src/main/java/org/apache/nifi/action/FlowActionReporterConfigurationContext.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.action;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.X509TrustManager;
+import java.util.Optional;
+
+/**
+ * A context that will be passed to the reporter in order to obtain 
configuration.
+ */
+public interface FlowActionReporterConfigurationContext {
+    /**
+     * Retrieves SSLContext if set
+     * @return SSLContext
+     */
+    Optional<SSLContext> getSSLContext();
+
+    /**
+     * Retrieves the trust manager if set

Review Comment:
   ```suggestion
        * Retrieves the trust manager if configured in application properties
   ```



##########
nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/framework/configuration/FlowControllerConfiguration.java:
##########
@@ -471,4 +479,38 @@ public AssetSynchronizer assetSynchronizer() throws 
Exception {
     public AssetComponentManager affectedComponentManager() throws Exception {
         return new StandardAssetComponentManager(flowController());
     }
+
+    /**
+     * Flow Action Reporter configured from NiFi Application Properties
+     *
+     * @return Flow Action Reporter
+     * @throws Exception Thrown on failures to create Flow Action Reporter
+     */
+    @Bean(destroyMethod = "preDestruction")
+    public FlowActionReporter flowActionReporter() throws Exception {
+        final String configuredClassName = 
properties.getProperty(FLOW_ACTION_REPORTER_IMPLEMENTATION, 
DEFAULT_FLOW_ACTION_REPORTER_IMPLEMENTATION);
+        if (StringUtils.isBlank(configuredClassName)) {
+            throw new RuntimeException("Cannot create FlowActionReporter 
because the configuration is missing the following property: "
+                + FLOW_ACTION_REPORTER_IMPLEMENTATION);
+        }
+        try {
+            FlowActionReporter reporter = 
NarThreadContextClassLoader.createInstance(extensionManager, 
configuredClassName, FlowActionReporter.class, properties);
+            reporter.onConfigured(new 
StandardFlowActionReporterConfigurationContext(sslContext, trustManager));
+            return reporter;
+        } catch (final Exception e) {
+            throw new RuntimeException("Failed to create FlowActionReporter 
with class " + configuredClassName, e);

Review Comment:
   ```suggestion
               throw new IllegalStateException("Failed to create 
FlowActionReporter with class " + configuredClassName, e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to