1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
pub mod archive;
pub mod archived_workflows;
pub mod cancel;
pub mod create;
pub mod definition;
pub mod delete;
pub mod list;
pub mod properties;
pub mod start;
use archive::{WorkflowArchive, WorkflowArchiveBuilder};
use archived_workflows::{ArchivedWorkflowList, ArchivedWorkflowListBuilder};
use definition::{WorkflowDefinition, WorkflowDefinitionBuilder};
use serde::{Deserialize, Serialize};
use crate::{ClientCore, Result};
use self::cancel::{WorkflowCancel, WorkflowCancelBuilder};
use self::create::{WorkflowCreate, WorkflowCreateBuilder};
use self::delete::WorkflowDeleteBuilder;
use self::list::{WorkflowList, WorkflowListBuilder};
use self::properties::{WorkflowProperties, WorkflowPropertiesBuilder};
use self::start::WorkflowStartBuilder;
/// # Workflows
#[derive(Clone, Debug)]
pub struct WorkflowsClient {
core: ClientCore,
}
impl WorkflowsClient {
pub(crate) fn new(core: ClientCore) -> Self {
WorkflowsClient { core }
}
/// # Examples
///
/// Create a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// # use z_osmf::workflows::WorkflowAccess;
/// let workflow_create = zosmf
/// .workflows()
/// .create(
/// "AutomationExample",
/// "/usr/lpp/zosmf/samples/workflow_sample_automation.xml",
/// "SY1",
/// "zosmfad",
/// )
/// .assign_to_owner(true)
/// .access_type(WorkflowAccess::Restricted)
/// .delete_completed_jobs(true)
/// .auto_delete_on_completion(true)
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn create<N, F, S, O>(
&self,
name: N,
definition_file: F,
system: S,
owner: O,
) -> WorkflowCreateBuilder<WorkflowCreate>
where
N: std::fmt::Display,
F: std::fmt::Display,
S: std::fmt::Display,
O: std::fmt::Display,
{
WorkflowCreateBuilder::new(self.core.clone(), name, definition_file, system, owner)
}
/// # Examples
///
/// Get the properties of a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// let workflow_properties = zosmf
/// .workflows()
/// .properties("26f1fd84-058b-443c-8e06-5ec318ecdb86")
/// .steps()
/// .variables()
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn properties<K>(&self, key: K) -> WorkflowPropertiesBuilder<WorkflowProperties>
where
K: std::fmt::Display,
{
WorkflowPropertiesBuilder::new(self.core.clone(), WorkflowType::Workflows, key)
}
/// # Examples
///
/// List z/OSMF Workflows on a system or sysplex:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// let workflow_list = zosmf
/// .workflows()
/// .list()
/// .name("AutomationExample.*")
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list(&self) -> WorkflowListBuilder<WorkflowList> {
WorkflowListBuilder::new(self.core.clone())
}
/// # Examples
///
/// Start a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// zosmf.workflows()
/// .start("d043b5f1-adab-48e7-b7c3-d41cd95fa4b0")
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn start<K>(&self, key: K) -> WorkflowStartBuilder<()>
where
K: std::fmt::Display,
{
WorkflowStartBuilder::new(self.core.clone(), key)
}
/// # Examples
///
/// Cancel execution of a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// let workflow_cancel = zosmf.workflows()
/// .cancel("d043b5f1-adab-48e7-b7c3-d41cd95fa4b0")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn cancel<K>(&self, key: K) -> Result<WorkflowCancel>
where
K: std::fmt::Display,
{
WorkflowCancelBuilder::new(self.core.clone(), key)
.build()
.await
}
/// # Examples
///
/// Delete a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// zosmf.workflows()
/// .delete("d043b5f1-adab-48e7-b7c3-d41cd95fa4b0")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn delete<K>(&self, key: K) -> Result<()>
where
K: std::fmt::Display,
{
WorkflowDeleteBuilder::new(self.core.clone(), WorkflowType::Workflows, key)
.build()
.await
}
/// # Examples
///
/// Retrieve a z/OSMF Workflow definition:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// let workflow_definition = zosmf
/// .workflows()
/// .definition("/usr/lpp/zosmf/samples/workflow_sample_program_execution.xml")
/// .steps()
/// .variables()
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn definition<P>(&self, path: P) -> WorkflowDefinitionBuilder<WorkflowDefinition>
where
P: std::fmt::Display,
{
WorkflowDefinitionBuilder::new(self.core.clone(), path)
}
/// # Examples
///
/// Archive a z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// let workflow_archive = zosmf
/// .workflows()
/// .archive("2535b19e-a8c3-4a52-9d77-e30bb920f912")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn archive<K>(&self, key: K) -> Result<WorkflowArchive>
where
K: std::fmt::Display,
{
WorkflowArchiveBuilder::new(self.core.clone(), key)
.build()
.await
}
/// # Examples
///
/// List archived z/OSMF Workflows:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// # use z_osmf::workflows::archived_workflows::WorkflowOrderBy;
/// let archived_workflow_list = zosmf
/// .workflows()
/// .list_archived()
/// .order_by(WorkflowOrderBy::Desc)
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list_archived(&self) -> ArchivedWorkflowListBuilder<ArchivedWorkflowList> {
ArchivedWorkflowListBuilder::new(self.core.clone())
}
/// # Examples
///
/// Get the properties of an archived z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// # use z_osmf::workflows::archived_workflows::WorkflowOrderBy;
/// let archived_workflow_properties = zosmf
/// .workflows()
/// .properties_archived("2535b19e-a8c3-4a52-9d77-e30bb920f912")
/// .build()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn properties_archived<K>(&self, key: K) -> WorkflowPropertiesBuilder<WorkflowProperties>
where
K: std::fmt::Display,
{
WorkflowPropertiesBuilder::new(self.core.clone(), WorkflowType::ArchivedWorkflows, key)
}
/// # Examples
///
/// Delete an archived z/OSMF Workflow:
/// ```
/// # async fn example(zosmf: z_osmf::ZOsmf) -> anyhow::Result<()> {
/// zosmf.workflows()
/// .delete_archived("7c4bac42-16a3-4af5-a5b9-263e60b280a4")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn delete_archived<K>(&self, key: K) -> Result<()>
where
K: std::fmt::Display,
{
WorkflowDeleteBuilder::new(self.core.clone(), WorkflowType::ArchivedWorkflows, key)
.build()
.await
}
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum WorkflowAccess {
Private,
Public,
Restricted,
}
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum WorkflowStatus {
AutomationInProgress,
Canceled,
Complete,
InProgress,
}
#[derive(Clone, Debug)]
enum ReturnData {
Steps,
StepsVariables,
Variables,
}
#[derive(Clone, Debug)]
enum WorkflowType {
ArchivedWorkflows,
Workflows,
}
impl std::fmt::Display for WorkflowType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
WorkflowType::ArchivedWorkflows => "archivedworkflows",
WorkflowType::Workflows => "workflows",
}
)
}
}