Search in sources :

Example 16 with ConfiguredComponent

use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.

the class StandardControllerServiceProvider method unscheduleReferencingComponents.

@Override
public Set<ConfiguredComponent> unscheduleReferencingComponents(final ControllerServiceNode serviceNode) {
    // find all of the schedulable components (processors, reporting tasks) that refer to this Controller Service,
    // or a service that references this controller service, etc.
    final List<ProcessorNode> processors = serviceNode.getReferences().findRecursiveReferences(ProcessorNode.class);
    final List<ReportingTaskNode> reportingTasks = serviceNode.getReferences().findRecursiveReferences(ReportingTaskNode.class);
    final Set<ConfiguredComponent> updated = new HashSet<>();
    // verify that  we can stop all components (that are running) before doing anything
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.verifyCanStop();
        }
    }
    // stop all of the components that are running
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            node.getProcessGroup().stopProcessor(node);
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() == ScheduledState.RUNNING) {
            processScheduler.unschedule(node);
            updated.add(node);
        }
    }
    return updated;
}
Also used : ProcessorNode(org.apache.nifi.controller.ProcessorNode) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet)

Example 17 with ConfiguredComponent

use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.

the class StandardControllerServiceReference method getActiveReferences.

@Override
public Set<ConfiguredComponent> getActiveReferences() {
    final Set<ConfiguredComponent> activeReferences = new HashSet<>();
    final Set<ControllerServiceNode> serviceNodes = new HashSet<>();
    for (final ConfiguredComponent component : components) {
        if (component instanceof ControllerServiceNode) {
            serviceNodes.add((ControllerServiceNode) component);
            if (((ControllerServiceNode) component).isActive()) {
                activeReferences.add(component);
            }
        } else if (isRunning(component)) {
            activeReferences.add(component);
        }
    }
    activeReferences.addAll(getActiveIndirectReferences(serviceNodes));
    return activeReferences;
}
Also used : ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet)

Example 18 with ConfiguredComponent

use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.

the class StandardNiFiServiceFacade method findControllerServiceReferencingComponentIdentifiers.

/**
 * Finds the identifiers for all components referencing a ControllerService.
 *
 * @param reference      ControllerServiceReference
 * @param visited        ControllerServices we've already visited
 */
private void findControllerServiceReferencingComponentIdentifiers(final ControllerServiceReference reference, final Set<ControllerServiceNode> visited) {
    for (final ConfiguredComponent component : reference.getReferencingComponents()) {
        // if this is a ControllerService consider it's referencing components
        if (component instanceof ControllerServiceNode) {
            final ControllerServiceNode node = (ControllerServiceNode) component;
            if (!visited.contains(node)) {
                findControllerServiceReferencingComponentIdentifiers(node.getReferences(), visited);
            }
            visited.add(node);
        }
    }
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent)

Example 19 with ConfiguredComponent

use of org.apache.nifi.controller.ConfiguredComponent in project nifi by apache.

the class StandardNiFiServiceFacade method getComponentsAffectedByVariableRegistryUpdate.

@Override
public Set<AffectedComponentEntity> getComponentsAffectedByVariableRegistryUpdate(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<AffectedComponentEntity> affectedComponentEntities = new HashSet<>();
    final Set<String> updatedVariableNames = getUpdatedVariables(group, variableMap);
    for (final String variableName : updatedVariableNames) {
        final Set<ConfiguredComponent> affectedComponents = group.getComponentsAffectedByVariable(variableName);
        affectedComponentEntities.addAll(dtoFactory.createAffectedComponentEntities(affectedComponents, revisionManager));
    }
    return affectedComponentEntities;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) 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) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)19 HashSet (java.util.HashSet)13 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)11 LinkedHashSet (java.util.LinkedHashSet)8 HashMap (java.util.HashMap)7 ProcessorNode (org.apache.nifi.controller.ProcessorNode)7 LinkedHashMap (java.util.LinkedHashMap)5 ControllerServiceReference (org.apache.nifi.controller.service.ControllerServiceReference)5 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Set (java.util.Set)4 List (java.util.List)3 ReportingTaskNode (org.apache.nifi.controller.ReportingTaskNode)3 ProcessGroup (org.apache.nifi.groups.ProcessGroup)3 URL (java.net.URL)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 UUID (java.util.UUID)2