-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensor-calibration.arazzo.yaml
More file actions
123 lines (109 loc) · 3.65 KB
/
Copy pathsensor-calibration.arazzo.yaml
File metadata and controls
123 lines (109 loc) · 3.65 KB
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
arazzo: 1.1.0
info:
title: Sensor Calibration Workflow with NATS
version: 1.0.0
description: |
### Workflow Overview
This workflow ensures a sensor is registered, sends a calibration command via NATS,
waits for a confirmation, and then notifies a technician via email.
1. **Check Sensor**
Query sensor details using `GET /sensors/{sensorId}`.
2. **Register Sensor (if not found)**
Register a new sensor using `POST /sensors`.
3. **Send Calibration Command**
Send a calibration message to `sensors.{sensorId}.calibrate`.
4. **Wait for Calibration Result**
Wait for a confirmation event on `sensors.{sensorId}.calibrated`.
5. **Notify Technician**
Send an email confirming calibration completion.
sourceDescriptions:
- name: SensorOpenApi
type: openapi
url: ./sensor-mgmt-email.openapi.yaml
- name: AsyncAPISensorEvents
type: asyncapi
url: ./sensor-calibration-nats.asyncapi.yaml
workflows:
- workflowId: calibrateSensor
inputs:
required: [sensorId, calibrationLevel, technicianEmail]
type: object
properties:
sensorId:
type: string
calibrationLevel:
type: integer
technicianEmail:
type: string
steps:
- stepId: GetSensor
operationId: $sourceDescriptions.SensorOpenApi.getSensor
parameters:
- name: sensorId
in: path
value: $inputs.sensorId
successCriteria:
- condition: $statusCode == 200
outputs:
sensorType: $response.body#/type
onFailure:
- condition: $statusCode == 404
type: goto
stepId: RegisterSensor
- stepId: RegisterSensor
operationId: $sourceDescriptions.SensorOpenApi.registerSensor
requestBody:
contentType: application/json
payload: |
{
"sensorId": "{$inputs.sensorId}",
"type": "generic"
}
successCriteria:
- condition: $statusCode == 201
onSuccess:
- condition: $statusCode == 201
type: goto
stepId: GetSensor
- stepId: SendCalibration
operationId: $sourceDescriptions.AsyncAPISensorEvents.sendCalibration
action: send
parameters:
- name: sensorId
in: path
value: $inputs.sensorId
- name: correlationId
in: header
value: $inputs.sensorId
requestBody:
contentType: application/json
payload: |
{
"sensorId": "{$inputs.sensorId}",
"calibrationLevel": {$inputs.calibrationLevel}
}
- stepId: WaitForCalibration
operationId: $sourceDescriptions.AsyncAPISensorEvents.receiveCalibration
action: receive
correlationId: $inputs.sensorId
timeout: 8000
successCriteria:
- condition: $message.payload.status == "calibrated"
outputs:
calibrationStatus: $message.payload.status
- stepId: SendNotification
operationId: $sourceDescriptions.SensorOpenApi.sendEmail
dependsOn:
- $steps.WaitForCalibration
requestBody:
contentType: application/json
payload: |
{
"to": "{$inputs.technicianEmail}",
"subject": "Calibration Complete",
"body": "Sensor {$inputs.sensorId} calibration completed with status '{$steps.WaitForCalibration.outputs.calibrationStatus}'."
}
successCriteria:
- condition: $statusCode == 200
outputs:
- status: "completed successfully"