use of org.apache.nifi.action.Component in project nifi by apache.
the class SnippetAuditor method determineConnectableType.
/**
* Determines the type of component the specified connectable is.
*/
private Component determineConnectableType(ConnectableDTO connectable) {
Component component = Component.Controller;
final String connectableType = connectable.getType();
if (ConnectableType.PROCESSOR.name().equals(connectableType)) {
component = Component.Processor;
} else if (ConnectableType.INPUT_PORT.name().equals(connectableType)) {
component = Component.InputPort;
} else if (ConnectableType.OUTPUT_PORT.name().equals(connectableType)) {
component = Component.OutputPort;
} else if (ConnectableType.FUNNEL.name().equals(connectableType)) {
component = Component.Funnel;
} else {
component = Component.RemoteProcessGroup;
}
return component;
}
use of org.apache.nifi.action.Component 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;
}
use of org.apache.nifi.action.Component in project nifi by apache.
the class StandardNiFiServiceFacade method updateProcessor.
@Override
public ProcessorEntity updateProcessor(final Revision revision, final ProcessorDTO processorDTO) {
// get the component, ensure we have access to it, and perform the update request
final ProcessorNode processorNode = processorDAO.getProcessor(processorDTO.getId());
final RevisionUpdate<ProcessorDTO> snapshot = updateComponent(revision, processorNode, () -> processorDAO.updateProcessor(processorDTO), proc -> dtoFactory.createProcessorDto(proc));
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(processorNode);
final ProcessorStatusDTO status = dtoFactory.createProcessorStatusDto(controllerFacade.getProcessorStatus(processorNode.getIdentifier()));
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(processorNode.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createProcessorEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, status, bulletinEntities);
}
use of org.apache.nifi.action.Component in project nifi by apache.
the class StandardNiFiServiceFacade method createReportingTask.
@Override
public ReportingTaskEntity createReportingTask(final Revision revision, final ReportingTaskDTO reportingTaskDTO) {
final NiFiUser user = NiFiUserUtils.getNiFiUser();
// request claim for component to be created... revision already verified (version == 0)
final RevisionClaim claim = new StandardRevisionClaim(revision);
// update revision through revision manager
final RevisionUpdate<ReportingTaskDTO> snapshot = revisionManager.updateRevision(claim, user, () -> {
// create the reporting task
final ReportingTaskNode reportingTask = reportingTaskDAO.createReportingTask(reportingTaskDTO);
// save the update
controllerFacade.save();
final ReportingTaskDTO dto = dtoFactory.createReportingTaskDto(reportingTask);
final FlowModification lastMod = new FlowModification(revision.incrementRevision(revision.getClientId()), user.getIdentity());
return new StandardRevisionUpdate<>(dto, lastMod);
});
final ReportingTaskNode reportingTask = reportingTaskDAO.getReportingTask(reportingTaskDTO.getId());
final PermissionsDTO permissions = dtoFactory.createPermissionsDto(reportingTask);
final List<BulletinDTO> bulletins = dtoFactory.createBulletinDtos(bulletinRepository.findBulletinsForSource(reportingTask.getIdentifier()));
final List<BulletinEntity> bulletinEntities = bulletins.stream().map(bulletin -> entityFactory.createBulletinEntity(bulletin, permissions.getCanRead())).collect(Collectors.toList());
return entityFactory.createReportingTaskEntity(snapshot.getComponent(), dtoFactory.createRevisionDTO(snapshot.getLastModification()), permissions, bulletinEntities);
}
use of org.apache.nifi.action.Component in project nifi by apache.
the class StandardNiFiServiceFacade method authorizeAction.
private AuthorizationResult authorizeAction(final Action action) {
final String sourceId = action.getSourceId();
final Component type = action.getSourceType();
Authorizable authorizable;
try {
switch(type) {
case Processor:
authorizable = authorizableLookup.getProcessor(sourceId).getAuthorizable();
break;
case ReportingTask:
authorizable = authorizableLookup.getReportingTask(sourceId).getAuthorizable();
break;
case ControllerService:
authorizable = authorizableLookup.getControllerService(sourceId).getAuthorizable();
break;
case Controller:
authorizable = controllerFacade;
break;
case InputPort:
authorizable = authorizableLookup.getInputPort(sourceId);
break;
case OutputPort:
authorizable = authorizableLookup.getOutputPort(sourceId);
break;
case ProcessGroup:
authorizable = authorizableLookup.getProcessGroup(sourceId).getAuthorizable();
break;
case RemoteProcessGroup:
authorizable = authorizableLookup.getRemoteProcessGroup(sourceId);
break;
case Funnel:
authorizable = authorizableLookup.getFunnel(sourceId);
break;
case Connection:
authorizable = authorizableLookup.getConnection(sourceId).getAuthorizable();
break;
case AccessPolicy:
authorizable = authorizableLookup.getAccessPolicyById(sourceId);
break;
case User:
case UserGroup:
authorizable = authorizableLookup.getTenant();
break;
default:
throw new WebApplicationException(Response.serverError().entity("An unexpected type of component is the source of this action.").build());
}
} catch (final ResourceNotFoundException e) {
// if the underlying component is gone, use the controller to see if permissions should be allowed
authorizable = controllerFacade;
}
// perform the authorization
return authorizable.checkAuthorization(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
}
Aggregations