Skip to content

Commit 789df24

Browse files
Java worker kitchen sink (#42)
Initial Java Worker
1 parent 74b4a43 commit 789df24

25 files changed

+45847
-9
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
110
workers/python/protos/*pb2.py* linguist-generated=true
211
loadgen/kitchensink/kitchen_sink.pb.go linguist-generated=true
312
loadgen/kitchensink/temporal/** linguist-generated=true

.github/workflows/all-docker-images.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
py-ver:
1010
description: Python SDK ver to build. Skipped if not specified. Must start with v.
1111
type: string
12+
java-ver:
13+
description: Java SDK ver to build. Skipped if not specified. Must start with v.
14+
type: string
1215
do-push:
1316
description: If set, push the built images to Docker Hub.
1417
type: boolean
@@ -23,6 +26,9 @@ on:
2326
py-ver:
2427
description: Python SDK ver to build. Skipped if not specified. Must start with v.
2528
type: string
29+
java-ver:
30+
description: Java SDK ver to build. Skipped if not specified. Must start with v.
31+
type: string
2632
do-push:
2733
description: If set, push the built images to Docker Hub.
2834
type: boolean
@@ -47,3 +53,12 @@ jobs:
4753
lang: py
4854
sdk-version: ${{ inputs.py-ver }}
4955
do-push: ${{ inputs.do-push }}
56+
57+
build-java-docker-images:
58+
if: inputs.java-ver
59+
uses: ./.github/workflows/docker-images.yml
60+
secrets: inherit
61+
with:
62+
lang: java
63+
sdk-version: ${{ inputs.java-ver }}
64+
do-push: ${{ inputs.do-push }}

.github/workflows/ci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,37 @@ jobs:
3131
- name: Run scenario against image
3232
run: ./temporal-omes run-scenario --scenario workflow_with_single_noop_activity --log-level debug --server-address 127.0.0.1:10233 --run-id {{ github.run_id }} --connect-timeout 1m --iterations 5
3333

34+
build-lint-test-java:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Print build information
38+
run: "echo head_ref: ${{ github.head_ref }}, ref: ${{ github.ref }}"
39+
- name: Checkout repo
40+
uses: actions/checkout@v4
41+
- name: Setup Java
42+
uses: actions/setup-java@v2
43+
with:
44+
distribution: 'temurin'
45+
java-version: '11'
46+
- name: Set up Gradle
47+
uses: gradle/gradle-build-action@v2
48+
- name: Lint Java worker
49+
run: cd workers/java && ./gradlew --no-daemon spotlessCheck
50+
- name: Setup Go
51+
uses: actions/setup-go@v2
52+
with:
53+
go-version: "^1.20"
54+
- name: Build exe
55+
run: go build -o temporal-omes ./cmd
56+
- name: Run local scenario with worker
57+
run: ./temporal-omes run-scenario-with-worker --scenario workflow_with_single_noop_activity --log-level debug --language java --embedded-server --iterations 5
58+
- name: Build worker image
59+
run: ./temporal-omes build-worker-image --language java --version 1.22.3 --tag-as-latest
60+
- name: Run worker image
61+
run: docker run --rm --detach -i -p 10233:10233 omes:java-1.22.3 --scenario workflow_with_single_noop_activity --log-level debug --language java --run-id {{ github.run_id }} --embedded-server-address 0.0.0.0:10233
62+
- name: Run scenario against image
63+
run: ./temporal-omes run-scenario --scenario workflow_with_single_noop_activity --log-level debug --server-address 127.0.0.1:10233 --run-id {{ github.run_id }} --connect-timeout 1m --iterations 5
64+
3465
build-lint-test-python:
3566
runs-on: ubuntu-latest
3667
steps:

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,11 @@
44
go.work
55
go.work.sum
66
.idea/
7+
# Ignore Gradle project-specific cache directory
8+
.gradle
9+
10+
# Ignore Gradle build output directory
11+
workers/java/bin
12+
workers/java/build
13+
714
/loadgen/kitchen-sink-gen/target/

cmd/prepare_worker.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func (b *workerBuilder) build(ctx context.Context) (sdkbuild.Program, error) {
7878
return b.buildGo(ctx, baseDir)
7979
case "python":
8080
return b.buildPython(ctx, baseDir)
81+
case "java":
82+
return b.buildJava(ctx, baseDir)
8183
default:
8284
return nil, fmt.Errorf("unrecognized language %v", lang)
8385
}
@@ -144,14 +146,29 @@ func (b *workerBuilder) buildPython(ctx context.Context, baseDir string) (sdkbui
144146
return prog, nil
145147
}
146148

149+
func (b *workerBuilder) buildJava(ctx context.Context, baseDir string) (sdkbuild.Program, error) {
150+
prog, err := sdkbuild.BuildJavaProgram(ctx, sdkbuild.BuildJavaProgramOptions{
151+
BaseDir: baseDir,
152+
DirName: b.dirName,
153+
Version: b.version,
154+
MainClass: "io.temporal.omes.Main",
155+
HarnessDependency: "io.temporal:omes:0.1.0",
156+
Build: true,
157+
})
158+
if err != nil {
159+
return nil, fmt.Errorf("failed preparing: %w", err)
160+
}
161+
return prog, nil
162+
}
163+
147164
func rootDir() string {
148165
_, currFile, _, _ := runtime.Caller(0)
149166
return filepath.Dir(filepath.Dir(currFile))
150167
}
151168

152169
func normalizeLangName(lang string) (string, error) {
153170
switch lang {
154-
case "go", "python":
171+
case "go", "python", "java":
155172
case "py":
156173
lang = "python"
157174
default:

cmd/run_worker.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ func (r *workerRunner) run(ctx context.Context) error {
144144
prog, err = sdkbuild.GoProgramFromDir(filepath.Join(baseDir, r.dirName))
145145
case "python":
146146
prog, err = sdkbuild.PythonProgramFromDir(filepath.Join(baseDir, r.dirName))
147+
case "java":
148+
prog, err = sdkbuild.JavaProgramFromDir(filepath.Join(baseDir, r.dirName))
147149
default:
148150
return fmt.Errorf("unrecognized language %v", lang)
149151
}

dockerfiles/java.Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Build in a full featured container
2+
FROM eclipse-temurin:11 as build
3+
4+
RUN apt-get update \
5+
&& DEBIAN_FRONTEND=noninteractive \
6+
apt-get install --no-install-recommends --assume-yes \
7+
protobuf-compiler=3.12.4* git=1:2.34.1-1ubuntu1
8+
9+
# Get go compiler
10+
ARG PLATFORM=amd64
11+
RUN wget -q https://go.dev/dl/go1.20.4.linux-${PLATFORM}.tar.gz \
12+
&& tar -C /usr/local -xzf go1.20.4.linux-${PLATFORM}.tar.gz
13+
14+
WORKDIR /app
15+
16+
# Copy CLI build dependencies
17+
COPY cmd ./cmd
18+
COPY loadgen ./loadgen
19+
COPY scenarios ./scenarios
20+
COPY workers ./workers
21+
COPY go.mod go.sum ./
22+
23+
# Build the CLI
24+
RUN CGO_ENABLED=0 /usr/local/go/bin/go build -o temporal-omes ./cmd
25+
26+
ARG SDK_VERSION
27+
28+
# Optional SDK dir to copy, defaults to unimportant file
29+
ARG SDK_DIR=.gitignore
30+
COPY ${SDK_DIR} ./repo
31+
32+
# Build the worker
33+
ENV GRADLE_USER_HOME="/gradle"
34+
RUN CGO_ENABLED=0 ./temporal-omes prepare-worker --language java --dir-name prepared --version "$SDK_VERSION"
35+
36+
# Copy the CLI and prepared feature to a "run" container. Distroless isn't used here since we run
37+
# through Gradle and it's more annoying than it's worth to get its deps to line up
38+
FROM eclipse-temurin:11
39+
ENV GRADLE_USER_HOME="/gradle"
40+
41+
COPY --from=build /app/temporal-omes /app/temporal-omes
42+
COPY --from=build /app/workers/java /app/workers/java
43+
44+
# Use entrypoint instead of command to "bake" the default command options
45+
ENTRYPOINT ["/app/temporal-omes", "run-worker", "--language", "java", "--dir-name", "prepared"]

loadgen/kitchen-sink-gen/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3838
let protoc = protoc_from_env();
3939
for (lang, out_dir) in [
4040
("python", "../../workers/python/protos"),
41+
("java", "../../workers/java"),
4142
("go", "../../loadgen/kitchensink"),
4243
] {
4344
let mut cmd = Command::new(protoc.clone());
@@ -52,6 +53,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
5253
if lang == "python" {
5354
cmd.arg(format!("--python_out={out_dir}"));
5455
cmd.arg(format!("--pyi_out={out_dir}"));
56+
} else if lang == "java" {
57+
cmd.arg(format!("--java_out={out_dir}"));
5558
} else if lang == "go" {
5659
cmd.arg("--go_opt=paths=source_relative");
5760
cmd.arg(format!("--go_out={out_dir}"));

loadgen/kitchensink/kitchen_sink.pb.go

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

workers/java/build.gradle

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
plugins {
2+
id 'java'
3+
id 'com.diffplug.spotless' version '6.18.0'
4+
}
5+
6+
group 'io.temporal'
7+
version '0.1.0'
8+
9+
java {
10+
sourceCompatibility = JavaVersion.VERSION_1_10
11+
targetCompatibility = JavaVersion.VERSION_1_10
12+
}
13+
14+
repositories {
15+
mavenCentral()
16+
}
17+
18+
spotless {
19+
java {
20+
googleJavaFormat('1.16.0')
21+
}
22+
}
23+
24+
dependencies {
25+
implementation 'ch.qos.logback:logback-classic:1.2.9'
26+
implementation 'com.google.guava:guava:31.0.1-jre'
27+
implementation 'com.google.code.gson:gson:2.8.9'
28+
implementation 'com.jayway.jsonpath:json-path:2.6.0'
29+
implementation 'info.picocli:picocli:4.6.2'
30+
implementation 'io.temporal:temporal-sdk:1.22.3'
31+
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
32+
implementation 'org.reflections:reflections:0.10.2'
33+
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
34+
implementation "io.micrometer:micrometer-registry-prometheus"
35+
36+
implementation(platform("com.fasterxml.jackson:jackson-bom:2.15.2"))
37+
implementation "com.fasterxml.jackson.core:jackson-databind"
38+
implementation "com.fasterxml.jackson.core:jackson-core"
39+
implementation 'com.google.protobuf:protobuf-java:3.25.0'
40+
41+
}
42+
43+
sourceSets {
44+
main {
45+
java {
46+
srcDirs = ['./']
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)