Class KubernetesRuntime

  • All Implemented Interfaces:
    Runtime

    public class KubernetesRuntime
    extends java.lang.Object
    implements Runtime
    Kubernetes based runtime for running functions. This runtime provides the usual methods to start/stop/getfunctionstatus interfaces to control the kubernetes job running function. We first create a headless service and then a statefulset for starting function pods Each function instance runs as a pod itself. The reason using statefulset as opposed to a regular deployment is that functions require a unique instance_id for each instance. The service abstraction is used for getting functionstatus.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern VALID_POD_NAME_REGEX  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String createJobName​(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails, java.lang.String jobName)  
      void deleteService()  
      void deleteStatefulSet()  
      static void doChecks​(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails, java.lang.String overridenJobName)  
      java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.MetricsData> getAndResetMetrics()  
      java.lang.Throwable getDeathException()  
      protected java.util.List<java.lang.String> getExecutorCommand()  
      java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus> getFunctionStatus​(int instanceId)  
      java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.MetricsData> getMetrics​(int instanceId)  
      java.lang.String getPrometheusMetrics()  
      boolean isAlive()  
      void join()  
      void reinitialize()  
      java.util.concurrent.CompletableFuture<java.lang.Void> resetMetrics()  
      void start()
      The core logic that creates a service first followed by statefulset.
      void stop()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.apache.pulsar.functions.runtime.Runtime

        terminate
    • Field Detail

      • VALID_POD_NAME_REGEX

        public static final java.util.regex.Pattern VALID_POD_NAME_REGEX
    • Method Detail

      • start

        public void start()
                   throws java.lang.Exception
        The core logic that creates a service first followed by statefulset.
        Specified by:
        start in interface Runtime
        Throws:
        java.lang.Exception
      • join

        public void join()
                  throws java.lang.Exception
        Specified by:
        join in interface Runtime
        Throws:
        java.lang.Exception
      • stop

        public void stop()
                  throws java.lang.Exception
        Specified by:
        stop in interface Runtime
        Throws:
        java.lang.Exception
      • getDeathException

        public java.lang.Throwable getDeathException()
        Specified by:
        getDeathException in interface Runtime
      • getFunctionStatus

        public java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.FunctionStatus> getFunctionStatus​(int instanceId)
        Specified by:
        getFunctionStatus in interface Runtime
      • getAndResetMetrics

        public java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.MetricsData> getAndResetMetrics()
        Specified by:
        getAndResetMetrics in interface Runtime
      • resetMetrics

        public java.util.concurrent.CompletableFuture<java.lang.Void> resetMetrics()
        Specified by:
        resetMetrics in interface Runtime
      • getMetrics

        public java.util.concurrent.CompletableFuture<org.apache.pulsar.functions.proto.InstanceCommunication.MetricsData> getMetrics​(int instanceId)
        Specified by:
        getMetrics in interface Runtime
      • getPrometheusMetrics

        public java.lang.String getPrometheusMetrics()
                                              throws java.io.IOException
        Specified by:
        getPrometheusMetrics in interface Runtime
        Throws:
        java.io.IOException
      • isAlive

        public boolean isAlive()
        Specified by:
        isAlive in interface Runtime
      • deleteStatefulSet

        public void deleteStatefulSet()
                               throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • deleteService

        public void deleteService()
                           throws java.lang.InterruptedException
        Throws:
        java.lang.InterruptedException
      • getExecutorCommand

        protected java.util.List<java.lang.String> getExecutorCommand()
      • createJobName

        public static java.lang.String createJobName​(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails,
                                                     java.lang.String jobName)
      • doChecks

        public static void doChecks​(org.apache.pulsar.functions.proto.Function.FunctionDetails functionDetails,
                                    java.lang.String overridenJobName)