Java Code Examples for org.apache.nifi.controller.ProcessorNode#setScheduldingPeriod()

The following examples show how to use org.apache.nifi.controller.ProcessorNode#setScheduldingPeriod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkIntegrationTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
protected void triggerOnce(final ProcessorNode processor) throws ExecutionException, InterruptedException {
    final String schedulingPeriod = processor.getSchedulingPeriod();
    final FlowFileEvent initialReport = getStatusReport(processor);
    final int initialInvocations = (initialReport == null) ? 0 : initialReport.getInvocations();

    processor.setScheduldingPeriod("1 hour");

    // We will only trigger the Processor to run once per hour. So we need to ensure that
    // we don't trigger the Processor while it's yielded. So if its yield expiration is in the future,
    // wait until the yield expires.
    while (processor.getYieldExpiration() > System.currentTimeMillis()) {
        Thread.sleep(1L);
    }

    start(processor).get();

    int totalInvocations = initialInvocations;
    while (totalInvocations < initialInvocations + 1) {
        final FlowFileEvent currentReport = getStatusReport(processor);
        totalInvocations = currentReport == null ? 0 : currentReport.getInvocations();
    }

    stop(processor).get();
    processor.setScheduldingPeriod(schedulingPeriod);
}
 
Example 2
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the processors start/stop sequence where the order of
 * operations can only be @OnScheduled, @OnUnscheduled, @OnStopped.
 */
@Test
@Ignore
public void validateSuccessfullAndOrderlyShutdown() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    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());
    Thread.sleep(2000); // let it run for a while
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);

    fc.stopAllProcessors();

    Thread.sleep(randomDelayLimit); // up to randomDelayLimit, otherwise next assertion may fail as the processor still executing

    // validates that regardless of how many running tasks, lifecycle
    // operation are invoked atomically (once each).
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    // . . . hence only 3 operations must be in the list
    assertEquals(3, testProcessor.operationNames.size());
    // . . . and ordered as @OnScheduled, @OnUnscheduled, @OnStopped
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
    assertEquals("@OnStopped", testProcessor.operationNames.get(2));
}
 
Example 3
Source File: StandardProcessGroupIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testComponentsAffectedByVariableOverridden() {
    final ProcessGroup child = getFlowController().getFlowManager().createProcessGroup("child");
    child.setName("Child");
    child.setVariables(Collections.singletonMap("number", "5"));

    getRootGroup().setVariables(Collections.singletonMap("number", "1"));
    getRootGroup().addProcessGroup(child);

    final ProcessorNode processor = createProcessorNode(NumberRefProcessor.class);
    processor.setProperties(Collections.singletonMap(NumberRefProcessor.NUMBER.getName(), "${number}"));
    moveProcessor(processor, child);

    final Set<ComponentNode> componentsAffected = child.getComponentsAffectedByVariable("number");
    assertEquals(1, componentsAffected.size());
    assertTrue(componentsAffected.contains(processor));

    final Set<ComponentNode> rootAffected = getRootGroup().getComponentsAffectedByVariable("number");
    assertTrue(rootAffected.isEmpty());

    processor.setScheduldingPeriod("1 hour");
    child.startProcessor(processor, false);

    getRootGroup().setVariables(Collections.singletonMap("number", "2"));

    try {
        child.setVariables(Collections.singletonMap("number", "10"));
        Assert.fail("Updated variable that is referenced by a running processor");
    } catch (final IllegalStateException ise) {
        // Expected
    }

    child.stopProcessor(processor);
}
 
Example 4
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * 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 FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();
    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    ProcessorNode testProcNode = flowManager.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);

    flowManager.getGroup(testGroup.getIdentifier()).startProcessing();
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), SHORT_DELAY_TOLERANCE);

    flowManager.getRootGroup().stopProcessing();

    Thread.sleep(randomDelayLimit); // up to randomDelayLimit, otherwise next assertion may fail as the processor still executing

    // validates that regardless of how many running tasks, lifecycle
    // operation are invoked atomically (once each).
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), SHORT_DELAY_TOLERANCE);
    // . . . hence only 3 operations must be in the list
    assertCondition(() -> testProcessor.operationNames.size() == 3, SHORT_DELAY_TOLERANCE);
    // . . . and ordered as @OnScheduled, @OnUnscheduled, @OnStopped
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
    assertEquals("@OnStopped", testProcessor.operationNames.get(2));
}