Search in sources :

Example 31 with Action

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

the class TestRemoteProcessGroupAuditor method testConfigureYieldDuration.

@Test
public void testConfigureYieldDuration() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getYieldDuration()).thenReturn("10 sec");
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setYieldDuration("11 sec");
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "Yield Duration", existingRPG.getYieldDuration(), inputRPGDTO.getYieldDuration());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 32 with Action

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

the class TestRemoteProcessGroupAuditor method testConfigureProxyUserClear.

@Test
public void testConfigureProxyUserClear() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getProxyUser()).thenReturn("proxy-user");
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setProxyUser(null);
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "Proxy User", existingRPG.getProxyUser(), inputRPGDTO.getProxyUser());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 33 with Action

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

the class TestRemoteProcessGroupAuditor method testConfigureCommunicationsTimeout.

@Test
public void testConfigureCommunicationsTimeout() throws Throwable {
    final RemoteProcessGroup existingRPG = defaultRemoteProcessGroup();
    when(existingRPG.getCommunicationsTimeout()).thenReturn("30 sec");
    final RemoteProcessGroupDTO inputRPGDTO = defaultInput();
    inputRPGDTO.setCommunicationsTimeout("31 sec");
    final Collection<Action> actions = updateProcessGroupConfiguration(inputRPGDTO, existingRPG);
    assertEquals(1, actions.size());
    final Action action = actions.iterator().next();
    assertEquals(Operation.Configure, action.getOperation());
    assertConfigureDetails(action.getActionDetails(), "Communications Timeout", existingRPG.getCommunicationsTimeout(), inputRPGDTO.getCommunicationsTimeout());
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) RemoteProcessGroupDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO) Test(org.junit.Test)

Example 34 with Action

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

the class StandardActionDAO method findActions.

@Override
public History findActions(HistoryQuery historyQuery) throws DataAccessException {
    // get the sort column
    String sortColumn = "ACTION_TIMESTAMP";
    if (StringUtils.isNotBlank(historyQuery.getSortColumn())) {
        String rawColumnName = historyQuery.getSortColumn();
        if (!columnMap.containsKey(rawColumnName)) {
            throw new IllegalArgumentException(String.format("Unrecognized column name '%s'.", rawColumnName));
        }
        sortColumn = columnMap.get(rawColumnName);
    }
    // get the sort order
    String sortOrder = "desc";
    if (StringUtils.isNotBlank(historyQuery.getSortOrder())) {
        sortOrder = historyQuery.getSortOrder();
    }
    History actionResult = new History();
    Collection<Action> actions = new ArrayList<>();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        List<String> where = new ArrayList<>();
        // append the start time
        if (historyQuery.getStartDate() != null) {
            where.add("ACTION_TIMESTAMP >= ?");
        }
        // append the end time
        if (historyQuery.getEndDate() != null) {
            where.add("ACTION_TIMESTAMP <= ?");
        }
        // append the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            where.add("UPPER(IDENTITY) LIKE ?");
        }
        // append the source id as necessary
        if (historyQuery.getSourceId() != null) {
            where.add("SOURCE_ID = ?");
        }
        String sql = SELECT_ACTION_COUNT;
        if (!where.isEmpty()) {
            sql += " WHERE " + StringUtils.join(where, " AND ");
        }
        // get the total number of actions
        statement = connection.prepareStatement(sql);
        int paramIndex = 1;
        // set the start date as necessary
        if (historyQuery.getStartDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
        }
        // set the end date as necessary
        if (historyQuery.getEndDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
        }
        // set the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
        }
        // set the source id as necessary
        if (historyQuery.getSourceId() != null) {
            statement.setString(paramIndex, historyQuery.getSourceId());
        }
        // execute the statement
        rs = statement.executeQuery();
        // ensure there are results
        if (rs.next()) {
            actionResult.setTotal(rs.getInt("ACTION_COUNT"));
        } else {
            throw new DataAccessException("Unable to determine total action count.");
        }
        sql = SELECT_ACTIONS;
        if (!where.isEmpty()) {
            sql += " WHERE " + StringUtils.join(where, " AND ");
        }
        // append the sort criteria
        sql += (" ORDER BY " + sortColumn + " " + sortOrder);
        // append the offset and limit
        sql += " LIMIT ? OFFSET ?";
        // close the previous statement
        statement.close();
        // create the statement
        statement = connection.prepareStatement(sql);
        paramIndex = 1;
        // set the start date as necessary
        if (historyQuery.getStartDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
        }
        // set the end date as necessary
        if (historyQuery.getEndDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
        }
        // set the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
        }
        // set the source id as necessary
        if (historyQuery.getSourceId() != null) {
            statement.setString(paramIndex++, historyQuery.getSourceId());
        }
        // set the limit
        statement.setInt(paramIndex++, historyQuery.getCount());
        // set the offset according to the currented page calculated above
        statement.setInt(paramIndex, historyQuery.getOffset());
        // execute the query
        rs = statement.executeQuery();
        // create each corresponding action
        while (rs.next()) {
            final Integer actionId = rs.getInt("ID");
            final Operation operation = Operation.valueOf(rs.getString("OPERATION"));
            final Component component = Component.valueOf(rs.getString("SOURCE_TYPE"));
            FlowChangeAction action = new FlowChangeAction();
            action.setId(actionId);
            action.setUserIdentity(rs.getString("IDENTITY"));
            action.setOperation(Operation.valueOf(rs.getString("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.valueOf(rs.getString("SOURCE_TYPE")));
            // 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);
            }
            // add the action
            actions.add(action);
        }
        // populate the action result
        actionResult.setActions(actions);
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return actionResult;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Operation(org.apache.nifi.action.Operation) History(org.apache.nifi.history.History) Date(java.util.Date) ResultSet(java.sql.ResultSet) ActionDetails(org.apache.nifi.action.details.ActionDetails) Component(org.apache.nifi.action.Component) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 35 with Action

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

the class StandardNiFiServiceFacade method getAction.

@Override
public ActionEntity getAction(final Integer actionId) {
    // get the action
    final Action action = auditService.getAction(actionId);
    // ensure the action was found
    if (action == null) {
        throw new ResourceNotFoundException(String.format("Unable to find action with id '%s'.", actionId));
    }
    final AuthorizationResult result = authorizeAction(action);
    final boolean authorized = Result.Approved.equals(result.getResult());
    if (!authorized) {
        throw new AccessDeniedException(result.getExplanation());
    }
    // return the action
    return entityFactory.createActionEntity(dtoFactory.createActionDto(action), authorized);
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) RequestAction(org.apache.nifi.authorization.RequestAction) Action(org.apache.nifi.action.Action) AccessDeniedException(org.apache.nifi.authorization.AccessDeniedException) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult)

Aggregations

Action (org.apache.nifi.action.Action)68 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)46 Around (org.aspectj.lang.annotation.Around)40 ArrayList (java.util.ArrayList)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)21 Date (java.util.Date)19 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)19 Test (org.junit.Test)19 RemoteProcessGroupDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)15 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)12 Operation (org.apache.nifi.action.Operation)8 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)8 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)7 ActionDetails (org.apache.nifi.action.details.ActionDetails)5 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)5 Connection (org.apache.nifi.connectable.Connection)5 Port (org.apache.nifi.connectable.Port)5 ProcessorNode (org.apache.nifi.controller.ProcessorNode)5 ProcessGroup (org.apache.nifi.groups.ProcessGroup)5 RemoteProcessGroupPortDTO (org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO)5