Search in sources :

Example 56 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class TestFlowController method testInstantiateSnippetWhenControllerServiceMissingBundle.

@Test(expected = IllegalArgumentException.class)
public void testInstantiateSnippetWhenControllerServiceMissingBundle() throws ProcessorInstantiationException {
    final String id = UUID.randomUUID().toString();
    final BundleCoordinate coordinate = systemBundle.getBundleDetails().getCoordinate();
    final ControllerServiceNode controllerServiceNode = controller.createControllerService(ServiceA.class.getName(), id, coordinate, null, true);
    // create the controller service dto
    final ControllerServiceDTO csDto = new ControllerServiceDTO();
    // use a different id
    csDto.setId(UUID.randomUUID().toString());
    csDto.setParentGroupId(controllerServiceNode.getProcessGroup() == null ? null : controllerServiceNode.getProcessGroup().getIdentifier());
    csDto.setName(controllerServiceNode.getName());
    csDto.setType(controllerServiceNode.getCanonicalClassName());
    // missing bundle
    csDto.setBundle(null);
    csDto.setState(controllerServiceNode.getState().name());
    csDto.setAnnotationData(controllerServiceNode.getAnnotationData());
    csDto.setComments(controllerServiceNode.getComments());
    csDto.setPersistsState(controllerServiceNode.getControllerServiceImplementation().getClass().isAnnotationPresent(Stateful.class));
    csDto.setRestricted(controllerServiceNode.isRestricted());
    csDto.setExtensionMissing(controllerServiceNode.isExtensionMissing());
    csDto.setDescriptors(new LinkedHashMap<>());
    csDto.setProperties(new LinkedHashMap<>());
    // create the snippet with the controller service
    final FlowSnippetDTO flowSnippetDTO = new FlowSnippetDTO();
    flowSnippetDTO.setControllerServices(Collections.singleton(csDto));
    // instantiate the snippet
    assertEquals(0, controller.getRootGroup().getControllerServices(false).size());
    controller.instantiateSnippet(controller.getRootGroup(), flowSnippetDTO);
}
Also used : Stateful(org.apache.nifi.annotation.behavior.Stateful) ControllerServiceDTO(org.apache.nifi.web.api.dto.ControllerServiceDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Test(org.junit.Test)

Example 57 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardProcessGroup method getComponentsAffectedByVariable.

@Override
public Set<ConfiguredComponent> getComponentsAffectedByVariable(final String variableName) {
    final Set<ConfiguredComponent> affected = new HashSet<>();
    // Determine any Processors that references the variable
    for (final ProcessorNode processor : getProcessors()) {
        for (final VariableImpact impact : getVariableImpact(processor)) {
            if (impact.isImpacted(variableName)) {
                affected.add(processor);
            }
        }
    }
    // find any references to that service and add it.
    for (final ControllerServiceNode service : getControllerServices(false)) {
        for (final VariableImpact impact : getVariableImpact(service)) {
            if (impact.isImpacted(variableName)) {
                affected.add(service);
                final ControllerServiceReference reference = service.getReferences();
                affected.addAll(reference.findRecursiveReferences(ConfiguredComponent.class));
            }
        }
    }
    // is overriding the variable and its components are actually referencing a different variable.
    for (final ProcessGroup childGroup : getProcessGroups()) {
        final ComponentVariableRegistry childRegistry = childGroup.getVariableRegistry();
        final VariableDescriptor descriptor = childRegistry.getVariableKey(variableName);
        final boolean overridden = childRegistry.getVariableMap().containsKey(descriptor);
        if (!overridden) {
            affected.addAll(childGroup.getComponentsAffectedByVariable(variableName));
        }
    }
    return affected;
}
Also used : VariableImpact(org.apache.nifi.attribute.expression.language.VariableImpact) ProcessorNode(org.apache.nifi.controller.ProcessorNode) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 58 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardProcessGroup method updateVersionedComponentIds.

private void updateVersionedComponentIds(final ProcessGroup processGroup, final Map<String, String> versionedComponentIds) {
    if (versionedComponentIds == null || versionedComponentIds.isEmpty()) {
        return;
    }
    applyVersionedComponentIds(processGroup, versionedComponentIds::get);
    // If we versioned any parent groups' Controller Services, set their versioned component id's too.
    final ProcessGroup parent = processGroup.getParent();
    if (parent != null) {
        for (final ControllerServiceNode service : parent.getControllerServices(true)) {
            if (!service.getVersionedComponentId().isPresent()) {
                final String versionedId = versionedComponentIds.get(service.getIdentifier());
                if (versionedId != null) {
                    service.setVersionedComponentId(versionedId);
                }
            }
        }
    }
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)

Example 59 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardProcessGroup method getServiceInstanceId.

private String getServiceInstanceId(final String serviceVersionedComponentId, final ProcessGroup group) {
    for (final ControllerServiceNode serviceNode : group.getControllerServices(true)) {
        final Optional<String> optionalVersionedId = serviceNode.getVersionedComponentId();
        final String versionedId = optionalVersionedId.orElseGet(() -> UUID.nameUUIDFromBytes(serviceNode.getIdentifier().getBytes(StandardCharsets.UTF_8)).toString());
        if (versionedId.equals(serviceVersionedComponentId)) {
            return serviceNode.getIdentifier();
        }
    }
    final ProcessGroup parent = group.getParent();
    if (parent == null) {
        return null;
    }
    return getServiceInstanceId(serviceVersionedComponentId, parent);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)

Example 60 with ControllerServiceNode

use of org.apache.nifi.controller.service.ControllerServiceNode in project nifi by apache.

the class StandardProcessGroup method findAncestorControllerService.

private ControllerServiceNode findAncestorControllerService(final String id, final ProcessGroup start) {
    if (start == null) {
        return null;
    }
    final ControllerServiceNode serviceNode = start.getControllerService(id);
    if (serviceNode != null) {
        return serviceNode;
    }
    final ProcessGroup parent = start.getParent();
    return findAncestorControllerService(id, parent);
}
Also used : ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup)

Aggregations

ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)88 HashSet (java.util.HashSet)29 ProcessGroup (org.apache.nifi.groups.ProcessGroup)26 HashMap (java.util.HashMap)25 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)25 ArrayList (java.util.ArrayList)24 Map (java.util.Map)24 LinkedHashSet (java.util.LinkedHashSet)22 Test (org.junit.Test)19 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)18 ProcessorNode (org.apache.nifi.controller.ProcessorNode)18 ConfiguredComponent (org.apache.nifi.controller.ConfiguredComponent)17 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)17 Set (java.util.Set)16 Connection (org.apache.nifi.connectable.Connection)16 List (java.util.List)15 Port (org.apache.nifi.connectable.Port)15 Label (org.apache.nifi.controller.label.Label)15 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)15 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)15