Search in sources :

Example 6 with VariableDescriptor

use of org.apache.nifi.registry.VariableDescriptor 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 7 with VariableDescriptor

use of org.apache.nifi.registry.VariableDescriptor in project nifi by apache.

the class StandardComponentVariableRegistry method getVariableValue.

@Override
public String getVariableValue(final String name) {
    if (name == null) {
        return null;
    }
    final VariableDescriptor descriptor = new VariableDescriptor(name);
    final String value = getVariableMap().get(descriptor);
    if (value != null) {
        return value;
    }
    return parent.getVariableValue(descriptor);
}
Also used : VariableDescriptor(org.apache.nifi.registry.VariableDescriptor)

Example 8 with VariableDescriptor

use of org.apache.nifi.registry.VariableDescriptor in project nifi by apache.

the class StandardFlowSerializer method addProcessGroup.

private void addProcessGroup(final Element parentElement, final ProcessGroup group, final String elementName, final ScheduledStateLookup scheduledStateLookup) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement(elementName);
    parentElement.appendChild(element);
    addTextElement(element, "id", group.getIdentifier());
    addTextElement(element, "versionedComponentId", group.getVersionedComponentId());
    addTextElement(element, "name", group.getName());
    addPosition(element, group.getPosition());
    addTextElement(element, "comment", group.getComments());
    final VersionControlInformation versionControlInfo = group.getVersionControlInformation();
    if (versionControlInfo != null) {
        final Element versionControlInfoElement = doc.createElement("versionControlInformation");
        addTextElement(versionControlInfoElement, "registryId", versionControlInfo.getRegistryIdentifier());
        addTextElement(versionControlInfoElement, "bucketId", versionControlInfo.getBucketIdentifier());
        addTextElement(versionControlInfoElement, "bucketName", versionControlInfo.getBucketName());
        addTextElement(versionControlInfoElement, "flowId", versionControlInfo.getFlowIdentifier());
        addTextElement(versionControlInfoElement, "flowName", versionControlInfo.getFlowName());
        addTextElement(versionControlInfoElement, "flowDescription", versionControlInfo.getFlowDescription());
        addTextElement(versionControlInfoElement, "version", versionControlInfo.getVersion());
        element.appendChild(versionControlInfoElement);
    }
    for (final ProcessorNode processor : group.getProcessors()) {
        addProcessor(element, processor, scheduledStateLookup);
    }
    if (group.isRootGroup()) {
        for (final Port port : group.getInputPorts()) {
            addRootGroupPort(element, (RootGroupPort) port, "inputPort", scheduledStateLookup);
        }
        for (final Port port : group.getOutputPorts()) {
            addRootGroupPort(element, (RootGroupPort) port, "outputPort", scheduledStateLookup);
        }
    } else {
        for (final Port port : group.getInputPorts()) {
            addPort(element, port, "inputPort", scheduledStateLookup);
        }
        for (final Port port : group.getOutputPorts()) {
            addPort(element, port, "outputPort", scheduledStateLookup);
        }
    }
    for (final Label label : group.getLabels()) {
        addLabel(element, label);
    }
    for (final Funnel funnel : group.getFunnels()) {
        addFunnel(element, funnel);
    }
    for (final ProcessGroup childGroup : group.getProcessGroups()) {
        addProcessGroup(element, childGroup, "processGroup", scheduledStateLookup);
    }
    for (final RemoteProcessGroup remoteRef : group.getRemoteProcessGroups()) {
        addRemoteProcessGroup(element, remoteRef, scheduledStateLookup);
    }
    for (final Connection connection : group.getConnections()) {
        addConnection(element, connection);
    }
    for (final ControllerServiceNode service : group.getControllerServices(false)) {
        addControllerService(element, service);
    }
    for (final Template template : group.getTemplates()) {
        addTemplate(element, template);
    }
    final VariableRegistry variableRegistry = group.getVariableRegistry();
    for (final Map.Entry<VariableDescriptor, String> entry : variableRegistry.getVariableMap().entrySet()) {
        addVariable(element, entry.getKey().getName(), entry.getValue());
    }
}
Also used : Funnel(org.apache.nifi.connectable.Funnel) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Element(org.w3c.dom.Element) Port(org.apache.nifi.connectable.Port) RootGroupPort(org.apache.nifi.remote.RootGroupPort) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) Label(org.apache.nifi.controller.label.Label) Connection(org.apache.nifi.connectable.Connection) VariableRegistry(org.apache.nifi.registry.VariableRegistry) Document(org.w3c.dom.Document) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Template(org.apache.nifi.controller.Template) ProcessorNode(org.apache.nifi.controller.ProcessorNode) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Map(java.util.Map)

Example 9 with VariableDescriptor

use of org.apache.nifi.registry.VariableDescriptor in project nifi by apache.

the class TestFileBasedVariableRegistry method testCreateCustomVariableRegistry.

@Test
public void testCreateCustomVariableRegistry() {
    final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties");
    final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties");
    Path[] paths = { fooPath, testPath };
    final String vendorUrl = System.getProperty("java.vendor.url");
    VariableRegistry variableRegistry = new FileBasedVariableRegistry(paths);
    final Map<VariableDescriptor, String> variables = variableRegistry.getVariableMap();
    assertTrue(variables.containsKey(new VariableDescriptor("fake.property.3")));
    assertEquals(vendorUrl, variableRegistry.getVariableValue("java.vendor.url"));
    assertEquals("test me out 3, test me out 4", variableRegistry.getVariableValue("fake.property.3"));
}
Also used : Path(java.nio.file.Path) VariableRegistry(org.apache.nifi.registry.VariableRegistry) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry) Test(org.junit.Test)

Aggregations

VariableDescriptor (org.apache.nifi.registry.VariableDescriptor)9 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 ComponentVariableRegistry (org.apache.nifi.registry.ComponentVariableRegistry)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 VariableImpact (org.apache.nifi.attribute.expression.language.VariableImpact)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ControllerServiceNode (org.apache.nifi.controller.service.ControllerServiceNode)2 VariableRegistry (org.apache.nifi.registry.VariableRegistry)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 SecureRandom (java.security.SecureRandom)1 Collections (java.util.Collections)1