Skip to content

Commit 868e6d1

Browse files
authored
Move workbench docs (#550)
* Move workbench docs * Use imagesdir to set images folder
1 parent 31737cf commit 868e6d1

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

docs/images/flow_chart.png

25 KB
Loading

docs/operators.adoc

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
ifndef::imagesdir[:imagesdir: ./images]
2+
3+
= Trento Agent Operators
4+
5+
An `+operator+` is a unit of code that can perform write operations on target machines.
6+
7+
Each operator knows how to execute actions and how to roll them back in
8+
case of failure.
9+
10+
== Operator
11+
12+
image::flow_chart.png[flowchart]
13+
14+
An operator is a unit of code that can perform write operations on
15+
target machines. +
16+
A write operation can either fail or succeed. If it succeeds, the
17+
operation displays a diff highlighting the changes before and after the
18+
commit phase.
19+
20+
The operator accepts arguments to specify how to perform the operations.
21+
The arguments are in the form of a `+map[string]any+`, and each operator
22+
knows how to extract and validate them. +
23+
It follows a transactional approach, where each operation has distinct
24+
stages:
25+
26+
* PLAN +
27+
* COMMIT +
28+
* VERIFY +
29+
* ROLLBACK
30+
31+
The documentation for each of the operators can be found in the
32+
operators go source.
33+
34+
=== PLAN
35+
36+
The goal of the PLAN stage is to collect information about the
37+
operations and verify prerequisites. +
38+
This is also the phase where information for diffing is gathered by
39+
collecting the `+before+` state.
40+
41+
Additionally, during this phase, it is important to ensure that any
42+
resources modified during the COMMIT phase are backed up. This allows
43+
restoration during the ROLLBACK phase or manual recovery by system
44+
administrators if the rollback fails.
45+
46+
If an error occurs during the PLAN phase, no rollback is needed; the
47+
operation is simply aborted with the plan error.
48+
49+
=== COMMIT
50+
51+
The COMMIT phase executes the actual write operations on the system,
52+
utilizing the information collected during the PLAN phase. +
53+
If an error occurs during this phase, a rollback is triggered.
54+
55+
The COMMIT phase should be idempotent. If a requested change has already
56+
been applied, the commit operation is simply skipped without returning
57+
an error. +
58+
Idempotency should be implemented appropriately based on the type of
59+
operations to be performed.
60+
61+
=== VERIFY
62+
63+
The VERIFY phase ensures that the actions applied during the COMMIT
64+
phase have produced the expected results on the system. +
65+
If an error occurs during this phase, the rollback process is initiated.
66+
67+
This phase is also when the `+after+` state is recorded for the diff,
68+
highlighting changes made during the commit phase.
69+
70+
=== ROLLBACK
71+
72+
The ROLLBACK phase must implement mechanisms to revert any changes made
73+
during the COMMIT phase. +
74+
It can use information collected during the PLAN phase to restore the
75+
system to its previous state. +
76+
The rollback implementation may vary depending on the type of operation
77+
performed during the COMMIT phase. +
78+
Be sure to provide clear error messages and log actions appropriately.
79+
80+
If the rollback fails, the error is returned without further action.
81+
82+
== Executor
83+
84+
The Executor is a wrapper around an operator. The operator implements
85+
the phase interface and must be wrapped in an Executor.
86+
87+
The Executor manages operations transactionally. +
88+
For library users, the Executor is transparent—using an Operator means
89+
it is already wrapped within an Executor.
90+
91+
== Registry
92+
93+
The Registry holds all available operators. Each operator has a version.
94+
By default, if no version is specified when requesting an operator, the
95+
latest version is fetched from the Registry.
96+
97+
To use an operator, it must be fetched using the `+GetOperatorBuilder+`
98+
function, providing the operator name as an argument.
99+
100+
[source,go]
101+
----
102+
builder, err := registry.GetOperatorBuilder(operatorName)
103+
op := builder("test-cli", opArgs)
104+
report := op.Run(ctx)
105+
// the report contains the success or the error of the execution
106+
----
107+
108+
The operator name follows this format: `+<operatorname>@<version>+`.
109+
110+
The Registry returns an Operator Builder:
111+
112+
[source,go]
113+
----
114+
type OperatorBuilder func(operationID string, arguments OperatorArguments) Operator
115+
----
116+
117+
The `+operationID+` is a unique identifier for the operation, and
118+
`+arguments+` are modeled as `+map[string]any+`.
119+
120+
== CLI
121+
122+
The operators execution is also exposed as a `+CLI+`. The functionality is
123+
hidden as it is intended only for testing and development purposes.
124+
125+
=== Usage
126+
127+
....
128+
Run operator
129+
130+
Usage:
131+
trento-agent operator run [flags]
132+
133+
Flags:
134+
-a, --arguments string The used operator arguments
135+
-h, --help help for run
136+
-o, --operator string The operator to use
137+
138+
....
139+
140+
The CLI accepts the name of an operator as an argument, following the
141+
same convention `+<operatorname>@<version>+`, and requires the `+-a+`
142+
option to pass the arguments.
143+
144+
The arguments must be provided as a JSON string.
145+
146+
=== Example
147+
148+
[source,bash]
149+
----
150+
sudo ./trento-agent operator run -o saptuneapplysolution -a '{"solution": "HANA"}'
151+
----
152+
153+
Using `+sudo+` may be necessary depending on the type of operator being
154+
executed. +
155+
In this example, the `+saptuneapplysolution+` operator is called with
156+
the argument `+solution+` set to `+HANA+`.
157+
158+
The CLI will perform the operations, log any errors, and finally display
159+
the diff when the execution succeeds.

0 commit comments

Comments
 (0)