pulsar.functions.context

context.py: Context defines context information available during

processing of a request.

View Source
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

# -*- encoding: utf-8 -*-

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
"""context.py: Context defines context information available during
# processing of a request.
"""
from abc import abstractmethod

class Context(object):
  """Interface defining information available at process time"""
  @abstractmethod
  def get_message_id(self):
    """Return the messageid of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_key(self):
    """Return the key of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_eventtime(self):
    """Return the event time of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_properties(self):
    """Return the message properties kv map of the current message that we are processing"""
    pass

  @abstractmethod
  def get_current_message_topic_name(self):
    """Returns the topic name of the message that we are processing"""
    pass
  
  @abstractmethod
  def get_function_tenant(self):
    """Returns the tenant of the message that's being processed"""
    pass

  @abstractmethod
  def get_function_namespace(self):
    """Returns the namespace of the message that's being processed"""

  @abstractmethod
  def get_function_name(self):
    """Returns the function name that we are a part of"""
    pass

  @abstractmethod
  def get_function_id(self):
    """Returns the function id that we are a part of"""
    pass

  @abstractmethod
  def get_instance_id(self):
    """Returns the instance id that is executing the function"""
    pass

  @abstractmethod
  def get_function_version(self):
    """Returns the version of function that we are executing"""
    pass

  @abstractmethod
  def get_logger(self):
    """Returns the logger object that can be used to do logging"""
    pass

  @abstractmethod
  def get_user_config_value(self, key):
    """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
  def get_secret(self, secret_name):
    """Returns the secret value associated with the name. None if nothing was found"""
    pass

  @abstractmethod
  def get_partition_key(self):
    """Returns partition key of the input message is one exists"""
    pass


  @abstractmethod
  def record_metric(self, metric_name, metric_value):
    """Records the metric_value. metric_value has to satisfy isinstance(metric_value, numbers.Number)"""
    pass

  @abstractmethod
  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe", properties=None, compression_type=None, callback=None, message_conf=None):
    """Publishes message to topic_name by first serializing the message using serde_class_name serde
    The message will have properties specified if any

    The available options for message_conf:

      properties,
      partition_key,
      sequence_id,
      replication_clusters,
      disable_replication,
      event_timestamp

    """
    pass

  @abstractmethod
  def get_input_topics(self):
    """Returns the input topics of function"""
    pass

  @abstractmethod
  def get_output_topic(self):
    """Returns the output topic of function"""
    pass

  @abstractmethod
  def get_output_serde_class_name(self):
    """return output Serde class"""
    pass

  @abstractmethod
  def ack(self, msgid, topic):
    """ack this message id"""
    pass

  @abstractmethod
  def incr_counter(self, key, amount):
    """incr the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def get_counter(self, key):
    """get the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def del_counter(self, key):
    """delete the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def put_state(self, key, value):
    """update the value of a given key in the managed state"""
    pass

  @abstractmethod
  def get_state(self, key):
    """get the value of a given key in the managed state"""
    pass
#   class Context:
View Source
class Context(object):
  """Interface defining information available at process time"""
  @abstractmethod
  def get_message_id(self):
    """Return the messageid of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_key(self):
    """Return the key of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_eventtime(self):
    """Return the event time of the current message that we are processing"""
    pass

  @abstractmethod
  def get_message_properties(self):
    """Return the message properties kv map of the current message that we are processing"""
    pass

  @abstractmethod
  def get_current_message_topic_name(self):
    """Returns the topic name of the message that we are processing"""
    pass
  
  @abstractmethod
  def get_function_tenant(self):
    """Returns the tenant of the message that's being processed"""
    pass

  @abstractmethod
  def get_function_namespace(self):
    """Returns the namespace of the message that's being processed"""

  @abstractmethod
  def get_function_name(self):
    """Returns the function name that we are a part of"""
    pass

  @abstractmethod
  def get_function_id(self):
    """Returns the function id that we are a part of"""
    pass

  @abstractmethod
  def get_instance_id(self):
    """Returns the instance id that is executing the function"""
    pass

  @abstractmethod
  def get_function_version(self):
    """Returns the version of function that we are executing"""
    pass

  @abstractmethod
  def get_logger(self):
    """Returns the logger object that can be used to do logging"""
    pass

  @abstractmethod
  def get_user_config_value(self, key):
    """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
  def get_secret(self, secret_name):
    """Returns the secret value associated with the name. None if nothing was found"""
    pass

  @abstractmethod
  def get_partition_key(self):
    """Returns partition key of the input message is one exists"""
    pass


  @abstractmethod
  def record_metric(self, metric_name, metric_value):
    """Records the metric_value. metric_value has to satisfy isinstance(metric_value, numbers.Number)"""
    pass

  @abstractmethod
  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe", properties=None, compression_type=None, callback=None, message_conf=None):
    """Publishes message to topic_name by first serializing the message using serde_class_name serde
    The message will have properties specified if any

    The available options for message_conf:

      properties,
      partition_key,
      sequence_id,
      replication_clusters,
      disable_replication,
      event_timestamp

    """
    pass

  @abstractmethod
  def get_input_topics(self):
    """Returns the input topics of function"""
    pass

  @abstractmethod
  def get_output_topic(self):
    """Returns the output topic of function"""
    pass

  @abstractmethod
  def get_output_serde_class_name(self):
    """return output Serde class"""
    pass

  @abstractmethod
  def ack(self, msgid, topic):
    """ack this message id"""
    pass

  @abstractmethod
  def incr_counter(self, key, amount):
    """incr the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def get_counter(self, key):
    """get the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def del_counter(self, key):
    """delete the counter of a given key in the managed state"""
    pass

  @abstractmethod
  def put_state(self, key, value):
    """update the value of a given key in the managed state"""
    pass

  @abstractmethod
  def get_state(self, key):
    """get the value of a given key in the managed state"""
    pass

Interface defining information available at process time

#   Context()
#  
@abstractmethod
def get_message_id(self):
View Source
  @abstractmethod
  def get_message_id(self):
    """Return the messageid of the current message that we are processing"""
    pass

Return the messageid of the current message that we are processing

#  
@abstractmethod
def get_message_key(self):
View Source
  @abstractmethod
  def get_message_key(self):
    """Return the key of the current message that we are processing"""
    pass

Return the key of the current message that we are processing

#  
@abstractmethod
def get_message_eventtime(self):
View Source
  @abstractmethod
  def get_message_eventtime(self):
    """Return the event time of the current message that we are processing"""
    pass

Return the event time of the current message that we are processing

#  
@abstractmethod
def get_message_properties(self):
View Source
  @abstractmethod
  def get_message_properties(self):
    """Return the message properties kv map of the current message that we are processing"""
    pass

Return the message properties kv map of the current message that we are processing

#  
@abstractmethod
def get_current_message_topic_name(self):
View Source
  @abstractmethod
  def get_current_message_topic_name(self):
    """Returns the topic name of the message that we are processing"""
    pass

Returns the topic name of the message that we are processing

#  
@abstractmethod
def get_function_tenant(self):
View Source
  @abstractmethod
  def get_function_tenant(self):
    """Returns the tenant of the message that's being processed"""
    pass

Returns the tenant of the message that's being processed

#  
@abstractmethod
def get_function_namespace(self):
View Source
  @abstractmethod
  def get_function_namespace(self):
    """Returns the namespace of the message that's being processed"""

Returns the namespace of the message that's being processed

#  
@abstractmethod
def get_function_name(self):
View Source
  @abstractmethod
  def get_function_name(self):
    """Returns the function name that we are a part of"""
    pass

Returns the function name that we are a part of

#  
@abstractmethod
def get_function_id(self):
View Source
  @abstractmethod
  def get_function_id(self):
    """Returns the function id that we are a part of"""
    pass

Returns the function id that we are a part of

#  
@abstractmethod
def get_instance_id(self):
View Source
  @abstractmethod
  def get_instance_id(self):
    """Returns the instance id that is executing the function"""
    pass

Returns the instance id that is executing the function

#  
@abstractmethod
def get_function_version(self):
View Source
  @abstractmethod
  def get_function_version(self):
    """Returns the version of function that we are executing"""
    pass

Returns the version of function that we are executing

#  
@abstractmethod
def get_logger(self):
View Source
  @abstractmethod
  def get_logger(self):
    """Returns the logger object that can be used to do logging"""
    pass

Returns the logger object that can be used to do logging

#  
@abstractmethod
def get_user_config_value(self, key):
View Source
  @abstractmethod
  def get_user_config_value(self, key):
    """Returns the value of the user-defined config. If the key doesn't exist, None is returned"""
    pass

Returns the value of the user-defined config. If the key doesn't exist, None is returned

#  
@abstractmethod
def get_user_config_map(self):
View Source
  @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

Returns the entire user-defined config as a dict (the dict will be empty if no user-defined config is supplied)

#  
@abstractmethod
def get_secret(self, secret_name):
View Source
  @abstractmethod
  def get_secret(self, secret_name):
    """Returns the secret value associated with the name. None if nothing was found"""
    pass

Returns the secret value associated with the name. None if nothing was found

#  
@abstractmethod
def get_partition_key(self):
View Source
  @abstractmethod
  def get_partition_key(self):
    """Returns partition key of the input message is one exists"""
    pass

Returns partition key of the input message is one exists

#  
@abstractmethod
def record_metric(self, metric_name, metric_value):
View Source
  @abstractmethod
  def record_metric(self, metric_name, metric_value):
    """Records the metric_value. metric_value has to satisfy isinstance(metric_value, numbers.Number)"""
    pass

Records the metric_value. metric_value has to satisfy isinstance(metric_value, numbers.Number)

#  
@abstractmethod
def publish( self, topic_name, message, serde_class_name='serde.IdentitySerDe', properties=None, compression_type=None, callback=None, message_conf=None ):
View Source
  @abstractmethod
  def publish(self, topic_name, message, serde_class_name="serde.IdentitySerDe", properties=None, compression_type=None, callback=None, message_conf=None):
    """Publishes message to topic_name by first serializing the message using serde_class_name serde
    The message will have properties specified if any

    The available options for message_conf:

      properties,
      partition_key,
      sequence_id,
      replication_clusters,
      disable_replication,
      event_timestamp

    """
    pass

Publishes message to topic_name by first serializing the message using serde_class_name serde The message will have properties specified if any

The available options for message_conf:

properties, partition_key, sequence_id, replication_clusters, disable_replication, event_timestamp

#  
@abstractmethod
def get_input_topics(self):
View Source
  @abstractmethod
  def get_input_topics(self):
    """Returns the input topics of function"""
    pass

Returns the input topics of function

#  
@abstractmethod
def get_output_topic(self):
View Source
  @abstractmethod
  def get_output_topic(self):
    """Returns the output topic of function"""
    pass

Returns the output topic of function

#  
@abstractmethod
def get_output_serde_class_name(self):
View Source
  @abstractmethod
  def get_output_serde_class_name(self):
    """return output Serde class"""
    pass

return output Serde class

#  
@abstractmethod
def ack(self, msgid, topic):
View Source
  @abstractmethod
  def ack(self, msgid, topic):
    """ack this message id"""
    pass

ack this message id

#  
@abstractmethod
def incr_counter(self, key, amount):
View Source
  @abstractmethod
  def incr_counter(self, key, amount):
    """incr the counter of a given key in the managed state"""
    pass

incr the counter of a given key in the managed state

#  
@abstractmethod
def get_counter(self, key):
View Source
  @abstractmethod
  def get_counter(self, key):
    """get the counter of a given key in the managed state"""
    pass

get the counter of a given key in the managed state

#  
@abstractmethod
def del_counter(self, key):
View Source
  @abstractmethod
  def del_counter(self, key):
    """delete the counter of a given key in the managed state"""
    pass

delete the counter of a given key in the managed state

#  
@abstractmethod
def put_state(self, key, value):
View Source
  @abstractmethod
  def put_state(self, key, value):
    """update the value of a given key in the managed state"""
    pass

update the value of a given key in the managed state

#  
@abstractmethod
def get_state(self, key):
View Source
  @abstractmethod
  def get_state(self, key):
    """get the value of a given key in the managed state"""
    pass

get the value of a given key in the managed state