Java Code Examples for org.apache.nifi.controller.ProcessorNode#getScheduledState()
The following examples show how to use
org.apache.nifi.controller.ProcessorNode#getScheduledState() .
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: StandardProcessGroup.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void startProcessor(final ProcessorNode processor) { readLock.lock(); try { if (getProcessor(processor.getIdentifier()) == null) { throw new IllegalStateException("Processor is not a member of this Process Group"); } final ScheduledState state = processor.getScheduledState(); if (state == ScheduledState.DISABLED) { throw new IllegalStateException("Processor is disabled"); } else if (state == ScheduledState.RUNNING) { return; } scheduler.startProcessor(processor); } finally { readLock.unlock(); } }
Example 2
Source File: StandardProcessGroup.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void stopProcessor(final ProcessorNode processor) { readLock.lock(); try { if (!processors.containsKey(processor.getIdentifier())) { throw new IllegalStateException("No processor with ID " + processor.getIdentifier() + " belongs to this Process Group"); } final ScheduledState state = processor.getScheduledState(); if (state == ScheduledState.DISABLED) { throw new IllegalStateException("Processor is disabled"); } else if (state == ScheduledState.STOPPED) { return; } scheduler.stopProcessor(processor); } finally { readLock.unlock(); } }
Example 3
Source File: StandardProcessGroup.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void enableProcessor(final ProcessorNode processor) { readLock.lock(); try { if (!processors.containsKey(processor.getIdentifier())) { throw new IllegalStateException("No Processor with ID " + processor.getIdentifier() + " belongs to this Process Group"); } final ScheduledState state = processor.getScheduledState(); if (state == ScheduledState.STOPPED) { return; } else if (state == ScheduledState.RUNNING) { throw new IllegalStateException("Processor is currently running"); } scheduler.enableProcessor(processor); } finally { readLock.unlock(); } }
Example 4
Source File: StandardProcessGroup.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void disableProcessor(final ProcessorNode processor) { readLock.lock(); try { if (!processors.containsKey(processor.getIdentifier())) { throw new IllegalStateException("No Processor with ID " + processor.getIdentifier() + " belongs to this Process Group"); } final ScheduledState state = processor.getScheduledState(); if (state == ScheduledState.DISABLED) { return; } else if (state == ScheduledState.RUNNING) { throw new IllegalStateException("Processor is currently running"); } scheduler.disableProcessor(processor); } finally { readLock.unlock(); } }
Example 5
Source File: StandardControllerServiceProvider.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void verifyCanScheduleReferencingComponents(final ControllerServiceNode serviceNode) { final List<ControllerServiceNode> referencingServices = findRecursiveReferences(serviceNode, ControllerServiceNode.class); final List<ReportingTaskNode> referencingReportingTasks = findRecursiveReferences(serviceNode, ReportingTaskNode.class); final List<ProcessorNode> referencingProcessors = findRecursiveReferences(serviceNode, ProcessorNode.class); final Set<ControllerServiceNode> referencingServiceSet = new HashSet<>(referencingServices); for (final ReportingTaskNode taskNode : referencingReportingTasks) { if (taskNode.getScheduledState() != ScheduledState.DISABLED) { taskNode.verifyCanStart(referencingServiceSet); } } for (final ProcessorNode procNode : referencingProcessors) { if (procNode.getScheduledState() != ScheduledState.DISABLED) { procNode.verifyCanStart(referencingServiceSet); } } }
Example 6
Source File: StandardControllerServiceProvider.java From nifi with Apache License 2.0 | 6 votes |
@Override public void verifyCanScheduleReferencingComponents(final ControllerServiceNode serviceNode) { final List<ControllerServiceNode> referencingServices = serviceNode.getReferences().findRecursiveReferences(ControllerServiceNode.class); final List<ReportingTaskNode> referencingReportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class); final List<ProcessorNode> referencingProcessors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class); final Set<ControllerServiceNode> referencingServiceSet = new HashSet<>(referencingServices); for (final ReportingTaskNode taskNode : referencingReportingTasks) { if (taskNode.getScheduledState() != ScheduledState.DISABLED) { taskNode.verifyCanStart(referencingServiceSet); } } for (final ProcessorNode procNode : referencingProcessors) { if (procNode.getScheduledState() != ScheduledState.DISABLED) { procNode.verifyCanStart(referencingServiceSet); } } }
Example 7
Source File: ComponentCountTask.java From nifi with Apache License 2.0 | 6 votes |
private void countProcessors(final Collection<ProcessorNode> processors, final List<String> details) { final Map<String, Map<ScheduledState, Integer>> typeMap = new HashMap<>(); for (final ProcessorNode procNode : processors) { final String componentType = procNode.getComponentType(); final ScheduledState scheduledState = procNode.getScheduledState(); final Map<ScheduledState, Integer> stateCounts = typeMap.computeIfAbsent(componentType, key -> new HashMap<>()); final Integer count = stateCounts.computeIfAbsent(scheduledState, key -> 0); stateCounts.put(scheduledState, count + 1); } for (final Map.Entry<String, Map<ScheduledState, Integer>> typeEntry : typeMap.entrySet()) { final String type = typeEntry.getKey(); final Map<ScheduledState, Integer> stateMap = typeEntry.getValue(); final int total = stateMap.values().stream().mapToInt(Integer::intValue).sum(); details.add(type + " : " + total + " Total, " + stateMap.toString().toLowerCase()); } if (typeMap.isEmpty()) { details.add("No Processors"); } }
Example 8
Source File: StandardProcessScheduler.java From nifi with Apache License 2.0 | 5 votes |
@Override public synchronized void terminateProcessor(final ProcessorNode procNode) { if (procNode.getScheduledState() != ScheduledState.STOPPED) { throw new IllegalStateException("Cannot terminate " + procNode + " because it is not currently stopped"); } final LifecycleState state = getLifecycleState(procNode, false); if (state.getActiveThreadCount() == 0) { LOG.debug("Will not terminate {} because it has no active threads", procNode); return; } LOG.debug("Terminating {}", procNode); final int tasksTerminated = procNode.terminate(); state.terminate(); getSchedulingAgent(procNode).incrementMaxThreadCount(tasksTerminated); try { flowController.getReloadComponent().reload(procNode, procNode.getProcessor().getClass().getName(), procNode.getBundleCoordinate(), Collections.emptySet()); } catch (final ProcessorInstantiationException e) { // This shouldn't happen because we already have been able to instantiate the processor before LOG.error("Failed to replace instance of Processor for {} when terminating Processor", procNode); } LOG.info("Successfully terminated {} with {} active threads", procNode, tasksTerminated); }
Example 9
Source File: StandardProcessorDAO.java From localization_nifi with Apache License 2.0 | 4 votes |
private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) { // ensure the state, if specified, is valid if (isNotNull(processorDTO.getState())) { try { final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState()); // only attempt an action if it is changing if (!purposedScheduledState.equals(processor.getScheduledState())) { // perform the appropriate action switch (purposedScheduledState) { case RUNNING: processor.verifyCanStart(); break; case STOPPED: switch (processor.getScheduledState()) { case RUNNING: processor.verifyCanStop(); break; case DISABLED: processor.verifyCanEnable(); break; } break; case DISABLED: processor.verifyCanDisable(); break; } } } catch (IllegalArgumentException iae) { throw new IllegalArgumentException(String.format( "The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", processorDTO.getState())); } } boolean modificationRequest = false; if (isAnyNotNull(processorDTO.getName())) { modificationRequest = true; } final ProcessorConfigDTO configDTO = processorDTO.getConfig(); if (configDTO != null) { if (isAnyNotNull(configDTO.getAnnotationData(), configDTO.getAutoTerminatedRelationships(), configDTO.getBulletinLevel(), configDTO.getComments(), configDTO.getConcurrentlySchedulableTaskCount(), configDTO.getPenaltyDuration(), configDTO.getProperties(), configDTO.getSchedulingPeriod(), configDTO.getSchedulingStrategy(), configDTO.getExecutionNode(), configDTO.getYieldDuration())) { modificationRequest = true; } // validate the request final List<String> requestValidation = validateProposedConfiguration(processor, configDTO); // ensure there was no validation errors if (!requestValidation.isEmpty()) { throw new ValidationException(requestValidation); } } if (modificationRequest) { processor.verifyCanUpdate(); } }
Example 10
Source File: StandardProcessorDAO.java From localization_nifi with Apache License 2.0 | 4 votes |
@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 11
Source File: StandardProcessorDAO.java From nifi with Apache License 2.0 | 4 votes |
private void verifyUpdate(ProcessorNode processor, ProcessorDTO processorDTO) { // ensure the state, if specified, is valid if (isNotNull(processorDTO.getState())) { try { final ScheduledState purposedScheduledState = ScheduledState.valueOf(processorDTO.getState()); // only attempt an action if it is changing if (!purposedScheduledState.equals(processor.getScheduledState())) { // perform the appropriate action switch (purposedScheduledState) { case RUNNING: processor.verifyCanStart(); break; case STOPPED: switch (processor.getScheduledState()) { case RUNNING: processor.verifyCanStop(); break; case DISABLED: processor.verifyCanEnable(); break; } break; case DISABLED: processor.verifyCanDisable(); break; } } } catch (IllegalArgumentException iae) { throw new IllegalArgumentException(String.format( "The specified processor state (%s) is not valid. Valid options are 'RUNNING', 'STOPPED', and 'DISABLED'.", processorDTO.getState())); } } boolean modificationRequest = false; if (isAnyNotNull(processorDTO.getName(), processorDTO.getBundle())) { modificationRequest = true; } final BundleDTO bundleDTO = processorDTO.getBundle(); if (bundleDTO != null) { // ensures all nodes in a cluster have the bundle, throws exception if bundle not found for the given type final BundleCoordinate bundleCoordinate = BundleUtils.getBundle(flowController.getExtensionManager(), processor.getCanonicalClassName(), bundleDTO); // ensure we are only changing to a bundle with the same group and id, but different version processor.verifyCanUpdateBundle(bundleCoordinate); } final ProcessorConfigDTO configDTO = processorDTO.getConfig(); if (configDTO != null) { if (isAnyNotNull(configDTO.getAnnotationData(), configDTO.getAutoTerminatedRelationships(), configDTO.getBulletinLevel(), configDTO.getComments(), configDTO.getConcurrentlySchedulableTaskCount(), configDTO.getPenaltyDuration(), configDTO.getProperties(), configDTO.getSchedulingPeriod(), configDTO.getSchedulingStrategy(), configDTO.getExecutionNode(), configDTO.getYieldDuration())) { modificationRequest = true; } // validate the request final List<String> requestValidation = validateProposedConfiguration(processor, configDTO); // ensure there was no validation errors if (!requestValidation.isEmpty()) { throw new ValidationException(requestValidation); } } if (modificationRequest) { processor.verifyCanUpdate(); } }
Example 12
Source File: StandardProcessorDAO.java From nifi with Apache License 2.0 | 4 votes |
@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; }