Search in sources :

Example 6 with ConfiguredComponent

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

the class StandardControllerServiceReference method getActiveIndirectReferences.

private Set<ConfiguredComponent> getActiveIndirectReferences(final Set<ControllerServiceNode> referencingServices) {
    if (referencingServices.isEmpty()) {
        return Collections.emptySet();
    }
    final Set<ConfiguredComponent> references = new HashSet<>();
    for (final ControllerServiceNode referencingService : referencingServices) {
        final Set<ControllerServiceNode> serviceNodes = new HashSet<>();
        final ControllerServiceReference ref = referencingService.getReferences();
        for (final ConfiguredComponent component : ref.getReferencingComponents()) {
            if (component instanceof ControllerServiceNode) {
                serviceNodes.add((ControllerServiceNode) component);
            } else if (isRunning(component)) {
                references.add(component);
            }
        }
        references.addAll(getActiveIndirectReferences(serviceNodes));
    }
    return references;
}
Also used : ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet)

Example 7 with ConfiguredComponent

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

the class StandardControllerServiceReference method findRecursiveReferences.

private <T> List<T> findRecursiveReferences(final ControllerServiceNode referencedNode, final Class<T> componentType) {
    final List<T> references = new ArrayList<>();
    for (final ConfiguredComponent referencingComponent : referencedNode.getReferences().getReferencingComponents()) {
        if (componentType.isAssignableFrom(referencingComponent.getClass())) {
            references.add(componentType.cast(referencingComponent));
        }
        if (referencingComponent instanceof ControllerServiceNode) {
            final ControllerServiceNode referencingNode = (ControllerServiceNode) referencingComponent;
            // find components recursively that depend on referencingNode.
            final List<T> recursive = findRecursiveReferences(referencingNode, componentType);
            // For anything that depends on referencing node, we want to add it to the list, but we know
            // that it must come after the referencing node, so we first remove any existing occurrence.
            references.removeAll(recursive);
            references.addAll(recursive);
        }
    }
    return references;
}
Also used : ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ArrayList(java.util.ArrayList)

Example 8 with ConfiguredComponent

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

the class StandardNiFiServiceFacade method createControllerServiceReferencingComponentsEntity.

/**
 * Creates entities for components referencing a ControllerService using their current revision.
 *
 * @param reference ControllerServiceReference
 * @return The entity
 */
private ControllerServiceReferencingComponentsEntity createControllerServiceReferencingComponentsEntity(final ControllerServiceReference reference, final Set<String> lockedIds) {
    final Set<ControllerServiceNode> visited = new HashSet<>();
    visited.add(reference.getReferencedComponent());
    findControllerServiceReferencingComponentIdentifiers(reference, visited);
    final Map<String, Revision> referencingRevisions = new HashMap<>();
    for (final ConfiguredComponent component : reference.getReferencingComponents()) {
        referencingRevisions.put(component.getIdentifier(), revisionManager.getRevision(component.getIdentifier()));
    }
    return createControllerServiceReferencingComponentsEntity(reference, referencingRevisions);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 9 with ConfiguredComponent

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

the class StandardNiFiServiceFacade method updateControllerServiceReferencingComponents.

@Override
public ControllerServiceReferencingComponentsEntity updateControllerServiceReferencingComponents(final Map<String, Revision> referenceRevisions, final String controllerServiceId, final ScheduledState scheduledState, final ControllerServiceState controllerServiceState) {
    final RevisionClaim claim = new StandardRevisionClaim(referenceRevisions.values());
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    final RevisionUpdate<ControllerServiceReferencingComponentsEntity> update = revisionManager.updateRevision(claim, user, new UpdateRevisionTask<ControllerServiceReferencingComponentsEntity>() {

        @Override
        public RevisionUpdate<ControllerServiceReferencingComponentsEntity> update() {
            final Set<ConfiguredComponent> updated = controllerServiceDAO.updateControllerServiceReferencingComponents(controllerServiceId, scheduledState, controllerServiceState);
            final ControllerServiceReference updatedReference = controllerServiceDAO.getControllerService(controllerServiceId).getReferences();
            // get the revisions of the updated components
            final Map<String, Revision> updatedRevisions = new HashMap<>();
            for (final ConfiguredComponent component : updated) {
                final Revision currentRevision = revisionManager.getRevision(component.getIdentifier());
                final Revision requestRevision = referenceRevisions.get(component.getIdentifier());
                updatedRevisions.put(component.getIdentifier(), currentRevision.incrementRevision(requestRevision.getClientId()));
            }
            // ensure the revision for all referencing components is included regardless of whether they were updated in this request
            for (final ConfiguredComponent component : findAllReferencingComponents(updatedReference)) {
                updatedRevisions.putIfAbsent(component.getIdentifier(), revisionManager.getRevision(component.getIdentifier()));
            }
            final ControllerServiceReferencingComponentsEntity entity = createControllerServiceReferencingComponentsEntity(updatedReference, updatedRevisions);
            return new StandardRevisionUpdate<>(entity, null, new HashSet<>(updatedRevisions.values()));
        }
    });
    return update.getComponent();
}
Also used : ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) HashSet(java.util.HashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) RevisionUpdate(org.apache.nifi.web.revision.RevisionUpdate) StandardRevisionUpdate(org.apache.nifi.web.revision.StandardRevisionUpdate) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) RevisionClaim(org.apache.nifi.web.revision.RevisionClaim) StandardRevisionClaim(org.apache.nifi.web.revision.StandardRevisionClaim) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) StateMap(org.apache.nifi.components.state.StateMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 10 with ConfiguredComponent

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

the class StandardNiFiServiceFacade method createControllerServiceReferencingComponentsEntity.

/**
 * Creates entities for components referencing a ControllerServcie using the specified revisions.
 *
 * @param reference ControllerServiceReference
 * @param revisions The revisions
 * @param visited   Which services we've already considered (in case of cycle)
 * @return The entity
 */
private ControllerServiceReferencingComponentsEntity createControllerServiceReferencingComponentsEntity(final ControllerServiceReference reference, final Map<String, Revision> revisions, final Set<ControllerServiceNode> visited) {
    final String modifier = NiFiUserUtils.getNiFiUserIdentity();
    final Set<ConfiguredComponent> referencingComponents = reference.getReferencingComponents();
    final Set<ControllerServiceReferencingComponentEntity> componentEntities = new HashSet<>();
    for (final ConfiguredComponent refComponent : referencingComponents) {
        PermissionsDTO permissions = null;
        if (refComponent instanceof Authorizable) {
            permissions = dtoFactory.createPermissionsDto(refComponent);
        }
        final Revision revision = revisions.get(refComponent.getIdentifier());
        final FlowModification flowMod = new FlowModification(revision, modifier);
        final RevisionDTO revisionDto = dtoFactory.createRevisionDTO(flowMod);
        final ControllerServiceReferencingComponentDTO dto = dtoFactory.createControllerServiceReferencingComponentDTO(refComponent);
        if (refComponent instanceof ControllerServiceNode) {
            final ControllerServiceNode node = (ControllerServiceNode) refComponent;
            // indicate if we've hit a cycle
            dto.setReferenceCycle(visited.contains(node));
            // mark node as visited before building the reference cycle
            visited.add(node);
            // if we haven't encountered this service before include it's referencing components
            if (!dto.getReferenceCycle()) {
                final ControllerServiceReference refReferences = node.getReferences();
                final Map<String, Revision> referencingRevisions = new HashMap<>(revisions);
                for (final ConfiguredComponent component : refReferences.getReferencingComponents()) {
                    referencingRevisions.putIfAbsent(component.getIdentifier(), revisionManager.getRevision(component.getIdentifier()));
                }
                final ControllerServiceReferencingComponentsEntity references = createControllerServiceReferencingComponentsEntity(refReferences, referencingRevisions, visited);
                dto.setReferencingComponents(references.getControllerServiceReferencingComponents());
            }
        }
        componentEntities.add(entityFactory.createControllerServiceReferencingComponentEntity(dto, revisionDto, permissions));
    }
    final ControllerServiceReferencingComponentsEntity entity = new ControllerServiceReferencingComponentsEntity();
    entity.setControllerServiceReferencingComponents(componentEntities);
    return entity;
}
Also used : ControllerServiceReferencingComponentsEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentsEntity) ControllerServiceReferencingComponentEntity(org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) PermissionsDTO(org.apache.nifi.web.api.dto.PermissionsDTO) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) ControllerServiceReferencingComponentDTO(org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) Authorizable(org.apache.nifi.authorization.resource.Authorizable) 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