Search in sources :

Example 41 with Action

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

the class ControllerAuditor method updateControllerEventDrivenThreadsAdvice.

/**
 * Audits updating the max number of event driven threads for the controller.
 *
 * @param proceedingJoinPoint join point
 * @param maxEventDrivenThreadCount thread count
 * @param controllerFacade facade
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.controller.ControllerFacade) && " + "execution(void setMaxEventDrivenThreadCount(int)) && " + "args(maxEventDrivenThreadCount) && " + "target(controllerFacade)")
public void updateControllerEventDrivenThreadsAdvice(ProceedingJoinPoint proceedingJoinPoint, int maxEventDrivenThreadCount, ControllerFacade controllerFacade) throws Throwable {
    // get the current max thread count
    int previousMaxEventDrivenThreadCount = controllerFacade.getMaxEventDrivenThreadCount();
    // update the processors state
    proceedingJoinPoint.proceed();
    // ensure the value changed
    if (previousMaxEventDrivenThreadCount != maxEventDrivenThreadCount) {
        // get the current user
        NiFiUser user = NiFiUserUtils.getNiFiUser();
        // ensure the user was found
        if (user != null) {
            Collection<Action> actions = new ArrayList<>();
            // create the configure details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("Controller Max Event Driven Thread Count");
            configDetails.setValue(String.valueOf(maxEventDrivenThreadCount));
            configDetails.setPreviousValue(String.valueOf(previousMaxEventDrivenThreadCount));
            // create the config action
            FlowChangeAction configAction = new FlowChangeAction();
            configAction.setUserIdentity(user.getIdentity());
            configAction.setOperation(Operation.Configure);
            configAction.setTimestamp(new Date());
            configAction.setSourceId("Flow Controller");
            configAction.setSourceName("Flow Controller");
            configAction.setSourceType(Component.Controller);
            configAction.setActionDetails(configDetails);
            actions.add(configAction);
            // record the action
            saveActions(actions, logger);
        }
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ArrayList(java.util.ArrayList) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 42 with Action

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

the class ControllerAuditor method updateControllerTimerDrivenThreadsAdvice.

/**
 * Audits updating the max number of timer driven threads for the controller.
 *
 * @param proceedingJoinPoint joint point
 * @param maxTimerDrivenThreadCount thread count
 * @param controllerFacade facade
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.controller.ControllerFacade) && " + "execution(void setMaxTimerDrivenThreadCount(int)) && " + "args(maxTimerDrivenThreadCount) && " + "target(controllerFacade)")
public void updateControllerTimerDrivenThreadsAdvice(ProceedingJoinPoint proceedingJoinPoint, int maxTimerDrivenThreadCount, ControllerFacade controllerFacade) throws Throwable {
    // get the current max thread count
    int previousMaxTimerDrivenThreadCount = controllerFacade.getMaxTimerDrivenThreadCount();
    // update the processors state
    proceedingJoinPoint.proceed();
    // ensure the value changed
    if (previousMaxTimerDrivenThreadCount != maxTimerDrivenThreadCount) {
        // get the current user
        NiFiUser user = NiFiUserUtils.getNiFiUser();
        // ensure the user was found
        if (user != null) {
            Collection<Action> actions = new ArrayList<>();
            // create the configure details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("Controller Max Timer Driven Thread Count");
            configDetails.setValue(String.valueOf(maxTimerDrivenThreadCount));
            configDetails.setPreviousValue(String.valueOf(previousMaxTimerDrivenThreadCount));
            // create the config action
            FlowChangeAction configAction = new FlowChangeAction();
            configAction.setUserIdentity(user.getIdentity());
            configAction.setOperation(Operation.Configure);
            configAction.setTimestamp(new Date());
            configAction.setSourceId("Flow Controller");
            configAction.setSourceName("Flow Controller");
            configAction.setSourceType(Component.Controller);
            configAction.setActionDetails(configDetails);
            actions.add(configAction);
            // record the action
            saveActions(actions, logger);
        }
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ArrayList(java.util.ArrayList) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 43 with Action

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

the class ControllerServiceAuditor method removeControllerServiceAdvice.

/**
 * Audits the removal of a controller service via deleteControllerService().
 *
 * @param proceedingJoinPoint join point
 * @param controllerServiceId id
 * @param controllerServiceDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ControllerServiceDAO+) && " + "execution(void deleteControllerService(java.lang.String)) && " + "args(controllerServiceId) && " + "target(controllerServiceDAO)")
public void removeControllerServiceAdvice(ProceedingJoinPoint proceedingJoinPoint, String controllerServiceId, ControllerServiceDAO controllerServiceDAO) throws Throwable {
    // get the controller service before removing it
    ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
    // remove the controller service
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the controller service removal
    final Action action = generateAuditRecord(controllerService, 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) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) Around(org.aspectj.lang.annotation.Around)

Example 44 with Action

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

the class FunnelAuditor method createFunnelAdvice.

/**
 * Audits the creation of a funnel.
 *
 * @param proceedingJoinPoint join point
 * @return funnel
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.FunnelDAO+) && " + "execution(org.apache.nifi.connectable.Funnel createFunnel(java.lang.String, org.apache.nifi.web.api.dto.FunnelDTO))")
public Funnel createFunnelAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    // perform the underlying operation
    Funnel funnel = (Funnel) proceedingJoinPoint.proceed();
    // perform the audit
    final Action action = generateAuditRecord(funnel, Operation.Add);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
    return funnel;
}
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 45 with Action

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

the class PortAuditor method updatePortAdvice.

/**
 * Audits the update of a port.
 *
 * @param proceedingJoinPoint join point
 * @param portDTO port dto
 * @param portDAO port dao
 * @return port
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.PortDAO+) && " + "execution(org.apache.nifi.connectable.Port updatePort(org.apache.nifi.web.api.dto.PortDTO)) && " + "args(portDTO) && " + "target(portDAO)")
public Port updatePortAdvice(ProceedingJoinPoint proceedingJoinPoint, PortDTO portDTO, PortDAO portDAO) throws Throwable {
    final Port port = portDAO.getPort(portDTO.getId());
    final ScheduledState scheduledState = port.getScheduledState();
    final String name = port.getName();
    final String comments = port.getComments();
    final int maxConcurrentTasks = port.getMaxConcurrentTasks();
    final Set<String> existingUsers = new HashSet<>();
    final Set<String> existingGroups = new HashSet<>();
    boolean isRootGroupPort = false;
    if (port instanceof RootGroupPort) {
        isRootGroupPort = true;
        existingUsers.addAll(((RootGroupPort) port).getUserAccessControl());
        existingGroups.addAll(((RootGroupPort) port).getGroupAccessControl());
    }
    // perform the underlying operation
    final Port updatedPort = (Port) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<ActionDetails> configurationDetails = new ArrayList<>();
        // see if the name has changed
        if (name != null && portDTO.getName() != null && !name.equals(updatedPort.getName())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("Name");
            configDetails.setValue(updatedPort.getName());
            configDetails.setPreviousValue(name);
            configurationDetails.add(configDetails);
        }
        // see if the comments has changed
        if (comments != null && portDTO.getComments() != null && !comments.equals(updatedPort.getComments())) {
            // create the config details
            FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
            configDetails.setName("Comments");
            configDetails.setValue(updatedPort.getComments());
            configDetails.setPreviousValue(comments);
            configurationDetails.add(configDetails);
        }
        // if this is a root group port, consider concurrent tasks
        if (isRootGroupPort) {
            if (portDTO.getConcurrentlySchedulableTaskCount() != null && updatedPort.getMaxConcurrentTasks() != maxConcurrentTasks) {
                // create the config details
                FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
                configDetails.setName("Concurrent Tasks");
                configDetails.setValue(String.valueOf(updatedPort.getMaxConcurrentTasks()));
                configDetails.setPreviousValue(String.valueOf(maxConcurrentTasks));
                configurationDetails.add(configDetails);
            }
            // if user access control was specified in the request
            if (portDTO.getUserAccessControl() != null) {
                final Set<String> newUsers = new HashSet<>(portDTO.getUserAccessControl());
                newUsers.removeAll(existingUsers);
                final Set<String> removedUsers = new HashSet<>(existingUsers);
                removedUsers.removeAll(portDTO.getUserAccessControl());
                // if users were added/removed
                if (newUsers.size() > 0 || removedUsers.size() > 0) {
                    // create the config details
                    FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
                    configDetails.setName("User Access Control");
                    configDetails.setValue(StringUtils.join(portDTO.getUserAccessControl(), ", "));
                    configDetails.setPreviousValue(StringUtils.join(existingUsers, ", "));
                    configurationDetails.add(configDetails);
                }
            }
            // if group access control was specified in the request
            if (portDTO.getGroupAccessControl() != null) {
                final Set<String> newGroups = new HashSet<>(portDTO.getGroupAccessControl());
                newGroups.removeAll(existingGroups);
                final Set<String> removedGroups = new HashSet<>(existingGroups);
                removedGroups.removeAll(portDTO.getGroupAccessControl());
                // if groups were added/removed
                if (newGroups.size() > 0 || removedGroups.size() > 0) {
                    // create the config details
                    FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
                    configDetails.setName("Group Access Control");
                    configDetails.setValue(StringUtils.join(portDTO.getGroupAccessControl(), ", "));
                    configDetails.setPreviousValue(StringUtils.join(existingGroups, ", "));
                    configurationDetails.add(configDetails);
                }
            }
        }
        final Collection<Action> actions = new ArrayList<>();
        // determine the type of port
        Component componentType = Component.OutputPort;
        if (ConnectableType.INPUT_PORT == updatedPort.getConnectableType()) {
            componentType = Component.InputPort;
        }
        // add each configuration detail
        if (!configurationDetails.isEmpty()) {
            // create the timestamp for the update
            Date timestamp = new Date();
            // create the actions
            for (ActionDetails detail : configurationDetails) {
                // create the port action for updating the name
                FlowChangeAction portAction = new FlowChangeAction();
                portAction.setUserIdentity(user.getIdentity());
                portAction.setOperation(Operation.Configure);
                portAction.setTimestamp(timestamp);
                portAction.setSourceId(updatedPort.getIdentifier());
                portAction.setSourceName(updatedPort.getName());
                portAction.setSourceType(componentType);
                portAction.setActionDetails(detail);
                actions.add(portAction);
            }
        }
        // determine the new executing state
        final ScheduledState updatedScheduledState = updatedPort.getScheduledState();
        // determine if the running state has changed
        if (scheduledState != updatedScheduledState) {
            // create a processor action
            FlowChangeAction processorAction = new FlowChangeAction();
            processorAction.setUserIdentity(user.getIdentity());
            processorAction.setTimestamp(new Date());
            processorAction.setSourceId(updatedPort.getIdentifier());
            processorAction.setSourceName(updatedPort.getName());
            processorAction.setSourceType(componentType);
            // 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 updatedPort;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) ArrayList(java.util.ArrayList) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Date(java.util.Date) ScheduledState(org.apache.nifi.controller.ScheduledState) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ActionDetails(org.apache.nifi.action.details.ActionDetails) Component(org.apache.nifi.action.Component) HashSet(java.util.HashSet) 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