Agent Service

Agent Service provides HTTP interface to interact with all agent machines uniquely located using agent prefix. APIs to spawn components takes agent prefix as parameter. Agent prefix is used to locate agent machine using Location Service.

Agent Service provides APIs to spawn Sequence Manager, Sequence Components and to kill spawned components.

Creation of Agent Service

Pre-requisite

In order to use agent service APIs

  1. Agent machines should be up and running.
  2. Locations of agent machines should be registered in Location Service.
  3. Authorization token with correct access role. Documentation on how to fetch authorization token could be found here.

To create Agent Service client

Typescript
sourceconst tokenFactory = () => auth.token

const agentService: AgentService = await AgentService({ tokenFactory })
Async-Await

Note that the examples are using async/await which makes handling of promises more readable.

Usages of Agent Service

Type definitions for all Agent Service methods can be found here

Spawning a Sequence Manager

Agent Service requires agent (a component of type :Machine) to be able to process requests. Once it locates an agent using Location Service with the help of agent prefix, it sends a spawn Sequence Manager command to the agent machine. The corresponding API call fails if the Sequence Manager is already running, or the underlying agent fails to spawn it.

Type definitions for spawnSequenceManager can be found here

Typescript
sourceconst agentPrefix = new Prefix('ESW', 'agent1')
const obsModeConfigPath = '/obs-mode.conf'
const sequenceManagerVersion = '1.0.0'

const spawnResponse1: SpawnResponse = await agentService.spawnSequenceManager(
  agentPrefix,
  obsModeConfigPath,
  false,
  sequenceManagerVersion
)

Spawning a Sequence Component

Similar to spawning a Sequence Manager, Agent Service locates an agent and then it sends a spawn Sequence Component command to the agent machine. The corresponding API call fails if the Sequence Component is already running, or the underlying agent fails to spawn it.

Type definitions for spawnSequenceComponent can be found here

Typescript
sourceconst ocsAppVersion = '1.2.1'
const spawnResponse2: SpawnResponse = await agentService.spawnSequenceComponent(
  agentPrefix,
  'component1',
  ocsAppVersion
)

Kill a Sequence Component

Agent service kills any process running on the agent machine using the process id (pid) of that component. it uses location service to find the process id from the metadata field of location information.

Type definitions for killComponent can be found here

Typescript
sourceconst compPrefix = new Prefix('ESW', 'SomeComponent')
const componentToBeKilled = new ComponentId(compPrefix, 'Service')
const killResponse: KillResponse = await agentService.killComponent(componentToBeKilled)

Getting Agent Status

To get Agent Status for a running Agent, AgentService provides getAgentStatus method. This method allows showing status of TMT ecosystem components (agents, sequence components and sequencers). It returns all agents that are up and running, sequence components running on those agents and sequencer script loaded on sequence component.

Type definitions of getAgentStatus method can be found here

The following example shows how to call getAgentStatus method:

Typescript
sourceconst agentStatus: AgentStatusResponse = await agentService.getAgentStatus()