Skip to content

Commit 0eba5e0

Browse files
committed
[Fix #520] Updating readme
Signed-off-by: Francisco Javier Tirado Sarti <[email protected]>
1 parent 3064323 commit 0eba5e0

File tree

10 files changed

+293
-20
lines changed

10 files changed

+293
-20
lines changed

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Provides the Java API for the [Serverless Workflow Specification](https://github
88
With the SDK you can:
99

1010
* Read workflow JSON and YAML definitions
11-
* Write workflow in JSON and YAML format.
11+
* Write workflow definition in JSON and YAML format.
12+
* Test your workflow definitions using the reference implementation.
1213

13-
Serverless Workflow Java SDK is **not** a workflow runtime implementation but can be used by Java runtime implementations to parse workflow definitions.
1414

15-
### Status
15+
## Status
1616

1717
| Latest Releases | Conformance to spec version |
1818
| :---: | :---: |
@@ -25,17 +25,17 @@ Serverless Workflow Java SDK is **not** a workflow runtime implementation but ca
2525

2626
Note that 6.0.0.Final, which will be the one for specification version 0.9, is skipped intentionally in case someone want to work on it.
2727

28-
### JDK Version
28+
## JDK Version
2929

3030
| SDK Version | JDK Version |
3131
| :---: | :---: |
3232
| 5.0.0 and after | 11 |
3333
| 4.0.x and before | 8 |
3434

35-
### Getting Started
35+
## Getting Started
3636

3737

38-
#### Building SNAPSHOT locally
38+
### Building SNAPSHOT locally
3939

4040
To build project and run tests locally:
4141

@@ -47,7 +47,7 @@ mvn clean install
4747
The project uses [Google's code styleguide](https://google.github.io/styleguide/javaguide.html).
4848
Your changes should be automatically formatted during the build.
4949

50-
#### Maven projects:
50+
### Maven projects:
5151

5252
Add the following dependencies to your pom.xml `dependencies` section:
5353

@@ -59,19 +59,28 @@ Add the following dependencies to your pom.xml `dependencies` section:
5959
</dependency>
6060
```
6161

62-
#### Gradle projects:
62+
### Gradle projects:
6363

6464
Add the following dependencies to your build.gradle `dependencies` section:
6565

6666
```text
6767
implementation("io.serverlessworkflow:serverlessworkflow-api:7.0.0-SNAPSHOT")
6868
```
6969

70-
### How to Use
70+
## How to Use
7171

72-
#### Creating from JSON/YAML source
72+
There are, roughly speaking, two kind of users of this SDK:
73+
* Those ones interested on implementing their own runtime using Java.
74+
* Those ones interested on using the provided runtime reference implementation.
7375

74-
You can create a Workflow instance from JSON/YAML source:
76+
### Implementing your own runtime
77+
78+
For those ones interested on implementing their own runtime, this SDK provides an easy way to load an in memory representation of a given workflow definition.
79+
This memory representation consist of a hierarchy of POJOS directly generated from the Serverless Workflow specification [schema](api/src/main/resources/schema/workflow.yaml), which ensures the internal representation is aligned with the specification schema. The root of the hierarchy is `io.serverlessworkflow.api.types.Workflow` class
80+
81+
#### Reading workflow definition from JSON/YAML source
82+
83+
You can read a Workflow definition from JSON/YAML source:
7584

7685
Let's say you have a simple YAML based workflow definition in a file name `simple.yaml` located in your working dir:
7786

@@ -93,7 +102,7 @@ do:
93102

94103
```
95104

96-
To parse it and create a Workflow instance you can do:
105+
To parse it and get a Workflow instance you can do:
97106

98107
``` java
99108

@@ -102,15 +111,30 @@ try (InputStream in = new FileInputStream("simple.yaml")) {
102111
// Once you have the Workflow instance you can use its API to inspect it
103112
}
104113
```
114+
By default, Workflows are not validated against the schema (performance being the priority). If you want to enable validation, you can do that by using:
105115

106-
#### Writing a workflow
116+
``` java
117+
try (InputStream in = new FileInputStream("simple.yaml")) {
118+
Workflow workflow = WorkflowReader.validation().readWorkflow (in, WorkflowFormat.YAML);
119+
// Once you have the Workflow instance you can use its API to inspect it
120+
}
121+
```
122+
123+
For additional reading helper methods, including the one to read a workflow definition from classpath, check [WorkflowReader](api/src/main/java/io/serverlessworkflow/api/WorkflowReader.java) class.
124+
125+
#### Writing workflow definition to a a JSON/YAML target
107126

108-
Given a workflow definition, you can store it using JSON or YAML format.
127+
Given a Workflow instance, you can store it using JSON or YAML format.
109128
For example, to store a workflow using json format in a file called `simple.json`, you write
110129

111130
``` java
112131
try (OutputStream out = new FileOutputStream("simple.json")) {
113132
WorkflowWriter.writeWorkflow(out, workflow, WorkflowFormat.JSON);
114133
}
115134

116-
```
135+
```
136+
For additional writing helper methods, check [WorkflowWriter](api/src/main/java/io/serverlessworkflow/api/WorkflowWriter.java) class.
137+
138+
### Reference implementation
139+
See Reference implementation [readme](impl/README.md).
140+

impl/bom/pom.xml renamed to examples/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,25 @@
22
<modelVersion>4.0.0</modelVersion>
33
<parent>
44
<groupId>io.serverlessworkflow</groupId>
5-
<artifactId>serverlessworkflow-impl</artifactId>
5+
<artifactId>serverlessworkflow-parent</artifactId>
66
<version>7.0.0-SNAPSHOT</version>
77
</parent>
8-
<artifactId>serverlessworkflow-impl-bom</artifactId>
9-
<packaging>pom</packaging>
8+
<artifactId>examples</artifactId>
109
<dependencies>
1110
<dependency>
1211
<groupId>io.serverlessworkflow</groupId>
1312
<artifactId>serverlessworkflow-impl-core</artifactId>
13+
<version>${project.version}</version>
1414
</dependency>
1515
<dependency>
1616
<groupId>io.serverlessworkflow</groupId>
1717
<artifactId>serverlessworkflow-impl-http</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-simple</artifactId>
23+
<version>2.0.16</version>
1824
</dependency>
1925
</dependencies>
2026
</project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import java.io.IOException;
20+
import java.util.Map;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
public class BlockingExample {
25+
26+
private static final Logger logger = LoggerFactory.getLogger(BlockingExample.class);
27+
28+
public static void main(String[] args) throws IOException {
29+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
30+
logger.info(
31+
"Workflow output is {}",
32+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml"))
33+
.instance(Map.of("petId", 10))
34+
.start()
35+
.join());
36+
}
37+
}
38+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.serverlessworkflow.impl;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import java.io.IOException;
20+
import java.util.Map;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
public class NotBlockingExample {
25+
26+
private static final Logger logger = LoggerFactory.getLogger(NotBlockingExample.class);
27+
28+
public static void main(String[] args) throws IOException {
29+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
30+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml"))
31+
.instance(Map.of("petId", 10))
32+
.start()
33+
.thenAccept(node -> logger.info("Workflow output is {}", node));
34+
}
35+
}
36+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: call-http-shorthand-endpoint
5+
version: '0.1.0'
6+
do:
7+
- getPet:
8+
call: http
9+
with:
10+
method: get
11+
endpoint: https://petstore.swagger.io/v2/pet/{petId}

impl/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
![Verify JAVA SDK](https://github.com/serverlessworkflow/sdk-java/workflows/Verify%20JAVA%20SDK/badge.svg)
2+
![Deploy JAVA SDK](https://github.com/serverlessworkflow/sdk-java/workflows/Deploy%20JAVA%20SDK/badge.svg) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/serverlessworkflow/sdk-java)
3+
4+
# Serverless Workflow Specification - Java SDK- Reference Implementation
5+
6+
Welcome to Java SDK runtime reference implementation, a lightweight implementation of the Serverless Workflow specification which provides a simple, non blocking, reactive API for workflow execution.
7+
8+
Although initially conceived mainly for testing purposes, it was designed to be easily expanded, so it can eventually become production ready.
9+
10+
## Status.
11+
12+
This reference implementation is currently capable of running workflows consisting of:
13+
14+
15+
* Switch
16+
* Set
17+
* Do
18+
* Raise
19+
* Listen
20+
* Emit
21+
* Fork
22+
* For
23+
* Try
24+
* Wait
25+
* Call
26+
* HTTP
27+
* Input and output schema validation.
28+
* Input, output and export filters.
29+
* Runtime expression special keyword
30+
* Error definitions
31+
32+
33+
## Setup
34+
35+
### JDK Version
36+
37+
Reference implementation requires [Java 17](https://openjdk.org/projects/jdk/17/) or newer versions.
38+
39+
### Maven projects:
40+
41+
Add the following dependencies to your pom.xml `dependencies` section:
42+
43+
```xml
44+
<dependency>
45+
<groupId>io.serverlessworkflow</groupId>
46+
<artifactId>serverlessworkflow-impl-core</artifactId>
47+
<version>7.0.0-SNAPSHOT</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.serverlessworkflow</groupId>
51+
<artifactId>serverlessworkflow-impl-http</artifactId>
52+
<version>7.0.0-SNAPSHOT</version>
53+
</dependency>
54+
```
55+
56+
### Gradle projects:
57+
58+
Add the following dependencies to your build.gradle `dependencies` section:
59+
60+
```text
61+
implementation("io.serverlessworkflow:serverlessworkflow-impl-core:7.0.0-SNAPSHOT")
62+
implementation("io.serverlessworkflow:serverlessworkflow-impl-http:7.0.0-SNAPSHOT")
63+
```
64+
65+
## How to use
66+
67+
This section is split in two.
68+
Quick version is intended for impatient users that want to try something as soon as possible.
69+
Detailed version is more suitable for those users interested on a more thoughtful discussion of the API
70+
Full code of the examples is available [here](/examples)
71+
72+
### Quick version
73+
74+
Assuming you have a workflow definition stored in a file called "do-single.yaml" available in your classpath
75+
76+
```yaml
77+
document:
78+
dsl: '1.0.0-alpha5'
79+
namespace: examples
80+
name: call-http-shorthand-endpoint
81+
version: '0.1.0'
82+
do:
83+
- getPet:
84+
call: http
85+
with:
86+
method: get
87+
endpoint: https://petstore.swagger.io/v2/pet/{petId}
88+
```
89+
90+
In order to execute it, blocking the thread till the http request is completed, you should write
91+
92+
``` java
93+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
94+
logger.info(
95+
"Workflow output is {}",
96+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml"))
97+
.instance(Map.of("petId", 10))
98+
.start()
99+
.join());
100+
}
101+
```
102+
103+
In order to execute it, without blocking the calling thread till the http request is completed, you should write
104+
105+
``` java
106+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
107+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("do-single.yaml"))
108+
.instance(Map.of("petId", 10))
109+
.start()
110+
.thenAccept(node -> logger.info("Workflow output is {}", node));
111+
}
112+
```
113+
When the http request is done, both examples will print a similar output
114+
115+
`Workflow output is {"id":10,"category":{"id":10,"name":"string"},"name":"doggie","photoUrls":["string"],"tags":[{"id":10,"name":"string"}],"status":"string"}`
116+
117+
118+
### Detailed version
119+
120+
TBD

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public WorkflowDefinition workflowDefinition(Workflow workflow) {
193193
}
194194

195195
@Override
196-
public void close() throws Exception {
196+
public void close() {
197197
for (WorkflowDefinition definition : definitions.values()) {
198198
definition.close();
199199
}

0 commit comments

Comments
 (0)