You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2015/04/10 15:43:51 UTC
[16/62] [abbrv] incubator-nifi git commit: Squashed commit of the
following:
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ProcessorAuditor.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/ProcessorAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ProcessorAuditor.java
index c3c70c4..ff377a3 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ProcessorAuditor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ProcessorAuditor.java
@@ -30,7 +30,7 @@ import java.util.Set;
import org.apache.nifi.action.Action;
import org.apache.nifi.action.Component;
import org.apache.nifi.action.Operation;
-import org.apache.nifi.action.component.details.ProcessorDetails;
+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;
@@ -78,13 +78,10 @@ public class ProcessorAuditor extends NiFiAuditor {
* advice precedence. By normalizing all advice into Around advice we can
* alleviate this issue.
*
- * @param processor
+ * @param proceedingJoinPoint
+ * @return
+ * @throws java.lang.Throwable
*/
-// @AfterReturning(
-// pointcut="within(org.apache.nifi.web.dao.ProcessorDAO+) && "
-// + "execution(org.apache.nifi.web.api.dto.ProcessorDTO createProcessor(org.apache.nifi.web.api.dto.ProcessorDTO))",
-// returning="processor"
-// )
@Around("within(org.apache.nifi.web.dao.ProcessorDAO+) && "
+ "execution(org.apache.nifi.controller.ProcessorNode createProcessor(java.lang.String, org.apache.nifi.web.api.dto.ProcessorDTO))")
public ProcessorNode createProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
@@ -106,6 +103,7 @@ public class ProcessorAuditor extends NiFiAuditor {
* Audits the configuration of a single processor.
*
* @param proceedingJoinPoint
+ * @param groupId
* @param processorDTO
* @param processorDAO
* @return
@@ -115,7 +113,7 @@ public class ProcessorAuditor extends NiFiAuditor {
+ "execution(org.apache.nifi.controller.ProcessorNode updateProcessor(java.lang.String, org.apache.nifi.web.api.dto.ProcessorDTO)) && "
+ "args(groupId, processorDTO) && "
+ "target(processorDAO)")
- public Object updateProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ProcessorDTO processorDTO, ProcessorDAO processorDAO) throws Throwable {
+ public ProcessorNode updateProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ProcessorDTO processorDTO, ProcessorDAO processorDAO) throws Throwable {
// determine the initial values for each property/setting thats changing
ProcessorNode processor = processorDAO.getProcessor(groupId, processorDTO.getId());
final Map<String, String> values = extractConfiguredPropertyValues(processor, processorDTO);
@@ -137,7 +135,7 @@ public class ProcessorAuditor extends NiFiAuditor {
Map<String, String> updatedValues = extractConfiguredPropertyValues(processor, processorDTO);
// create the processor details
- ProcessorDetails processorDetails = new ProcessorDetails();
+ ExtensionDetails processorDetails = new ExtensionDetails();
processorDetails.setType(processor.getProcessor().getClass().getSimpleName());
// create a processor action
@@ -240,6 +238,7 @@ public class ProcessorAuditor extends NiFiAuditor {
* Audits the removal of a processor via deleteProcessor().
*
* @param proceedingJoinPoint
+ * @param groupId
* @param processorId
* @param processorDAO
* @throws Throwable
@@ -281,6 +280,7 @@ public class ProcessorAuditor extends NiFiAuditor {
*
* @param processor
* @param operation
+ * @param actionDetails
* @return
*/
public Action generateAuditRecord(ProcessorNode processor, Operation operation, ActionDetails actionDetails) {
@@ -292,7 +292,7 @@ public class ProcessorAuditor extends NiFiAuditor {
// ensure the user was found
if (user != null) {
// create the processor details
- ProcessorDetails processorDetails = new ProcessorDetails();
+ ExtensionDetails processorDetails = new ExtensionDetails();
processorDetails.setType(processor.getProcessor().getClass().getSimpleName());
// create the processor action for adding this processor
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RelationshipAuditor.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/RelationshipAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RelationshipAuditor.java
index 9cc694b..ba78141 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RelationshipAuditor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RelationshipAuditor.java
@@ -76,16 +76,13 @@ public class RelationshipAuditor extends NiFiAuditor {
* advice precedence. By normalizing all advice into Around advice we can
* alleviate this issue.
*
- * @param connection
+ * @param proceedingJoinPoint
+ * @return
+ * @throws java.lang.Throwable
*/
-// @AfterReturning(
-// pointcut="within(org.apache.nifi.view.dao.ConnectionDAO+) && "
-// + "execution(org.apache.nifi.view.model.Connection createConnection(org.apache.nifi.api.dto.ConnectionDTO))",
-// returning="connection"
-// )
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && "
+ "execution(org.apache.nifi.connectable.Connection createConnection(java.lang.String, org.apache.nifi.web.api.dto.ConnectionDTO))")
- public Object createConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ public Connection createConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// perform the underlying operation
Connection connection = (Connection) proceedingJoinPoint.proceed();
@@ -105,6 +102,7 @@ public class RelationshipAuditor extends NiFiAuditor {
* Audits the creation and removal of relationships via updateConnection().
*
* @param proceedingJoinPoint
+ * @param groupId
* @param connectionDTO
* @param connectionDAO
* @return
@@ -114,7 +112,7 @@ public class RelationshipAuditor extends NiFiAuditor {
+ "execution(org.apache.nifi.connectable.Connection updateConnection(java.lang.String, org.apache.nifi.web.api.dto.ConnectionDTO)) && "
+ "args(groupId, connectionDTO) && "
+ "target(connectionDAO)")
- public Object updateConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ConnectionDTO connectionDTO, ConnectionDAO connectionDAO) throws Throwable {
+ public Connection updateConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, String groupId, ConnectionDTO connectionDTO, ConnectionDAO connectionDAO) throws Throwable {
// get the previous configuration
Connection connection = connectionDAO.getConnection(groupId, connectionDTO.getId());
Connectable previousDestination = connection.getDestination();
@@ -218,6 +216,7 @@ public class RelationshipAuditor extends NiFiAuditor {
* Audits the removal of relationships via deleteConnection().
*
* @param proceedingJoinPoint
+ * @param groupId
* @param id
* @param connectionDAO
* @throws Throwable
@@ -251,7 +250,9 @@ public class RelationshipAuditor extends NiFiAuditor {
* Creates action details for connect/disconnect actions.
*
* @param connection
+ * @param source
* @param relationships
+ * @param destination
* @return
*/
public ConnectDetails createConnectDetails(final Connection connection, final Connectable source, final Collection<Relationship> relationships, final Connectable destination) {
@@ -327,6 +328,7 @@ public class RelationshipAuditor extends NiFiAuditor {
*
* @param connection
* @param operation
+ * @param actionDetails
* @return
*/
public Action generateAuditRecordForConnection(Connection connection, Operation operation, ActionDetails actionDetails) {
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RemoteProcessGroupAuditor.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/RemoteProcessGroupAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RemoteProcessGroupAuditor.java
index a10495d..d0836d4 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RemoteProcessGroupAuditor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/RemoteProcessGroupAuditor.java
@@ -60,16 +60,13 @@ public class RemoteProcessGroupAuditor extends NiFiAuditor {
* advice precedence. By normalizing all advice into Around advice we can
* alleviate this issue.
*
- * @param processor
+ * @param proceedingJoinPoint
+ * @return
+ * @throws java.lang.Throwable
*/
-// @AfterReturning(
-// pointcut="within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && "
-// + "execution(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO createRemoteProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupDTO))",
-// returning="remoteProcessGroup"
-// )
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && "
+ "execution(org.apache.nifi.groups.RemoteProcessGroup createRemoteProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupDTO))")
- public Object createRemoteProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ public RemoteProcessGroup createRemoteProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// create the remote process group
RemoteProcessGroup remoteProcessGroup = (RemoteProcessGroup) proceedingJoinPoint.proceed();
@@ -99,7 +96,7 @@ public class RemoteProcessGroupAuditor extends NiFiAuditor {
+ "execution(org.apache.nifi.groups.RemoteProcessGroup updateRemoteProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)) && "
+ "args(groupId, remoteProcessGroupDTO) && "
+ "target(remoteProcessGroupDAO)")
- public Object auditUpdateProcessGroupConfiguration(ProceedingJoinPoint proceedingJoinPoint, String groupId, RemoteProcessGroupDTO remoteProcessGroupDTO, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
+ public RemoteProcessGroup auditUpdateProcessGroupConfiguration(ProceedingJoinPoint proceedingJoinPoint, String groupId, RemoteProcessGroupDTO remoteProcessGroupDTO, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(groupId, remoteProcessGroupDTO.getId());
// record the current value of this remoteProcessGroups configuration for comparisons later
@@ -332,7 +329,9 @@ public class RemoteProcessGroupAuditor extends NiFiAuditor {
/**
* Generates an audit record for the specified remote process group.
*
- * @param port
+ * @param remoteProcessGroup
+ * @param operation
+ * @return
*/
public Action generateAuditRecord(RemoteProcessGroup remoteProcessGroup, Operation operation) {
return generateAuditRecord(remoteProcessGroup, operation, null);
@@ -341,7 +340,10 @@ public class RemoteProcessGroupAuditor extends NiFiAuditor {
/**
* Generates an audit record for the specified remote process group.
*
- * @param port
+ * @param remoteProcessGroup
+ * @param operation
+ * @param actionDetails
+ * @return
*/
public Action generateAuditRecord(RemoteProcessGroup remoteProcessGroup, Operation operation, ActionDetails actionDetails) {
Action action = null;
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ReportingTaskAuditor.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/ReportingTaskAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ReportingTaskAuditor.java
new file mode 100644
index 0000000..ba2cdfb
--- /dev/null
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/ReportingTaskAuditor.java
@@ -0,0 +1,353 @@
+/*
+ * 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.audit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.nifi.action.Action;
+import org.apache.nifi.action.Component;
+import org.apache.nifi.action.Operation;
+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.ReportingTaskNode;
+import org.apache.nifi.controller.ScheduledState;
+import org.apache.nifi.web.security.user.NiFiUserUtils;
+import org.apache.nifi.user.NiFiUser;
+import org.apache.nifi.web.api.dto.ReportingTaskDTO;
+import org.apache.nifi.web.dao.ReportingTaskDAO;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Audits reporting creation/removal and configuration changes.
+ */
+@Aspect
+public class ReportingTaskAuditor extends NiFiAuditor {
+
+ private static final Logger logger = LoggerFactory.getLogger(ReportingTaskAuditor.class);
+
+ private static final String NAME = "Name";
+ private static final String ANNOTATION_DATA = "Annotation Data";
+
+ /**
+ * Audits the creation of reporting task via createReportingTask().
+ *
+ * This method only needs to be run 'after returning'. However, in Java 7
+ * the order in which these methods are returned from
+ * Class.getDeclaredMethods (even though there is no order guaranteed) seems
+ * to differ from Java 6. SpringAOP depends on this ordering to determine
+ * advice precedence. By normalizing all advice into Around advice we can
+ * alleviate this issue.
+ *
+ * @param proceedingJoinPoint
+ * @return
+ * @throws java.lang.Throwable
+ */
+ @Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && "
+ + "execution(org.apache.nifi.controller.ReportingTaskNode createReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO))")
+ public ReportingTaskNode createReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ // update the reporting task state
+ ReportingTaskNode reportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
+
+ // if no exceptions were thrown, add the reporting task action...
+ final Action action = generateAuditRecord(reportingTask, Operation.Add);
+
+ // save the actions
+ if (action != null) {
+ saveAction(action, logger);
+ }
+
+ return reportingTask;
+ }
+
+ /**
+ * Audits the configuration of a reporting task.
+ *
+ * @param proceedingJoinPoint
+ * @param reportingTaskDTO
+ * @param reportingTaskDAO
+ * @return
+ * @throws Throwable
+ */
+ @Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && "
+ + "execution(org.apache.nifi.controller.ReportingTaskNode updateReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO)) && "
+ + "args(reportingTaskDTO) && "
+ + "target(reportingTaskDAO)")
+ public Object updateReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskDTO reportingTaskDTO, ReportingTaskDAO reportingTaskDAO) throws Throwable {
+ // determine the initial values for each property/setting thats changing
+ ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
+ final Map<String, String> values = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
+ final ScheduledState scheduledState = reportingTask.getScheduledState();
+
+ // update the reporting task state
+ final ReportingTaskNode updatedReportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
+
+ // if no exceptions were thrown, add the reporting task action...
+ reportingTask = reportingTaskDAO.getReportingTask(updatedReportingTask.getIdentifier());
+
+ // get the current user
+ final NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+ // ensure the user was found
+ if (user != null) {
+ // determine the updated values
+ Map<String, String> updatedValues = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
+
+ // create the reporting task details
+ ExtensionDetails taskDetails = new ExtensionDetails();
+ taskDetails.setType(reportingTask.getReportingTask().getClass().getSimpleName());
+
+ // create a reporting task action
+ Date actionTimestamp = new Date();
+ Collection<Action> actions = new ArrayList<>();
+
+ // go through each updated value
+ for (String property : updatedValues.keySet()) {
+ String newValue = updatedValues.get(property);
+ String oldValue = values.get(property);
+ Operation operation = null;
+
+ // determine the type of operation
+ if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
+ operation = Operation.Configure;
+ }
+
+ // create a configuration action accordingly
+ if (operation != null) {
+ // clear the value if this property is sensitive
+ final PropertyDescriptor propertyDescriptor = reportingTask.getReportingTask().getPropertyDescriptor(property);
+ if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
+ if (newValue != null) {
+ newValue = "********";
+ }
+ if (oldValue != null) {
+ oldValue = "********";
+ }
+ } else if (ANNOTATION_DATA.equals(property)) {
+ if (newValue != null) {
+ newValue = "<annotation data not shown>";
+ }
+ if (oldValue != null) {
+ oldValue = "<annotation data not shown>";
+ }
+ }
+
+ final ConfigureDetails actionDetails = new ConfigureDetails();
+ actionDetails.setName(property);
+ actionDetails.setValue(newValue);
+ actionDetails.setPreviousValue(oldValue);
+
+ // create a configuration action
+ Action configurationAction = new Action();
+ configurationAction.setUserDn(user.getDn());
+ configurationAction.setUserName(user.getUserName());
+ configurationAction.setOperation(operation);
+ configurationAction.setTimestamp(actionTimestamp);
+ configurationAction.setSourceId(reportingTask.getIdentifier());
+ configurationAction.setSourceName(reportingTask.getName());
+ configurationAction.setSourceType(Component.ReportingTask);
+ configurationAction.setComponentDetails(taskDetails);
+ configurationAction.setActionDetails(actionDetails);
+ actions.add(configurationAction);
+ }
+ }
+
+ // determine the new executing state
+ final ScheduledState updatedScheduledState = reportingTask.getScheduledState();
+
+ // determine if the running state has changed and its not disabled
+ if (scheduledState != updatedScheduledState) {
+ // create a reporting task action
+ Action taskAction = new Action();
+ taskAction.setUserDn(user.getDn());
+ taskAction.setUserName(user.getUserName());
+ taskAction.setTimestamp(new Date());
+ taskAction.setSourceId(reportingTask.getIdentifier());
+ taskAction.setSourceName(reportingTask.getName());
+ taskAction.setSourceType(Component.ReportingTask);
+ taskAction.setComponentDetails(taskDetails);
+
+ // set the operation accordingly
+ if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
+ taskAction.setOperation(Operation.Start);
+ } else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
+ taskAction.setOperation(Operation.Disable);
+ } else {
+ // state is now stopped... consider the previous state
+ if (ScheduledState.RUNNING.equals(scheduledState)) {
+ taskAction.setOperation(Operation.Stop);
+ } else if (ScheduledState.DISABLED.equals(scheduledState)) {
+ taskAction.setOperation(Operation.Enable);
+ }
+ }
+ actions.add(taskAction);
+ }
+
+ // ensure there are actions to record
+ if (!actions.isEmpty()) {
+ // save the actions
+ saveActions(actions, logger);
+ }
+ }
+
+ return updatedReportingTask;
+ }
+
+ /**
+ * Audits the removal of a reporting task via deleteReportingTask().
+ *
+ * @param proceedingJoinPoint
+ * @param reportingTaskId
+ * @param reportingTaskDAO
+ * @throws Throwable
+ */
+ @Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && "
+ + "execution(void deleteReportingTask(java.lang.String)) && "
+ + "args(reportingTaskId) && "
+ + "target(reportingTaskDAO)")
+ public void removeReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, String reportingTaskId, ReportingTaskDAO reportingTaskDAO) throws Throwable {
+ // get the reporting task before removing it
+ ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskId);
+
+ // remove the reporting task
+ proceedingJoinPoint.proceed();
+
+ // if no exceptions were thrown, add removal actions...
+ // audit the reporting task removal
+ final Action action = generateAuditRecord(reportingTask, Operation.Remove);
+
+ // save the actions
+ if (action != null) {
+ saveAction(action, logger);
+ }
+ }
+
+ /**
+ * Generates an audit record for the creation of a reporting task.
+ *
+ * @param reportingTask
+ * @param operation
+ * @return
+ */
+ public Action generateAuditRecord(ReportingTaskNode reportingTask, Operation operation) {
+ return generateAuditRecord(reportingTask, operation, null);
+ }
+
+ /**
+ * Generates an audit record for the creation of a reporting task.
+ *
+ * @param reportingTask
+ * @param operation
+ * @param actionDetails
+ * @return
+ */
+ public Action generateAuditRecord(ReportingTaskNode reportingTask, Operation operation, ActionDetails actionDetails) {
+ Action action = null;
+
+ // get the current user
+ NiFiUser user = NiFiUserUtils.getNiFiUser();
+
+ // ensure the user was found
+ if (user != null) {
+ // create the reporting task details
+ ExtensionDetails taskDetails = new ExtensionDetails();
+ taskDetails.setType(reportingTask.getReportingTask().getClass().getSimpleName());
+
+ // create the reporting task action for adding this reporting task
+ action = new Action();
+ action.setUserDn(user.getDn());
+ action.setUserName(user.getUserName());
+ action.setOperation(operation);
+ action.setTimestamp(new Date());
+ action.setSourceId(reportingTask.getIdentifier());
+ action.setSourceName(reportingTask.getName());
+ action.setSourceType(Component.ReportingTask);
+ action.setComponentDetails(taskDetails);
+
+ if (actionDetails != null) {
+ action.setActionDetails(actionDetails);
+ }
+ }
+
+ return action;
+ }
+
+ /**
+ * Extracts the values for the configured properties from the specified ReportingTask.
+ *
+ * @param reportingTask
+ * @param reportingTaskDTO
+ * @return
+ */
+ private Map<String, String> extractConfiguredPropertyValues(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) {
+ Map<String, String> values = new HashMap<>();
+
+ if (reportingTaskDTO.getName() != null) {
+ values.put(NAME, reportingTask.getName());
+ }
+ if (reportingTaskDTO.getAnnotationData() != null) {
+ values.put(ANNOTATION_DATA, reportingTask.getAnnotationData());
+ }
+ if (reportingTaskDTO.getProperties() != null) {
+ // for each property specified, extract its configured value
+ Map<String, String> properties = reportingTaskDTO.getProperties();
+ Map<PropertyDescriptor, String> configuredProperties = reportingTask.getProperties();
+ for (String propertyName : properties.keySet()) {
+ // build a descriptor for getting the configured value
+ PropertyDescriptor propertyDescriptor = new PropertyDescriptor.Builder().name(propertyName).build();
+ String configuredPropertyValue = configuredProperties.get(propertyDescriptor);
+
+ // if the configured value couldn't be found, use the default value from the actual descriptor
+ if (configuredPropertyValue == null) {
+ propertyDescriptor = locatePropertyDescriptor(configuredProperties.keySet(), propertyDescriptor);
+ configuredPropertyValue = propertyDescriptor.getDefaultValue();
+ }
+ values.put(propertyName, configuredPropertyValue);
+ }
+ }
+
+ return values;
+ }
+
+ /**
+ * Locates the actual property descriptor for the given spec property
+ * descriptor.
+ *
+ * @param propertyDescriptors
+ * @param specDescriptor
+ * @return
+ */
+ private PropertyDescriptor locatePropertyDescriptor(Set<PropertyDescriptor> propertyDescriptors, PropertyDescriptor specDescriptor) {
+ for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+ if (propertyDescriptor.equals(specDescriptor)) {
+ return propertyDescriptor;
+ }
+ }
+ return specDescriptor;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/SnippetAuditor.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/SnippetAuditor.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/SnippetAuditor.java
index 9c075e5..1f8942b 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/SnippetAuditor.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/audit/SnippetAuditor.java
@@ -25,7 +25,7 @@ import java.util.Set;
import org.apache.nifi.action.Action;
import org.apache.nifi.action.Component;
import org.apache.nifi.action.Operation;
-import org.apache.nifi.action.component.details.ProcessorDetails;
+import org.apache.nifi.action.component.details.ExtensionDetails;
import org.apache.nifi.action.component.details.RemoteProcessGroupDetails;
import org.apache.nifi.action.details.ConnectDetails;
import org.apache.nifi.connectable.ConnectableType;
@@ -94,7 +94,7 @@ public class SnippetAuditor extends NiFiAuditor {
*/
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && "
+ "execution(org.apache.nifi.web.api.dto.FlowSnippetDTO copySnippet(java.lang.String, java.lang.String, java.lang.Double, java.lang.Double))")
- public Object copySnippetAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ public FlowSnippetDTO copySnippetAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// perform the underlying operation
FlowSnippetDTO snippet = (FlowSnippetDTO) proceedingJoinPoint.proceed();
auditSnippet(snippet);
@@ -110,7 +110,7 @@ public class SnippetAuditor extends NiFiAuditor {
*/
@Around("within(org.apache.nifi.web.dao.TemplateDAO+) && "
+ "execution(org.apache.nifi.web.api.dto.FlowSnippetDTO instantiateTemplate(java.lang.String, java.lang.Double, java.lang.Double, java.lang.String))")
- public Object instantiateTemplateAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
+ public FlowSnippetDTO instantiateTemplateAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// perform the underlying operation
FlowSnippetDTO snippet = (FlowSnippetDTO) proceedingJoinPoint.proceed();
auditSnippet(snippet);
@@ -153,7 +153,7 @@ public class SnippetAuditor extends NiFiAuditor {
// processors
for (final ProcessorDTO processor : snippet.getProcessors()) {
- final ProcessorDetails processorDetails = new ProcessorDetails();
+ final ExtensionDetails processorDetails = new ExtensionDetails();
processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));
final Action action = generateAuditRecord(processor.getId(), processor.getName(), Component.Processor, Operation.Add, timestamp);
@@ -256,15 +256,16 @@ public class SnippetAuditor extends NiFiAuditor {
* Audits a bulk move.
*
* @param proceedingJoinPoint
- * @param snippetId
+ * @param snippetDTO
* @param snippetDAO
+ * @return
* @throws Throwable
*/
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && "
+ "execution(org.apache.nifi.controller.Snippet updateSnippet(org.apache.nifi.web.api.dto.SnippetDTO)) && "
+ "args(snippetDTO) && "
+ "target(snippetDAO)")
- public Object updateSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, SnippetDTO snippetDTO, SnippetDAO snippetDAO) throws Throwable {
+ public Snippet updateSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, SnippetDTO snippetDTO, SnippetDAO snippetDAO) throws Throwable {
// get the snippet before removing it
Snippet snippet = snippetDAO.getSnippet(snippetDTO.getId());
final String previousGroupId = snippet.getParentGroupId();
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/e9647717/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
index 63d302c..e3afbf9 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiServiceFacade.java
@@ -19,14 +19,17 @@ package org.apache.nifi.web;
import java.util.Collection;
import java.util.Date;
import java.util.Set;
+import org.apache.nifi.controller.ScheduledState;
import org.apache.nifi.controller.repository.claim.ContentDirection;
+import org.apache.nifi.controller.service.ControllerServiceState;
import org.apache.nifi.web.api.dto.BulletinBoardDTO;
import org.apache.nifi.web.api.dto.BulletinQueryDTO;
import org.apache.nifi.web.api.dto.ClusterDTO;
import org.apache.nifi.web.api.dto.ConnectionDTO;
import org.apache.nifi.web.api.dto.ControllerConfigurationDTO;
import org.apache.nifi.web.api.dto.ControllerDTO;
+import org.apache.nifi.web.api.dto.ControllerServiceDTO;
import org.apache.nifi.web.api.dto.CounterDTO;
import org.apache.nifi.web.api.dto.CountersDTO;
import org.apache.nifi.web.api.dto.DocumentedTypeDTO;
@@ -38,9 +41,12 @@ import org.apache.nifi.web.api.dto.NodeSystemDiagnosticsDTO;
import org.apache.nifi.web.api.dto.PortDTO;
import org.apache.nifi.web.api.dto.ProcessGroupDTO;
import org.apache.nifi.web.api.dto.ProcessorDTO;
-import org.apache.nifi.web.api.dto.ProcessorHistoryDTO;
+import org.apache.nifi.web.api.dto.ComponentHistoryDTO;
+import org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO;
+import org.apache.nifi.web.api.dto.PropertyDescriptorDTO;
import org.apache.nifi.web.api.dto.RemoteProcessGroupDTO;
import org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO;
+import org.apache.nifi.web.api.dto.ReportingTaskDTO;
import org.apache.nifi.web.api.dto.RevisionDTO;
import org.apache.nifi.web.api.dto.SnippetDTO;
import org.apache.nifi.web.api.dto.SystemDiagnosticsDTO;
@@ -242,7 +248,21 @@ public interface NiFiServiceFacade {
* @return The list of available processor types
*/
Set<DocumentedTypeDTO> getProcessorTypes();
-
+
+ /**
+ * Returns the list of controller service types.
+ *
+ * @return The list of available controller types
+ */
+ Set<DocumentedTypeDTO> getControllerServiceTypes();
+
+ /**
+ * Returns the list of reporting task types.
+ *
+ * @return The list of available reporting task types
+ */
+ Set<DocumentedTypeDTO> getReportingTaskTypes();
+
/**
* Returns the list of prioritizer types.
*
@@ -360,6 +380,16 @@ public interface NiFiServiceFacade {
StatusHistoryDTO getProcessorStatusHistory(String groupId, String id);
/**
+ * Get the descriptor for the specified property of the specified processor.
+ *
+ * @param groupId
+ * @param id
+ * @param property
+ * @return
+ */
+ PropertyDescriptorDTO getProcessorPropertyDescriptor(String groupId, String id, String property);
+
+ /**
* Gets all the Processor transfer objects for this controller.
*
* @param groupId
@@ -924,6 +954,172 @@ public interface NiFiServiceFacade {
ConfigurationSnapshot<Void> deleteLabel(Revision revision, String groupId, String labelId);
// ----------------------------------------
+ // Controller Services methods
+ // ----------------------------------------
+
+ /**
+ * Creates a controller service.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param controllerServiceDTO The controller service DTO
+ * @return The controller service DTO
+ */
+ ConfigurationSnapshot<ControllerServiceDTO> createControllerService(Revision revision, ControllerServiceDTO controllerServiceDTO);
+
+ /**
+ * Gets all controller services.
+ *
+ * @return
+ */
+ Set<ControllerServiceDTO> getControllerServices();
+
+ /**
+ * Gets the specified controller service.
+ *
+ * @param controllerServiceId
+ * @return
+ */
+ ControllerServiceDTO getControllerService(String controllerServiceId);
+
+ /**
+ * Get the descriptor for the specified property of the specified controller service.
+ *
+ * @param id
+ * @param property
+ * @return
+ */
+ PropertyDescriptorDTO getControllerServicePropertyDescriptor(String id, String property);
+
+ /**
+ * Gets the references for specified controller service.
+ *
+ * @param controllerServiceId
+ * @return
+ */
+ Set<ControllerServiceReferencingComponentDTO> getControllerServiceReferencingComponents(String controllerServiceId);
+
+ /**
+ * Updates the referencing components for the specified controller service.
+ *
+ * @param revision
+ * @param controllerServiceId
+ * @param scheduledState
+ * @param controllerServiceState the value of state
+ * @return The referencing component dtos
+ */
+ ConfigurationSnapshot<Set<ControllerServiceReferencingComponentDTO>> updateControllerServiceReferencingComponents(Revision revision, String controllerServiceId, ScheduledState scheduledState, ControllerServiceState controllerServiceState);
+
+ /**
+ * Updates the specified label.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param controllerServiceDTO The controller service DTO
+ * @return The controller service DTO
+ */
+ ConfigurationSnapshot<ControllerServiceDTO> updateControllerService(Revision revision, ControllerServiceDTO controllerServiceDTO);
+
+ /**
+ * Deletes the specified label.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param controllerServiceId The controller service id
+ * @return
+ */
+ ConfigurationSnapshot<Void> deleteControllerService(Revision revision, String controllerServiceId);
+
+ /**
+ * Verifies the specified controller service can be updated.
+ *
+ * @param controllerServiceDTO
+ */
+ void verifyUpdateControllerService(ControllerServiceDTO controllerServiceDTO);
+
+ /**
+ * Verifies the referencing components of the specified controller service can be updated.
+ *
+ * @param controllerServiceId
+ * @param scheduledState
+ * @param controllerServiceState
+ */
+ void verifyUpdateControllerServiceReferencingComponents(String controllerServiceId, ScheduledState scheduledState, ControllerServiceState controllerServiceState);
+
+ /**
+ * Verifies the specified controller service can be removed.
+ *
+ * @param controllerServiceId
+ */
+ void verifyDeleteControllerService(String controllerServiceId);
+
+ // ----------------------------------------
+ // Reporting Task methods
+ // ----------------------------------------
+
+ /**
+ * Creates a reporting task.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param reportingTaskDTO The reporting task DTO
+ * @return The reporting task DTO
+ */
+ ConfigurationSnapshot<ReportingTaskDTO> createReportingTask(Revision revision, ReportingTaskDTO reportingTaskDTO);
+
+ /**
+ * Gets all reporting tasks.
+ *
+ * @return
+ */
+ Set<ReportingTaskDTO> getReportingTasks();
+
+ /**
+ * Gets the specified reporting task.
+ *
+ * @param reportingTaskId
+ * @return
+ */
+ ReportingTaskDTO getReportingTask(String reportingTaskId);
+
+ /**
+ * Get the descriptor for the specified property of the specified reporting task.
+ *
+ * @param id
+ * @param property
+ * @return
+ */
+ PropertyDescriptorDTO getReportingTaskPropertyDescriptor(String id, String property);
+
+ /**
+ * Updates the specified reporting task.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param reportingTaskDTO The reporting task DTO
+ * @return The reporting task DTO
+ */
+ ConfigurationSnapshot<ReportingTaskDTO> updateReportingTask(Revision revision, ReportingTaskDTO reportingTaskDTO);
+
+ /**
+ * Deletes the specified reporting task.
+ *
+ * @param revision Revision to compare with current base revision
+ * @param reportingTaskId The reporting task id
+ * @return
+ */
+ ConfigurationSnapshot<Void> deleteReportingTask(Revision revision, String reportingTaskId);
+
+ /**
+ * Verifies the specified reporting task can be updated.
+ *
+ * @param reportingTaskDTO
+ */
+ void verifyUpdateReportingTask(ReportingTaskDTO reportingTaskDTO);
+
+ /**
+ * Verifies the specified reporting task can be removed.
+ *
+ * @param reportingTaskId
+ */
+ void verifyDeleteReportingTask(String reportingTaskId);
+
+ // ----------------------------------------
// History methods
// ----------------------------------------
/**
@@ -950,12 +1146,12 @@ public interface NiFiServiceFacade {
void deleteActions(Date endDate);
/**
- * Gets the history for the specified property for the specified processor.
+ * Gets the history for the specified property for the specified component.
*
- * @param processorId
+ * @param componentId
* @return
*/
- ProcessorHistoryDTO getProcessorHistory(String processorId);
+ ComponentHistoryDTO getComponentHistory(String componentId);
// ----------------------------------------
// Snippet methods