Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Workflow hello world example #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
# When adding a new example make sure it's listed here
- name: Find and replace restateVersion in build.gradle.kts for java examples
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda food-ordering/app tour-of-restate patterns; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' java/$jvmDir/build.gradle.kts; done
run: for jvmDir in hello-world-http hello-world-lambda hello-world-workflow food-ordering/app tour-of-restate patterns; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' java/$jvmDir/build.gradle.kts; done
- name: Find and replace restateVersion in build.gradle.kts for kotlin templates
if: github.event.inputs.sdkJavaVersion != ''
run: for jvmDir in hello-world-http hello-world-lambda; do sed -i 's/val restateVersion = "[0-9A-Z.-]*"/val restateVersion = "${{ inputs.sdkJavaVersion }}"/' kotlin/$jvmDir/build.gradle.kts; done
Expand All @@ -81,6 +81,12 @@ jobs:
with:
arguments: check
build-root-directory: java/hello-world-lambda
- name: Test java/hello-world-workflow
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-workflow
- name: Test java/food-ordering
if: github.event.inputs.sdkJavaVersion != ''
uses: gradle/gradle-build-action@v2
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
typescript-tour-of-restate.zip
java-hello-world-http.zip
java-hello-world-lambda.zip
java-hello-world-worfklow.zip
java-food-ordering.zip
java-tour-of-restate.zip
kotlin-hello-world-http.zip
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
with:
arguments: check
build-root-directory: java/hello-world-lambda
- name: Test java/hello-world-workflow
uses: gradle/gradle-build-action@v2
with:
arguments: check
build-root-directory: java/hello-world-workflow
- name: Test java/food-ordering
uses: gradle/gradle-build-action@v2
with:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Browse this repository to see how easy distributed applications development beco
| TypeScript | [Hello world on AWS Lambda + CDK](typescript/hello-world-lambda-cdk) |
| Java | [Hello World HTTP](java/hello-world-http) |
| Java | [Hello world on AWS Lambda](java/hello-world-lambda) |
| Java | [Hello World Workflow](java/hello-world-workflow) |
| Kotlin | [Hello World HTTP](kotlin/hello-world-http) |
| Kotlin | [Hello world on AWS Lambda](kotlin/hello-world-lambda) |
| Kotlin | [Hello world on AWS Lambda + CDK](kotlin/hello-world-lambda-cdk) |
Expand Down
9 changes: 5 additions & 4 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
This directory contains Restate examples using the Java SDK.

## Starters
| Language | Name / Link |
|-----------|-----------------------------------------------------------------|
| Java | [Hello World HTTP](hello-world-http) |
| Java | [Hello world on AWS Lambda](hello-world-lambda) |
| Language | Name / Link |
|-----------|-------------------------------------------------|
| Java | [Hello World HTTP](hello-world-http) |
| Java | [Hello world on AWS Lambda](hello-world-lambda) |
| Java | [Hello World Workflow](hello-world-workflow) |

## Tutorials
| Language | Name / Link |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* https://github.com/restatedev/examples/
*/

package dev.restate.sdk.examples;
package dev.restate.sdk.examples;

import dev.restate.sdk.RestateContext;
import dev.restate.sdk.common.CoreSerdes;
Expand Down
35 changes: 35 additions & 0 deletions java/hello-world-workflow/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

.idea
*.iml

# Unignore the gradle wrapper
!gradle/wrapper/gradle-wrapper.jar
46 changes: 46 additions & 0 deletions java/hello-world-workflow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Hello world - Java Workflow example

Sample project configuration of a Restate worfklow using the Java interface and HTTP server. It contains:

* [`build.gradle.kts`](build.gradle.kts)
* [Workflow implementation `LoanApproval`](src/main/java/my/restate/examples/LoanApproval.java)
* [Test `LoanApprovalTest`](src/test/java/my/restate/examples/LoanApprovalTest.java)
* [Logging configuration](src/main/resources/log4j2.properties)

## Download the example

- Via the CLI:
```shell
restate example java-hello-world-workflow && cd java-hello-world-workflow
```

- Via git clone:
```shell
git clone [email protected]:restatedev/examples.git
cd examples/java/hello-world-workflow
```

- Via `wget`:
```shell
wget https://github.com/restatedev/examples/releases/latest/download/java-hello-world-workflow.zip && unzip java-hello-world-workflow.zip -d java-hello-world-workflow && rm java-hello-world-workflow.zip
```

## Running the example

You can run the example via:

```shell
./gradlew run
```

Or from your IDE.

## Running the tests

You can run the tests either via:

```shell
./gradlew check
```

Or from your IDE.
42 changes: 42 additions & 0 deletions java/hello-world-workflow/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import com.google.protobuf.gradle.id

plugins {
java
application

id("com.google.protobuf") version "0.9.1"
}

repositories {
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}

val restateVersion = "0.8.0-SNAPSHOT"

dependencies {
// Restate SDK
annotationProcessor("dev.restate:sdk-api-gen:$restateVersion")
implementation("dev.restate:sdk-api:$restateVersion")
implementation("dev.restate:sdk-workflow-api:$restateVersion")
implementation("dev.restate:sdk-http-vertx:$restateVersion")
// To use Jackson to read/write state entries (optional)
implementation("dev.restate:sdk-serde-jackson:$restateVersion")

// Logging (optional)
implementation("org.apache.logging.log4j:log4j-core:2.20.0")

// Testing (optional)
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("dev.restate:sdk-testing:$restateVersion")
}

// Configure test platform
tasks.withType<Test> {
useJUnitPlatform()
}

// Set main class
application {
mainClass.set("my.restate.examples.LoanApproval")
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading