Search in sources :

Example 16 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class RemoteProcessGroupAuditor method removeRemoteProcessGroupAdvice.

/**
 * Audits the removal of a process group via deleteProcessGroup().
 *
 * @param proceedingJoinPoint join point
 * @param remoteProcessGroupId remote group id
 * @param remoteProcessGroupDAO remote group dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && " + "execution(void deleteRemoteProcessGroup(java.lang.String)) && " + "args(remoteProcessGroupId) && " + "target(remoteProcessGroupDAO)")
public void removeRemoteProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, String remoteProcessGroupId, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
    // get the remote process group before removing it
    RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId);
    // remove the remote process group
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    final Action action = generateAuditRecord(remoteProcessGroup, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) Around(org.aspectj.lang.annotation.Around)

Example 17 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ReportingTaskAuditor method updateReportingTaskAdvice.

/**
 * Audits the configuration of a reporting task.
 *
 * @param proceedingJoinPoint joinpoint
 * @param reportingTaskDTO dto
 * @param reportingTaskDAO dao
 * @return object
 * @throws Throwable ex
 */
@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
        FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
        taskDetails.setType(reportingTask.getComponentType());
        // 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 FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                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
            FlowChangeAction taskAction = new FlowChangeAction();
            taskAction.setUserIdentity(user.getIdentity());
            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;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ScheduledState(org.apache.nifi.controller.ScheduledState) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 18 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ReportingTaskAuditor method createReportingTaskAdvice.

/**
 * 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 joinpoint
 * @return node
 * @throws java.lang.Throwable ex
 */
@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;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) Around(org.aspectj.lang.annotation.Around)

Example 19 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class ReportingTaskAuditor method removeReportingTaskAdvice.

/**
 * Audits the removal of a reporting task via deleteReportingTask().
 *
 * @param proceedingJoinPoint join point
 * @param reportingTaskId task id
 * @param reportingTaskDAO task dao
 * @throws Throwable ex
 */
@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);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) Around(org.aspectj.lang.annotation.Around)

Example 20 with Action

use of org.apache.nifi.action.Action in project nifi by apache.

the class SnippetAuditor method updateSnippetAdvice.

/**
 * Audits a bulk move.
 *
 * @param proceedingJoinPoint join point
 * @param snippetDTO dto
 * @param snippetDAO dao
 * @return snippet
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(org.apache.nifi.controller.Snippet updateSnippetComponents(org.apache.nifi.web.api.dto.SnippetDTO)) && " + "args(snippetDTO) && " + "target(snippetDAO)")
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();
    // perform the underlying operation
    snippet = (Snippet) proceedingJoinPoint.proceed();
    // if this snippet is linked and its parent group id has changed
    final String groupId = snippetDTO.getParentGroupId();
    if (!previousGroupId.equals(groupId)) {
        // create move audit records for all items in this snippet
        final Collection<Action> actions = new ArrayList<>();
        for (String id : snippet.getProcessors().keySet()) {
            final ProcessorNode processor = processorDAO.getProcessor(id);
            final Action action = processorAuditor.generateAuditRecord(processor, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getFunnels().keySet()) {
            final Funnel funnel = funnelDAO.getFunnel(id);
            final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getInputPorts().keySet()) {
            final Port port = inputPortDAO.getPort(id);
            final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getOutputPorts().keySet()) {
            final Port port = outputPortDAO.getPort(id);
            final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getRemoteProcessGroups().keySet()) {
            final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(id);
            final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getProcessGroups().keySet()) {
            final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
            final ProcessGroup processGroup = processGroupDAO.getProcessGroup(id);
            final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        for (String id : snippet.getConnections().keySet()) {
            final Connection connection = connectionDAO.getConnection(id);
            final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
            if (action != null) {
                actions.add(action);
            }
        }
        // save the actions
        if (CollectionUtils.isNotEmpty(actions)) {
            saveActions(actions, logger);
        }
    }
    return snippet;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Connection(org.apache.nifi.connectable.Connection) Snippet(org.apache.nifi.controller.Snippet) Around(org.aspectj.lang.annotation.Around)

Aggregations

Action (org.apache.nifi.action.Action)68 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)46 Around (org.aspectj.lang.annotation.Around)40 ArrayList (java.util.ArrayList)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)21 Date (java.util.Date)19 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)19 Test (org.junit.Test)19 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)15 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)12 Operation (org.apache.nifi.action.Operation)8 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)8 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 ActionDetails (org.apache.nifi.action.details.ActionDetails)5 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)5 Connection (org.apache.nifi.connectable.Connection)5 Port (org.apache.nifi.connectable.Port)5 ProcessorNode (org.apache.nifi.controller.ProcessorNode)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)5