merlimat closed pull request #1498: Enable Pulsar Functions to access entire 
user config map
URL: https://github.com/apache/incubator-pulsar/pull/1498
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-client-cpp/python/functions/context.py 
b/pulsar-client-cpp/python/functions/context.py
index 4e1a969547..c1f30edc94 100644
--- a/pulsar-client-cpp/python/functions/context.py
+++ b/pulsar-client-cpp/python/functions/context.py
@@ -81,7 +81,12 @@ def get_logger(self):
 
   @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 a1abf30d8f..c4d78c2ade 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 @@
 import org.slf4j.Logger;
 
 import java.util.Collection;
+import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 
@@ -112,6 +113,12 @@
      */
     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
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 02fa616a78..3db2010260 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
@@ -184,6 +184,11 @@ public String getUserConfigValueOrDefault(String key, 
String defaultValue) {
         return getUserConfigValue(key).orElse(defaultValue);
     }
 
+    @Override
+    public Map<String, String> getUserConfigMap() {
+        return config.getFunctionConfig().getUserConfigMap();
+    }
+
     @Override
     public void incrCounter(String key, long amount) {
         if (null != stateContext) {
diff --git a/pulsar-functions/instance/src/main/python/contextimpl.py 
b/pulsar-functions/instance/src/main/python/contextimpl.py
index 9c77fd1c39..f950abf964 100644
--- a/pulsar-functions/instance/src/main/python/contextimpl.py
+++ b/pulsar-functions/instance/src/main/python/contextimpl.py
@@ -92,6 +92,9 @@ def get_user_config_value(self, key):
       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:


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to