Search in sources :

Example 6 with Action

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

the class FunnelAuditor method removeFunnelAdvice.

/**
 * Audits the removal of a funnel.
 *
 * @param proceedingJoinPoint join point
 * @param funnelId funnel id
 * @param funnelDAO funnel dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.FunnelDAO+) && " + "execution(void deleteFunnel(java.lang.String)) && " + "args(funnelId) && " + "target(funnelDAO)")
public void removeFunnelAdvice(ProceedingJoinPoint proceedingJoinPoint, String funnelId, FunnelDAO funnelDAO) throws Throwable {
    // get the funnel before removing it
    Funnel funnel = funnelDAO.getFunnel(funnelId);
    // remove the funnel
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    final Action action = generateAuditRecord(funnel, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) Around(org.aspectj.lang.annotation.Around)

Example 7 with Action

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

the class PortAuditor method createPortAdvice.

/**
 * Audits the creation of a port.
 *
 * @param proceedingJoinPoint join point
 * @return port
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.PortDAO+) && " + "execution(org.apache.nifi.connectable.Port createPort(java.lang.String, org.apache.nifi.web.api.dto.PortDTO))")
public Port createPortAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    Port port = (Port) proceedingJoinPoint.proceed();
    // audit the port creation
    final Action action = generateAuditRecord(port, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return port;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Around(org.aspectj.lang.annotation.Around)

Example 8 with Action

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

the class ProcessGroupAuditor method createProcessGroupAdvice.

/**
 * Audits the creation of process groups via createProcessGroup().
 *
 * 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 join point
 * @return group
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup createProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.ProcessGroupDTO))")
public ProcessGroup createProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the process group
    ProcessGroup processGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the process group action...
    // audit process group creation
    final Action action = generateAuditRecord(processGroup, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return processGroup;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Around(org.aspectj.lang.annotation.Around)

Example 9 with Action

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

the class ProcessGroupAuditor method updateProcessGroupAdvice.

/**
 * Audits the update of process group configuration.
 *
 * @param proceedingJoinPoint join point
 * @param processGroupDTO dto
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroup(org.apache.nifi.web.api.dto.ProcessGroupDTO)) && " + "args(processGroupDTO)")
public ProcessGroup updateProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessGroupDTO processGroupDTO) throws Throwable {
    ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupDTO.getId());
    String name = processGroup.getName();
    String comments = processGroup.getComments();
    // perform the underlying operation
    ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<ActionDetails> details = new ArrayList<>();
        // see if the name has changed
        if (name != null && updatedProcessGroup.getName() != null && !name.equals(updatedProcessGroup.getName())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("name");
            configDetails.setValue(updatedProcessGroup.getName());
            configDetails.setPreviousValue(name);
            details.add(configDetails);
        }
        // see if the comments has changed
        if (comments != null && updatedProcessGroup.getComments() != null && !comments.equals(updatedProcessGroup.getComments())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("comments");
            configDetails.setValue(updatedProcessGroup.getComments());
            configDetails.setPreviousValue(comments);
            details.add(configDetails);
        }
        // hold all actions
        Collection<Action> actions = new ArrayList<>();
        // save the actions if necessary
        if (!details.isEmpty()) {
            Date timestamp = new Date();
            // create the actions
            for (ActionDetails detail : details) {
                // determine the type of operation being performed
                Operation operation = Operation.Configure;
                if (detail instanceof FlowChangeMoveDetails) {
                    operation = Operation.Move;
                }
                // create the port action for updating the name
                FlowChangeAction processGroupAction = new FlowChangeAction();
                processGroupAction.setUserIdentity(user.getIdentity());
                processGroupAction.setOperation(operation);
                processGroupAction.setTimestamp(timestamp);
                processGroupAction.setSourceId(updatedProcessGroup.getIdentifier());
                processGroupAction.setSourceName(updatedProcessGroup.getName());
                processGroupAction.setSourceType(Component.ProcessGroup);
                processGroupAction.setActionDetails(detail);
                actions.add(processGroupAction);
            }
        }
        // save actions if necessary
        if (!actions.isEmpty()) {
            saveActions(actions, logger);
        }
    }
    return updatedProcessGroup;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ActionDetails(org.apache.nifi.action.details.ActionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 10 with Action

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

the class ProcessorAuditor method updateProcessorAdvice.

/**
 * Audits the configuration of a single processor.
 *
 * @param proceedingJoinPoint join point
 * @param processorDTO dto
 * @param processorDAO dao
 * @return node
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessorDAO+) && " + "execution(org.apache.nifi.controller.ProcessorNode updateProcessor(org.apache.nifi.web.api.dto.ProcessorDTO)) && " + "args(processorDTO) && " + "target(processorDAO)")
public ProcessorNode updateProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessorDTO processorDTO, ProcessorDAO processorDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    ProcessorNode processor = processorDAO.getProcessor(processorDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(processor, processorDTO);
    final ScheduledState scheduledState = processor.getScheduledState();
    // update the processor state
    final ProcessorNode updatedProcessor = (ProcessorNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the processor action...
    processor = processorDAO.getProcessor(updatedProcessor.getIdentifier());
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(processor, processorDTO);
        // create the processor details
        FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(processor.getComponentType());
        // create a processor 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 = processor.getProcessor().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(processor.getIdentifier());
                configurationAction.setSourceName(processor.getName());
                configurationAction.setSourceType(Component.Processor);
                configurationAction.setComponentDetails(processorDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final ScheduledState updatedScheduledState = processor.getScheduledState();
        // determine if the running state has changed and its not disabled
        if (scheduledState != updatedScheduledState) {
            // create a processor action
            FlowChangeAction processorAction = new FlowChangeAction();
            processorAction.setUserIdentity(user.getIdentity());
            processorAction.setTimestamp(new Date());
            processorAction.setSourceId(processor.getIdentifier());
            processorAction.setSourceName(processor.getName());
            processorAction.setSourceType(Component.Processor);
            processorAction.setComponentDetails(processorDetails);
            // set the operation accordingly
            if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
                processorAction.setOperation(Operation.Start);
            } else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
                processorAction.setOperation(Operation.Disable);
            } else {
                // state is now stopped... consider the previous state
                if (ScheduledState.RUNNING.equals(scheduledState)) {
                    processorAction.setOperation(Operation.Stop);
                } else if (ScheduledState.DISABLED.equals(scheduledState)) {
                    processorAction.setOperation(Operation.Enable);
                }
            }
            actions.add(processorAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedProcessor;
}
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) ProcessorNode(org.apache.nifi.controller.ProcessorNode) 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)

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