use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.
the class ProcessGroupAuditor method updateVersionControlInformationAdvice.
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateVersionControlInformation(..))")
public ProcessGroup updateVersionControlInformationAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
final VersionControlInformationDTO vciDto = (VersionControlInformationDTO) proceedingJoinPoint.getArgs()[0];
final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(vciDto.getGroupId());
final VersionControlInformation vci = processGroup.getVersionControlInformation();
final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
final Operation operation;
if (vci == null) {
operation = Operation.StartVersionControl;
} else {
operation = Operation.CommitLocalChanges;
}
saveUpdateAction(NiFiUserUtils.getNiFiUser(), vciDto.getGroupId(), operation);
return updatedProcessGroup;
}
use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.
the class ProcessGroupAuditor method saveUpdateAction.
private void saveUpdateAction(final NiFiUser user, final String groupId, final Operation operation) throws Throwable {
ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
// if the user was starting/stopping this process group
FlowChangeAction action = new FlowChangeAction();
action.setUserIdentity(user.getIdentity());
action.setSourceId(processGroup.getIdentifier());
action.setSourceName(processGroup.getName());
action.setSourceType(Component.ProcessGroup);
action.setTimestamp(new Date());
action.setOperation(operation);
// add this action
saveAction(action, logger);
}
use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.
the class ProcessGroupAuditor method updateProcessGroupAdvice.
/**
* Audits the update of process group configuration.
*
* @param proceedingJoinPoint join point
* @param processGroupDTO dto
* @return group
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroup(org.apache.nifi.web.api.dto.ProcessGroupDTO)) && " + "args(processGroupDTO)")
public ProcessGroup updateProcessGroupAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessGroupDTO processGroupDTO) throws Throwable {
ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
ProcessGroup processGroup = processGroupDAO.getProcessGroup(processGroupDTO.getId());
String name = processGroup.getName();
String comments = processGroup.getComments();
// perform the underlying operation
ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
Collection<ActionDetails> details = new ArrayList<>();
// see if the name has changed
if (name != null && updatedProcessGroup.getName() != null && !name.equals(updatedProcessGroup.getName())) {
// create the config details
FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
configDetails.setName("name");
configDetails.setValue(updatedProcessGroup.getName());
configDetails.setPreviousValue(name);
details.add(configDetails);
}
// see if the comments has changed
if (comments != null && updatedProcessGroup.getComments() != null && !comments.equals(updatedProcessGroup.getComments())) {
// create the config details
FlowChangeConfigureDetails configDetails = new FlowChangeConfigureDetails();
configDetails.setName("comments");
configDetails.setValue(updatedProcessGroup.getComments());
configDetails.setPreviousValue(comments);
details.add(configDetails);
}
// hold all actions
Collection<Action> actions = new ArrayList<>();
// save the actions if necessary
if (!details.isEmpty()) {
Date timestamp = new Date();
// create the actions
for (ActionDetails detail : details) {
// determine the type of operation being performed
Operation operation = Operation.Configure;
if (detail instanceof FlowChangeMoveDetails) {
operation = Operation.Move;
}
// create the port action for updating the name
FlowChangeAction processGroupAction = new FlowChangeAction();
processGroupAction.setUserIdentity(user.getIdentity());
processGroupAction.setOperation(operation);
processGroupAction.setTimestamp(timestamp);
processGroupAction.setSourceId(updatedProcessGroup.getIdentifier());
processGroupAction.setSourceName(updatedProcessGroup.getName());
processGroupAction.setSourceType(Component.ProcessGroup);
processGroupAction.setActionDetails(detail);
actions.add(processGroupAction);
}
}
// save actions if necessary
if (!actions.isEmpty()) {
saveActions(actions, logger);
}
}
return updatedProcessGroup;
}
use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.
the class SnippetAuditor method updateSnippetAdvice.
/**
* Audits a bulk move.
*
* @param proceedingJoinPoint join point
* @param snippetDTO dto
* @param snippetDAO dao
* @return snippet
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(org.apache.nifi.controller.Snippet updateSnippetComponents(org.apache.nifi.web.api.dto.SnippetDTO)) && " + "args(snippetDTO) && " + "target(snippetDAO)")
public Snippet updateSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, SnippetDTO snippetDTO, SnippetDAO snippetDAO) throws Throwable {
// get the snippet before removing it
Snippet snippet = snippetDAO.getSnippet(snippetDTO.getId());
final String previousGroupId = snippet.getParentGroupId();
// perform the underlying operation
snippet = (Snippet) proceedingJoinPoint.proceed();
// if this snippet is linked and its parent group id has changed
final String groupId = snippetDTO.getParentGroupId();
if (!previousGroupId.equals(groupId)) {
// create move audit records for all items in this snippet
final Collection<Action> actions = new ArrayList<>();
for (String id : snippet.getProcessors().keySet()) {
final ProcessorNode processor = processorDAO.getProcessor(id);
final Action action = processorAuditor.generateAuditRecord(processor, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getFunnels().keySet()) {
final Funnel funnel = funnelDAO.getFunnel(id);
final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getInputPorts().keySet()) {
final Port port = inputPortDAO.getPort(id);
final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getOutputPorts().keySet()) {
final Port port = outputPortDAO.getPort(id);
final Action action = portAuditor.generateAuditRecord(port, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getRemoteProcessGroups().keySet()) {
final RemoteProcessGroup remoteProcessGroup = remoteProcessGroupDAO.getRemoteProcessGroup(id);
final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getProcessGroups().keySet()) {
final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(id);
final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
for (String id : snippet.getConnections().keySet()) {
final Connection connection = connectionDAO.getConnection(id);
final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Move, createMoveDetails(previousGroupId, groupId, logger));
if (action != null) {
actions.add(action);
}
}
// save the actions
if (CollectionUtils.isNotEmpty(actions)) {
saveActions(actions, logger);
}
}
return snippet;
}
use of org.apache.nifi.web.dao.ProcessGroupDAO in project nifi by apache.
the class ProcessGroupAuditor method updateProcessGroupFlowAdvice.
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateProcessGroupFlow(..))")
public ProcessGroup updateProcessGroupFlowAdvice(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
final Object[] args = proceedingJoinPoint.getArgs();
final String groupId = (String) args[0];
final NiFiUser user = (NiFiUser) args[1];
final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
final ProcessGroup processGroup = processGroupDAO.getProcessGroup(groupId);
final VersionControlInformation vci = processGroup.getVersionControlInformation();
final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
final VersionControlInformation updatedVci = updatedProcessGroup.getVersionControlInformation();
final Operation operation;
if (vci == null) {
operation = Operation.StartVersionControl;
} else {
if (updatedVci == null) {
operation = Operation.StopVersionControl;
} else if (vci.getVersion() == updatedVci.getVersion()) {
operation = Operation.RevertLocalChanges;
} else {
operation = Operation.ChangeVersion;
}
}
saveUpdateAction(user, groupId, operation);
return updatedProcessGroup;
}
Aggregations