Search in sources :

Example 11 with Operation

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

the class ProcessGroupAuditor method updateProcessGroupFlowAdvice.

@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroupFlow(..))")
public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    final Object[] args = proceedingJoinPoint.getArgs();
    final String groupId = (String) args[0];
    final NiFiUser user = (NiFiUser) args[1];
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
    final VersionControlInformation vci = processGroup.getVersionControlInformation();
    final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
    final VersionControlInformation updatedVci = updatedProcessGroup.getVersionControlInformation();
    final Operation operation;
    if (vci == null) {
        operation = Operation.StartVersionControl;
    } else {
        if (updatedVci == null) {
            operation = Operation.StopVersionControl;
        } else if (vci.getVersion() == updatedVci.getVersion()) {
            operation = Operation.RevertLocalChanges;
        } else {
            operation = Operation.ChangeVersion;
        }
    }
    saveUpdateAction(user, groupId, operation);
    return updatedProcessGroup;
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Operation(org.apache.nifi.action.Operation) Around(org.aspectj.lang.annotation.Around)

Example 12 with Operation

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

the class UserGroupAuditor method updateUserAdvice.

/**
 * Audits the configuration of a single user.
 *
 * @param proceedingJoinPoint join point
 * @param userGroupDTO dto
 * @param userGroupDAO dao
 * @return node
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.UserGroupDAO+) && " + "execution(org.apache.nifi.authorization.Group updateUserGroup(org.apache.nifi.web.api.dto.UserGroupDTO)) && " + "args(userGroupDTO) && " + "target(userGroupDAO)")
public Group updateUserAdvice(ProceedingJoinPoint proceedingJoinPoint, UserGroupDTO userGroupDTO, UserGroupDAO userGroupDAO) throws Throwable {
    // determine the initial values for each property/setting that's changing
    Group user = userGroupDAO.getUserGroup(userGroupDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(user, userGroupDTO);
    // update the user state
    final Group updatedUserGroup = (Group) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the user group action...
    user = userGroupDAO.getUserGroup(updatedUserGroup.getIdentifier());
    // get the current user
    NiFiUser niFiUser = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (niFiUser != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(user, userGroupDTO);
        // create a user action
        Date actionTimestamp = new Date();
        Collection<Action> actions = new ArrayList<>();
        // go through each updated value
        for (String property : updatedValues.keySet()) {
            String newValue = updatedValues.get(property);
            String oldValue = values.get(property);
            Operation operation = null;
            // determine the type of operation
            if (oldValue == null || newValue == null || !newValue.equals(oldValue)) {
                operation = Operation.Configure;
            }
            // create a configuration action accordingly
            if (operation != null) {
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(niFiUser.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(user.getIdentifier());
                configurationAction.setSourceName(user.getName());
                configurationAction.setSourceType(Component.UserGroup);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedUserGroup;
}
Also used : Group(org.apache.nifi.authorization.Group) 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) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 13 with Operation

use of org.apache.nifi.action.Operation 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

Operation (org.apache.nifi.action.Operation)13 Around (org.aspectj.lang.annotation.Around)11 Date (java.util.Date)9 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)9 ArrayList (java.util.ArrayList)8 Action (org.apache.nifi.action.Action)8 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)8 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)7 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)3 ActionDetails (org.apache.nifi.action.details.ActionDetails)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 ProcessGroupDAO (org.apache.nifi.web.dao.ProcessGroupDAO)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Future (java.util.concurrent.Future)2 Component (org.apache.nifi.action.Component)2 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2