Skip to main content

UniversalExtension Class (1.5.0)

Classes

class RequestType

Enum representing the type of work the Extension worker process will be performing.

The value will be one of:

  • EXTENSION_START
  • DYNAMIC_CHOICE
  • DYNAMIC_COMMAND

class UniversalExtension

Base class for Stonebranch Universal Extension module implementations

Class variables

ExtensionConfig

A namedtuple that, as of API version 1.5.0, accepts an optional meter_provider and tracer_provider which will be used to initialize the Opentelemetry framework.

The value of meter_provider can either be None or an instance of MeterProvider provided by the Opentelemetry library. Similarly, for the tracer_provider, the value must either be None or an instance of TracerProvider. The default arguments for both meter_provider and tracer_provider is None.

Examples
>>> ec1 = ExtensionConfig()
>>> ec2 = ExtensionConfig(
... meter_provider=MeterProvider(
... resource=Resource.create({"attr1": "value1"})
... )
... )

Instance variables

uip

can be used to access the following properties of an Extension task instance:

  • task_variables : dict
  • is_triggered : bool
  • trigger_id : str
  • instance_id : str
  • monitor_id : str

Starting with API version 1.5.0, uip will also contain a property called request_type that will be one of:

  • RequestType.EXTENSION_START
  • RequestType.DYNAMIC_CHOICE
  • RequestType.DYNAMIC_COMMAND

If the request type is a dynamic choice, there will be an additional property called choice_field_name in uip. Similarly, for dynamic command, the dynamic_command_name property will be defined.

Examples
>>> ops_task_id = self.uip.task_variables['ops_task_id']
>>> is_triggered = self.uip.is_triggered
>>> trigger_id = self.uip.trigger_id
>>> instance_id = self.uip.instance_id
>>> monitor_id = self.uip.monitor_id

Class methods

extension_new(fields)

Optional class method which, if implemented, will be run before the Extension() class is initialized.

info

The cls class instance will have the uip context when this method is called.

Parameters

fields : dict

Depending on the type of work (i.e. extension_start, dynamic_choice_command, or dynamic_command) that will be executed, the dictionary will be populated with the appropriate field values from the selected in the Controller.

Returns

ExtensionConfig

An instance of ExtensionConfig

Instance Methods

extension_start(self, fields)

Serves as the starting point for work that will be performed for a task instance. It must be implemented in the derived class.

Parameters

fields : dict

populated with field values from the associated task instance launched in the Controller

Returns

ExtensionResult

once the work is done, an instance of ExtensionResult must be returned. See the ExtensionResult documentation for a full list of parameters that can be passed to the class constructor

extension_cancel(self)

Optional method that allows the Extension to do any cleanup work before terminating. To use it, implement in the derived class.

Parameters

None

Returns

None

update_extension_status(self, fields)

Propagate state changes back to the associated extension instance in the Controller.

  • Can be called at any time by an Extension instance.
  • Any/all output fields defined in the associated Extension Template can be updated using this method.
Parameters

fields : dict

The fields parameter expects a dictionary of output fields to be sent back to the controller for the associated Extension instance. Field names are implementation dependent and correlate with the Universal Template field names in the Controller's Template definition for the associated task.

Returns

None

Examples
>>> fields = {"foo": "bar"}
>>> self.update_extension_status(fields)