use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.
the class ComponentStateAuditor method clearControllerServiceStateAdvice.
/**
* Audits clearing of state from a Controller Service.
*
* @param proceedingJoinPoint join point
* @param controllerService the controller service
* @throws java.lang.Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.service.ControllerServiceNode)) && " + "args(controllerService)")
public StateMap clearControllerServiceStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceNode controllerService) throws Throwable {
// update the controller service 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 controller service details
FlowChangeExtensionDetails controllerServiceDetails = new FlowChangeExtensionDetails();
controllerServiceDetails.setType(controllerService.getComponentType());
// create the clear action
FlowChangeAction configAction = new FlowChangeAction();
configAction.setUserIdentity(user.getIdentity());
configAction.setOperation(Operation.ClearState);
configAction.setTimestamp(new Date());
configAction.setSourceId(controllerService.getIdentifier());
configAction.setSourceName(controllerService.getName());
configAction.setSourceType(Component.ControllerService);
configAction.setComponentDetails(controllerServiceDetails);
actions.add(configAction);
// record the action
saveActions(actions, logger);
}
return stateMap;
}
use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.
the class ControllerServiceAuditor method getUpdateActionsForReferencingComponents.
/**
* Gets the update actions for all specified referencing components.
*
* @param user user
* @param actions actions
* @param visitedServices services
* @param referencingComponents components
*/
private void getUpdateActionsForReferencingComponents(final NiFiUser user, final Collection<Action> actions, final Collection<String> visitedServices, final Set<ConfiguredComponent> referencingComponents) {
// consider each component updates
for (final ConfiguredComponent component : referencingComponents) {
if (component instanceof ProcessorNode) {
final ProcessorNode processor = ((ProcessorNode) component);
// create the processor details
FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
processorDetails.setType(processor.getComponentType());
// create a processor action
FlowChangeAction processorAction = new FlowChangeAction();
processorAction.setUserIdentity(user.getIdentity());
processorAction.setTimestamp(new Date());
processorAction.setSourceId(processor.getIdentifier());
processorAction.setSourceName(processor.getName());
processorAction.setSourceType(Component.Processor);
processorAction.setComponentDetails(processorDetails);
processorAction.setOperation(ScheduledState.RUNNING.equals(processor.getScheduledState()) ? Operation.Start : Operation.Stop);
actions.add(processorAction);
} else if (component instanceof ReportingTask) {
final ReportingTaskNode reportingTask = ((ReportingTaskNode) component);
// create the reporting task details
FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
taskDetails.setType(reportingTask.getComponentType());
// create a reporting task action
FlowChangeAction reportingTaskAction = new FlowChangeAction();
reportingTaskAction.setUserIdentity(user.getIdentity());
reportingTaskAction.setTimestamp(new Date());
reportingTaskAction.setSourceId(reportingTask.getIdentifier());
reportingTaskAction.setSourceName(reportingTask.getName());
reportingTaskAction.setSourceType(Component.ReportingTask);
reportingTaskAction.setComponentDetails(taskDetails);
reportingTaskAction.setOperation(ScheduledState.RUNNING.equals(reportingTask.getScheduledState()) ? Operation.Start : Operation.Stop);
actions.add(reportingTaskAction);
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode controllerService = ((ControllerServiceNode) component);
// create the controller service details
FlowChangeExtensionDetails serviceDetails = new FlowChangeExtensionDetails();
serviceDetails.setType(controllerService.getComponentType());
// create a controller service action
FlowChangeAction serviceAction = new FlowChangeAction();
serviceAction.setUserIdentity(user.getIdentity());
serviceAction.setTimestamp(new Date());
serviceAction.setSourceId(controllerService.getIdentifier());
serviceAction.setSourceName(controllerService.getName());
serviceAction.setSourceType(Component.ControllerService);
serviceAction.setComponentDetails(serviceDetails);
serviceAction.setOperation(isDisabled(controllerService) ? Operation.Disable : Operation.Enable);
actions.add(serviceAction);
// need to consider components referencing this controller service (transitive)
if (!visitedServices.contains(controllerService.getIdentifier())) {
getUpdateActionsForReferencingComponents(user, actions, visitedServices, controllerService.getReferences().getReferencingComponents());
}
}
}
}
use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.
the class ReportingTaskAuditor method generateAuditRecord.
/**
* Generates an audit record for the creation of a reporting task.
*
* @param reportingTask task
* @param operation operation
* @param actionDetails details
* @return action
*/
public Action generateAuditRecord(ReportingTaskNode reportingTask, 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 reporting task details
FlowChangeExtensionDetails taskDetails = new FlowChangeExtensionDetails();
taskDetails.setType(reportingTask.getComponentType());
// create the reporting task action for adding this reporting task
action = new FlowChangeAction();
action.setUserIdentity(user.getIdentity());
action.setOperation(operation);
action.setTimestamp(new Date());
action.setSourceId(reportingTask.getIdentifier());
action.setSourceName(reportingTask.getName());
action.setSourceType(Component.ReportingTask);
action.setComponentDetails(taskDetails);
if (actionDetails != null) {
action.setActionDetails(actionDetails);
}
}
return action;
}
use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.
the class SnippetAuditor method auditSnippet.
/**
* Audits the specified snippet.
*/
private void auditSnippet(final FlowSnippetDTO snippet) {
final Collection<Action> actions = new ArrayList<>();
final Date timestamp = new Date();
// input ports
for (final PortDTO inputPort : snippet.getInputPorts()) {
actions.add(generateAuditRecord(inputPort.getId(), inputPort.getName(), Component.InputPort, Operation.Add, timestamp));
}
// output ports
for (final PortDTO outputPort : snippet.getOutputPorts()) {
actions.add(generateAuditRecord(outputPort.getId(), outputPort.getName(), Component.OutputPort, Operation.Add, timestamp));
}
// remote processor groups
for (final RemoteProcessGroupDTO remoteProcessGroup : snippet.getRemoteProcessGroups()) {
FlowChangeRemoteProcessGroupDetails remoteProcessGroupDetails = new FlowChangeRemoteProcessGroupDetails();
remoteProcessGroupDetails.setUri(remoteProcessGroup.getTargetUri());
final FlowChangeAction action = generateAuditRecord(remoteProcessGroup.getId(), remoteProcessGroup.getName(), Component.RemoteProcessGroup, Operation.Add, timestamp);
action.setComponentDetails(remoteProcessGroupDetails);
actions.add(action);
}
// processor groups
for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
actions.add(generateAuditRecord(processGroup.getId(), processGroup.getName(), Component.ProcessGroup, Operation.Add, timestamp));
}
// processors
for (final ProcessorDTO processor : snippet.getProcessors()) {
final FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
processorDetails.setType(StringUtils.substringAfterLast(processor.getType(), "."));
final FlowChangeAction action = generateAuditRecord(processor.getId(), processor.getName(), Component.Processor, Operation.Add, timestamp);
action.setComponentDetails(processorDetails);
actions.add(action);
}
// funnels
for (final FunnelDTO funnel : snippet.getFunnels()) {
actions.add(generateAuditRecord(funnel.getId(), StringUtils.EMPTY, Component.Funnel, Operation.Add, timestamp));
}
// connections
for (final ConnectionDTO connection : snippet.getConnections()) {
final ConnectableDTO source = connection.getSource();
final ConnectableDTO destination = connection.getDestination();
// determine the relationships and connection name
final String relationships = CollectionUtils.isEmpty(connection.getSelectedRelationships()) ? StringUtils.EMPTY : StringUtils.join(connection.getSelectedRelationships(), ", ");
final String name = StringUtils.isBlank(connection.getName()) ? relationships : connection.getName();
// create the connect details
FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
connectDetails.setSourceId(source.getId());
connectDetails.setSourceName(source.getName());
connectDetails.setSourceType(determineConnectableType(source));
connectDetails.setRelationship(relationships);
connectDetails.setDestinationId(destination.getId());
connectDetails.setDestinationName(destination.getName());
connectDetails.setDestinationType(determineConnectableType(destination));
// create the audit record
final FlowChangeAction action = generateAuditRecord(connection.getId(), name, Component.Connection, Operation.Connect, timestamp);
action.setActionDetails(connectDetails);
actions.add(action);
}
// save the actions
if (!actions.isEmpty()) {
saveActions(actions, logger);
}
}
use of org.apache.nifi.action.component.details.FlowChangeExtensionDetails in project nifi by apache.
the class StandardNiFiWebConfigurationContext method saveActions.
@Override
public void saveActions(final NiFiWebRequestContext requestContext, final Collection<ConfigurationAction> configurationActions) {
Objects.requireNonNull(configurationActions, "Actions cannot be null.");
// ensure the path could be
if (requestContext.getExtensionType() == null) {
throw new IllegalArgumentException("The UI extension type must be specified.");
}
Component componentType = null;
switch(requestContext.getExtensionType()) {
case ProcessorConfiguration:
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable authorizable = lookup.getProcessor(requestContext.getId()).getAuthorizable();
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
});
componentType = Component.Processor;
break;
case ControllerServiceConfiguration:
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable authorizable = lookup.getControllerService(requestContext.getId()).getAuthorizable();
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
});
componentType = Component.ControllerService;
break;
case ReportingTaskConfiguration:
// authorize access
serviceFacade.authorizeAccess(lookup -> {
final Authorizable authorizable = lookup.getReportingTask(requestContext.getId()).getAuthorizable();
authorizable.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
});
componentType = Component.ReportingTask;
break;
}
if (componentType == null) {
throw new IllegalArgumentException("UI extension type must support Processor, ControllerService, or ReportingTask configuration.");
}
// - when running standalone or cluster ncm - actions from custom UIs are stored locally
// - clustered nodes do not serve custom UIs directly to users so they should never be invoking this method
final Date now = new Date();
final Collection<Action> actions = new HashSet<>(configurationActions.size());
for (final ConfigurationAction configurationAction : configurationActions) {
final FlowChangeExtensionDetails extensionDetails = new FlowChangeExtensionDetails();
extensionDetails.setType(configurationAction.getType());
final FlowChangeConfigureDetails configureDetails = new FlowChangeConfigureDetails();
configureDetails.setName(configurationAction.getName());
configureDetails.setPreviousValue(configurationAction.getPreviousValue());
configureDetails.setValue(configurationAction.getValue());
final FlowChangeAction action = new FlowChangeAction();
action.setTimestamp(now);
action.setSourceId(configurationAction.getId());
action.setSourceName(configurationAction.getName());
action.setSourceType(componentType);
action.setOperation(Operation.Configure);
action.setUserIdentity(getCurrentUserIdentity());
action.setComponentDetails(extensionDetails);
action.setActionDetails(configureDetails);
actions.add(action);
}
if (!actions.isEmpty()) {
try {
// record the operations
auditService.addActions(actions);
} catch (final Throwable t) {
logger.warn("Unable to record actions: " + t.getMessage());
if (logger.isDebugEnabled()) {
logger.warn(StringUtils.EMPTY, t);
}
}
}
}
Aggregations