Class RuntimeUtils

java.lang.Object
org.apache.pulsar.functions.runtime.RuntimeUtils

public class RuntimeUtils extends Object
Util class for common runtime functionality.
  • Field Details

  • Constructor Details

    • RuntimeUtils

      public RuntimeUtils()
  • Method Details

    • composeCmd

      public static List<String> composeCmd(org.apache.pulsar.functions.instance.InstanceConfig instanceConfig, String instanceFile, String extraDependenciesDir, String logDirectory, String originalCodeFileName, String pulsarServiceUrl, String stateStorageServiceUrl, org.apache.pulsar.functions.instance.AuthenticationConfig authConfig, String shardId, Integer grpcPort, Long expectedHealthCheckInterval, String logConfigFile, String secretsProviderClassName, String secretsProviderConfig, Boolean installUserCodeDependencies, String pythonDependencyRepository, String pythonExtraDependencyRepository, String narExtractionDirectory, String functionInstanceClassPath, String pulsarWebServiceUrl) throws Exception
      Throws:
      Exception
    • getArgsBeforeCmd

      public static List<String> getArgsBeforeCmd(org.apache.pulsar.functions.instance.InstanceConfig instanceConfig, String extraDependenciesDir)
    • getGoInstanceCmd

      public static List<String> getGoInstanceCmd(org.apache.pulsar.functions.instance.InstanceConfig instanceConfig, String originalCodeFileName, String pulsarServiceUrl, boolean k8sRuntime) throws IOException
      Different from python and java function, Go function uploads a complete executable file(including: instance file + user code file). Its parameter list is provided to the broker in the form of a yaml file, the advantage of this approach is that backward compatibility is guaranteed. In Java and Python the instance is managed by broker (or function worker) so the changes in command line is under control; but in Go the instance is compiled with the user function, so pulsar doesn't have the control what instance is used in the function. Hence in order to support BC for go function, we can't dynamically add more commandline arguments. Using an instance config to pass the parameters from function worker to go instance is the best way for maintaining the BC.

      When we run the go function, we only need to specify the location of the go-function file and the yaml file. The content of the yaml file will be automatically generated according to the content provided by instanceConfig.

      Throws:
      IOException
    • getCmd

      public static List<String> getCmd(org.apache.pulsar.functions.instance.InstanceConfig instanceConfig, String instanceFile, String extraDependenciesDir, String logDirectory, String originalCodeFileName, String pulsarServiceUrl, String stateStorageServiceUrl, org.apache.pulsar.functions.instance.AuthenticationConfig authConfig, String shardId, Integer grpcPort, Long expectedHealthCheckInterval, String logConfigFile, String secretsProviderClassName, String secretsProviderConfig, Boolean installUserCodeDependencies, String pythonDependencyRepository, String pythonExtraDependencyRepository, String narExtractionDirectory, String functionInstanceClassPath, boolean k8sRuntime, String pulsarWebServiceUrl) throws Exception
      Throws:
      Exception
    • genFunctionLogFolder

      public static String genFunctionLogFolder(String logDirectory, org.apache.pulsar.functions.instance.InstanceConfig instanceConfig)
    • getPrometheusMetrics

      public static String getPrometheusMetrics(int metricsPort) throws IOException
      Throws:
      IOException
    • splitRuntimeArgs

      public static String[] splitRuntimeArgs(String input)
      Regex for splitting a string using space when not surrounded by single or double quotes
    • getRuntimeFunctionConfig

      public static <T> T getRuntimeFunctionConfig(Map<String,Object> configMap, Class<T> functionRuntimeConfigClass)
    • registerDefaultCollectors

      public static void registerDefaultCollectors(org.apache.pulsar.functions.instance.stats.FunctionCollectorRegistry registry)