Search in sources :

Example 11 with Action

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

the class ProcessorAuditor method createProcessorAdvice.

/**
 * Audits the creation of processors via createProcessor().
 *
 * 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 node
 * @throws java.lang.Throwable ex
 */
@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 {
    // update the processor state
    ProcessorNode processor = (ProcessorNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the processor action...
    final Action action = generateAuditRecord(processor, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return processor;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Around(org.aspectj.lang.annotation.Around)

Example 12 with Action

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

the class RelationshipAuditor method createConnectionAdvice.

/**
 * Audits the creation of relationships via createConnection().
 *
 * 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 connection
 * @throws java.lang.Throwable ex
 */
@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 Connection createConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    Connection connection = (Connection) proceedingJoinPoint.proceed();
    // audit the connection creation
    final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
    final Action action = generateAuditRecordForConnection(connection, Operation.Connect, connectDetails);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return connection;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) Around(org.aspectj.lang.annotation.Around)

Example 13 with Action

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

the class RelationshipAuditor method removeConnectionAdvice.

/**
 * Audits the removal of relationships via deleteConnection().
 *
 * @param proceedingJoinPoint join point
 * @param id id
 * @param connectionDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ConnectionDAO+) && " + "execution(void deleteConnection(java.lang.String)) && " + "args(id) && " + "target(connectionDAO)")
public void removeConnectionAdvice(ProceedingJoinPoint proceedingJoinPoint, String id, ConnectionDAO connectionDAO) throws Throwable {
    // get the connection before performing the update
    Connection connection = connectionDAO.getConnection(id);
    // perform the underlying operation
    proceedingJoinPoint.proceed();
    // audit the connection creation
    final ConnectDetails connectDetails = createConnectDetails(connection, connection.getRelationships());
    final Action action = generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) Around(org.aspectj.lang.annotation.Around)

Example 14 with Action

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

the class RemoteProcessGroupAuditor method createRemoteProcessGroupAdvice.

/**
 * Audits the creation of remote process groups via createRemoteProcessGroup().
 *
 * 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.RemoteProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.RemoteProcessGroup createRemoteProcessGroup(java.lang.String, org.apache.nifi.web.api.dto.RemoteProcessGroupDTO))")
public RemoteProcessGroup createRemoteProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // create the remote process group
    RemoteProcessGroup remoteProcessGroup = (RemoteProcessGroup) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the remote process group action...
    // get the creation audits
    final Action action = generateAuditRecord(remoteProcessGroup, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return remoteProcessGroup;
}
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 15 with Action

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

the class RemoteProcessGroupAuditor method auditUpdateProcessGroupConfiguration.

/**
 * Audits the update of remote process group configuration.
 *
 * @param proceedingJoinPoint   join point
 * @param remoteProcessGroupDTO dto
 * @param remoteProcessGroupDAO dao
 * @return group
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.RemoteProcessGroup updateRemoteProcessGroup(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)) && " + "args(remoteProcessGroupDTO) && " + "target(remoteProcessGroupDAO)")
public RemoteProcessGroup auditUpdateProcessGroupConfiguration(ProceedingJoinPoint proceedingJoinPoint, RemoteProcessGroupDTO remoteProcessGroupDTO, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
    final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
    // record the current value of this remoteProcessGroups configuration for comparisons later
    final boolean transmissionState = remoteProcessGroup.isTransmitting();
    final Map<String, Object> previousValues = ConfigurationRecorder.capturePreviousValues(CONFIG_RECORDERS, remoteProcessGroup);
    // perform the underlying operation
    final RemoteProcessGroup updatedRemoteProcessGroup = (RemoteProcessGroup) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        final Collection<ActionDetails> details = new ArrayList<>();
        // see if any property has changed
        ConfigurationRecorder.checkConfigured(CONFIG_RECORDERS, remoteProcessGroupDTO, updatedRemoteProcessGroup, previousValues, details);
        final Date timestamp = new Date();
        final Collection<Action> actions = new ArrayList<>();
        // create the remote process group details
        final FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
        // save the actions if necessary
        if (!details.isEmpty()) {
            // create the actions
            for (ActionDetails detail : details) {
                // create a configure action for each updated property
                FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
                remoteProcessGroupAction.setOperation(Operation.Configure);
                remoteProcessGroupAction.setActionDetails(detail);
                actions.add(remoteProcessGroupAction);
            }
        }
        // determine the new executing state
        boolean updatedTransmissionState = updatedRemoteProcessGroup.isTransmitting();
        // determine if the running state has changed
        if (transmissionState != updatedTransmissionState) {
            // create a remote process group action
            FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
            // set the operation accordingly
            if (updatedTransmissionState) {
                remoteProcessGroupAction.setOperation(Operation.Start);
            } else {
                remoteProcessGroupAction.setOperation(Operation.Stop);
            }
            actions.add(remoteProcessGroupAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedRemoteProcessGroup;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ArrayList(java.util.ArrayList) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) Date(java.util.Date) ActionDetails(org.apache.nifi.action.details.ActionDetails) 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