You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mc...@apache.org on 2015/02/17 21:32:57 UTC

[4/4] incubator-nifi git commit: NIFI-250: - Adding auditing to activating/deactivating controller service references.

NIFI-250:
- Adding auditing to activating/deactivating controller service references.

Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/6457929b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/6457929b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/6457929b

Branch: refs/heads/NIFI-250
Commit: 6457929b25ba5923bebeb6ab4566e4208d1a092e
Parents: e61a01a
Author: Matt Gilman <ma...@gmail.com>
Authored: Tue Feb 17 15:32:31 2015 -0500
Committer: Matt Gilman <ma...@gmail.com>
Committed: Tue Feb 17 15:32:31 2015 -0500

----------------------------------------------------------------------
 .../nifi/audit/ControllerServiceAuditor.java    | 74 ++++++++++++++++++++
 1 file changed, 74 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/6457929b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ControllerServiceAuditor.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ControllerServiceAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ControllerServiceAuditor.java
index 849bdae..a97d768 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ControllerServiceAuditor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ControllerServiceAuditor.java
@@ -30,9 +30,13 @@ import org.apache.nifi.action.component.details.ExtensionDetails;
 import org.apache.nifi.action.details.ActionDetails;
 import org.apache.nifi.action.details.ConfigureDetails;
 import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.ConfiguredComponent;
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.controller.ScheduledState;
 import org.apache.nifi.web.security.user.NiFiUserUtils;
 import org.apache.nifi.user.NiFiUser;
 import org.apache.nifi.controller.service.ControllerServiceNode;
+import org.apache.nifi.controller.service.ControllerServiceReference;
 import org.apache.nifi.web.api.dto.ControllerServiceDTO;
 import org.apache.nifi.web.dao.ControllerServiceDAO;
 import org.aspectj.lang.ProceedingJoinPoint;
@@ -213,6 +217,76 @@ public class ControllerServiceAuditor extends NiFiAuditor {
     }
 
     /**
+     * Audits the update of a component referencing a controller service.
+     *
+     * @param proceedingJoinPoint
+     * @return
+     * @throws Throwable
+     */
+    @Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && "
+            + "execution(org.apache.nifi.controller.service.ControllerServiceReference updateControllerServiceReferencingComponents(java.lang.String, boolean))")
+    public Object updateControllerServiceReferenceAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+        // update the controller service references
+        final ControllerServiceReference controllerServiceReference = (ControllerServiceReference) proceedingJoinPoint.proceed();
+        
+        // get the current user
+        final NiFiUser user = NiFiUserUtils.getNiFiUser();
+        
+        if (user != null) {
+            final Collection<Action> actions = new ArrayList<>();
+            
+            // consider each component updates
+            for (final ConfiguredComponent component : controllerServiceReference.getReferencingComponents()) {
+                if (component instanceof ProcessorNode) {
+                    final ProcessorNode processor = ((ProcessorNode) component);
+
+                    // create the processor details
+                    ExtensionDetails processorDetails = new ExtensionDetails();
+                    processorDetails.setType(processor.getProcessor().getClass().getSimpleName());
+
+                    // create a processor action
+                    Action processorAction = new Action();
+                    processorAction.setUserDn(user.getDn());
+                    processorAction.setUserName(user.getUserName());
+                    processorAction.setTimestamp(new Date());
+                    processorAction.setSourceId(processor.getIdentifier());
+                    processorAction.setSourceName(processor.getName());
+                    processorAction.setSourceType(Component.Processor);
+                    processorAction.setComponentDetails(processorDetails);
+                    processorAction.setOperation(ScheduledState.RUNNING.equals(processor.getScheduledState()) ? Operation.Start : Operation.Stop);
+                    actions.add(processorAction);
+                } else if (component instanceof ControllerServiceNode) {
+                    final ControllerServiceNode controllerService = ((ControllerServiceNode) component);
+                    
+                    // create the processor details
+                    ExtensionDetails serviceDetails = new ExtensionDetails();
+                    serviceDetails.setType(controllerService.getControllerServiceImplementation().getClass().getSimpleName());
+                    
+                    // create a controller service action
+                    Action serviceAction = new Action();
+                    serviceAction.setUserDn(user.getDn());
+                    serviceAction.setUserName(user.getUserName());
+                    serviceAction.setTimestamp(new Date());
+                    serviceAction.setSourceId(controllerService.getIdentifier());
+                    serviceAction.setSourceName(controllerService.getName());
+                    serviceAction.setSourceType(Component.ControllerService);
+                    serviceAction.setComponentDetails(serviceDetails);
+                    serviceAction.setOperation(controllerService.isDisabled() ? Operation.Disable : Operation.Enable);
+                    actions.add(serviceAction);
+                }
+            }
+            
+            // ensure there are actions to record
+            if (!actions.isEmpty()) {
+                // save the actions
+                saveActions(actions, logger);
+            }
+        }
+        
+        return controllerServiceReference;
+    }
+    
+    /**
      * Audits the removal of a controller service via deleteControllerService().
      *
      * @param proceedingJoinPoint