NIFI-2208 This closes #754. refactored as per comments on JIRA. Reduced API expsosure and tightened lifecycle management.
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/05a99a93 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/05a99a93 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/05a99a93 Branch: refs/heads/master Commit: 05a99a93cbd255554c7b52313a4c5505c55d6572 Parents: 7f45251 Author: joewitt <joew...@apache.org> Authored: Sun Jul 31 15:14:22 2016 -0400 Committer: joewitt <joew...@apache.org> Committed: Mon Aug 1 14:17:26 2016 -0400 ---------------------------------------------------------------------- .../nifi/components/PropertyDescriptor.java | 2 +- .../apache/nifi/components/PropertyValue.java | 154 ++++--- .../nifi/expression/AttributeExpression.java | 33 +- .../expression/AttributeValueDecorator.java | 5 +- .../nifi/registry/FileVariableRegistry.java | 67 --- .../apache/nifi/registry/ImmutableMultiMap.java | 145 ------- .../nifi/registry/MultiMapVariableRegistry.java | 70 --- .../registry/PropertiesVariableRegistry.java | 82 ---- .../nifi/registry/VariableDescriptor.java | 154 +++++++ .../apache/nifi/registry/VariableRegistry.java | 118 ++++- .../nifi/registry/VariableRegistryFactory.java | 48 -- .../nifi/registry/VariableRegistryProvider.java | 23 - .../nifi/registry/VariableRegistryUtils.java | 87 ---- .../nifi/registry/TestVariableRegistry.java | 170 ++------ .../registry/TestVariableRegistryUtils.java | 143 ------ .../TestVariableRegistry/foobar.properties | 16 - .../TestVariableRegistry/test.properties | 17 - nifi-bootstrap/pom.xml | 85 ++-- .../bootstrap/NotificationServiceManager.java | 5 +- .../expression/language/EmptyPreparedQuery.java | 4 +- .../language/InvalidPreparedQuery.java | 4 +- .../expression/language/PreparedQuery.java | 4 +- .../attribute/expression/language/Query.java | 17 +- .../language/StandardAttributeExpression.java | 12 +- .../StandardExpressionLanguageCompiler.java | 4 + .../language/StandardPreparedQuery.java | 5 +- .../language/StandardPropertyValue.java | 26 +- .../expression/language/ValueLookup.java | 184 ++++++++ .../expression/language/QueryGroovyTest.groovy | 17 +- .../expression/language/TestQuery.java | 154 +++---- .../language/TestStandardPreparedQuery.java | 7 +- .../expression/language/TestValueLookup.java | 150 +++++++ .../org/apache/nifi/util/NiFiProperties.java | 2 +- .../nifi/web/NiFiWebConfigurationContext.java | 3 +- .../nifi/util/MockConfigurationContext.java | 16 +- .../apache/nifi/util/MockProcessContext.java | 6 +- .../org/apache/nifi/util/MockPropertyValue.java | 8 + .../apache/nifi/util/MockValidationContext.java | 4 + .../java/org/apache/nifi/util/TestRunners.java | 3 +- .../CurrentTestStandardProcessorTestRunner.java | 4 +- .../nifi/util/TestMockProcessContext.java | 3 +- .../ambari/TestAmbariReportingTask.java | 10 +- .../elasticsearch/TestFetchElasticsearch.java | 6 +- .../authorization/AuthorizerFactoryBean.java | 7 +- .../main/resources/nifi-authorizer-context.xml | 1 - .../nifi/authorization/FileAuthorizerTest.java | 36 +- .../StandardAuthorizerConfigurationContext.java | 7 +- .../apache/nifi/controller/FlowController.java | 433 +++++++++++-------- .../nifi/util/FileBasedVariableRegistry.java | 88 ++++ .../src/main/resources/nifi-context.xml | 2 +- .../controller/StandardFlowServiceTest.java | 4 +- .../nifi/controller/TestFlowController.java | 4 +- .../scheduling/TestProcessorLifecycle.java | 4 +- .../TestStandardProcessScheduler.java | 3 +- .../StandardControllerServiceProviderTest.java | 4 +- .../TestStandardControllerServiceProvider.java | 3 +- .../local/TestWriteAheadLocalStateProvider.java | 7 +- .../zookeeper/TestZooKeeperStateProvider.java | 8 +- .../processor/TestStandardPropertyValue.java | 36 +- .../util/TestFileBasedVariableRegistry.java | 45 ++ .../TestVariableRegistry/foobar.properties | 16 + .../TestVariableRegistry/test.properties | 17 + .../StandardNiFiWebConfigurationContext.java | 6 - .../authorization/TestRangerNiFiAuthorizer.java | 34 +- .../processors/script/TestInvokeGroovy.java | 13 +- .../TestSiteToSiteProvenanceReportingTask.java | 3 +- .../standard/TestRouteOnAttribute.java | 9 +- .../nifi/controller/MonitorMemoryTest.java | 15 +- .../cache/server/TestServerAndClient.java | 14 +- .../attributes/UpdateAttributeModelFactory.java | 8 +- .../update/attributes/api/RuleResource.java | 20 +- 71 files changed, 1436 insertions(+), 1488 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java b/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java index 7b382f6..532a034 100644 --- a/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java +++ b/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.nifi.controller.ControllerService; /** - * An immutable object for holding information about a type of processor + * An immutable object for holding information about a type of component * property. * */ http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/components/PropertyValue.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/components/PropertyValue.java b/nifi-api/src/main/java/org/apache/nifi/components/PropertyValue.java index edaddd7..666ada5 100644 --- a/nifi-api/src/main/java/org/apache/nifi/components/PropertyValue.java +++ b/nifi-api/src/main/java/org/apache/nifi/components/PropertyValue.java @@ -24,6 +24,7 @@ import org.apache.nifi.expression.AttributeValueDecorator; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.processor.DataUnit; import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.registry.VariableRegistry; /** * <p> @@ -121,144 +122,183 @@ public interface PropertyValue { /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language; a PropertyValue with the new value is then returned, supporting - * call chaining. + * Replaces values in the Property Value using the NiFi Expression Language; + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * * @return a PropertyValue with the new value is returned, supporting call * chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions() throws ProcessException; /** * <p> * Replaces values in the Property Value using the NiFi Expression Language; - * a PropertyValue with the new value is then returned, supporting call chaining. + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param attributes a Map of attributes that the Expression can reference, in addition - * to JVM System Properties and Environmental Properties. + * @param attributes a Map of attributes that the Expression can reference. + * These will take precedence over any underlying variable registry values. * * @return a PropertyValue with the new value * - * @throws ProcessException if the Expression cannot be compiled or evaluating the Expression against - * the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(Map<String, String> attributes) throws ProcessException; /** * <p> * Replaces values in the Property Value using the NiFi Expression Language. - * The supplied decorator is then given a chance to decorate the - * value, and a PropertyValue with the new value is then returned, - * supporting call chaining. + * The supplied decorator is then given a chance to decorate the value, and + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param attributes a Map of attributes that the Expression can reference, in addition - * to JVM System Properties and Environmental Properties. - * @param decorator the decorator to use in order to update the values returned by the Expression Language + * @param attributes a Map of attributes that the Expression can reference. + * These will take precedence over any variables in any underlying variable + * registry. + * @param decorator the decorator to use in order to update the values + * returned after variable substitution and expression language evaluation. * * @return a PropertyValue with the new value * - * @throws ProcessException if the Expression cannot be compiled or evaluating the Expression against - * the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(Map<String, String> attributes, AttributeValueDecorator decorator) throws ProcessException; /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language; a PropertyValue with the new value is then returned, supporting - * call chaining. + * Replaces values in the Property Value using the NiFi Expression Language; + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param flowFile to evaluate attributes of + * @param flowFile to evaluate attributes of. It's flow file properties and + * then flow file attributes will take precedence over any underlying + * variable registry. * @return a PropertyValue with the new value is returned, supporting call * chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(FlowFile flowFile) throws ProcessException; /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language; a PropertyValue with the new value is then returned, supporting - * call chaining. + * Replaces values in the Property Value using the NiFi Expression Language; + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param flowFile to evaluate attributes of - * @param additionalAttributes a Map of additional attributes that the Expression can reference. If entries in - * this Map conflict with entries in the FlowFile's attributes, the entries in this Map are given a higher priority. + * @param flowFile to evaluate attributes of. It's flow file properties and + * then flow file attributes will take precedence over any underlying + * variable registry. + * @param additionalAttributes a Map of additional attributes that the + * Expression can reference. These attributes will take precedence over any + * conflicting attributes in the provided flowfile or any underlying + * variable registry. * * @return a PropertyValue with the new value is returned, supporting call * chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(FlowFile flowFile, Map<String, String> additionalAttributes) throws ProcessException; /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language; a PropertyValue with the new value is then returned, supporting - * call chaining. + * Replaces values in the Property Value using the NiFi Expression Language; + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param flowFile to evaluate attributes of - * @param additionalAttributes a Map of additional attributes that the Expression can reference. If entries in - * this Map conflict with entries in the FlowFile's attributes, the entries in this Map are given a higher priority. - * @param decorator the decorator to use in order to update the values returned by the Expression Language + * @param flowFile to evaluate attributes of. It's flow file properties and + * then flow file attributes will take precedence over any underlying + * variable registry. + * @param additionalAttributes a Map of additional attributes that the + * Expression can reference. These attributes will take precedence over any + * conflicting attributes in the provided flowfile or any underlying + * variable registry. + * @param decorator the decorator to use in order to update the values + * returned after variable substitution and expression language evaluation. * * @return a PropertyValue with the new value is returned, supporting call * chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(FlowFile flowFile, Map<String, String> additionalAttributes, AttributeValueDecorator decorator) throws ProcessException; /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language. The supplied decorator is then given a chance to decorate the - * value, and a PropertyValue with the new value is then returned, - * supporting call chaining. + * Replaces values in the Property Value using the NiFi Expression Language. + * The supplied decorator is then given a chance to decorate the value, and + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * - * @param decorator The supplied decorator is then given a chance to - * decorate the value + * @param decorator the decorator to use in order to update the values + * returned after variable substitution and expression language evaluation. * @return a PropertyValue with the new value is then returned, supporting * call chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(AttributeValueDecorator decorator) throws ProcessException; /** * <p> - * Replaces values in the Property Value using the NiFi Expression - * Language. The supplied decorator is then given a chance to decorate the - * value, and a PropertyValue with the new value is then returned, - * supporting call chaining. + * Replaces values in the Property Value using the NiFi Expression Language. + * The supplied decorator is then given a chance to decorate the value, and + * a PropertyValue with the new value is then returned, supporting call + * chaining. Before executing the expression language statement any + * variables names found within any underlying {@link VariableRegistry} will + * be substituted with their values. * </p> * * @param flowFile to evaluate expressions against - * @param decorator The supplied decorator is then given a chance to - * decorate the value + * @param decorator the decorator to use in order to update the values + * returned after variable substitution and expression language evaluation. + * * * @return a PropertyValue with the new value is then returned, supporting * call chaining * - * @throws ProcessException if the Expression cannot be compiled or evaluating - * the Expression against the given attributes causes an Exception to be thrown + * @throws ProcessException if the Expression cannot be compiled or + * evaluating the Expression against the given attributes causes an + * Exception to be thrown */ PropertyValue evaluateAttributeExpressions(FlowFile flowFile, AttributeValueDecorator decorator) throws ProcessException; } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/expression/AttributeExpression.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/expression/AttributeExpression.java b/nifi-api/src/main/java/org/apache/nifi/expression/AttributeExpression.java index ed409ea..1cd3d5c 100644 --- a/nifi-api/src/main/java/org/apache/nifi/expression/AttributeExpression.java +++ b/nifi-api/src/main/java/org/apache/nifi/expression/AttributeExpression.java @@ -18,32 +18,37 @@ package org.apache.nifi.expression; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.processor.exception.ProcessException; +import org.apache.nifi.registry.VariableRegistry; +/** + * Defines a type of expression language statement that can be applied + * parameterized by various attributes and properties as specified in each of + * the method calls. AttributeExpression evaluations may be also backed by a + * {@link VariableRegistry} used to substitute attributes and variables found in + * the expression for which the registry has a value. + */ public interface AttributeExpression { /** - * @return Evaluates the expression without providing any FlowFile Attributes. This - * will evaluate the expression based only on System Properties and JVM - * Environment properties + * @return Evaluates the expression without any additional attributes. * @throws ProcessException if unable to evaluate */ String evaluate() throws ProcessException; /** - * Evaluates the expression without providing any FlowFile Attributes. This - * will evaluate the expression based only on System Properties and JVM - * Environment properties but allows the values to be decorated + * Evaluates the expression without additional attributes but enables the + * expression result to be decorated before returning. * - * @param decorator for attribute value + * @param decorator to execute on the resulting expression value * @return evaluated value * @throws ProcessException if failure in evaluation */ String evaluate(AttributeValueDecorator decorator) throws ProcessException; /** - * Evaluates the expression, providing access to the attributes, file size, - * id, etc. of the given FlowFile, as well as System Properties and JVM - * Environment properties + * Evaluates the expression providing access to additional variables + * including the flow file properties such as file size, identifier, etc.. + * and also all of the flow file attributes. * * @param flowFile to evaluate * @return evaluated value @@ -52,9 +57,11 @@ public interface AttributeExpression { String evaluate(FlowFile flowFile) throws ProcessException; /** - * Evaluates the expression, providing access to the attributes, file size, - * id, etc. of the given FlowFile, as well as System Properties and JVM - * Environment properties and allows the values to be decorated + * Evaluates the expression providing access to additional variables + * including the flow file properties such as file size, identifier, etc.. + * and also all of the flow file attributes. The resulting value after + * executing any variable substitution and expression evaluation is run + * through the given decorator and returned. * * @param flowFile to evaluate * @param decorator for evaluation http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/expression/AttributeValueDecorator.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/expression/AttributeValueDecorator.java b/nifi-api/src/main/java/org/apache/nifi/expression/AttributeValueDecorator.java index 4cea248..b2500dd 100644 --- a/nifi-api/src/main/java/org/apache/nifi/expression/AttributeValueDecorator.java +++ b/nifi-api/src/main/java/org/apache/nifi/expression/AttributeValueDecorator.java @@ -16,12 +16,11 @@ */ package org.apache.nifi.expression; +@FunctionalInterface public interface AttributeValueDecorator { /** - * Decorates the value of a FlowFile Attribute or System/JVM property in - * some way - * + * Decorates the given value * @param attributeValue to decorate * @return decorated value */ http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/FileVariableRegistry.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/FileVariableRegistry.java b/nifi-api/src/main/java/org/apache/nifi/registry/FileVariableRegistry.java deleted file mode 100644 index 9d77d6c..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/FileVariableRegistry.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.nifi.registry; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Map; - - -abstract class FileVariableRegistry extends MultiMapVariableRegistry { - - FileVariableRegistry() { - super(); - } - - FileVariableRegistry(File... files) throws IOException{ - super(); - addVariables(files); - } - - FileVariableRegistry(Path... paths) throws IOException{ - super(); - addVariables(paths); - } - - private void addVariables(File ...files) throws IOException{ - if(files != null) { - for (final File file : files) { - Map<String,String> map = convertFile(file); - if(map != null) { - registry.addMap(convertFile(file)); - } - } - - } - } - - private void addVariables(Path ...paths) throws IOException{ - if(paths != null) { - for (final Path path : paths) { - Map<String,String> map = convertFile(path.toFile()); - if(map != null) { - registry.addMap(map); - } - } - } - } - - protected abstract Map<String,String> convertFile(File file) throws IOException; - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/ImmutableMultiMap.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/ImmutableMultiMap.java b/nifi-api/src/main/java/org/apache/nifi/registry/ImmutableMultiMap.java deleted file mode 100644 index 2fba560..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/ImmutableMultiMap.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class ImmutableMultiMap<V> implements Map<String,V> { - - private final List<Map<String,V>> maps; - - ImmutableMultiMap() { - this.maps = new ArrayList<>(); - } - - @Override - public int size() { - return keySet().size(); - } - - @Override - public boolean isEmpty() { - for (final Map<String,V> map : maps) { - if (!map.isEmpty()) { - return false; - } - } - return true; - } - - @Override - public boolean containsKey(final Object key) { - if (key == null) { - return false; - } - - for (final Map<String,V> map : maps) { - if (map.containsKey(key)) { - return true; - } - } - return false; - } - - @Override - public boolean containsValue(final Object value) { - for (final Map<String,V> map : maps) { - if (map.containsValue(value)) { - return true; - } - } - return false; - } - - @Override - @SuppressWarnings("rawtypes") - public V get(final Object key) { - if (key == null) { - throw new IllegalArgumentException("Null Keys are not allowed"); - } - - for (final Map<String,V> map : maps) { - final V val = map.get(key); - if (val != null) { - return val; - } - } - return null; - } - - @Override - public V put(String key, V value) { - throw new UnsupportedOperationException(); - } - - @Override - public V remove(Object key) { - throw new UnsupportedOperationException(); - } - - @Override - public void putAll(Map<? extends String, ? extends V> m) { - throw new UnsupportedOperationException(); - } - - @Override - public void clear() { - throw new UnsupportedOperationException(); - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public Set<String> keySet() { - final Set<String> keySet = new HashSet<>(); - for (final Map map : maps) { - keySet.addAll(map.keySet()); - } - return keySet; - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public Collection<V> values() { - final Set<V> values = new HashSet<>(); - for (final Map map : maps) { - values.addAll(map.values()); - } - return values; - } - - @Override - @SuppressWarnings({"unchecked", "rawtypes"}) - public Set<java.util.Map.Entry<String, V>> entrySet() { - final Set<java.util.Map.Entry<String, V>> entrySet = new HashSet<>(); - for (final Map map : maps) { - entrySet.addAll(map.entrySet()); - } - return entrySet; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - void addMap(Map<String,V> map){ - this.maps.add(map); - } - - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/MultiMapVariableRegistry.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/MultiMapVariableRegistry.java b/nifi-api/src/main/java/org/apache/nifi/registry/MultiMapVariableRegistry.java deleted file mode 100644 index 029bfb5..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/MultiMapVariableRegistry.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.util.Map; -import java.util.Set; - -/*** - * This implementation of variable registry uses the ImmutableMultiMap which stores one or more - * registries that can be searched, accessed and appended. NOTE: Duplicate values within - * or between added registries will be stored however on retrieval the first value encountered will be returned. - * */ -public class MultiMapVariableRegistry implements VariableRegistry { - - protected final ImmutableMultiMap<String> registry; - - MultiMapVariableRegistry() { - this.registry = new ImmutableMultiMap<>(); - } - - @SafeVarargs - MultiMapVariableRegistry(Map<String,String>...maps){ - this(); - if(maps != null) { - for (Map<String, String> map : maps) { - addVariables(map); - } - } - } - - public void addVariables(Map<String, String> map) { - this.registry.addMap(map); - } - - @Override - public void addRegistry(VariableRegistry variableRegistry) { - if(variableRegistry != null && !variableRegistry.getVariables().isEmpty()) { - this.registry.addMap(variableRegistry.getVariables()); - } - } - - @Override - public Map<String, String> getVariables() { - return registry; - } - - @Override - public String getVariableValue(String variable) { - return registry.get(variable); - } - - @Override - public Set<String> getVariableNames() { - return this.registry.keySet(); - } -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/PropertiesVariableRegistry.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/PropertiesVariableRegistry.java b/nifi-api/src/main/java/org/apache/nifi/registry/PropertiesVariableRegistry.java deleted file mode 100644 index 8798930..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/PropertiesVariableRegistry.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class PropertiesVariableRegistry extends FileVariableRegistry { - - private static final Logger LOG = LoggerFactory.getLogger(PropertiesVariableRegistry.class); - - PropertiesVariableRegistry(File... files) throws IOException{ - super(files); - } - - PropertiesVariableRegistry(Path... paths) throws IOException { - super(paths); - } - - PropertiesVariableRegistry(Properties...properties){ - super(); - addVariables(properties); - } - - private void addVariables(Properties... properties){ - if(properties != null) { - for (Properties props : properties) { - addVariables(convertToMap(props)); - } - } - } - - @Override - protected Map<String,String> convertFile(File file) throws IOException{ - - if(file.exists()) { - try (final InputStream inStream = new BufferedInputStream(new FileInputStream(file))) { - Properties properties = new Properties(); - properties.load(inStream); - return convertToMap(properties); - } - }else{ - LOG.warn("Could not add file " + file.getName() + ". file did not exist."); - return null; - } - - } - - private Map<String,String> convertToMap(Properties properties){ - HashMap<String,String> propertiesMap = new HashMap<>(properties.keySet().size()); - for(Object key: properties.keySet()){ - propertiesMap.put((String)key,(String) properties.get(key)); - } - return propertiesMap; - } - - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/VariableDescriptor.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/VariableDescriptor.java b/nifi-api/src/main/java/org/apache/nifi/registry/VariableDescriptor.java new file mode 100644 index 0000000..5b1e88f --- /dev/null +++ b/nifi-api/src/main/java/org/apache/nifi/registry/VariableDescriptor.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.registry; + +/** + * An immutable object for holding information about a type of processor + * property. + * + */ +public final class VariableDescriptor implements Comparable<VariableDescriptor> { + + /** + * The name (or key) of the variable by which all access/lookups to the + * value will occur. This is the mechanism of establishing identity and + * comparing equality. + */ + private final String name; + + /** + * A brief description of the variable. This description is meant to be + * displayed to a user or simply provide a mechanism of documenting intent. + */ + private final String description; + + /** + * indicates that the value for this variable should be considered sensitive + * and protected whenever stored or represented + */ + private final boolean sensitive; + + /** + * Convenience constructor to create a descriptor based on name alone. To + * include additional parameters use Builder instead. + * + * @param name name used as unique identifier for this descriptor + */ + public VariableDescriptor(final String name) { + this(new Builder(name)); + } + + protected VariableDescriptor(final Builder builder) { + this.name = builder.name; + this.description = builder.description; + this.sensitive = builder.sensitive; + } + + @Override + public int compareTo(final VariableDescriptor o) { + if (o == null) { + return -1; + } + return getName().compareTo(o.getName()); + } + + public static final class Builder { + + private String name = null; + private String description = ""; + private boolean sensitive = false; + + /** + * Establishes the unique identifier or key name of the variable. + * + * @param name of the property + */ + public Builder(final String name) { + if (null == name || name.trim().isEmpty()) { + throw new IllegalArgumentException("Name must not be null or empty"); + } + this.name = name.trim(); + } + + /** + * @param description of the variable + * @return the builder + */ + public Builder description(final String description) { + if (null != description) { + this.description = description; + } + return this; + } + + /** + * @param sensitive true if sensitive; false otherwise + * @return the builder + */ + public Builder sensitive(final boolean sensitive) { + this.sensitive = sensitive; + return this; + } + + /** + * @return a VariableDescriptor as configured + * + */ + public VariableDescriptor build() { + return new VariableDescriptor(this); + } + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public boolean isSensitive() { + return sensitive; + } + + @Override + public boolean equals(final Object other) { + if (other == null) { + return false; + } + if (!(other instanceof VariableDescriptor)) { + return false; + } + if (this == other) { + return true; + } + + final VariableDescriptor desc = (VariableDescriptor) other; + return this.name.equals(desc.name); + } + + @Override + public int hashCode() { + return 797 + this.name.hashCode() * 97; + } + + @Override + public String toString() { + return getClass().getSimpleName() + "[" + name + "]"; + } + +} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistry.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistry.java b/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistry.java index 48eacfd..d9ae4b1 100644 --- a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistry.java +++ b/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistry.java @@ -16,45 +16,115 @@ */ package org.apache.nifi.registry; - +import java.util.Collections; +import java.util.HashMap; import java.util.Map; -import java.util.Set; /** - * Access key/value pairs throughout the application. + * Provides a registry of variables available for use by various components and + * extension points. This enables components to reference variable names rather + * than explicit values which can make configurations of those components more + * portable. */ public interface VariableRegistry { /** - * Returns a map of key/value pairs stored in the registry - * @return variables - **/ - Map<String, String> getVariables(); + * Returns an empty registry which can be used as a more intentional null + * value. + */ + public static final VariableRegistry EMPTY_REGISTRY = () -> Collections.EMPTY_MAP; /** - * Return a value for a given variable - * @param variable variable - * @return value - **/ - String getVariableValue(String variable); + * Provides a registry containing all environment variables and system + * properties. System properties receive precedence. + */ + public static final VariableRegistry ENVIRONMENT_SYSTEM_REGISTRY = new VariableRegistry() { + final Map<VariableDescriptor, String> map = new HashMap<>(); + + { + System.getenv().entrySet().stream().forEach((entry) -> { + final VariableDescriptor desc = new VariableDescriptor.Builder(entry.getKey()) + .description("Env Var") + .sensitive(false) + .build(); + map.put(desc, entry.getValue()); + }); + System.getProperties().entrySet().stream().forEach((entry) -> { + final VariableDescriptor desc = new VariableDescriptor.Builder(entry.getKey().toString()) + .description("System Property") + .sensitive(false) + .build(); + map.put(desc, entry.getValue().toString()); + }); + + } + + @Override + public Map<VariableDescriptor, String> getVariableMap() { + return Collections.unmodifiableMap(map); + + } + + }; /** - * Concatenate a variable registry - * @param variableRegistry variableRegistry - * */ - void addRegistry(VariableRegistry variableRegistry); + * Provides access to a map of variable key/value pairs. For variables + * considered to be sensitive care must be taken to ensure their values are + * protected whenever stored or exposed. + * + * @return An immutable map of all variables in the registry + */ + + Map<VariableDescriptor, String> getVariableMap(); /** - * Returns a set variable names in the registry - * @return variableNames - **/ - Set<String> getVariableNames(); + * Returns the VariableDescriptor for the given key name if it exists. + * + * @param name the string name of the VariableDescriptor to lookup. + * @return the variable descriptor registered for this name if it exists; + * null otherwise + */ + default VariableDescriptor getVariableKey(final String name) { + if (name == null) { + return null; + } + final VariableDescriptor spec = new VariableDescriptor(name); + for (final Map.Entry<VariableDescriptor, String> entry : getVariableMap().entrySet()) { + if (entry.getKey().equals(spec)) { + return entry.getKey(); + } + } + return null; + + } /** - * Concatenate variable key value pair to registry - * @param variables variable Map - * */ - void addVariables(Map<String,String> variables); + * Gets the variable value + * + * @param name the string name of the VariableDescriptor that is the key of + * the value to lookup. + * @return the value associated with the given variable name if found; null + * otherwise + */ + default String getVariableValue(final String name) { + if (name == null) { + return null; + } + return getVariableMap().get(new VariableDescriptor(name)); + } + /** + * Gets the variable value + * + * @param descriptor the descriptor for which to lookup the variable value. + * @return the variable value if the given descriptor is equivalent to one + * of the entries in the registry; null otherwise + */ + default String getVariableValue(final VariableDescriptor descriptor) { + if (descriptor == null) { + return null; + } + return getVariableMap().get(descriptor); + } } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryFactory.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryFactory.java b/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryFactory.java deleted file mode 100644 index 1852ad4..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Map; -import java.util.Properties; - -public class VariableRegistryFactory { - - public static VariableRegistry getPropertiesInstance(final Properties...properties){ - return new PropertiesVariableRegistry(properties); - } - - public static VariableRegistry getPropertiesInstance(final Path... paths) throws IOException{ - return new PropertiesVariableRegistry(paths); - } - - public static VariableRegistry getPropertiesInstance(final File ...files) throws IOException{ - return new PropertiesVariableRegistry(files); - } - - @SafeVarargs - public static VariableRegistry getInstance(final Map<String,String> ...maps){ - return new MultiMapVariableRegistry(maps); - } - - public static VariableRegistry getInstance(){ - return new MultiMapVariableRegistry(); - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryProvider.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryProvider.java b/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryProvider.java deleted file mode 100644 index af7ab38..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryProvider.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -public interface VariableRegistryProvider { - - VariableRegistry getVariableRegistry(); - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryUtils.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryUtils.java b/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryUtils.java deleted file mode 100644 index 6e280d6..0000000 --- a/nifi-api/src/main/java/org/apache/nifi/registry/VariableRegistryUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.io.IOException; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; - -import org.apache.nifi.flowfile.FlowFile; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class VariableRegistryUtils { - - private final static Logger LOG = LoggerFactory.getLogger(VariableRegistryUtils.class); - - public static VariableRegistry createSystemVariableRegistry(){ - VariableRegistry variableRegistry = VariableRegistryFactory.getInstance(); - VariableRegistry propRegistry = VariableRegistryFactory.getPropertiesInstance(System.getProperties()); - VariableRegistry envRegistry = VariableRegistryFactory.getInstance(System.getenv()); - variableRegistry.addRegistry(propRegistry); - variableRegistry.addRegistry(envRegistry); - return variableRegistry; - } - - public static VariableRegistry createCustomVariableRegistry(Path[] properties){ - - VariableRegistry customRegistry = null; - try { - customRegistry = VariableRegistryFactory.getPropertiesInstance(properties); - customRegistry.addRegistry(createSystemVariableRegistry()); - } catch (IOException ioe){ - LOG.error("Exception thrown while attempting to add properties to registry",ioe); - } - return customRegistry; - } - - public static VariableRegistry createFlowVariableRegistry(VariableRegistry variableRegistry, final FlowFile flowFile, final Map<String, String> additionalAttributes){ - final Map<String, String> flowFileAttributes = flowFile == null ? null : flowFile.getAttributes(); - final Map<String, String> additionalMap = additionalAttributes == null ? null : additionalAttributes; - - Map<String, String> flowFileProps = null; - if (flowFile != null) { - flowFileProps = new HashMap<>(); - flowFileProps.put("flowFileId", String.valueOf(flowFile.getId())); - flowFileProps.put("fileSize", String.valueOf(flowFile.getSize())); - flowFileProps.put("entryDate", String.valueOf(flowFile.getEntryDate())); - flowFileProps.put("lineageStartDate", String.valueOf(flowFile.getLineageStartDate())); - flowFileProps.put("lastQueueDate",String.valueOf(flowFile.getLastQueueDate())); - flowFileProps.put("queueDateIndex",String.valueOf(flowFile.getQueueDateIndex())); - } - - VariableRegistry newRegistry = VariableRegistryFactory.getInstance(); - - if(flowFileAttributes != null) { - newRegistry.addVariables(flowFileAttributes); - } - if(additionalMap != null) { - newRegistry.addVariables(additionalMap); - } - if(flowFileProps != null) { - newRegistry.addVariables(flowFileProps); - } - - if(variableRegistry != null) { - newRegistry.addRegistry(variableRegistry); - } - - return newRegistry; - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java b/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java index 93099b2..e326fab 100644 --- a/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java +++ b/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java @@ -14,157 +14,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.nifi.registry; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - import org.junit.Test; - -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class TestVariableRegistry { @Test - public void testReadMap(){ - Map<String,String> variables1 = new HashMap<>(); - variables1.put("fake.property.1","fake test value"); - - Map<String,String> variables2 = new HashMap<>(); - variables1.put("fake.property.2","fake test value"); - - VariableRegistry registry = VariableRegistryFactory.getInstance(variables1,variables2); - - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.size() == 2); - assertTrue(variables.get("fake.property.1").equals("fake test value")); - assertTrue(registry.getVariableValue("fake.property.2").equals("fake test value")); - } - - @Test - public void testReadProperties(){ - Properties properties = new Properties(); - properties.setProperty("fake.property.1","fake test value"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(properties); - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.get("fake.property.1").equals("fake test value")); - } - - @Test - public void testReadFiles() throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(fooPath.toFile(),testPath.toFile()); - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.size() == 3); - assertTrue(variables.get("fake.property.1").equals("test me out 1")); - assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); - } - - @Test - public void testExcludeInvalidFiles() throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - final Path fakePath = Paths.get("src/test/resources/TestVariableRegistry/fake.properties"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(fooPath.toFile(),testPath.toFile(),fakePath.toFile()); - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.size() == 3); - assertTrue(variables.get("fake.property.1").equals("test me out 1")); - assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); - } - - - @Test - public void testReadPaths() throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(fooPath,testPath); - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.size() == 3); - assertTrue(variables.get("fake.property.1").equals("test me out 1")); - assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); - } - - @Test - public void testExcludeInvalidPaths() throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - final Path fakePath = Paths.get("src/test/resources/TestVariableRegistry/fake.properties"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(fooPath,testPath,fakePath); - Map<String,String> variables = registry.getVariables(); - assertTrue(variables.size() == 3); - } - - @Test - public void testAddRegistry() throws IOException{ - - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - VariableRegistry pathRegistry = VariableRegistryFactory.getPropertiesInstance(fooPath); - - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - VariableRegistry fileRegistry = VariableRegistryFactory.getPropertiesInstance(testPath.toFile()); - - Properties properties = new Properties(); - properties.setProperty("fake.property.5","test me out 5"); - VariableRegistry propRegistry = VariableRegistryFactory.getPropertiesInstance(properties); - - propRegistry.addRegistry(pathRegistry); - propRegistry.addRegistry(fileRegistry); - - Map<String,String> variables = propRegistry.getVariables(); - assertTrue(variables.size() == 4); - } - - @Test - public void testAttemptToAddNullRegistry() throws IOException{ - - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - VariableRegistry pathRegistry = VariableRegistryFactory.getPropertiesInstance(fooPath); - VariableRegistry nullRegistry = null; - pathRegistry.addRegistry(nullRegistry); - assertTrue(pathRegistry.getVariables().size() == 1); + public void testSystemProp() { + assertNull(System.getProperty("ALKJAFLKJDFLSKJSDFLKJSDF")); + final VariableRegistry sysEvnReg = VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY; + System.setProperty("ALKJAFLKJDFLSKJSDFLKJSDF", "here now"); + //should not be in Variable Registry + assertNull(sysEvnReg.getVariableValue("ALKJAFLKJDFLSKJSDFLKJSDF")); + //should be in System properties now though... + assertEquals("here now", System.getProperty("ALKJAFLKJDFLSKJSDFLKJSDF")); + + //Test should be stable but a security manager could block it. The following assertions are optional and based on access to the following property. + //It was chosen from this list https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html + final String vendorUrl = System.getProperty("java.vendor.url"); + if (vendorUrl != null) { // we can run this extra test + //var reg value matches system property + assertEquals(vendorUrl, sysEvnReg.getVariableValue("java.vendor.url")); + //change system property + System.setProperty("java.vendor.url", "http://fake.vendor.url/"); + //changed in system properties + assertEquals("http://fake.vendor.url/", System.getProperty("java.vendor.url")); + //var reg value matches system property still + assertEquals(vendorUrl, sysEvnReg.getVariableValue("java.vendor.url")); + //restore to its old value + System.setProperty("java.vendor.url", vendorUrl); + } } - @Test - public void testNoOverwriteRegistry()throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - VariableRegistry pathRegistry = VariableRegistryFactory.getPropertiesInstance(fooPath); - - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - VariableRegistry fileRegistry = VariableRegistryFactory.getPropertiesInstance(testPath.toFile()); - - Properties properties = new Properties(); - properties.setProperty("fake.property.3","test me out 5"); - VariableRegistry propRegistry = VariableRegistryFactory.getPropertiesInstance(properties); - - propRegistry.addRegistry(pathRegistry); - propRegistry.addRegistry(fileRegistry); - - Map<String,String> variables = propRegistry.getVariables(); - String testDuplicate = propRegistry.getVariableValue("fake.property.3"); - assertTrue(variables.size() == 3); - assertTrue(testDuplicate.equals("test me out 5")); - } - - @Test - public void testGetVariableNames() throws IOException{ - final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); - final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); - VariableRegistry registry = VariableRegistryFactory.getPropertiesInstance(fooPath,testPath); - Set<String> variableNames= registry.getVariableNames(); - assertTrue(variableNames.size() == 3); - assertTrue(variableNames.contains("fake.property.1")); - assertTrue(variableNames.contains("fake.property.2")); - assertTrue(variableNames.contains("fake.property.3")); - assertTrue(!variableNames.contains("fake.property.4")); - } - - - } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistryUtils.java ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistryUtils.java b/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistryUtils.java deleted file mode 100644 index a3c4ae4..0000000 --- a/nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistryUtils.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.nifi.registry; - -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; - -import org.apache.nifi.flowfile.FlowFile; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class TestVariableRegistryUtils { - - @Test - public void testCreateSystemVariableRegistry(){ - System.setProperty("fake","test"); - VariableRegistry variableRegistry = VariableRegistryUtils.createSystemVariableRegistry(); - Map<String,String> variables = variableRegistry.getVariables(); - assertTrue(variables.containsKey("PATH")); - assertTrue(variables.get("fake").equals("test")); - } - - @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}; - System.setProperty("fake","test"); - VariableRegistry variableRegistry = VariableRegistryUtils.createCustomVariableRegistry(paths); - Map<String,String> variables = variableRegistry.getVariables(); - assertTrue(variables.containsKey("PATH")); - assertTrue(variables.containsKey("fake.property.3")); - assertTrue(variables.get("fake").equals("test")); - assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); - } - - @Test - public void testCreateFlowVariableRegistry(){ - System.setProperty("fake","test"); - FlowFile flowFile = createFlowFile(); - - VariableRegistry variableRegistry = VariableRegistryUtils.createSystemVariableRegistry(); - VariableRegistry populatedRegistry = VariableRegistryUtils.createFlowVariableRegistry(variableRegistry,flowFile,null); - Map<String,String> variables = populatedRegistry.getVariables(); - assertTrue(variables.containsKey("PATH")); - assertTrue(variables.get("fake").equals("test")); - assertTrue(variables.get("flowFileId").equals("1")); - assertTrue(variables.get("fileSize").equals("50")); - assertTrue(variables.get("entryDate").equals("1000")); - assertTrue(variables.get("lineageStartDate").equals("10000")); - assertTrue(variables.get("filename").equals("fakefile.txt")); - } - - @Test - public void testPopulateRegistryWithEmptyFlowFileAndAttributes(){ - System.setProperty("fake","test"); - VariableRegistry variableRegistry = VariableRegistryUtils.createSystemVariableRegistry(); - VariableRegistry populatedRegistry = VariableRegistryUtils.createFlowVariableRegistry(variableRegistry,null,null); - Map<String,String> variables = populatedRegistry.getVariables(); - assertTrue( variables.containsKey("PATH")); - assertTrue( variables.get("fake").equals("test")); - } - - - private FlowFile createFlowFile(){ - return new FlowFile() { - @Override - public long getId() { - return 1; - } - - @Override - public long getEntryDate() { - return 1000; - } - - @Override - public long getLineageStartDate() { - return 10000; - } - - @Override - public Long getLastQueueDate() { - return null; - } - - @Override - public boolean isPenalized() { - return false; - } - - @Override - public String getAttribute(String key) { - return null; - } - - @Override - public long getSize() { - return 50; - } - - @Override - public long getLineageStartIndex() { - return 0; - } - - @Override - public long getQueueDateIndex() { - return 0; - } - - @Override - public Map<String, String> getAttributes() { - Map<String,String> attributes = new HashMap<>(); - attributes.put("filename","fakefile.txt"); - return attributes; - } - - @Override - public int compareTo(FlowFile o) { - return 0; - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/test/resources/TestVariableRegistry/foobar.properties ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/resources/TestVariableRegistry/foobar.properties b/nifi-api/src/test/resources/TestVariableRegistry/foobar.properties deleted file mode 100644 index 1094e1b..0000000 --- a/nifi-api/src/test/resources/TestVariableRegistry/foobar.properties +++ /dev/null @@ -1,16 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -fake.property.3=test me out 3, test me out 4 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-api/src/test/resources/TestVariableRegistry/test.properties ---------------------------------------------------------------------- diff --git a/nifi-api/src/test/resources/TestVariableRegistry/test.properties b/nifi-api/src/test/resources/TestVariableRegistry/test.properties deleted file mode 100644 index 6191449..0000000 --- a/nifi-api/src/test/resources/TestVariableRegistry/test.properties +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -fake.property.1=test me out 1 -fake.property.2=test me out 2 http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-bootstrap/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-bootstrap/pom.xml b/nifi-bootstrap/pom.xml index 5694fd9..8a0ef09 100644 --- a/nifi-bootstrap/pom.xml +++ b/nifi-bootstrap/pom.xml @@ -1,50 +1,45 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor - license agreements. See the NOTICE file distributed with this work for additional - information regarding copyright ownership. The ASF licenses this file to - You under the Apache License, Version 2.0 (the "License"); you may not use - this file except in compliance with the License. You may obtain a copy of - the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required - by applicable law or agreed to in writing, software distributed under the - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS - OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. --> +license agreements. See the NOTICE file distributed with this work for additional +information regarding copyright ownership. The ASF licenses this file to +You under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of +the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required +by applicable law or agreed to in writing, software distributed under the +License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, either express or implied. See the License for the specific +language governing permissions and limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.nifi</groupId> - <artifactId>nifi</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - <artifactId>nifi-bootstrap</artifactId> - <packaging>jar</packaging> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <artifactId>nifi-bootstrap</artifactId> + <packaging>jar</packaging> - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.nifi</groupId> - <artifactId>nifi-api</artifactId> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.apache.nifi</groupId> - <artifactId>nifi-processor-utils</artifactId> - </dependency> - <dependency> - <groupId>javax.mail</groupId> - <artifactId>mail</artifactId> - </dependency> - <dependency> - <groupId>org.apache.nifi</groupId> - <artifactId>nifi-expression-language</artifactId> - </dependency> - <dependency> - <groupId>org.spockframework</groupId> - <artifactId>spock-core</artifactId> - <scope>test</scope> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-api</artifactId> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-processor-utils</artifactId> + </dependency> + <dependency> + <groupId>javax.mail</groupId> + <artifactId>mail</artifactId> + </dependency> + <dependency> + <groupId>org.apache.nifi</groupId> + <artifactId>nifi-expression-language</artifactId> + </dependency> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/NotificationServiceManager.java ---------------------------------------------------------------------- diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/NotificationServiceManager.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/NotificationServiceManager.java index 233c66d..869658a 100644 --- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/NotificationServiceManager.java +++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/NotificationServiceManager.java @@ -47,7 +47,6 @@ import org.apache.nifi.components.PropertyValue; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; import org.apache.nifi.registry.VariableRegistry; -import org.apache.nifi.registry.VariableRegistryUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -68,10 +67,10 @@ public class NotificationServiceManager { public NotificationServiceManager() { - this(VariableRegistryUtils.createSystemVariableRegistry()); + this(VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY); } - NotificationServiceManager(VariableRegistry variableRegistry){ + NotificationServiceManager(final VariableRegistry variableRegistry){ this.variableRegistry = variableRegistry; notificationExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() { @Override http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/EmptyPreparedQuery.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/EmptyPreparedQuery.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/EmptyPreparedQuery.java index 5dec2fa..5ed00ed 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/EmptyPreparedQuery.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/EmptyPreparedQuery.java @@ -17,9 +17,9 @@ package org.apache.nifi.attribute.expression.language; +import java.util.Map; import org.apache.nifi.expression.AttributeValueDecorator; import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.registry.VariableRegistry; public class EmptyPreparedQuery implements PreparedQuery { @@ -30,7 +30,7 @@ public class EmptyPreparedQuery implements PreparedQuery { } @Override - public String evaluateExpressions(VariableRegistry variableRegistry, AttributeValueDecorator decorator) throws ProcessException { + public String evaluateExpressions(Map<String, String> valueLookup, AttributeValueDecorator decorator) throws ProcessException { return value; } } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java index 0ca9a8f..cbf6c66 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/InvalidPreparedQuery.java @@ -17,10 +17,10 @@ package org.apache.nifi.attribute.expression.language; +import java.util.Map; import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException; import org.apache.nifi.expression.AttributeValueDecorator; import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.registry.VariableRegistry; /** * An implementation of PreparedQuery that throws an @@ -39,7 +39,7 @@ public class InvalidPreparedQuery implements PreparedQuery { } @Override - public String evaluateExpressions(final VariableRegistry variableRegistry, final AttributeValueDecorator decorator) throws ProcessException { + public String evaluateExpressions(final Map<String,String> valueLookup, final AttributeValueDecorator decorator) throws ProcessException { throw new AttributeExpressionLanguageException("Invalid Expression: " + query + " due to " + explanation); } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/PreparedQuery.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/PreparedQuery.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/PreparedQuery.java index 37d8b86..e1a1db7 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/PreparedQuery.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/PreparedQuery.java @@ -17,12 +17,12 @@ package org.apache.nifi.attribute.expression.language; +import java.util.Map; import org.apache.nifi.expression.AttributeValueDecorator; import org.apache.nifi.processor.exception.ProcessException; -import org.apache.nifi.registry.VariableRegistry; public interface PreparedQuery { - String evaluateExpressions(VariableRegistry registry, AttributeValueDecorator decorator) throws ProcessException; + String evaluateExpressions(Map<String, String> valueLookup, AttributeValueDecorator decorator) throws ProcessException; } http://git-wip-us.apache.org/repos/asf/nifi/blob/05a99a93/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java index f2d3915..9162815 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java @@ -194,7 +194,6 @@ import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpre import static org.apache.nifi.attribute.expression.language.antlr.AttributeExpressionParser.UUID; import org.apache.nifi.attribute.expression.language.evaluation.selection.MappingEvaluator; -import org.apache.nifi.registry.VariableRegistry; /** * Class used for creating and evaluating NiFi Expression Language. Once a Query @@ -364,8 +363,8 @@ public class Query { return -1; } - static String evaluateExpression(final Tree tree, final String queryText, final VariableRegistry registry, final AttributeValueDecorator decorator) throws ProcessException { - final Object evaluated = Query.fromTree(tree, queryText).evaluate(registry).getValue(); + static String evaluateExpression(final Tree tree, final String queryText, final Map<String, String> valueMap, final AttributeValueDecorator decorator) throws ProcessException { + final Object evaluated = Query.fromTree(tree, queryText).evaluate(valueMap).getValue(); if (evaluated == null) { return null; } @@ -375,12 +374,12 @@ public class Query { return decorator == null ? escaped : decorator.decorate(escaped); } - static String evaluateExpressions(final String rawValue, VariableRegistry registry) throws ProcessException { - return evaluateExpressions(rawValue, registry, null); + static String evaluateExpressions(final String rawValue, final Map<String, String> valueLookup) throws ProcessException { + return evaluateExpressions(rawValue, valueLookup, null); } - static String evaluateExpressions(final String rawValue, VariableRegistry registry, final AttributeValueDecorator decorator) throws ProcessException { - return Query.prepare(rawValue).evaluateExpressions(registry, decorator); + static String evaluateExpressions(final String rawValue, final Map<String, String> valueLookup, final AttributeValueDecorator decorator) throws ProcessException { + return Query.prepare(rawValue).evaluateExpressions(valueLookup, decorator); } private static Evaluator<?> getRootSubjectEvaluator(final Evaluator<?> evaluator) { @@ -542,12 +541,12 @@ public class Query { return evaluator.getResultType(); } - QueryResult<?> evaluate(final VariableRegistry registry) { + QueryResult<?> evaluate(final Map<String, String> map) { if (evaluated.getAndSet(true)) { throw new IllegalStateException("A Query cannot be evaluated more than once"); } - return evaluator.evaluate(registry.getVariables()); + return evaluator.evaluate(map); } Tree getTree() {