Search in sources :

Example 16 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardKeyService method deleteKey.

@Override
public void deleteKey(String identity) {
    Transaction transaction = null;
    writeLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // delete the keys
        DeleteKeysAction deleteKeys = new DeleteKeysAction(identity);
        transaction.execute(deleteKeys);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        writeLock.unlock();
    }
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) DeleteKeysAction(org.apache.nifi.admin.service.action.DeleteKeysAction) AdministrationException(org.apache.nifi.admin.service.AdministrationException) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 17 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardActionDAO method deleteActions.

@Override
public void deleteActions(Date endDate) throws DataAccessException {
    PreparedStatement statement = null;
    try {
        // -----------------
        // component details
        // -----------------
        // create the move delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "PROCESSOR_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // create the move delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "REMOTE_PROCESS_GROUP_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // --------------
        // action details
        // --------------
        // create the move delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "MOVE_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // create the configure delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "CONFIGURE_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // create the connect delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "CONNECT_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // create the relationship delete statement
        statement = connection.prepareStatement(String.format(DELETE_SPECIFIC_ACTIONS, "PURGE_DETAILS", "ACTION_ID"));
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
        statement.close();
        // -------
        // actions
        // -------
        // create the action delete statement
        statement = connection.prepareStatement(DELETE_ACTIONS);
        statement.setTimestamp(1, new java.sql.Timestamp(endDate.getTime()));
        statement.executeUpdate();
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 18 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardActionDAO method getConfigureDetails.

private ConfigureDetails getConfigureDetails(Integer actionId) throws DataAccessException {
    FlowChangeConfigureDetails configurationDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_CONFIGURE_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            configurationDetails = new FlowChangeConfigureDetails();
            configurationDetails.setName(rs.getString("NAME"));
            configurationDetails.setValue(rs.getString("VALUE"));
            configurationDetails.setPreviousValue(rs.getString("PREVIOUS_VALUE"));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return configurationDetails;
}
Also used : FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 19 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException 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)

Example 20 with DataAccessException

use of org.apache.nifi.admin.dao.DataAccessException in project nifi by apache.

the class StandardActionDAO method getConnectDetails.

private ConnectDetails getConnectDetails(Integer actionId) throws DataAccessException {
    FlowChangeConnectDetails connectionDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_CONNECT_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            final Component sourceComponent = Component.valueOf(rs.getString("SOURCE_TYPE"));
            final Component destinationComponent = Component.valueOf(rs.getString("DESTINATION_TYPE"));
            connectionDetails = new FlowChangeConnectDetails();
            connectionDetails.setSourceId(rs.getString("SOURCE_ID"));
            connectionDetails.setSourceName(rs.getString("SOURCE_NAME"));
            connectionDetails.setSourceType(sourceComponent);
            connectionDetails.setRelationship(rs.getString("RELATIONSHIP"));
            connectionDetails.setDestinationId(rs.getString("DESTINATION_ID"));
            connectionDetails.setDestinationName(rs.getString("DESTINATION_NAME"));
            connectionDetails.setDestinationType(destinationComponent);
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return connectionDetails;
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Component(org.apache.nifi.action.Component) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Aggregations

DataAccessException (org.apache.nifi.admin.dao.DataAccessException)30 PreparedStatement (java.sql.PreparedStatement)22 SQLException (java.sql.SQLException)22 ResultSet (java.sql.ResultSet)14 AdministrationException (org.apache.nifi.admin.service.AdministrationException)8 Transaction (org.apache.nifi.admin.service.transaction.Transaction)8 TransactionException (org.apache.nifi.admin.service.transaction.TransactionException)8 Key (org.apache.nifi.key.Key)5 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 Component (org.apache.nifi.action.Component)3 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)3 ActionDetails (org.apache.nifi.action.details.ActionDetails)3 List (java.util.List)2 Action (org.apache.nifi.action.Action)2 Operation (org.apache.nifi.action.Operation)2 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)2 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)2 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)2