Search in sources :

Example 21 with ProcessorNode

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

the class StandardProcessorDAO method terminate.

@Override
public void terminate(final String processorId) {
    final ProcessorNode processor = locateProcessor(processorId);
    processor.getProcessGroup().terminateProcessor(processor);
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode)

Example 22 with ProcessorNode

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

the class StandardProcessorDAO method locateProcessor.

private ProcessorNode locateProcessor(final String processorId) {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
    final ProcessorNode processor = rootGroup.findProcessor(processorId);
    if (processor == null) {
        throw new ResourceNotFoundException(String.format("Unable to find processor with id '%s'.", processorId));
    } else {
        return processor;
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Example 23 with ProcessorNode

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

the class TestProcessorLifecycle method validateDisableOperation.

@Test
public void validateDisableOperation() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    fc = fcsb.getFlowController();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(), fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getPhysicalScheduledState());
    // validates idempotency
    for (int i = 0; i < 2; i++) {
        testProcNode.disable();
    }
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getScheduledState());
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getPhysicalScheduledState());
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.DISABLED == testProcNode.getPhysicalScheduledState());
}
Also used : ProcessScheduler(org.apache.nifi.controller.ProcessScheduler) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Test(org.junit.Test)

Example 24 with ProcessorNode

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

the class TestProcessorLifecycle method validateSuccessfulAndOrderlyShutdown.

/**
 * Validates the processors start/stop sequence where the order of
 * operations can only be @OnScheduled, @OnUnscheduled, @OnStopped.
 */
@Test
@Ignore
public void validateSuccessfulAndOrderlyShutdown() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    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
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);
    testProcNode.setMaxConcurrentTasks(4);
    testProcNode.setScheduldingPeriod("500 millis");
    testProcNode.setAutoTerminatedRelationships(Collections.singleton(new Relationship.Builder().name("success").build()));
    testGroup.addProcessor(testProcNode);
    fc.startProcessGroup(testGroup.getIdentifier());
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 2000L);
    fc.stopAllProcessors();
    // up to randomDelayLimit, otherwise next assertion may fail as the processor still executing
    Thread.sleep(randomDelayLimit);
    // validates that regardless of how many running tasks, lifecycle
    // operation are invoked atomically (once each).
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 1000L);
    // . . . hence only 3 operations must be in the list
    assertCondition(() -> testProcessor.operationNames.size() == 3, 2000L);
    // . . . and ordered as @OnScheduled, @OnUnscheduled, @OnStopped
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
    assertEquals("@OnStopped", testProcessor.operationNames.get(2));
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 25 with ProcessorNode

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

the class TestProcessorLifecycle method validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyInterruptable.

/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely but written to react to thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyInterruptable() throws Exception {
    final FlowControllerAndSystemBundle fcsb = this.buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "5 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.blockingInterruptableOnUnschedule(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), 2000L);
    ps.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), 5000L);
}
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