Search in sources :

Example 1 with ConfiguredComponent

use of org.apache.nifi.controller.ConfiguredComponent 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 2 with ConfiguredComponent

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

the class StandardControllerServiceDAO method updateControllerService.

@Override
public ControllerServiceNode updateControllerService(final ControllerServiceDTO controllerServiceDTO) {
    // get the controller service
    final ControllerServiceNode controllerService = locateControllerService(controllerServiceDTO.getId());
    // ensure we can perform the update
    verifyUpdate(controllerService, controllerServiceDTO);
    // perform the update
    configureControllerService(controllerService, controllerServiceDTO);
    // attempt to change the underlying controller service if an updated bundle is specified
    // updating the bundle must happen after configuring so that any additional classpath resources are set first
    updateBundle(controllerService, controllerServiceDTO);
    // enable or disable as appropriate
    if (isNotNull(controllerServiceDTO.getState())) {
        final ControllerServiceState purposedControllerServiceState = ControllerServiceState.valueOf(controllerServiceDTO.getState());
        // only attempt an action if it is changing
        if (!purposedControllerServiceState.equals(controllerService.getState())) {
            if (ControllerServiceState.ENABLED.equals(purposedControllerServiceState)) {
                serviceProvider.enableControllerService(controllerService);
            } else if (ControllerServiceState.DISABLED.equals(purposedControllerServiceState)) {
                serviceProvider.disableControllerService(controllerService);
            }
        }
    }
    final ProcessGroup group = controllerService.getProcessGroup();
    if (group != null) {
        group.onComponentModified();
        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        controllerService.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(group.getIdentifier())).forEach(groupId -> {
            final ProcessGroup descendant = group.findProcessGroup(groupId);
            if (descendant != null) {
                descendant.onComponentModified();
            }
        });
    }
    return controllerService;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfigurableComponent(org.apache.nifi.components.ConfigurableComponent) BundleDTO(org.apache.nifi.web.api.dto.BundleDTO) ArrayList(java.util.ArrayList) ComponentStateDAO(org.apache.nifi.web.dao.ComponentStateDAO) ControllerServiceDAO(org.apache.nifi.web.dao.ControllerServiceDAO) ROOT_GROUP_ID_ALIAS(org.apache.nifi.controller.FlowController.ROOT_GROUP_ID_ALIAS) Scope(org.apache.nifi.components.state.Scope) Map(java.util.Map) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Set(java.util.Set) BundleUtils(org.apache.nifi.util.BundleUtils) StateMap(org.apache.nifi.components.state.StateMap) FlowController(org.apache.nifi.controller.FlowController) NiFiCoreException(org.apache.nifi.web.NiFiCoreException) List(java.util.List) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Collections(java.util.Collections) ValidationException(org.apache.nifi.controller.exception.ValidationException) ControllerServiceState(org.apache.nifi.controller.service.ControllerServiceState) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ProcessGroup(org.apache.nifi.groups.ProcessGroup)

Example 3 with ConfiguredComponent

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

the class StandardAuthorizableLookup method findControllerServiceReferencingComponent.

private ConfiguredComponent findControllerServiceReferencingComponent(final ControllerServiceReference referencingComponents, final String id) {
    ConfiguredComponent reference = null;
    for (final ConfiguredComponent component : referencingComponents.getReferencingComponents()) {
        if (component.getIdentifier().equals(id)) {
            reference = component;
            break;
        }
        if (component instanceof ControllerServiceNode) {
            final ControllerServiceNode refControllerService = (ControllerServiceNode) component;
            reference = findControllerServiceReferencingComponent(refControllerService.getReferences(), id);
            if (reference != null) {
                break;
            }
        }
    }
    return reference;
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent)

Example 4 with ConfiguredComponent

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

the class NiFiRegistryFlowMapper method mapProperties.

private Map<String, String> mapProperties(final ConfiguredComponent component, final ControllerServiceProvider serviceProvider) {
    final Map<String, String> mapped = new HashMap<>();
    component.getProperties().keySet().stream().filter(property -> !property.isSensitive()).forEach(property -> {
        String value = component.getProperty(property);
        if (value == null) {
            value = property.getDefaultValue();
        }
        if (value != null && property.getControllerServiceDefinition() != null) {
            // Property references a Controller Service. Instead of storing the existing value, we want
            // to store the Versioned Component ID of the service.
            final ControllerServiceNode controllerService = serviceProvider.getControllerServiceNode(value);
            if (controllerService != null) {
                value = getId(controllerService.getVersionedComponentId(), controllerService.getIdentifier());
            }
        }
        mapped.put(property.getName(), value);
    });
    return mapped;
}
Also used : ProcessGroup(org.apache.nifi.groups.ProcessGroup) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Port(org.apache.nifi.connectable.Port) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ClassUtils(org.apache.commons.lang3.ClassUtils) ComponentType(org.apache.nifi.registry.flow.ComponentType) ControllerServiceAPI(org.apache.nifi.registry.flow.ControllerServiceAPI) Map(java.util.Map) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Connectable(org.apache.nifi.connectable.Connectable) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Label(org.apache.nifi.controller.label.Label) Bundle(org.apache.nifi.registry.flow.Bundle) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) PortType(org.apache.nifi.registry.flow.PortType) BatchSize(org.apache.nifi.registry.flow.BatchSize) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ControllerService(org.apache.nifi.controller.ControllerService) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Optional(java.util.Optional) ExtensionManager(org.apache.nifi.nar.ExtensionManager) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) HashMap(java.util.HashMap) Position(org.apache.nifi.registry.flow.Position) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) Relationship(org.apache.nifi.processor.Relationship) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) LinkedHashSet(java.util.LinkedHashSet) ConnectableComponentType(org.apache.nifi.registry.flow.ConnectableComponentType) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) TimeUnit(java.util.concurrent.TimeUnit) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) HashMap(java.util.HashMap) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode)

Example 5 with ConfiguredComponent

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

the class StandardControllerServiceProvider method scheduleReferencingComponents.

@Override
public Set<ConfiguredComponent> scheduleReferencingComponents(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 start all components (that are not disabled) before doing anything
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.verifyCanStart();
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.verifyCanStart();
            updated.add(node);
        }
    }
    // start all of the components that are not disabled
    for (final ProcessorNode node : processors) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            node.getProcessGroup().startProcessor(node, true);
            updated.add(node);
        }
    }
    for (final ReportingTaskNode node : reportingTasks) {
        if (node.getScheduledState() != ScheduledState.DISABLED) {
            processScheduler.schedule(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)

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