Search in sources :

Example 61 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class StandardFlowSerializer method addProcessGroup.

private void addProcessGroup(final Element parentElement, final ProcessGroup group, final String elementName, final ScheduledStateLookup scheduledStateLookup) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement(elementName);
    parentElement.appendChild(element);
    addTextElement(element, "id", group.getIdentifier());
    addTextElement(element, "versionedComponentId", group.getVersionedComponentId());
    addTextElement(element, "name", group.getName());
    addPosition(element, group.getPosition());
    addTextElement(element, "comment", group.getComments());
    final VersionControlInformation versionControlInfo = group.getVersionControlInformation();
    if (versionControlInfo != null) {
        final Element versionControlInfoElement = doc.createElement("versionControlInformation");
        addTextElement(versionControlInfoElement, "registryId", versionControlInfo.getRegistryIdentifier());
        addTextElement(versionControlInfoElement, "bucketId", versionControlInfo.getBucketIdentifier());
        addTextElement(versionControlInfoElement, "bucketName", versionControlInfo.getBucketName());
        addTextElement(versionControlInfoElement, "flowId", versionControlInfo.getFlowIdentifier());
        addTextElement(versionControlInfoElement, "flowName", versionControlInfo.getFlowName());
        addTextElement(versionControlInfoElement, "flowDescription", versionControlInfo.getFlowDescription());
        addTextElement(versionControlInfoElement, "version", versionControlInfo.getVersion());
        element.appendChild(versionControlInfoElement);
    }
    for (final ProcessorNode processor : group.getProcessors()) {
        addProcessor(element, processor, scheduledStateLookup);
    }
    if (group.isRootGroup()) {
        for (final Port port : group.getInputPorts()) {
            addRootGroupPort(element, (RootGroupPort) port, "inputPort", scheduledStateLookup);
        }
        for (final Port port : group.getOutputPorts()) {
            addRootGroupPort(element, (RootGroupPort) port, "outputPort", scheduledStateLookup);
        }
    } else {
        for (final Port port : group.getInputPorts()) {
            addPort(element, port, "inputPort", scheduledStateLookup);
        }
        for (final Port port : group.getOutputPorts()) {
            addPort(element, port, "outputPort", scheduledStateLookup);
        }
    }
    for (final Label label : group.getLabels()) {
        addLabel(element, label);
    }
    for (final Funnel funnel : group.getFunnels()) {
        addFunnel(element, funnel);
    }
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        addProcessGroup(element, childGroup, "processGroup", scheduledStateLookup);
    }
    for (final RemoteProcessGroup remoteRef : group.getRemoteProcessGroups()) {
        addRemoteProcessGroup(element, remoteRef, scheduledStateLookup);
    }
    for (final Connection connection : group.getConnections()) {
        addConnection(element, connection);
    }
    for (final ControllerServiceNode service : group.getControllerServices(false)) {
        addControllerService(element, service);
    }
    for (final Template template : group.getTemplates()) {
        addTemplate(element, template);
    }
    final VariableRegistry variableRegistry = group.getVariableRegistry();
    for (final Map.Entry<VariableDescriptor, String> entry : variableRegistry.getVariableMap().entrySet()) {
        addVariable(element, entry.getKey().getName(), entry.getValue());
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Element(org.w3c.dom.Element) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) Connection(org.apache.nifi.connectable.Connection) VariableRegistry(org.apache.nifi.registry.VariableRegistry) Document(org.w3c.dom.Document) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Template(org.apache.nifi.controller.Template) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Map(java.util.Map)

Example 62 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode 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());
            }
        }
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Example 63 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class ProcessorAuditor method removeProcessorAdvice.

/**
 * Audits the removal of a processor via deleteProcessor().
 *
 * @param proceedingJoinPoint join point
 * @param processorId processor id
 * @param processorDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.ProcessorDAO+) && " + "execution(void deleteProcessor(java.lang.String)) && " + "args(processorId) && " + "target(processorDAO)")
public void removeProcessorAdvice(ProceedingJoinPoint proceedingJoinPoint, String processorId, ProcessorDAO processorDAO) throws Throwable {
    // get the processor before removing it
    ProcessorNode processor = processorDAO.getProcessor(processorId);
    // remove the processor
    proceedingJoinPoint.proceed();
    // if no exceptions were thrown, add removal actions...
    // audit the processor removal
    final Action action = generateAuditRecord(processor, Operation.Remove);
    // save the actions
    if (action != null) {
        saveAction(action, logger);
    }
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Around(org.aspectj.lang.annotation.Around)

Example 64 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class SnippetAuditor method removeSnippetAdvice.

/**
 * Audits bulk delete.
 *
 * @param proceedingJoinPoint join point
 * @param snippetId snippet id
 * @param snippetDAO dao
 * @throws Throwable ex
 */
@Around("within(org.apache.nifi.web.dao.SnippetDAO+) && " + "execution(void deleteSnippetComponents(java.lang.String)) && " + "args(snippetId) && " + "target(snippetDAO)")
public void removeSnippetAdvice(ProceedingJoinPoint proceedingJoinPoint, String snippetId, SnippetDAO snippetDAO) throws Throwable {
    // get the snippet before removing it
    final Snippet snippet = snippetDAO.getSnippet(snippetId);
    // locate all the components being removed
    final Set<Funnel> funnels = new HashSet<>();
    for (String id : snippet.getFunnels().keySet()) {
        funnels.add(funnelDAO.getFunnel(id));
    }
    final Set<Port> inputPorts = new HashSet<>();
    for (String id : snippet.getInputPorts().keySet()) {
        inputPorts.add(inputPortDAO.getPort(id));
    }
    final Set<Port> outputPorts = new HashSet<>();
    for (String id : snippet.getOutputPorts().keySet()) {
        outputPorts.add(outputPortDAO.getPort(id));
    }
    final Set<RemoteProcessGroup> remoteProcessGroups = new HashSet<>();
    for (String id : snippet.getRemoteProcessGroups().keySet()) {
        remoteProcessGroups.add(remoteProcessGroupDAO.getRemoteProcessGroup(id));
    }
    final Set<ProcessGroup> processGroups = new HashSet<>();
    final ProcessGroupDAO processGroupDAO = getProcessGroupDAO();
    for (String id : snippet.getProcessGroups().keySet()) {
        processGroups.add(processGroupDAO.getProcessGroup(id));
    }
    final Set<ProcessorNode> processors = new HashSet<>();
    for (String id : snippet.getProcessors().keySet()) {
        processors.add(processorDAO.getProcessor(id));
    }
    final Set<Connection> connections = new HashSet<>();
    for (String id : snippet.getConnections().keySet()) {
        connections.add(connectionDAO.getConnection(id));
    }
    // remove the snippet and components
    proceedingJoinPoint.proceed();
    final Collection<Action> actions = new ArrayList<>();
    // audit funnel removal
    for (Funnel funnel : funnels) {
        final Action action = funnelAuditor.generateAuditRecord(funnel, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port inputPort : inputPorts) {
        final Action action = portAuditor.generateAuditRecord(inputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Port outputPort : outputPorts) {
        final Action action = portAuditor.generateAuditRecord(outputPort, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (RemoteProcessGroup remoteProcessGroup : remoteProcessGroups) {
        final Action action = remoteProcessGroupAuditor.generateAuditRecord(remoteProcessGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessGroup processGroup : processGroups) {
        final Action action = processGroupAuditor.generateAuditRecord(processGroup, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (ProcessorNode processor : processors) {
        final Action action = processorAuditor.generateAuditRecord(processor, Operation.Remove);
        if (action != null) {
            actions.add(action);
        }
    }
    for (Connection connection : connections) {
        final ConnectDetails connectDetails = relationshipAuditor.createConnectDetails(connection, connection.getRelationships());
        final Action action = relationshipAuditor.generateAuditRecordForConnection(connection, Operation.Disconnect, connectDetails);
        if (action != null) {
            actions.add(action);
        }
    }
    // save the actions
    if (CollectionUtils.isNotEmpty(actions)) {
        saveActions(actions, logger);
    }
}
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) Port(org.apache.nifi.connectable.Port) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) Snippet(org.apache.nifi.controller.Snippet) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroupDAO(org.apache.nifi.web.dao.ProcessGroupDAO) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) HashSet(java.util.HashSet) Around(org.aspectj.lang.annotation.Around)

Example 65 with ProcessorNode

use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.

the class TestProcessorLifecycle method validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyUninterruptable.

/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely and written to ignore thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyUninterruptable() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "1 sec");
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    // sets the scenario for the processor to run
    this.blockingUninterruptableOnUnschedule(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 3000L);
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 4000L);
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Aggregations

ProcessorNode (org.apache.nifi.controller.ProcessorNode)88 ProcessGroup (org.apache.nifi.groups.ProcessGroup)45 Port (org.apache.nifi.connectable.Port)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Connection (org.apache.nifi.connectable.Connection)22 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 HashSet (java.util.HashSet)20 Funnel (org.apache.nifi.connectable.Funnel)20 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)20 RootGroupPort (org.apache.nifi.remote.RootGroupPort)20 HashMap (java.util.HashMap)19 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)17 FlowController (org.apache.nifi.controller.FlowController)17 Map (java.util.Map)16 Connectable (org.apache.nifi.connectable.Connectable)16 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)16 LinkedHashSet (java.util.LinkedHashSet)15