Search in sources :

Example 11 with ProcessorNode

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);
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) StateMap(org.apache.nifi.components.state.StateMap)

Example 12 with ProcessorNode

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;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) AffectedComponentDTO(org.apache.nifi.web.api.dto.AffectedComponentDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 13 with ProcessorNode

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();
    }
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 14 with ProcessorNode

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;
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 15 with ProcessorNode

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;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ProcessGroup(org.apache.nifi.groups.ProcessGroup) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException)

Aggregations

ProcessorNode (org.apache.nifi.controller.ProcessorNode)88 ProcessGroup (org.apache.nifi.groups.ProcessGroup)45 Port (org.apache.nifi.connectable.Port)25 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)23 Connection (org.apache.nifi.connectable.Connection)22 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)22 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)22 HashSet (java.util.HashSet)20 Funnel (org.apache.nifi.connectable.Funnel)20 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)20 RootGroupPort (org.apache.nifi.remote.RootGroupPort)20 HashMap (java.util.HashMap)19 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)18 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)17 FlowController (org.apache.nifi.controller.FlowController)17 Map (java.util.Map)16 Connectable (org.apache.nifi.connectable.Connectable)16 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)16 LinkedHashSet (java.util.LinkedHashSet)15