Class FunctionRuntimeManager

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class FunctionRuntimeManager
    extends java.lang.Object
    implements java.lang.AutoCloseable
    This class managers all aspects of functions assignments and running of function assignments for this worker
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void deleteAssignment​(java.lang.String fullyQualifiedInstanceId)  
      org.apache.pulsar.functions.proto.Function.Assignment findFunctionAssignment​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName, int instanceId)
      Find a assignment of a function
      java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> findFunctionAssignments​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName)
      Find all instance assignments of function
      static java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> findFunctionAssignments​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName, java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​org.apache.pulsar.functions.proto.Function.Assignment>> workerIdToAssignments)  
      java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​org.apache.pulsar.functions.proto.Function.Assignment>> getCurrentAssignments()
      Get current assignments
      org.apache.pulsar.common.policies.data.FunctionInstanceStatsDataImpl getFunctionInstanceStats​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName, int instanceId, java.net.URI uri)
      Get stats of a function instance.
      FunctionRuntimeInfo getFunctionRuntimeInfo​(java.lang.String fullyQualifiedInstanceId)  
      java.util.Map<java.lang.String,​FunctionRuntimeInfo> getFunctionRuntimeInfos()  
      org.apache.pulsar.common.policies.data.FunctionStatsImpl getFunctionStats​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName, java.net.URI uri)
      Get stats of all function instances.
      int getMyInstances()
      Methods for metrics
      org.apache.pulsar.client.api.MessageId initialize()
      Initializes the FunctionRuntimeManager.
      void processAssignment​(org.apache.pulsar.functions.proto.Function.Assignment newAssignment)
      Process an assignment update from the assignment topic
      void processAssignmentMessage​(org.apache.pulsar.client.api.Message<byte[]> msg)  
      void removeAssignments​(java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> assignments)
      Removes a collection of assignments
      void restartFunctionInstance​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName, int instanceId, java.net.URI uri)  
      void restartFunctionInstances​(java.lang.String tenant, java.lang.String namespace, java.lang.String functionName)  
      void stopAllOwnedFunctions()
      It stops all functions instances owned by current worker
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FunctionRuntimeManager

        public FunctionRuntimeManager​(org.apache.pulsar.functions.worker.WorkerConfig workerConfig,
                                      PulsarWorkerService workerService,
                                      org.apache.distributedlog.api.namespace.Namespace dlogNamespace,
                                      MembershipManager membershipManager,
                                      org.apache.pulsar.functions.worker.ConnectorsManager connectorsManager,
                                      FunctionsManager functionsManager,
                                      FunctionMetaDataManager functionMetaDataManager,
                                      WorkerStatsManager workerStatsManager,
                                      ErrorNotifier errorNotifier)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
    • Method Detail

      • initialize

        public org.apache.pulsar.client.api.MessageId initialize()
        Initializes the FunctionRuntimeManager. Does the following: 1. Consume all existing assignments to establish existing/latest set of assignments 2. After current assignments are read, assignments belonging to this worker will be processed
        Returns:
        the message id of the message processed during init phase
      • getCurrentAssignments

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​org.apache.pulsar.functions.proto.Function.Assignment>> getCurrentAssignments()
        Get current assignments
        Returns:
        a map of current assignments in the following format {workerId : {FullyQualifiedInstanceId : Assignment}}
      • findFunctionAssignment

        public org.apache.pulsar.functions.proto.Function.Assignment findFunctionAssignment​(java.lang.String tenant,
                                                                                            java.lang.String namespace,
                                                                                            java.lang.String functionName,
                                                                                            int instanceId)
        Find a assignment of a function
        Parameters:
        tenant - the tenant the function belongs to
        namespace - the namespace the function belongs to
        functionName - the function name
        Returns:
        the assignment of the function
      • findFunctionAssignments

        public java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> findFunctionAssignments​(java.lang.String tenant,
                                                                                                                   java.lang.String namespace,
                                                                                                                   java.lang.String functionName)
        Find all instance assignments of function
        Parameters:
        tenant -
        namespace -
        functionName -
        Returns:
      • findFunctionAssignments

        public static java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> findFunctionAssignments​(java.lang.String tenant,
                                                                                                                          java.lang.String namespace,
                                                                                                                          java.lang.String functionName,
                                                                                                                          java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​org.apache.pulsar.functions.proto.Function.Assignment>> workerIdToAssignments)
      • removeAssignments

        public void removeAssignments​(java.util.Collection<org.apache.pulsar.functions.proto.Function.Assignment> assignments)
        Removes a collection of assignments
        Parameters:
        assignments - assignments to remove
      • restartFunctionInstance

        public void restartFunctionInstance​(java.lang.String tenant,
                                            java.lang.String namespace,
                                            java.lang.String functionName,
                                            int instanceId,
                                            java.net.URI uri)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • restartFunctionInstances

        public void restartFunctionInstances​(java.lang.String tenant,
                                             java.lang.String namespace,
                                             java.lang.String functionName)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • stopAllOwnedFunctions

        public void stopAllOwnedFunctions()
        It stops all functions instances owned by current worker
        Throws:
        java.lang.Exception
      • getFunctionInstanceStats

        public org.apache.pulsar.common.policies.data.FunctionInstanceStatsDataImpl getFunctionInstanceStats​(java.lang.String tenant,
                                                                                                             java.lang.String namespace,
                                                                                                             java.lang.String functionName,
                                                                                                             int instanceId,
                                                                                                             java.net.URI uri)
        Get stats of a function instance. If this worker is not running the function instance.
        Parameters:
        tenant - the tenant the function belongs to
        namespace - the namespace the function belongs to
        functionName - the function name
        instanceId - the function instance id
        Returns:
        jsonObject containing stats for instance
      • getFunctionStats

        public org.apache.pulsar.common.policies.data.FunctionStatsImpl getFunctionStats​(java.lang.String tenant,
                                                                                         java.lang.String namespace,
                                                                                         java.lang.String functionName,
                                                                                         java.net.URI uri)
                                                                                  throws org.apache.pulsar.client.admin.PulsarAdminException
        Get stats of all function instances.
        Parameters:
        tenant - the tenant the function belongs to
        namespace - the namespace the function belongs to
        functionName - the function name
        Returns:
        a list of function statuses
        Throws:
        org.apache.pulsar.client.admin.PulsarAdminException
      • processAssignmentMessage

        public void processAssignmentMessage​(org.apache.pulsar.client.api.Message<byte[]> msg)
      • processAssignment

        public void processAssignment​(org.apache.pulsar.functions.proto.Function.Assignment newAssignment)
        Process an assignment update from the assignment topic
        Parameters:
        newAssignment - the assignment
      • deleteAssignment

        public void deleteAssignment​(java.lang.String fullyQualifiedInstanceId)
      • getFunctionRuntimeInfos

        public java.util.Map<java.lang.String,​FunctionRuntimeInfo> getFunctionRuntimeInfos()
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • getFunctionRuntimeInfo

        public FunctionRuntimeInfo getFunctionRuntimeInfo​(java.lang.String fullyQualifiedInstanceId)
      • getMyInstances

        public int getMyInstances()
        Methods for metrics