use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class DtoFactory method createAffectedComponentDto.
public AffectedComponentDTO createAffectedComponentDto(final ConfiguredComponent component) {
final AffectedComponentDTO dto = new AffectedComponentDTO();
dto.setId(component.getIdentifier());
dto.setName(component.getName());
dto.setProcessGroupId(component.getProcessGroupIdentifier());
if (component instanceof ProcessorNode) {
final ProcessorNode node = ((ProcessorNode) component);
dto.setState(node.getScheduledState().name());
dto.setActiveThreadCount(node.getActiveThreadCount());
dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_PROCESSOR);
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode node = ((ControllerServiceNode) component);
dto.setState(node.getState().name());
dto.setReferenceType(AffectedComponentDTO.COMPONENT_TYPE_CONTROLLER_SERVICE);
}
final Collection<ValidationResult> validationErrors = component.getValidationErrors();
if (validationErrors != null && !validationErrors.isEmpty()) {
final List<String> errors = new ArrayList<>();
for (final ValidationResult validationResult : validationErrors) {
errors.add(validationResult.toString());
}
dto.setValidationErrors(errors);
}
return dto;
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class ControllerSearchServiceTest method setupMockedProcessor.
/**
* Mocks Processor including isAuthorized() and its name & id.
*
* @param processorName Desired processor name
* @param containingProcessGroup The process group
* @param authorizedToRead Can the processor data be read?
* @param variableRegistry The variable registry
*/
private static void setupMockedProcessor(final String processorName, final ProcessGroup containingProcessGroup, boolean authorizedToRead, final MutableVariableRegistry variableRegistry) {
final String processorId = processorName + "Id";
final Processor processor1 = mock(Processor.class);
final ProcessorNode processorNode1 = mock(StandardProcessorNode.class);
Mockito.doReturn(authorizedToRead).when(processorNode1).isAuthorized(any(Authorizer.class), eq(RequestAction.READ), any(NiFiUser.class));
Mockito.doReturn(variableRegistry).when(processorNode1).getVariableRegistry();
Mockito.doReturn(processor1).when(processorNode1).getProcessor();
// set processor node's attributes
Mockito.doReturn(processorId).when(processorNode1).getIdentifier();
// not actually searching based on versioned component id
Mockito.doReturn(Optional.ofNullable(null)).when(processorNode1).getVersionedComponentId();
Mockito.doReturn(processorName).when(processorNode1).getName();
// assign processor node to its PG
Mockito.doReturn(new HashSet<ProcessorNode>() {
{
add(processorNode1);
}
}).when(containingProcessGroup).getProcessors();
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardProcessorDAO method clearState.
@Override
public void clearState(String processorId) {
final ProcessorNode processor = locateProcessor(processorId);
componentStateDAO.clearState(processor);
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardProcessorDAO method verifyTerminate.
@Override
public void verifyTerminate(final String processorId) {
final ProcessorNode processor = locateProcessor(processorId);
processor.verifyCanTerminate();
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardProcessorDAO method updateProcessor.
@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;
}
Aggregations