This is an automated email from the ASF dual-hosted git repository. mmerli pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git
The following commit(s) were added to refs/heads/master by this push: new b5781a1 Enable Pulsar Functions to access entire user config map (#1498) b5781a1 is described below commit b5781a15367f234a4c1c2fe23931a4904f2fe893 Author: Luc Perkins <lucperk...@gmail.com> AuthorDate: Fri Apr 6 11:54:46 2018 -0700 Enable Pulsar Functions to access entire user config map (#1498) * add full user config map fetch capability to pulsar funtions context * add full user config map fetch for Python API * Standardize naming across java and python --- pulsar-client-cpp/python/functions/context.py | 7 ++++++- .../src/main/java/org/apache/pulsar/functions/api/Context.java | 7 +++++++ .../java/org/apache/pulsar/functions/instance/ContextImpl.java | 5 +++++ pulsar-functions/instance/src/main/python/contextimpl.py | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pulsar-client-cpp/python/functions/context.py b/pulsar-client-cpp/python/functions/context.py index 4e1a969..c1f30ed 100644 --- a/pulsar-client-cpp/python/functions/context.py +++ b/pulsar-client-cpp/python/functions/context.py @@ -81,7 +81,12 @@ class Context(object): @abstractmethod def get_user_config_value(self, key): - """Returns the value of the user defined config. If the key doesnt exist return null instead""" + """Returns the value of the user-defined config. If the key doesn't exist, None is returned""" + pass + + @abstractmethod + def get_user_config_map(self): + """Returns the entire user-defined config as a dict (the dict will be empty if no user-defined config is supplied)""" pass @abstractmethod diff --git a/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/Context.java b/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/Context.java index a1abf30..c4d78c2 100644 --- a/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/Context.java +++ b/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/Context.java @@ -21,6 +21,7 @@ package org.apache.pulsar.functions.api; import org.slf4j.Logger; import java.util.Collection; +import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -113,6 +114,12 @@ public interface Context { void incrCounter(String key, long amount); /** + * Get a map of all user-defined key/value configs for the function + * @return The full map of user-defined config values + */ + Map<String, String> getUserConfigMap(); + + /** * Get any user-defined key/value * @param key The key * @return The Optional value specified by the user for that key. diff --git a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java index 02fa616..3db2010 100644 --- a/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java +++ b/pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/ContextImpl.java @@ -185,6 +185,11 @@ class ContextImpl implements Context { } @Override + public Map<String, String> getUserConfigMap() { + return config.getFunctionConfig().getUserConfigMap(); + } + + @Override public void incrCounter(String key, long amount) { if (null != stateContext) { stateContext.incr(key, amount); diff --git a/pulsar-functions/instance/src/main/python/contextimpl.py b/pulsar-functions/instance/src/main/python/contextimpl.py index 9c77fd1..f950abf 100644 --- a/pulsar-functions/instance/src/main/python/contextimpl.py +++ b/pulsar-functions/instance/src/main/python/contextimpl.py @@ -92,6 +92,9 @@ class ContextImpl(pulsar.Context): return str(self.instance_config.function_config.userConfig[key]) else: return None + + def get_user_config_map(self): + return self.instance_config.function_config.userConfig def record_metric(self, metric_name, metric_value): if not metric_name in self.accumulated_metrics: -- To stop receiving notification emails like this one, please contact mme...@apache.org.