Search in sources :

Example 21 with FlowChangeAction

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

the class ComponentStateAuditor method clearProcessorStateAdvice.

/**
 * Audits clearing of state from a Processor.
 *
 * @param proceedingJoinPoint join point
 * @param processor the processor
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.ProcessorNode)) && " + "args(processor)")
public StateMap clearProcessorStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessorNode processor) throws Throwable {
    // update the processors state
    final StateMap stateMap = (StateMap) proceedingJoinPoint.proceed();
    // if no exception were thrown, add the clear action...
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<Action> actions = new ArrayList<>();
        // create the processor details
        FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(processor.getComponentType());
        // create the clear action
        FlowChangeAction configAction = new FlowChangeAction();
        configAction.setUserIdentity(user.getIdentity());
        configAction.setOperation(Operation.ClearState);
        configAction.setTimestamp(new Date());
        configAction.setSourceId(processor.getIdentifier());
        configAction.setSourceName(processor.getName());
        configAction.setSourceType(Component.Processor);
        configAction.setComponentDetails(processorDetails);
        actions.add(configAction);
        // record the action
        saveActions(actions, logger);
    }
    return stateMap;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) StateMap(org.apache.nifi.components.state.StateMap) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ArrayList(java.util.ArrayList) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 22 with FlowChangeAction

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

the class ComponentStateAuditor method clearControllerServiceStateAdvice.

/**
 * Audits clearing of state from a Controller Service.
 *
 * @param proceedingJoinPoint join point
 * @param controllerService the controller service
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.service.ControllerServiceNode)) && " + "args(controllerService)")
public StateMap clearControllerServiceStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceNode controllerService) throws Throwable {
    // update the controller service state
    final StateMap stateMap = (StateMap) proceedingJoinPoint.proceed();
    // if no exception were thrown, add the clear action...
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        Collection<Action> actions = new ArrayList<>();
        // create the controller service details
        FlowChangeExtensionDetails controllerServiceDetails = new FlowChangeExtensionDetails();
        controllerServiceDetails.setType(controllerService.getComponentType());
        // create the clear action
        FlowChangeAction configAction = new FlowChangeAction();
        configAction.setUserIdentity(user.getIdentity());
        configAction.setOperation(Operation.ClearState);
        configAction.setTimestamp(new Date());
        configAction.setSourceId(controllerService.getIdentifier());
        configAction.setSourceName(controllerService.getName());
        configAction.setSourceType(Component.ControllerService);
        configAction.setComponentDetails(controllerServiceDetails);
        actions.add(configAction);
        // record the action
        saveActions(actions, logger);
    }
    return stateMap;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) StateMap(org.apache.nifi.components.state.StateMap) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ArrayList(java.util.ArrayList) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 23 with FlowChangeAction

use of org.apache.nifi.action.FlowChangeAction 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 24 with FlowChangeAction

use of org.apache.nifi.action.FlowChangeAction 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 25 with FlowChangeAction

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

the class ControllerServiceAuditor method getUpdateActionsForReferencingComponents.

/**
 * Gets the update actions for all specified referencing components.
 *
 * @param user user
 * @param actions actions
 * @param visitedServices services
 * @param referencingComponents components
 */
private void getUpdateActionsForReferencingComponents(final NiFiUser user, final Collection<Action> actions, final Collection<String> visitedServices, final Set<ConfiguredComponent> referencingComponents) {
    // consider each component updates
    for (final ConfiguredComponent component : referencingComponents) {
        if (component instanceof ProcessorNode) {
            final ProcessorNode processor = ((ProcessorNode) component);
            // create the processor details
            FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
            processorDetails.setType(processor.getComponentType());
            // 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);
            processorAction.setOperation(ScheduledState.RUNNING.equals(processor.getScheduledState()) ? Operation.Start : Operation.Stop);
            actions.add(processorAction);
        } else if (component instanceof ReportingTask) {
            final ReportingTaskNode reportingTask = ((ReportingTaskNode) component);
            // create the reporting task details
            FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
            taskDetails.setType(reportingTask.getComponentType());
            // create a reporting task action
            FlowChangeAction reportingTaskAction = new FlowChangeAction();
            reportingTaskAction.setUserIdentity(user.getIdentity());
            reportingTaskAction.setTimestamp(new Date());
            reportingTaskAction.setSourceId(reportingTask.getIdentifier());
            reportingTaskAction.setSourceName(reportingTask.getName());
            reportingTaskAction.setSourceType(Component.ReportingTask);
            reportingTaskAction.setComponentDetails(taskDetails);
            reportingTaskAction.setOperation(ScheduledState.RUNNING.equals(reportingTask.getScheduledState()) ? Operation.Start : Operation.Stop);
            actions.add(reportingTaskAction);
        } else if (component instanceof ControllerServiceNode) {
            final ControllerServiceNode controllerService = ((ControllerServiceNode) component);
            // create the controller service details
            FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
            serviceDetails.setType(controllerService.getComponentType());
            // create a controller service action
            FlowChangeAction serviceAction = new FlowChangeAction();
            serviceAction.setUserIdentity(user.getIdentity());
            serviceAction.setTimestamp(new Date());
            serviceAction.setSourceId(controllerService.getIdentifier());
            serviceAction.setSourceName(controllerService.getName());
            serviceAction.setSourceType(Component.ControllerService);
            serviceAction.setComponentDetails(serviceDetails);
            serviceAction.setOperation(isDisabled(controllerService) ? Operation.Disable : Operation.Enable);
            actions.add(serviceAction);
            // need to consider components referencing this controller service (transitive)
            if (!visitedServices.contains(controllerService.getIdentifier())) {
                getUpdateActionsForReferencingComponents(user, actions, visitedServices, controllerService.getReferences().getReferencingComponents());
            }
        }
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Aggregations

FlowChangeAction (org.apache.nifi.action.FlowChangeAction)39 Date (java.util.Date)34 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)29 Action (org.apache.nifi.action.Action)19 ArrayList (java.util.ArrayList)18 Around (org.aspectj.lang.annotation.Around)15 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)13 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)13 Operation (org.apache.nifi.action.Operation)9 ActionDetails (org.apache.nifi.action.details.ActionDetails)7 Component (org.apache.nifi.action.Component)5 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)5 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 HashSet (java.util.HashSet)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)3 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)3 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3