Search in sources :

Example 6 with ActionDetails

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

use of org.apache.nifi.action.details.ActionDetails in project nifi by apache.

the class StandardActionDAO method getAction.

@Override
public Action getAction(Integer actionId) throws DataAccessException {
    FlowChangeAction action = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_ACTION_BY_ID);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            Operation operation = Operation.valueOf(rs.getString("OPERATION"));
            Component component = Component.valueOf(rs.getString("SOURCE_TYPE"));
            // populate the action
            action = new FlowChangeAction();
            action.setId(rs.getInt("ID"));
            action.setUserIdentity(rs.getString("IDENTITY"));
            action.setOperation(operation);
            action.setTimestamp(new Date(rs.getTimestamp("ACTION_TIMESTAMP").getTime()));
            action.setSourceId(rs.getString("SOURCE_ID"));
            action.setSourceName(rs.getString("SOURCE_NAME"));
            action.setSourceType(component);
            // get the component details if appropriate
            ComponentDetails componentDetails = null;
            if (Component.Processor.equals(component) || Component.ControllerService.equals(component) || Component.ReportingTask.equals(component)) {
                componentDetails = getExtensionDetails(actionId);
            } else if (Component.RemoteProcessGroup.equals(component)) {
                componentDetails = getRemoteProcessGroupDetails(actionId);
            }
            if (componentDetails != null) {
                action.setComponentDetails(componentDetails);
            }
            // get the action details if appropriate
            ActionDetails actionDetails = null;
            if (Operation.Move.equals(operation)) {
                actionDetails = getMoveDetails(actionId);
            } else if (Operation.Configure.equals(operation)) {
                actionDetails = getConfigureDetails(actionId);
            } else if (Operation.Connect.equals(operation) || Operation.Disconnect.equals(operation)) {
                actionDetails = getConnectDetails(actionId);
            } else if (Operation.Purge.equals(operation)) {
                actionDetails = getPurgeDetails(actionId);
            }
            // set the action details
            if (actionDetails != null) {
                action.setActionDetails(actionDetails);
            }
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return action;
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ActionDetails(org.apache.nifi.action.details.ActionDetails) Operation(org.apache.nifi.action.Operation) Component(org.apache.nifi.action.Component) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) Date(java.util.Date) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Aggregations

FlowChangeAction (org.apache.nifi.action.FlowChangeAction)7 ActionDetails (org.apache.nifi.action.details.ActionDetails)7 Date (java.util.Date)6 ArrayList (java.util.ArrayList)5 Action (org.apache.nifi.action.Action)5 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 Component (org.apache.nifi.action.Component)3 Operation (org.apache.nifi.action.Operation)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)3 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)3 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)3 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)3 Around (org.aspectj.lang.annotation.Around)3 FlowChangeMoveDetails (org.apache.nifi.action.details.FlowChangeMoveDetails)2 HashSet (java.util.HashSet)1 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)1 RemoteProcessGroupDetails (org.apache.nifi.action.component.details.RemoteProcessGroupDetails)1