Search in sources :

Example 6 with FlowChangeExtensionDetails

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

the class ReportingTaskAuditor method updateReportingTaskAdvice.

/**
 * Audits the configuration of a reporting task.
 *
 * @param proceedingJoinPoint joinpoint
 * @param reportingTaskDTO dto
 * @param reportingTaskDAO dao
 * @return object
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ReportingTaskDAO+) && " + "execution(org.apache.nifi.controller.ReportingTaskNode updateReportingTask(org.apache.nifi.web.api.dto.ReportingTaskDTO)) && " + "args(reportingTaskDTO) && " + "target(reportingTaskDAO)")
public Object updateReportingTaskAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskDTO reportingTaskDTO, ReportingTaskDAO reportingTaskDAO) throws Throwable {
    // determine the initial values for each property/setting thats changing
    ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
    final Map<String, String> values = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
    final ScheduledState scheduledState = reportingTask.getScheduledState();
    // update the reporting task state
    final ReportingTaskNode updatedReportingTask = (ReportingTaskNode) proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add the reporting task action...
    reportingTask = reportingTaskDAO.getReportingTask(updatedReportingTask.getIdentifier());
    // get the current user
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    // ensure the user was found
    if (user != null) {
        // determine the updated values
        Map<String, String> updatedValues = extractConfiguredPropertyValues(reportingTask, reportingTaskDTO);
        // create the reporting task details
        FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
        taskDetails.setType(reportingTask.getComponentType());
        // create a reporting task 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) {
                // clear the value if this property is sensitive
                final PropertyDescriptor propertyDescriptor = reportingTask.getReportingTask().getPropertyDescriptor(property);
                if (propertyDescriptor != null && propertyDescriptor.isSensitive()) {
                    if (newValue != null) {
                        newValue = "********";
                    }
                    if (oldValue != null) {
                        oldValue = "********";
                    }
                } else if (ANNOTATION_DATA.equals(property)) {
                    if (newValue != null) {
                        newValue = "<annotation data not shown>";
                    }
                    if (oldValue != null) {
                        oldValue = "<annotation data not shown>";
                    }
                }
                final FlowChangeConfigureDetails actionDetails = new FlowChangeConfigureDetails();
                actionDetails.setName(property);
                actionDetails.setValue(newValue);
                actionDetails.setPreviousValue(oldValue);
                // create a configuration action
                FlowChangeAction configurationAction = new FlowChangeAction();
                configurationAction.setUserIdentity(user.getIdentity());
                configurationAction.setOperation(operation);
                configurationAction.setTimestamp(actionTimestamp);
                configurationAction.setSourceId(reportingTask.getIdentifier());
                configurationAction.setSourceName(reportingTask.getName());
                configurationAction.setSourceType(Component.ReportingTask);
                configurationAction.setComponentDetails(taskDetails);
                configurationAction.setActionDetails(actionDetails);
                actions.add(configurationAction);
            }
        }
        // determine the new executing state
        final ScheduledState updatedScheduledState = reportingTask.getScheduledState();
        // determine if the running state has changed and its not disabled
        if (scheduledState != updatedScheduledState) {
            // create a reporting task action
            FlowChangeAction taskAction = new FlowChangeAction();
            taskAction.setUserIdentity(user.getIdentity());
            taskAction.setTimestamp(new Date());
            taskAction.setSourceId(reportingTask.getIdentifier());
            taskAction.setSourceName(reportingTask.getName());
            taskAction.setSourceType(Component.ReportingTask);
            taskAction.setComponentDetails(taskDetails);
            // set the operation accordingly
            if (ScheduledState.RUNNING.equals(updatedScheduledState)) {
                taskAction.setOperation(Operation.Start);
            } else if (ScheduledState.DISABLED.equals(updatedScheduledState)) {
                taskAction.setOperation(Operation.Disable);
            } else {
                // state is now stopped... consider the previous state
                if (ScheduledState.RUNNING.equals(scheduledState)) {
                    taskAction.setOperation(Operation.Stop);
                } else if (ScheduledState.DISABLED.equals(scheduledState)) {
                    taskAction.setOperation(Operation.Enable);
                }
            }
            actions.add(taskAction);
        }
        // ensure there are actions to record
        if (!actions.isEmpty()) {
            // save the actions
            saveActions(actions, logger);
        }
    }
    return updatedReportingTask;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ArrayList(java.util.ArrayList) Operation(org.apache.nifi.action.Operation) Date(java.util.Date) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ScheduledState(org.apache.nifi.controller.ScheduledState) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Around(org.aspectj.lang.annotation.Around)

Example 7 with FlowChangeExtensionDetails

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

the class StandardActionDAO method createAction.

@Override
public Action createAction(Action action) throws DataAccessException {
    if (action.getUserIdentity() == null) {
        throw new IllegalArgumentException("User cannot be null.");
    }
    if (action.getTimestamp() == null) {
        throw new IllegalArgumentException("Action timestamp cannot be null.");
    }
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // obtain a statement to insert to the action table
        statement = connection.prepareStatement(INSERT_ACTION, Statement.RETURN_GENERATED_KEYS);
        statement.setString(1, StringUtils.left(action.getUserIdentity(), 4096));
        statement.setString(2, action.getSourceId());
        statement.setString(3, StringUtils.left(action.getSourceName(), 1000));
        statement.setString(4, action.getSourceType().name());
        statement.setString(5, action.getOperation().name());
        statement.setTimestamp(6, new java.sql.Timestamp(action.getTimestamp().getTime()));
        // insert the action
        int updateCount = statement.executeUpdate();
        final FlowChangeAction createdAction = new FlowChangeAction();
        createdAction.setUserIdentity(action.getUserIdentity());
        createdAction.setSourceId(action.getSourceId());
        createdAction.setSourceName(action.getSourceName());
        createdAction.setSourceType(action.getSourceType());
        createdAction.setOperation(action.getOperation());
        createdAction.setTimestamp(action.getTimestamp());
        createdAction.setActionDetails(action.getActionDetails());
        createdAction.setComponentDetails(action.getComponentDetails());
        // get the action id
        rs = statement.getGeneratedKeys();
        if (updateCount == 1 && rs.next()) {
            createdAction.setId(rs.getInt(1));
        } else {
            throw new DataAccessException("Unable to insert action.");
        }
        // close the previous statement
        statement.close();
        // determine the type of component
        ComponentDetails componentDetails = createdAction.getComponentDetails();
        if (componentDetails instanceof FlowChangeExtensionDetails) {
            createExtensionDetails(createdAction.getId(), (ExtensionDetails) componentDetails);
        } else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
            createRemoteProcessGroupDetails(createdAction.getId(), (RemoteProcessGroupDetails) componentDetails);
        }
        // determine the type of action
        ActionDetails details = createdAction.getActionDetails();
        if (details instanceof FlowChangeConnectDetails) {
            createConnectDetails(createdAction.getId(), (ConnectDetails) details);
        } else if (details instanceof FlowChangeMoveDetails) {
            createMoveDetails(createdAction.getId(), (MoveDetails) details);
        } else if (details instanceof FlowChangeConfigureDetails) {
            createConfigureDetails(createdAction.getId(), (ConfigureDetails) details);
        } else if (details instanceof FlowChangePurgeDetails) {
            createPurgeDetails(createdAction.getId(), (PurgeDetails) details);
        }
        return createdAction;
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) MoveDetails(org.apache.nifi.action.details.MoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PreparedStatement(java.sql.PreparedStatement) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ActionDetails(org.apache.nifi.action.details.ActionDetails) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 8 with FlowChangeExtensionDetails

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

the class StandardActionDAO method getExtensionDetails.

private ExtensionDetails getExtensionDetails(Integer actionId) throws DataAccessException {
    FlowChangeExtensionDetails extensionDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_EXTENSION_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            extensionDetails = new FlowChangeExtensionDetails();
            extensionDetails.setType(rs.getString("TYPE"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return extensionDetails;
}
Also used : SQLException(java.sql.SQLException) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 9 with FlowChangeExtensionDetails

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

the class ComponentStateAuditor method clearReportingTaskStateAdvice.

/**
 * Audits clearing of state from a Processor.
 *
 * @param proceedingJoinPoint join point
 * @param reportingTask the reporting task
 * @throws java.lang.Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.ReportingTaskNode)) && " + "args(reportingTask)")
public StateMap clearReportingTaskStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskNode reportingTask) throws Throwable {
    // update the reporting task 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 reporting task details
        FlowChangeExtensionDetails reportingTaskDetails = new FlowChangeExtensionDetails();
        reportingTaskDetails.setType(reportingTask.getReportingTask().getClass().getSimpleName());
        // create the clear action
        FlowChangeAction configAction = new FlowChangeAction();
        configAction.setUserIdentity(user.getIdentity());
        configAction.setOperation(Operation.ClearState);
        configAction.setTimestamp(new Date());
        configAction.setSourceId(reportingTask.getIdentifier());
        configAction.setSourceName(reportingTask.getName());
        configAction.setSourceType(Component.ReportingTask);
        configAction.setComponentDetails(reportingTaskDetails);
        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 10 with FlowChangeExtensionDetails

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

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