Search in sources :

Example 31 with FlowChangeAction

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

the class RemoteProcessGroupAuditor method auditUpdateProcessGroupPortConfiguration.

private RemoteGroupPort auditUpdateProcessGroupPortConfiguration(ProceedingJoinPoint proceedingJoinPoint, RemoteProcessGroupPortDTO remoteProcessGroupPortDto, RemoteProcessGroup remoteProcessGroup, RemoteGroupPort remoteProcessGroupPort) throws Throwable {
    final Map<String, Object> previousValues = ConfigurationRecorder.capturePreviousValues(PORT_CONFIG_RECORDERS, remoteProcessGroupPort);
    // perform the underlying operation
    final RemoteGroupPort updatedRemoteProcessGroupPort = (RemoteGroupPort) proceedingJoinPoint.proceed();
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user != null) {
        final Collection<ActionDetails> details = new ArrayList<>();
        // see if any property has changed
        ConfigurationRecorder.checkConfigured(PORT_CONFIG_RECORDERS, remoteProcessGroupPortDto, updatedRemoteProcessGroupPort, 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
        for (ActionDetails detail : details) {
            // create a configure action for each updated property
            FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, remoteProcessGroup, remoteProcessGroupDetails);
            remoteProcessGroupAction.setOperation(Operation.Configure);
            remoteProcessGroupAction.setActionDetails(detail);
            actions.add(remoteProcessGroupAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedRemoteProcessGroupPort;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) 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)

Example 32 with FlowChangeAction

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

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

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

the class SnippetAuditor method generateAuditRecord.

/**
 * Generates an audit record for the creation of the specified funnel.
 */
private FlowChangeAction generateAuditRecord(String id, String name, Component type, Operation operation, Date timestamp) {
    FlowChangeAction action = null;
    // get the current user
    NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // create the action for adding this funnel
        action = new FlowChangeAction();
        action.setUserIdentity(user.getIdentity());
        action.setOperation(operation);
        action.setTimestamp(timestamp);
        action.setSourceId(id);
        action.setSourceName(name);
        action.setSourceType(type);
    }
    return action;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 35 with FlowChangeAction

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

the class UserAuditor method generateAuditRecord.

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

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