Java Code Examples for org.apache.nifi.groups.ProcessGroup#startProcessor()

The following examples show how to use org.apache.nifi.groups.ProcessGroup#startProcessor() . 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: FlowController.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public void startProcessor(final String parentGroupId, final String processorId) {
    final ProcessGroup group = lookupGroup(parentGroupId);
    final ProcessorNode node = group.getProcessor(processorId);
    if (node == null) {
        throw new IllegalStateException("Cannot find ProcessorNode with ID " + processorId + " within ProcessGroup with ID " + parentGroupId);
    }

    writeLock.lock();
    try {
        if (initialized.get()) {
            group.startProcessor(node);
        } else {
            startConnectablesAfterInitialization.add(node);
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 2
Source File: FlowController.java    From nifi with Apache License 2.0 6 votes vote down vote up
public void startProcessor(final String parentGroupId, final String processorId, final boolean failIfStopping) {
    final ProcessGroup group = lookupGroup(parentGroupId);
    final ProcessorNode node = group.getProcessor(processorId);
    if (node == null) {
        throw new IllegalStateException("Cannot find ProcessorNode with ID " + processorId + " within ProcessGroup with ID " + parentGroupId);
    }

    writeLock.lock();
    try {
        if (initialized.get()) {
            group.startProcessor(node, failIfStopping);
        } else {
            startConnectablesAfterInitialization.add(node);
        }
    } finally {
        writeLock.unlock("startProcessor");
    }
}
 
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: StandardProcessorDAO.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();

    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);

    // configure the processor
    configureProcessor(processor, processorDTO);

    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor);
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }

    return processor;
}
 
Example 5
Source File: StandardProcessorDAO.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public ProcessorNode updateProcessor(ProcessorDTO processorDTO) {
    ProcessorNode processor = locateProcessor(processorDTO.getId());
    ProcessGroup parentGroup = processor.getProcessGroup();

    // ensure we can perform the update
    verifyUpdate(processor, processorDTO);

    // configure the processor
    configureProcessor(processor, processorDTO);
    parentGroup.onComponentModified();

    // attempt to change the underlying processor if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(processor, processorDTO);

    // see if an update is necessary
    if (isNotNull(processorDTO.getState())) {
        final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState());

        // only attempt an action if it is changing
        if (!purposedScheduledState.equals(processor.getScheduledState())) {
            try {
                // perform the appropriate action
                switch (purposedScheduledState) {
                    case RUNNING:
                        parentGroup.startProcessor(processor, true);
                        break;
                    case STOPPED:
                        switch (processor.getScheduledState()) {
                            case RUNNING:
                                parentGroup.stopProcessor(processor);
                                break;
                            case DISABLED:
                                parentGroup.enableProcessor(processor);
                                break;
                        }
                        break;
                    case DISABLED:
                        parentGroup.disableProcessor(processor);
                        break;
                }
            } catch (IllegalStateException | ComponentLifeCycleException ise) {
                throw new NiFiCoreException(ise.getMessage(), ise);
            } catch (RejectedExecutionException ree) {
                throw new NiFiCoreException("Unable to schedule all tasks for the specified processor.", ree);
            } catch (NullPointerException npe) {
                throw new NiFiCoreException("Unable to update processor run state.", npe);
            } catch (Exception e) {
                throw new NiFiCoreException("Unable to update processor run state: " + e, e);
            }
        }
    }

    return processor;
}