Gladier Base Client
- class gladier.client.GladierBaseClient(auto_registration: bool = True, login_manager: BaseLoginManager | None = None, flows_manager: FlowsManager | None = None, compute_manager: ComputeManager | None = None)
Bases:
object
The Gladier Client ties together commonly used compute functions and basic flows with auto-registration tools to make complex tasks easy to automate.
This class is intended to be subclassed as follows:
@generate_flow_definition class MyGladierClient(GladierBaseClient): gladier_tools = [MyTool]
And used like the following:
my_gc = MyGladierClient() flow = my_gc.run_flow(flow_input={"flow_input": {"my_field": "foo"}}) run_id = flow["run_id"] my_gc.progress(run_id) pprint(tar_and_transfer.get_status(run_id))
The following class variables can be set on clients to change their behavior when deploying and running flows.
- glaider_tools (default: [])
A list of Gladier Tools to build a working flow_defitinion. Each tool’s minimum input must be satisfied prior to running the flow. Can be used with the @generate_flow_definition decorator to automatically chain together flow definitions present on each tool in linear order.
- flow_definition (default: {})
An explicit flow definition to use for this client. Cannot be used with @generate_flow_definition. Changes are tracked on each run, and will result in a flow re-deploy on any change.
- flow_schema (default: {})
A flow schema to accompany the flow definition. Schema is checked on each run and are re-deployed if it changes. Overrides any existing schema set on a given flow_manager instance unless unset.
- subscription_id (default: None)
A subscription ID to associate with a flow. This typically is automatically determined and does not need to be supplied, but may be required if the user has more than one subscription
- secret_config_filename (default:
~/.gladier-secrets.cfg
) Storage are for Globus Tokens and general storage
- secret_config_filename (default:
- app_name (default: ‘Gladier Client’)
The app name used during a login flow
- client_id
The Globus Client ID used for native logins
- globus_group (default: None)
A Globus Group to be applied to all flow/run permissions. Group will automatically be added to flow_viewers, flow_starters, flow_administrators, run_managers, run_monitors
- alias_class (default: gladier.utils.tool_alias.StateSuffixVariablePrefix)
The default class used to for applying aliases to Tools
The following Environment variables can be set and are recognized by Gladier Clients:
- GLADIER_CLIENT_ID – Used only for setting confidential client credentials instead of user
credentials. This is a convenience feature, as an alternative to using a custom login_manager
GLADIER_CLIENT_SECRET – Secret used for confidential clients, using with GLADIER_CLIENT_ID
Default options are intended for CLI usage and maximum user convenience.
- Parameters:
auto_registration – Automatically register functions or flows if they are not previously registered or obsolete.
login_manager – Class defining login behavior. Defaults to AutoLoginManager, and will auto-login when additional scopes are needed.
flows_manager – A flows manager class with customized behavior. Attrs like group and login_manager will automatically be set if None
compute_manager – A compute manager class with customized behavior. EXPERIMENTAL. Will likely change in the future!
- Raises:
gladier.exc.AuthException – if authorizers given are insufficient
- login()
Call
login()
on the configured login manager. Attepmts to prepare the user to run flows, but may require being called twice if a flow is not yet deployed. Automatically called internally byrun_flow()
if required.
- logout()
Call
logout()
on the login manager, to revoke saved tokens and deactivate the current flow. The flow_id and function ids/checksums are unaffected, and can be re-used after another invocation oflogin()
.
- run_flow(flow_input=None, use_defaults=True, **flow_kwargs)
Start a Globus Automate flow. By default, the flow definiton is checked and synced if it has changed locally or deployed if it does not exist.
If a group is set, run permissions are updated and applied to the run (includes ‘run_managers’, ‘run_monitors’).
Any scope changes required post-deployment/update are propogated through the login_manager and may require an additional login. A new flow checksum/id may be tracked in storage if the flow changed or was newly deployed.
The run_flow method shadows the globus-automate-client method for running flows documented here: https://globus-automate-client.readthedocs.io/en/latest/python_sdk_reference.html#globus_automate_client.flows_client.FlowsClient.run_flow # noqa Additional arguments matching the method signature may be added. Common ones include the following:
label (Optional[str]) An optional label which can be used to identify this run
tags (Optional[List[str]]) Tags that will be associated with this Run.
Example:
myinput = { "input": { "args": "cat /proc/version", "capture_output": True, "compute_endpoint": "4b116d3c-1703-4f8f-9f6f-39921e5864df", } } my_client.run_flow(myinput, label='Check Version', tags=['version', 'POSIX'])
- Parameters:
flow_input – A dict of input to be passed to the automate flow. self.check_input() is called on each tool to ensure basic needs are met for each. Input MUST be wrapped inside an ‘input’ dict, for example {‘input’: {‘foo’: ‘bar’}}.
use_defaults – Use the result of self.get_input() to populate base input for the flow. All conflicting input provided by flow_input overrides values set in use_defaults.
**flow_kwargs – Set several keyed arguments that include the label to be used in the automate app. If no label is passed the standard automate label is used. Also ensure label <= 64 chars long.
- Raise:
gladier.exc.ConfigException by self.check_input()
- Raises:
gladier.exc.FlowObsolete
- Raises:
gladier.exc.NoFlowRegistered
- Raises:
gladier.exc.RegistrationException
- Raises:
gladier.exc.FunctionObsolete
- Raises:
gladier.exc.AuthException
- Raises:
Any globus_sdk.exc.BaseException
- get_flow_id() str | None
Get the flow id from the Flows Manager.
- get_input() dict
Get compute function ids, compute endpoints, and each tool’s default input. Default input may not be enough to run the flow. For example if a tool does processing on a local filesystem, the file will always need to be provided by the user when calling run_flow().
Defaults rely on GladierBaseTool.flow_input defined separately for each tool.
- Returns:
input for a flow wrapped in an ‘input’ dict. For example: {‘input’: {‘foo’: ‘bar’}}
- get_status(action_id: str)
Get the current status of the automate flow. Attempts to do additional work on compute functions to deserialize any exception output.
- Parameters:
action_id – The globus action UUID used for this flow. The Automate flow id is always the flow_id configured for this tool.
- Raises:
Globus Automate exceptions from self.flows_client.flow_action_status
- Returns:
a Globus Automate status object (with varying state structures)
- progress(action_id, callback=None, delay=2)
Continuously call self.get_status() until the flow completes. Each status response is used as a parameter to the provided callback, by default will use the builtin callback to print the current state to stdout.
- Parameters:
action_id – The action id for a running flow. The flow is automatically pulled based on the current tool’s flow_definition.
callback – The function to call with the result from self.get_status. Must take a single parameter: mycallback(self.get_status())