Search in sources :

Example 71 with ProcessGroup

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;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) Around(org.aspectj.lang.annotation.Around)

Example 72 with ProcessGroup

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;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) ProcessorNode(org.apache.nifi.controller.ProcessorNode) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Port(org.apache.nifi.connectable.Port) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Component(org.apache.nifi.action.Component)

Example 73 with ProcessGroup

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;
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) Port(org.apache.nifi.connectable.Port) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Connection(org.apache.nifi.connectable.Connection) Snippet(org.apache.nifi.controller.Snippet) Around(org.aspectj.lang.annotation.Around)

Example 74 with ProcessGroup

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());
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 75 with ProcessGroup

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)"));
    }
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) FlowSynchronizer(org.apache.nifi.controller.serialization.FlowSynchronizer) ProcessGroup(org.apache.nifi.groups.ProcessGroup) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) DataFlow(org.apache.nifi.cluster.protocol.DataFlow) Test(org.junit.Test)

Aggregations

ProcessGroup (org.apache.nifi.groups.ProcessGroup)185 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)97 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)68 ProcessorNode (org.apache.nifi.controller.ProcessorNode)50 Port (org.apache.nifi.connectable.Port)40 RootGroupPort (org.apache.nifi.remote.RootGroupPort)37 Connection (org.apache.nifi.connectable.Connection)36 ArrayList (java.util.ArrayList)35 InstantiatedVersionedProcessGroup (org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup)35 Test (org.junit.Test)35 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)34 HashSet (java.util.HashSet)32 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)32 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)29 FlowController (org.apache.nifi.controller.FlowController)27 Connectable (org.apache.nifi.connectable.Connectable)26 VersionControlInformation (org.apache.nifi.registry.flow.VersionControlInformation)25 Funnel (org.apache.nifi.connectable.Funnel)24 List (java.util.List)22 Label (org.apache.nifi.controller.label.Label)22