use of org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails in project nifi by apache.
the class DtoFactory method createComponentDetailsDto.
/**
* Creates a ComponentDetailsDTO for the specified ComponentDetails.
*
* @param componentDetails details
* @return dto
*/
private ComponentDetailsDTO createComponentDetailsDto(final ComponentDetails componentDetails) {
if (componentDetails == null) {
return null;
}
if (componentDetails instanceof FlowChangeExtensionDetails) {
final ExtensionDetailsDTO processorDetails = new ExtensionDetailsDTO();
processorDetails.setType(((ExtensionDetails) componentDetails).getType());
return processorDetails;
} else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
final RemoteProcessGroupDetailsDTO remoteProcessGroupDetails = new RemoteProcessGroupDetailsDTO();
remoteProcessGroupDetails.setUri(((RemoteProcessGroupDetails) componentDetails).getUri());
return remoteProcessGroupDetails;
} else {
throw new WebApplicationException(new IllegalArgumentException(String.format("Unrecognized type of component details encountered %s during serialization. ", componentDetails.toString())));
}
}
use of org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails in project nifi by apache.
the class RemoteProcessGroupAuditor method generateAuditRecord.
/**
* Generates an audit record for the specified remote process group.
*
* @param remoteProcessGroup group
* @param operation operation
* @param actionDetails details
* @return action
*/
public Action generateAuditRecord(RemoteProcessGroup remoteProcessGroup, Operation operation, ActionDetails actionDetails) {
FlowChangeAction action = null;
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
// create the remote process group details
FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
// create the remote process group action
action = new FlowChangeAction();
action.setUserIdentity(user.getIdentity());
action.setOperation(operation);
action.setTimestamp(new Date());
action.setSourceId(remoteProcessGroup.getIdentifier());
action.setSourceName(remoteProcessGroup.getName());
action.setSourceType(Component.RemoteProcessGroup);
action.setComponentDetails(remoteProcessGroupDetails);
if (actionDetails != null) {
action.setActionDetails(actionDetails);
}
}
return action;
}
use of org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails in project nifi by apache.
the class RemoteProcessGroupAuditor method auditUpdateProcessGroupConfiguration.
/**
* Audits the update of remote process group configuration.
*
* @param proceedingJoinPoint join point
* @param remoteProcessGroupDTO dto
* @param remoteProcessGroupDAO dao
* @return group
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.RemoteProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.RemoteProcessGroup updateRemoteProcessGroup(org.apache.nifi.web.api.dto.RemoteProcessGroupDTO)) && " + "args(remoteProcessGroupDTO) && " + "target(remoteProcessGroupDAO)")
public RemoteProcessGroup auditUpdateProcessGroupConfiguration(ProceedingJoinPoint proceedingJoinPoint, RemoteProcessGroupDTO remoteProcessGroupDTO, RemoteProcessGroupDAO remoteProcessGroupDAO) throws Throwable {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupDTO.getId());
// record the current value of this remoteProcessGroups configuration for comparisons later
final boolean transmissionState = remoteProcessGroup.isTransmitting();
final Map<String, Object> previousValues = ConfigurationRecorder.capturePreviousValues(CONFIG_RECORDERS, remoteProcessGroup);
// perform the underlying operation
final RemoteProcessGroup updatedRemoteProcessGroup = (RemoteProcessGroup) proceedingJoinPoint.proceed();
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
final Collection<ActionDetails> details = new ArrayList<>();
// see if any property has changed
ConfigurationRecorder.checkConfigured(CONFIG_RECORDERS, remoteProcessGroupDTO, updatedRemoteProcessGroup, previousValues, details);
final Date timestamp = new Date();
final Collection<Action> actions = new ArrayList<>();
// create the remote process group details
final FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = createFlowChangeDetails(remoteProcessGroup);
// save the actions if necessary
if (!details.isEmpty()) {
// create the actions
for (ActionDetails detail : details) {
// create a configure action for each updated property
FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
remoteProcessGroupAction.setOperation(Operation.Configure);
remoteProcessGroupAction.setActionDetails(detail);
actions.add(remoteProcessGroupAction);
}
}
// determine the new executing state
boolean updatedTransmissionState = updatedRemoteProcessGroup.isTransmitting();
// determine if the running state has changed
if (transmissionState != updatedTransmissionState) {
// create a remote process group action
FlowChangeAction remoteProcessGroupAction = createFlowChangeAction(user, timestamp, updatedRemoteProcessGroup, remoteProcessGroupDetails);
// set the operation accordingly
if (updatedTransmissionState) {
remoteProcessGroupAction.setOperation(Operation.Start);
} else {
remoteProcessGroupAction.setOperation(Operation.Stop);
}
actions.add(remoteProcessGroupAction);
}
// ensure there are actions to record
if (!actions.isEmpty()) {
// save the actions
saveActions(actions, logger);
}
}
return updatedRemoteProcessGroup;
}
use of org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails in project nifi by apache.
the class RemoteProcessGroupAuditor method createFlowChangeDetails.
private FlowChangeRemoteProcessGroupDetails createFlowChangeDetails(RemoteProcessGroup remoteProcessGroup) {
FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
return remoteProcessGroupDetails;
}
use of org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails 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);
}
}
Aggregations