Skip to content

Commit 3010f54

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

File tree

24 files changed

+542
-49
lines changed

24 files changed

+542
-49
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+

examples/events/.checkstyle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
4+
<local-check-config name="maven-checkstyle-plugin default" location="file:/home/ftirados/kogito_new/.metadata/.plugins/com.basistech.m2e.code.quality.checkstyle/events_inline_checkstyle.xml" type="remote" description="maven-checkstyle-plugin configuration default">
5+
<property name="checkstyle.header.file" value="/home/ftirados/kogito_new/.metadata/.plugins/org.eclipse.core.resources/.projects/events/com.basistech.m2e.code.quality.checkstyleConfigurator/checkstyle-header-default.txt"/>
6+
<property name="checkstyle.cache.file" value="${project_loc}/target/checkstyle-cachefile"/>
7+
</local-check-config>
8+
<fileset name="java-sources-default" enabled="true" check-config-name="maven-checkstyle-plugin default" local="true">
9+
<file-match-pattern match-pattern="^src/test/java/.*\/.*\.java" include-pattern="true"/>
10+
<file-match-pattern match-pattern="^src/main/java/.*\/.*\.java" include-pattern="true"/>
11+
<file-match-pattern match-pattern="^src/main/resources/.*\.properties" include-pattern="true"/>
12+
<file-match-pattern match-pattern="^src/test/resources/.*\.properties" include-pattern="true"/>
13+
</fileset>
14+
</fileset-config>

examples/events/pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>io.serverlessworkflow</groupId>
5+
<artifactId>serverlessworkflow-examples</artifactId>
6+
<version>7.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>events</artifactId>
9+
<dependencies>
10+
<dependency>
11+
<groupId>io.serverlessworkflow</groupId>
12+
<artifactId>serverlessworkflow-impl-core</artifactId>
13+
</dependency>
14+
<dependency>
15+
<groupId>org.slf4j</groupId>
16+
<artifactId>slf4j-simple</artifactId>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 events;
17+
18+
import io.serverlessworkflow.api.WorkflowReader;
19+
import io.serverlessworkflow.impl.WorkflowApplication;
20+
import io.serverlessworkflow.impl.WorkflowDefinition;
21+
import io.serverlessworkflow.impl.WorkflowInstance;
22+
import java.io.IOException;
23+
import java.util.Map;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
27+
public class EventExample {
28+
29+
private static final Logger logger = LoggerFactory.getLogger(EventExample.class);
30+
31+
public static void main(String[] args) throws IOException {
32+
try (WorkflowApplication appl = WorkflowApplication.builder().build()) {
33+
WorkflowDefinition listenDefinition =
34+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("listen.yaml"));
35+
WorkflowDefinition emitDefinition =
36+
appl.workflowDefinition(WorkflowReader.readWorkflowFromClasspath("emit.yaml"));
37+
WorkflowInstance waitingInstance = listenDefinition.instance(Map.of());
38+
waitingInstance
39+
.start()
40+
.thenAccept(node -> logger.info("Waiting instance completed with result {}", node));
41+
logger.info("Listen instance waiting for proper event, Status {}", waitingInstance.status());
42+
logger.info("Publishing event with temperature 35");
43+
emitDefinition.instance(Map.of("temperature", 35)).start().join();
44+
logger.info(
45+
"Listen instance still waiting for proper event, Status {}", waitingInstance.status());
46+
logger.info("Publishing event with temperature 39");
47+
emitDefinition.instance(Map.of("temperature", 39)).start().join();
48+
}
49+
}
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: test
4+
name: emit
5+
version: '0.1.0'
6+
do:
7+
- emitEvent:
8+
emit:
9+
event:
10+
with:
11+
source: https://hospital.com
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data:
14+
temperature: ${.temperature}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
document:
2+
dsl: '1.0.0-alpha5'
3+
namespace: examples
4+
name: listen
5+
version: '0.1.0'
6+
do:
7+
- callDoctor:
8+
listen:
9+
to:
10+
one:
11+
with:
12+
type: com.fake-hospital.vitals.measurements.temperature
13+
data: ${ .temperature > 38 }

examples/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>io.serverlessworkflow</groupId>
5+
<artifactId>serverlessworkflow-parent</artifactId>
6+
<version>7.0.0-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>serverlessworkflow-examples</artifactId>
9+
<packaging>pom</packaging>
10+
<dependencyManagement>
11+
<dependencies>
12+
<dependency>
13+
<groupId>io.serverlessworkflow</groupId>
14+
<artifactId>serverlessworkflow-impl-core</artifactId>
15+
<version>${project.version}</version>
16+
</dependency>
17+
<dependency>
18+
<groupId>io.serverlessworkflow</groupId>
19+
<artifactId>serverlessworkflow-impl-http</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.slf4j</groupId>
24+
<artifactId>slf4j-simple</artifactId>
25+
<version>2.0.16</version>
26+
</dependency>
27+
</dependencies>
28+
</dependencyManagement>
29+
<modules>
30+
<module>simpleGet</module>
31+
<module>events</module>
32+
</modules>
33+
</project>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
<modelVersion>4.0.0</modelVersion>
33
<parent>
44
<groupId>io.serverlessworkflow</groupId>
5-
<artifactId>serverlessworkflow-impl</artifactId>
5+
<artifactId>serverlessworkflow-examples</artifactId>
66
<version>7.0.0-SNAPSHOT</version>
77
</parent>
8-
<artifactId>serverlessworkflow-impl-bom</artifactId>
9-
<packaging>pom</packaging>
8+
<artifactId>simpleGet</artifactId>
109
<dependencies>
1110
<dependency>
1211
<groupId>io.serverlessworkflow</groupId>
@@ -16,5 +15,9 @@
1615
<groupId>io.serverlessworkflow</groupId>
1716
<artifactId>serverlessworkflow-impl-http</artifactId>
1817
</dependency>
18+
<dependency>
19+
<groupId>org.slf4j</groupId>
20+
<artifactId>slf4j-simple</artifactId>
21+
</dependency>
1922
</dependencies>
2023
</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("get.yaml"))
33+
.instance(Map.of("petId", 10))
34+
.start()
35+
.join());
36+
}
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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("get.yaml"))
31+
.instance(Map.of("petId", 10))
32+
.start()
33+
.thenAccept(node -> logger.info("Workflow output is {}", node));
34+
logger.info("The request has been sent, this thread might continue doing stuff");
35+
}
36+
}
37+
}
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}

0 commit comments

Comments
 (0)