use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class ProcessGroupAuditor method updateVariableRegistryAdvice.
/**
* Audits the update of process group variable registry.
*
* @param proceedingJoinPoint join point
* @param user the user performing the action
* @param variableRegistry variable registry
* @throws Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ProcessGroupDAO+) && " + "execution(org.apache.nifi.groups.ProcessGroup updateVariableRegistry(org.apache.nifi.authorization.user.NiFiUser, org.apache.nifi.web.api.dto.VariableRegistryDTO)) && " + "args(user, variableRegistry)")
public ProcessGroup updateVariableRegistryAdvice(final ProceedingJoinPoint proceedingJoinPoint, final NiFiUser user, final VariableRegistryDTO variableRegistry) throws Throwable {
final ProcessGroup updatedProcessGroup = (ProcessGroup) proceedingJoinPoint.proceed();
saveUpdateAction(user, variableRegistry.getProcessGroupId(), Operation.Configure);
return updatedProcessGroup;
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class RelationshipAuditor method determineConnectableType.
/**
* Determines the type of component the specified connectable is.
*/
private Component determineConnectableType(Connectable connectable) {
String sourceId = connectable.getIdentifier();
Component componentType = Component.Controller;
if (connectable instanceof ProcessorNode) {
componentType = Component.Processor;
} else if (connectable instanceof RemoteGroupPort) {
final RemoteGroupPort remoteGroupPort = (RemoteGroupPort) connectable;
if (TransferDirection.RECEIVE.equals(remoteGroupPort.getTransferDirection())) {
if (remoteGroupPort.getRemoteProcessGroup() == null) {
componentType = Component.InputPort;
} else {
componentType = Component.OutputPort;
}
} else {
if (remoteGroupPort.getRemoteProcessGroup() == null) {
componentType = Component.OutputPort;
} else {
componentType = Component.InputPort;
}
}
} else if (connectable instanceof Port) {
ProcessGroup processGroup = connectable.getProcessGroup();
if (processGroup.getInputPort(sourceId) != null) {
componentType = Component.InputPort;
} else if (processGroup.getOutputPort(sourceId) != null) {
componentType = Component.OutputPort;
}
} else if (connectable instanceof Funnel) {
componentType = Component.Funnel;
}
return componentType;
}
use of org.apache.nifi.groups.ProcessGroup 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.groups.ProcessGroup in project nifi by apache.
the class TestFlowController method testDeleteProcessGroup.
@Test
public void testDeleteProcessGroup() {
ProcessGroup pg = controller.createProcessGroup("my-process-group");
pg.setName("my-process-group");
ControllerServiceNode cs = controller.createControllerService("org.apache.nifi.NonExistingControllerService", "my-controller-service", systemBundle.getBundleDetails().getCoordinate(), null, false);
pg.addControllerService(cs);
controller.getRootGroup().addProcessGroup(pg);
controller.getRootGroup().removeProcessGroup(pg);
pg.getControllerServices(true);
assertTrue(pg.getControllerServices(true).isEmpty());
}
use of org.apache.nifi.groups.ProcessGroup in project nifi by apache.
the class TestFlowController method testSynchronizeFlowWhenExistingMissingComponentsAreDifferent.
@Test
public void testSynchronizeFlowWhenExistingMissingComponentsAreDifferent() throws IOException {
final StringEncryptor stringEncryptor = StringEncryptor.createEncryptor(nifiProperties);
final FlowSynchronizer standardFlowSynchronizer = new StandardFlowSynchronizer(stringEncryptor, nifiProperties);
final ProcessorNode mockProcessorNode = mock(ProcessorNode.class);
when(mockProcessorNode.getIdentifier()).thenReturn("1");
when(mockProcessorNode.isExtensionMissing()).thenReturn(true);
final ControllerServiceNode mockControllerServiceNode = mock(ControllerServiceNode.class);
when(mockControllerServiceNode.getIdentifier()).thenReturn("2");
when(mockControllerServiceNode.isExtensionMissing()).thenReturn(true);
final ReportingTaskNode mockReportingTaskNode = mock(ReportingTaskNode.class);
when(mockReportingTaskNode.getIdentifier()).thenReturn("3");
when(mockReportingTaskNode.isExtensionMissing()).thenReturn(true);
final ProcessGroup mockRootGroup = mock(ProcessGroup.class);
when(mockRootGroup.findAllProcessors()).thenReturn(Collections.singletonList(mockProcessorNode));
final SnippetManager mockSnippetManager = mock(SnippetManager.class);
when(mockSnippetManager.export()).thenReturn(new byte[0]);
final FlowController mockFlowController = mock(FlowController.class);
when(mockFlowController.getRootGroup()).thenReturn(mockRootGroup);
when(mockFlowController.getAllControllerServices()).thenReturn(new HashSet<>(Arrays.asList(mockControllerServiceNode)));
when(mockFlowController.getAllReportingTasks()).thenReturn(new HashSet<>(Arrays.asList(mockReportingTaskNode)));
when(mockFlowController.getAuthorizer()).thenReturn(authorizer);
when(mockFlowController.getSnippetManager()).thenReturn(mockSnippetManager);
final DataFlow proposedDataFlow = Mockito.mock(DataFlow.class);
when(proposedDataFlow.getMissingComponents()).thenReturn(new HashSet<>());
try {
standardFlowSynchronizer.sync(mockFlowController, proposedDataFlow, stringEncryptor);
Assert.fail("Should have thrown exception");
} catch (UninheritableFlowException e) {
assertTrue(e.getMessage(), e.getMessage().contains("Current flow has missing components that are not considered missing in the proposed flow (1,2,3)"));
}
}
Aggregations