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

The following examples show how to use org.apache.nifi.controller.ProcessorNode#getProcessor() . 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: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that processor can be stopped if onTrigger() keeps trowing
 * exceptions.
 */
@Test
public void validateProcessorCanBeStoppedWhenOnTriggerThrowsException() 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
    this.noop(testProcessor);
    testProcessor.generateExceptionOnTrigger = true;
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
    ps.disableProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 2
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that stop calls are harmless and idempotent if processor is not
 * in STARTING or RUNNING state.
 */
@Test
public void validateStopCallsAreMeaninglessIfProcessorNotStarted() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();
    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final ProcessorNode testProcNode = flowManager.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString(),
            fcsb.getSystemBundle().getBundleDetails().getCoordinate());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    // sets the scenario for the processor to run
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);

    processScheduler.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    assertTrue(testProcessor.operationNames.isEmpty());
}
 
Example 3
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Will validate the idempotent nature of processor start operation which
 * can be called multiple times without any side-effects.
 */
@Test
public void validateIdempotencyOfProcessorStartOperation() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();

    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final 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
    this.noop(testProcessor);

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    processScheduler.startProcessor(testProcNode, true);
    processScheduler.startProcessor(testProcNode, true);

    Thread.sleep(500);
    assertCondition(() -> testProcessor.operationNames.size() == 1);
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
}
 
Example 4
Source File: DiagnosticAnalysisTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private boolean isHighMemoryUtilizer(final ProcessorNode procNode) {
    final Processor processor = procNode.getProcessor();
    final SystemResourceConsideration consideration = processor.getClass().getAnnotation(SystemResourceConsideration.class);
    if (consideration != null) {
        if (SystemResource.MEMORY == consideration.resource()) {
            return true;
        }
    }

    final SystemResourceConsiderations considerations = processor.getClass().getAnnotation(SystemResourceConsiderations.class);
    if (considerations != null) {
        for (final SystemResourceConsideration systemResourceConsideration : considerations.value()) {
            if (SystemResource.MEMORY == systemResourceConsideration.resource()) {
                return true;
            }
        }
    }

    return false;
}
 
Example 5
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that Processor is eventually started once invocation of
 *
 * @OnSchedule stopped throwing exceptions.
 */
@Test
public void validateProcessScheduledAfterAdministrativeDelayDueToTheOnScheduledException() 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
    this.noop(testProcessor);
    testProcessor.generateExceptionOnScheduled = true;
    testProcessor.keepFailingOnScheduledTimes = 2;

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), LONG_DELAY_TOLERANCE);
    processScheduler.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), SHORT_DELAY_TOLERANCE);
}
 
Example 6
Source File: SearchableMatcher.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void match(final ProcessorNode component, final SearchQuery query, final List<String> matches) {
    final Processor processor = component.getProcessor();

    if (processor instanceof Searchable) {
        final Searchable searchable = (Searchable) processor;
        final String searchTerm = query.getTerm();
        final SearchContext context = new StandardSearchContext(searchTerm, component, flowController.getControllerServiceProvider(), variableRegistry);

        // search the processor using the appropriate thread context classloader
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(flowController.getExtensionManager(), component.getClass(), component.getIdentifier())) {
            searchable.search(context).stream().forEach(searchResult -> matches.add(searchResult.getLabel() + AttributeMatcher.SEPARATOR + searchResult.getMatch()));
        } catch (final Throwable t) {
            LOGGER.error("Error happened during searchable matching: {}", t.getMessage());
            t.printStackTrace();
        }
    }
}
 
Example 7
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validate that processor will not be validated on failing
 * ControllerService validation (not enabled).
 */
@Test(expected = IllegalStateException.class)
public void validateStartFailsOnInvalidProcessorWithDisabledService() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);

    ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "serv", true);
    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());

    properties.put("S", testServiceNode.getIdentifier());
    testProcNode.setProperties(properties);

    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    testProcessor.withService = true;

    ProcessScheduler ps = fc.getProcessScheduler();
    ps.startProcessor(testProcNode);
    fail();
}
 
Example 8
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that processor can be stopped if onTrigger() keeps throwing
 * exceptions.
 */
@Test
public void validateProcessorCanBeStoppedWhenOnTriggerThrowsException() 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
    this.noop(testProcessor);
    testProcessor.generateExceptionOnTrigger = true;

    testProcNode.performValidation();
    processScheduler.startProcessor(testProcNode, true);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), LONG_DELAY_TOLERANCE);
    processScheduler.disableProcessor(testProcNode);
    assertCondition(() -> ScheduledState.RUNNING == testProcNode.getScheduledState(), LONG_DELAY_TOLERANCE);
    processScheduler.stopProcessor(testProcNode);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState(), LONG_DELAY_TOLERANCE);
}
 
Example 9
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that the Processor can be stopped when @OnScheduled blocks
 * indefinitely but written to react to thread interrupts
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledBlocksIndefinitelyInterruptable() throws Exception {
    this.fc = buildFlowControllerForTest(NiFiProperties.PROCESSOR_SCHEDULING_TIMEOUT, "5 sec");
    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
    this.blockingInterruptableOnUnschedule(testProcessor);
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    Thread.sleep(4000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 10
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Validates that stop calls are harmless and idempotent if processor is not
 * in STARTING or RUNNING state.
 */
@Test
public void validateStopCallsAreMeaninglessIfProcessorNotStarted() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testProcNode.setProperties(properties);
    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    // sets the scenario for the processor to run
    int randomDelayLimit = 3000;
    this.randomOnTriggerDelay(testProcessor, randomDelayLimit);
    final ProcessScheduler ps = fc.getProcessScheduler();
    ps.stopProcessor(testProcNode);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    assertTrue(testProcessor.operationNames.size() == 0);
}
 
Example 11
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that Processor can be stopped when @OnScheduled constantly
 * fails. Basically validates that the re-try loop breaks if user initiated
 * stopProcessor.
 */
@Test
public void validateProcessorCanBeStoppedWhenOnScheduledConstantlyFails() 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
    this.longRunningOnUnschedule(testProcessor, 100);
    testProcessor.generateExceptionOnScheduled = true;
    testProcessor.keepFailingOnScheduledTimes = Integer.MAX_VALUE;
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 12
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that Processor is eventually started once invocation of
 *
 * @OnSchedule stopped throwing exceptions.
 */
@Test
public void validateProcessScheduledAfterAdministrativeDelayDueToTheOnScheduledException() 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
    this.noop(testProcessor);
    testProcessor.generateExceptionOnScheduled = true;
    testProcessor.keepFailingOnScheduledTimes = 2;
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    Thread.sleep(100);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
    ps.stopProcessor(testProcNode);
    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
}
 
Example 13
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * The successful processor start with ControllerService dependency.
 */
@Test
public void validateStartSucceedsOnProcessorWithEnabledService() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);

    ControllerServiceNode testServiceNode = fc.createControllerService(TestService.class.getName(), "foo", true);
    testGroup.addControllerService(testServiceNode);

    ProcessorNode testProcNode = fc.createProcessor(TestProcessor.class.getName(), UUID.randomUUID().toString());
    testGroup.addProcessor(testProcNode);

    properties.put("S", testServiceNode.getIdentifier());
    testProcNode.setProperties(properties);

    TestProcessor testProcessor = (TestProcessor) testProcNode.getProcessor();
    testProcessor.withService = true;
    this.noop(testProcessor);

    ProcessScheduler ps = fc.getProcessScheduler();
    ps.enableControllerService(testServiceNode);
    ps.startProcessor(testProcNode);

    Thread.sleep(500);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);
}
 
Example 14
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Validates that processor can be stopped before start sequence finished.
 */
@Test
public void validateProcessorUnscheduledAndStoppedWhenStopIsCalledBeforeProcessorFullyStarted() 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 delay = 2000;
    this.longRunningOnSchedule(testProcessor, delay);
    ProcessScheduler ps = fc.getProcessScheduler();

    ps.startProcessor(testProcNode);
    Thread.sleep(1000);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STARTING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.RUNNING);

    ps.stopProcessor(testProcNode);
    Thread.sleep(100);
    assertTrue(testProcNode.getPhysicalScheduledState() == ScheduledState.STOPPING);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    Thread.sleep(1000);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);

    assertEquals(2, testProcessor.operationNames.size());
    assertEquals("@OnScheduled", testProcessor.operationNames.get(0));
    assertEquals("@OnUnscheduled", testProcessor.operationNames.get(1));
}
 
Example 15
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 16
Source File: ProcessorParameterTokenIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void verifyText(final ProcessorNode procNode, final String text, final String password, final String expectedOutput) throws ExecutionException, InterruptedException {
    final Map<String, String> properties = new HashMap<>();
    properties.put(WriteText.TEXT.getName(), text);
    properties.put(WriteText.PASSWORD.getName(), password);

    procNode.setProperties(properties);
    triggerOnce(procNode);

    final WriteText writeText = (WriteText) procNode.getProcessor();
    final String textWritten = writeText.getTextLastWritten();

    assertEquals("For input text <" + text+ "> and password <" + password + ">, expected output was <" + expectedOutput + "> but got <" + textWritten + ">", expectedOutput, textWritten);
}
 
Example 17
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));
}
 
Example 18
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private ComponentSearchResultDTO search(final String searchStr, final ProcessorNode procNode) {
    final List<String> matches = new ArrayList<>();
    final Processor processor = procNode.getProcessor();

    addIfAppropriate(searchStr, procNode.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, procNode.getName(), "Name", matches);
    addIfAppropriate(searchStr, procNode.getComments(), "Comments", matches);

    // consider scheduling strategy
    if (SchedulingStrategy.EVENT_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("event", searchStr)) {
        matches.add("Scheduling strategy: Event driven");
    } else if (SchedulingStrategy.TIMER_DRIVEN.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("timer", searchStr)) {
        matches.add("Scheduling strategy: Timer driven");
    } else if (SchedulingStrategy.PRIMARY_NODE_ONLY.equals(procNode.getSchedulingStrategy()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        // PRIMARY_NODE_ONLY has been deprecated as a SchedulingStrategy and replaced by PRIMARY as an ExecutionNode.
        matches.add("Scheduling strategy: On primary node");
    }

    // consider execution node
    if (ExecutionNode.PRIMARY.equals(procNode.getExecutionNode()) && StringUtils.containsIgnoreCase("primary", searchStr)) {
        matches.add("Execution node: primary");
    }

    // consider scheduled state
    if (ScheduledState.DISABLED.equals(procNode.getScheduledState())) {
        if (StringUtils.containsIgnoreCase("disabled", searchStr)) {
            matches.add("Run status: Disabled");
        }
    } else {
        if (StringUtils.containsIgnoreCase("invalid", searchStr) && !procNode.isValid()) {
            matches.add("Run status: Invalid");
        } else if (ScheduledState.RUNNING.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("running", searchStr)) {
            matches.add("Run status: Running");
        } else if (ScheduledState.STOPPED.equals(procNode.getScheduledState()) && StringUtils.containsIgnoreCase("stopped", searchStr)) {
            matches.add("Run status: Stopped");
        }
    }

    for (final Relationship relationship : procNode.getRelationships()) {
        addIfAppropriate(searchStr, relationship.getName(), "Relationship", matches);
    }

    // Add both the actual class name and the component type. This allows us to search for 'Ghost'
    // to search for components that could not be instantiated.
    addIfAppropriate(searchStr, processor.getClass().getSimpleName(), "Type", matches);
    addIfAppropriate(searchStr, procNode.getComponentType(), "Type", matches);

    for (final Map.Entry<PropertyDescriptor, String> entry : procNode.getProperties().entrySet()) {
        final PropertyDescriptor descriptor = entry.getKey();

        addIfAppropriate(searchStr, descriptor.getName(), "Property name", matches);
        addIfAppropriate(searchStr, descriptor.getDescription(), "Property description", matches);

        // never include sensitive properties values in search results
        if (descriptor.isSensitive()) {
            continue;
        }

        String value = entry.getValue();

        // if unset consider default value
        if (value == null) {
            value = descriptor.getDefaultValue();
        }

        // evaluate if the value matches the search criteria
        if (StringUtils.containsIgnoreCase(value, searchStr)) {
            matches.add("Property value: " + descriptor.getName() + " - " + value);
        }
    }

    // consider searching the processor directly
    if (processor instanceof Searchable) {
        final Searchable searchable = (Searchable) processor;

        final SearchContext context = new StandardSearchContext(searchStr, procNode, flowController, variableRegistry);

        // search the processor using the appropriate thread context classloader
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(processor.getClass(), processor.getIdentifier())) {
            final Collection<SearchResult> searchResults = searchable.search(context);
            if (CollectionUtils.isNotEmpty(searchResults)) {
                for (final SearchResult searchResult : searchResults) {
                    matches.add(searchResult.getLabel() + ": " + searchResult.getMatch());
                }
            }
        } catch (final Throwable t) {
            // log this as error
        }
    }

    if (matches.isEmpty()) {
        return null;
    }

    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(procNode.getIdentifier());
    result.setMatches(matches);
    result.setName(procNode.getName());
    return result;
}
 
Example 19
Source File: TestProcessorLifecycle.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Concurrency test that is basically hammers on both stop and start
 * operation validating their idempotency.
 */
@Test
@Ignore
public void validateLifecycleOperationOrderWithConcurrentCallsToStartStop() throws Exception {
    fc = this.buildFlowControllerForTest();
    ProcessGroup testGroup = fc.createProcessGroup(UUID.randomUUID().toString());
    this.setControllerRootGroup(fc, testGroup);
    final 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
    this.noop(testProcessor);

    final ProcessScheduler ps = fc.getProcessScheduler();
    ExecutorService executor = Executors.newFixedThreadPool(100);
    int startCallsCount = 10000;
    final CountDownLatch countDownCounter = new CountDownLatch(startCallsCount);
    assertTrue(testProcNode.getScheduledState() == ScheduledState.STOPPED);
    final Random random = new Random();
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.stopProcessor(testProcNode);
                countDownCounter.countDown();
            }
        });
    }
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                ps.startProcessor(testProcNode);
                countDownCounter.countDown();
            }
        });
    }
    assertTrue(countDownCounter.await(1000000, TimeUnit.MILLISECONDS));
    String previousOperation = null;
    for (String operationName : testProcessor.operationNames) {
        if (previousOperation == null || previousOperation.equals("@OnStopped")) {
            assertEquals("@OnScheduled", operationName);
        } else if (previousOperation.equals("@OnScheduled")) {
            assertEquals("@OnUnscheduled", operationName);
        } else if (previousOperation.equals("@OnUnscheduled")) {
            assertTrue(operationName.equals("@OnStopped") || operationName.equals("@OnScheduled"));
        }
        previousOperation = operationName;
    }
    executor.shutdownNow();
}
 
Example 20
Source File: ProcessorLifecycleIT.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Concurrency test that is basically hammers on both stop and start
 * operation validating their idempotency.
 */
@Test
@Ignore
public void validateLifecycleOperationOrderWithConcurrentCallsToStartStop() throws Exception {
    final FlowManagerAndSystemBundle fcsb = this.buildFlowControllerForTest();
    flowManager = fcsb.getFlowManager();

    ProcessGroup testGroup = flowManager.createProcessGroup(UUID.randomUUID().toString());
    final 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
    this.noop(testProcessor);

    ExecutorService executor = Executors.newFixedThreadPool(100);
    int startCallsCount = 10000;
    final CountDownLatch countDownCounter = new CountDownLatch(startCallsCount);
    assertCondition(() -> ScheduledState.STOPPED == testProcNode.getScheduledState());
    final Random random = new Random();
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                processScheduler.stopProcessor(testProcNode);
                countDownCounter.countDown();
            }
        });
    }
    for (int i = 0; i < startCallsCount / 2; i++) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                LockSupport.parkNanos(random.nextInt(9000000));
                processScheduler.startProcessor(testProcNode, true);
                countDownCounter.countDown();
            }
        });
    }
    assertTrue(countDownCounter.await(1000000, TimeUnit.MILLISECONDS));
    String previousOperation = null;
    for (String operationName : testProcessor.operationNames) {
        if (previousOperation == null || previousOperation.equals("@OnStopped")) {
            assertEquals("@OnScheduled", operationName);
        } else if (previousOperation.equals("@OnScheduled")) {
            assertEquals("@OnUnscheduled", operationName);
        } else if (previousOperation.equals("@OnUnscheduled")) {
            assertTrue(operationName.equals("@OnStopped") || operationName.equals("@OnScheduled"));
        }
        previousOperation = operationName;
    }
    executor.shutdownNow();
}