use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessorState.
@Override
public ComponentStateDTO getProcessorState(final String processorId) {
final StateMap clusterState = isClustered() ? processorDAO.getState(processorId, Scope.CLUSTER) : null;
final StateMap localState = processorDAO.getState(processorId, Scope.LOCAL);
// processor will be non null as it was already found when getting the state
final ProcessorNode processor = processorDAO.getProcessor(processorId);
return dtoFactory.createComponentStateDTO(processorId, processor.getProcessor().getClass(), localState, clusterState);
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class StandardNiFiServiceFacade method getActiveComponentsAffectedByVariableRegistryUpdate.
@Override
public Set<AffectedComponentDTO> getActiveComponentsAffectedByVariableRegistryUpdate(final VariableRegistryDTO variableRegistryDto) {
final ProcessGroup group = processGroupDAO.getProcessGroup(variableRegistryDto.getProcessGroupId());
if (group == null) {
throw new ResourceNotFoundException("Could not find Process Group with ID " + variableRegistryDto.getProcessGroupId());
}
final Map<String, String> variableMap = new HashMap<>();
// have to use forEach here instead of using Collectors.toMap because value may be null
variableRegistryDto.getVariables().stream().map(VariableEntity::getVariable).forEach(var -> variableMap.put(var.getName(), var.getValue()));
final Set<AffectedComponentDTO> affectedComponentDtos = new HashSet<>();
final Set<String> updatedVariableNames = getUpdatedVariables(group, variableMap);
for (final String variableName : updatedVariableNames) {
final Set<ConfiguredComponent> affectedComponents = group.getComponentsAffectedByVariable(variableName);
for (final ConfiguredComponent component : affectedComponents) {
if (component instanceof ProcessorNode) {
final ProcessorNode procNode = (ProcessorNode) component;
if (procNode.isRunning()) {
affectedComponentDtos.add(dtoFactory.createAffectedComponentDto(procNode));
}
} else if (component instanceof ControllerServiceNode) {
final ControllerServiceNode serviceNode = (ControllerServiceNode) component;
if (serviceNode.isActive()) {
affectedComponentDtos.add(dtoFactory.createAffectedComponentDto(serviceNode));
}
} else {
throw new RuntimeException("Found unexpected type of Component [" + component.getCanonicalClassName() + "] dependending on variable");
}
}
}
return affectedComponentDtos;
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class ControllerFacade method findProcessGroupIdForProcessor.
/**
* Returns the group id that contains the specified processor.
*
* @param processorId processor id
* @return group id
*/
public String findProcessGroupIdForProcessor(String processorId) {
final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());
final ProcessorNode processor = rootGroup.findProcessor(processorId);
if (processor == null) {
return null;
} else {
return processor.getProcessGroup().getIdentifier();
}
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class ControllerFacade method getProcessorStatus.
/**
* Gets the status for the specified processor.
*
* @param processorId processor id
* @return the status for the specified processor
*/
public ProcessorStatus getProcessorStatus(final String processorId) {
final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
final ProcessorNode processor = root.findProcessor(processorId);
// ensure the processor was found
if (processor == null) {
throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
}
// calculate the process group status
final String groupId = processor.getProcessGroup().getIdentifier();
final ProcessGroupStatus processGroupStatus = flowController.getGroupStatus(groupId, NiFiUserUtils.getNiFiUser());
if (processGroupStatus == null) {
throw new ResourceNotFoundException(String.format("Unable to locate group with id '%s'.", groupId));
}
final ProcessorStatus status = processGroupStatus.getProcessorStatus().stream().filter(processorStatus -> processorId.equals(processorStatus.getId())).findFirst().orElse(null);
if (status == null) {
throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
}
return status;
}
use of org.apache.nifi.controller.ProcessorNode in project nifi by apache.
the class ControllerFacade method getProcessorStatusHistory.
/**
* Returns the status history for the specified processor.
*
* @param processorId processor id
* @return status history
*/
public StatusHistoryDTO getProcessorStatusHistory(final String processorId) {
final ProcessGroup root = flowController.getGroup(flowController.getRootGroupId());
final ProcessorNode processor = root.findProcessor(processorId);
// ensure the processor was found
if (processor == null) {
throw new ResourceNotFoundException(String.format("Unable to locate processor with id '%s'.", processorId));
}
final boolean authorized = processor.isAuthorized(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
final StatusHistoryDTO statusHistory = flowController.getProcessorStatusHistory(processorId, authorized);
// if not authorized
if (!authorized) {
statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_NAME, processorId);
statusHistory.getComponentDetails().put(ComponentStatusRepository.COMPONENT_DETAIL_TYPE, "Processor");
}
return statusHistory;
}
Aggregations