Search in sources :

Example 11 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails 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 12 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails 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)

Example 13 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class ReportingTaskAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of a reporting task.
 *
 * @param reportingTask task
 * @param operation operation
 * @param actionDetails details
 * @return action
 */
public Action generateAuditRecord(ReportingTaskNode reportingTask, Operation operation, ActionDetails actionDetails) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the reporting task details
        FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
        taskDetails.setType(reportingTask.getComponentType());
        // create the reporting task action for adding this reporting task
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(new Date());
        action.setSourceId(reportingTask.getIdentifier());
        action.setSourceName(reportingTask.getName());
        action.setSourceType(Component.ReportingTask);
        action.setComponentDetails(taskDetails);
        if (actionDetails != null) {
            action.setActionDetails(actionDetails);
        }
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 14 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class SnippetAuditor method auditSnippet.

/**
 * Audits the specified snippet.
 */
private void auditSnippet(final FlowSnippetDTO snippet) {
    final Collection<Action> actions = new ArrayList<>();
    final Date timestamp = new Date();
    // input ports
    for (final PortDTO inputPort : snippet.getInputPorts()) {
        actions.add(generateAuditRecord(inputPort.getId(), inputPort.getName(), Component.InputPort, Operation.Add, timestamp));
    }
    // output ports
    for (final PortDTO outputPort : snippet.getOutputPorts()) {
        actions.add(generateAuditRecord(outputPort.getId(), outputPort.getName(), Component.OutputPort, Operation.Add, timestamp));
    }
    // remote processor groups
    for (final RemoteProcessGroupDTO remoteProcessGroup : snippet.getRemoteProcessGroups()) {
        FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
        remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
        final FlowChangeAction action = generateAuditRecord(remoteProcessGroup.getId(), remoteProcessGroup.getName(), Component.RemoteProcessGroup, Operation.Add, timestamp);
        action.setComponentDetails(remoteProcessGroupDetails);
        actions.add(action);
    }
    // processor groups
    for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
        actions.add(generateAuditRecord(processGroup.getId(), processGroup.getName(), Component.ProcessGroup, Operation.Add, timestamp));
    }
    // processors
    for (final ProcessorDTO processor : snippet.getProcessors()) {
        final FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
        processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));
        final FlowChangeAction action = generateAuditRecord(processor.getId(), processor.getName(), Component.Processor, Operation.Add, timestamp);
        action.setComponentDetails(processorDetails);
        actions.add(action);
    }
    // funnels
    for (final FunnelDTO funnel : snippet.getFunnels()) {
        actions.add(generateAuditRecord(funnel.getId(), StringUtils.EMPTY, Component.Funnel, Operation.Add, timestamp));
    }
    // connections
    for (final ConnectionDTO connection : snippet.getConnections()) {
        final ConnectableDTO source = connection.getSource();
        final ConnectableDTO destination = connection.getDestination();
        // determine the relationships and connection name
        final String relationships = CollectionUtils.isEmpty(connection.getSelectedRelationships()) ? StringUtils.EMPTY : StringUtils.join(connection.getSelectedRelationships(), ", ");
        final String name = StringUtils.isBlank(connection.getName()) ? relationships : connection.getName();
        // create the connect details
        FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
        connectDetails.setSourceId(source.getId());
        connectDetails.setSourceName(source.getName());
        connectDetails.setSourceType(determineConnectableType(source));
        connectDetails.setRelationship(relationships);
        connectDetails.setDestinationId(destination.getId());
        connectDetails.setDestinationName(destination.getName());
        connectDetails.setDestinationType(determineConnectableType(destination));
        // create the audit record
        final FlowChangeAction action = generateAuditRecord(connection.getId(), name, Component.Connection, Operation.Connect, timestamp);
        action.setActionDetails(connectDetails);
        actions.add(action);
    }
    // save the actions
    if (!actions.isEmpty()) {
        saveActions(actions, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) PortDTO(org.apache.nifi.web.api.dto.PortDTO) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) ArrayList(java.util.ArrayList) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) Date(java.util.Date) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 15 with FlowChangeExtensionDetails

use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.

the class StandardNiFiWebConfigurationContext method saveActions.

@Override
public void saveActions(final NiFiWebRequestContext requestContext, final Collection<ConfigurationAction> configurationActions) {
    Objects.requireNonNull(configurationActions, "Actions cannot be null.");
    // ensure the path could be
    if (requestContext.getExtensionType() == null) {
        throw new IllegalArgumentException("The UI extension type must be specified.");
    }
    Component componentType = null;
    switch(requestContext.getExtensionType()) {
        case ProcessorConfiguration:
            // authorize access
            serviceFacade.authorizeAccess(lookup -> {
                final Authorizable authorizable = lookup.getProcessor(requestContext.getId()).getAuthorizable();
                authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            });
            componentType = Component.Processor;
            break;
        case ControllerServiceConfiguration:
            // authorize access
            serviceFacade.authorizeAccess(lookup -> {
                final Authorizable authorizable = lookup.getControllerService(requestContext.getId()).getAuthorizable();
                authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            });
            componentType = Component.ControllerService;
            break;
        case ReportingTaskConfiguration:
            // authorize access
            serviceFacade.authorizeAccess(lookup -> {
                final Authorizable authorizable = lookup.getReportingTask(requestContext.getId()).getAuthorizable();
                authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
            });
            componentType = Component.ReportingTask;
            break;
    }
    if (componentType == null) {
        throw new IllegalArgumentException("UI extension type must support Processor, ControllerService, or ReportingTask configuration.");
    }
    // - when running standalone or cluster ncm - actions from custom UIs are stored locally
    // - clustered nodes do not serve custom UIs directly to users so they should never be invoking this method
    final Date now = new Date();
    final Collection<Action> actions = new HashSet<>(configurationActions.size());
    for (final ConfigurationAction configurationAction : configurationActions) {
        final FlowChangeExtensionDetails extensionDetails = new FlowChangeExtensionDetails();
        extensionDetails.setType(configurationAction.getType());
        final FlowChangeConfigureDetails configureDetails = new FlowChangeConfigureDetails();
        configureDetails.setName(configurationAction.getName());
        configureDetails.setPreviousValue(configurationAction.getPreviousValue());
        configureDetails.setValue(configurationAction.getValue());
        final FlowChangeAction action = new FlowChangeAction();
        action.setTimestamp(now);
        action.setSourceId(configurationAction.getId());
        action.setSourceName(configurationAction.getName());
        action.setSourceType(componentType);
        action.setOperation(Operation.Configure);
        action.setUserIdentity(getCurrentUserIdentity());
        action.setComponentDetails(extensionDetails);
        action.setActionDetails(configureDetails);
        actions.add(action);
    }
    if (!actions.isEmpty()) {
        try {
            // record the operations
            auditService.addActions(actions);
        } catch (final Throwable t) {
            logger.warn("Unable to record actions: " + t.getMessage());
            if (logger.isDebugEnabled()) {
                logger.warn(StringUtils.EMPTY, t);
            }
        }
    }
}
Also used : Action(org.apache.nifi.action.Action) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) RequestAction(org.apache.nifi.authorization.RequestAction) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) Component(org.apache.nifi.action.Component) Date(java.util.Date) HashSet(java.util.HashSet) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Aggregations

FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)15 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)13 Date (java.util.Date)12 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)9 Action (org.apache.nifi.action.Action)8 ArrayList (java.util.ArrayList)7 Around (org.aspectj.lang.annotation.Around)6 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)5 Operation (org.apache.nifi.action.Operation)3 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 StateMap (org.apache.nifi.components.state.StateMap)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 RemoteProcessGroupDetails (org.apache.nifi.action.component.details.RemoteProcessGroupDetails)2 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)2