Skip to content

Commit 2e27637

Browse files
committed
Adds managing-github-issues and managing-ev-charging-stations use cases
Signed-off-by: Charles d'Avernas <[email protected]>
1 parent 1827680 commit 2e27637

File tree

4 files changed

+548
-0
lines changed

4 files changed

+548
-0
lines changed

use-cases/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Use Cases
2+
3+
This directory contains a collection of high-level use cases that demonstrate the capabilities and potential applications of the Serverless Workflow DSL. Each use case provides insights into how to effectively implement workflows in various scenarios, helping newcomers understand the framework's power and flexibility.
4+
5+
## Purpose
6+
7+
The primary purpose of these use cases is to:
8+
9+
- **Educate Newcomers:** Provide clear examples of how to utilize Serverless Workflow DSL for real-world applications.
10+
- **Inspire Innovation:** Showcase the diverse possibilities of workflow automation and orchestration.
11+
- **Facilitate Best Practices:** Encourage consistent structure and documentation, making it easier to share knowledge and experiences within the community.
12+
13+
## Structure
14+
15+
Each use case in this directory MUST follow a specific structure to ensure clarity and consistency. The structure is as follows:
16+
17+
### File Structure
18+
19+
```
20+
./my-cool-use-case 👈 The name of the use case. It must be lowercase and contain exclusively alphanumeric characters, except for '-'.
21+
/README.md 👈 Documentation of the use case's details and workflow.
22+
/diagram.png 👈 Visual representation of the use case workflow (optional).
23+
/... 👈 Additional files relevant to the use case documentation.
24+
```
25+
26+
### Case Structure
27+
28+
#### Overview
29+
30+
- **System:** A brief description of the system involved in the use case.
31+
- **Actors:** Identify the main participants or roles interacting with the system.
32+
- **Goals:** Outline the objectives that the use case aims to achieve.
33+
- **Preconditions:** Any conditions that must be met before the workflow can be executed.
34+
35+
#### Scenario
36+
37+
- **Triggers:** Events that initiate the workflow.
38+
- **Flow Breakdown:** Detailed step-by-step breakdown of the workflow, including key actions and decisions made throughout the process.
39+
- **Visualization:** Optional diagrams or flowcharts that illustrate the workflow's structure and progression.
40+
- **Example:** A YAML example of the workflow using Serverless Workflow DSL, demonstrating how the concepts discussed are implemented.
41+
42+
#### Conclusion
43+
44+
- A summary of the benefits and insights gained from the use case, reinforcing why Serverless Workflow is a suitable choice for the described scenario.
45+
46+
## Contributing
47+
48+
We invite everyone to submit their own use cases to enrich this directory and help others learn from their experiences.
49+
50+
If you would like to contribute, please refer to the [contributing.md](./contributing.md) for guidelines on how to contribute to the Serverless Workflow project.
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# Use Case: Managing EV Charging Stations
2+
3+
## Overview
4+
5+
### System
6+
7+
The system is an IoT device management workflow specifically designed for Electric Vehicle (EV) charging stations. It utilizes the Serverless Workflow DSL to automate the monitoring, management, and maintenance of EV charging units, ensuring they operate efficiently and are available for users.
8+
9+
### Actors
10+
11+
- **EV Drivers:** Individuals who use electric vehicles and need charging services.
12+
- **Charging Station Operators:** Businesses or entities managing the charging stations.
13+
- **IoT Devices:** Sensors and controllers in the charging stations that provide real-time data.
14+
- **Cloud Services:** External systems for storing data and providing analytics.
15+
16+
### Goals
17+
18+
- **Automate Charging Management:** Streamline the management of charging sessions, including starting, stopping, and monitoring.
19+
- **Monitor Station Health:** Enable real-time monitoring of the charging stations to detect and address issues proactively.
20+
- **Enhance User Experience:** Provide seamless experiences for EV drivers while charging their vehicles.
21+
22+
### Preconditions
23+
24+
- The workflow assumes that the charging stations are equipped with IoT devices that can send and receive events.
25+
- An appropriate cloud infrastructure is in place to handle the data from charging sessions and device statuses.
26+
27+
## Scenario
28+
29+
### Triggers
30+
31+
The workflow is triggered when:
32+
33+
- An EV charging session starts.
34+
- An EV charging session ends.
35+
- The charging station reports an error.
36+
37+
### Flow Breakdown
38+
39+
40+
### Visualization
41+
42+
The following diagram represents the high-level flow of the workflow:
43+
44+
![managing-ev-charging-stations-diagram](diagram.png)
45+
46+
### Example
47+
48+
```yaml
49+
document:
50+
dsl: '1.0.0'
51+
namespace: default
52+
name: managing-ev-charging-stations
53+
version: '0.1.0'
54+
schedule:
55+
on:
56+
any:
57+
- with:
58+
type: com.ev-power-supplier.charging-station.card-scanned.v1
59+
- with:
60+
type: com.ev-power-supplier.charging-station.faulted.v1
61+
do:
62+
63+
- initialize:
64+
set:
65+
event: ${ $workflow.input[0].data }
66+
export:
67+
as: .event
68+
69+
- handleStationEvents:
70+
switch:
71+
- sessionStarted:
72+
when: .event.type == "com.ev-power-supplier.charging-station.card-scanned.v1"
73+
then: tryGetActiveSession
74+
- stationError:
75+
when: .event.type == "com.ev-power-supplier.charging.station-faulted.v1"
76+
then: handleError
77+
then: raiseUnsupportedEventError
78+
79+
- tryGetActiveSession:
80+
try:
81+
- getSessionForCard:
82+
call: http
83+
with:
84+
method: get
85+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/session/{cardId}
86+
- setSessionInfo:
87+
set:
88+
session: ${ .session }
89+
catch:
90+
errors:
91+
with:
92+
status: 404
93+
94+
- handleActiveSession:
95+
switch:
96+
- sessionInProgress:
97+
when: .session != null
98+
then: endSession
99+
- noActiveSession:
100+
then: tryAquireSlot
101+
102+
- tryAquireSlot:
103+
try:
104+
- acquireSlot:
105+
call: http
106+
with:
107+
method: post
108+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}
109+
body:
110+
card: ${ $context.card }
111+
export:
112+
as: '$context + { slot: .slot }'
113+
catch:
114+
errors:
115+
with:
116+
status: 400
117+
when: .detail == "No charging slots available"
118+
do:
119+
- noSlotsAvailable:
120+
call: http
121+
with:
122+
method: post
123+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/main
124+
body:
125+
action: flicker
126+
color: red
127+
duration: 3000
128+
then: end
129+
130+
- startSession:
131+
do:
132+
- initialize:
133+
set:
134+
session:
135+
card: ${ $context.card }
136+
slotNumber: ${ $context.slot.number }
137+
export:
138+
as: '$context + { session: . }'
139+
- feedBack:
140+
call: http
141+
with:
142+
method: post
143+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/{slotNumber}
144+
body:
145+
action: 'on'
146+
color: blue
147+
- lockSlot:
148+
call: http
149+
with:
150+
method: put
151+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/slot/{slotNumber}/lock
152+
- start:
153+
call: http
154+
with:
155+
method: put
156+
endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/start
157+
- notify:
158+
emit:
159+
event:
160+
with:
161+
source: https://ev-power-supplier.com
162+
type: com.ev-power-supplier.charging-station.session-started.v1
163+
data: ${ $context.session }
164+
165+
- endSession:
166+
do:
167+
- end:
168+
call: http
169+
with:
170+
method: put
171+
endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/end
172+
- processPayment:
173+
call: http
174+
with:
175+
method: put
176+
endpoint: https://ev-power-supplier.com/api/v2/sessions/{sessionId}/pay
177+
- unlockSlot:
178+
call: http
179+
with:
180+
method: put
181+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/slot/{slotNumber}/unlock
182+
- feedBack:
183+
call: http
184+
with:
185+
method: post
186+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/{slotNumber}
187+
body:
188+
action: flicker
189+
color: white
190+
duration: 3000
191+
- notify:
192+
emit:
193+
event:
194+
with:
195+
source: https://ev-power-supplier.com
196+
type: com.ev-power-supplier.charging-station.session-ended.v1
197+
data: ${ $context.session }
198+
then: end
199+
200+
- handleError:
201+
do:
202+
- contactSupport:
203+
call: http
204+
with:
205+
method: post
206+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/support
207+
body:
208+
error: ${ $context.event.data.error }
209+
- feedBack:
210+
call: http
211+
with:
212+
method: post
213+
endpoint: https://ev-power-supplier.com/api/v2/stations/{stationId}/leds/main
214+
body:
215+
action: 'on'
216+
color: red
217+
- notify:
218+
emit:
219+
event:
220+
with:
221+
source: https://ev-power-supplier.com
222+
type: com.ev-power-supplier.charging-station.out-of-order.v1
223+
data: ${ $context.event.data.error }
224+
then: end
225+
226+
- raiseUnsupportedEventError:
227+
raise:
228+
error:
229+
type: https://serverlessworkflow.io/spec/1.0.0/errors/runtime
230+
status: 400
231+
title: Unsupported Event
232+
detail: ${ "The specified station event '\($context.event.type)' is not supported in this context" }
233+
then: end
234+
```
235+
236+
## Conclusion
237+
238+
This use case highlights the capabilities of Serverless Workflow in managing EV charging stations effectively. By automating charging sessions and monitoring station health, organizations can enhance user experiences for EV drivers while ensuring that their charging infrastructure operates efficiently. Leveraging Serverless Workflow enables responsive and scalable management solutions in the evolving landscape of electric vehicle infrastructure.

0 commit comments

Comments
 (0)