Skip to content

Commit

Permalink
Java worker kitchen sink (#42)
Browse files Browse the repository at this point in the history
Initial Java Worker
  • Loading branch information
Quinn-With-Two-Ns committed Dec 11, 2023
1 parent 74b4a43 commit 789df24
Show file tree
Hide file tree
Showing 25 changed files with 45,847 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

workers/python/protos/*pb2.py* linguist-generated=true
loadgen/kitchensink/kitchen_sink.pb.go linguist-generated=true
loadgen/kitchensink/temporal/** linguist-generated=true
15 changes: 15 additions & 0 deletions .github/workflows/all-docker-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
py-ver:
description: Python SDK ver to build. Skipped if not specified. Must start with v.
type: string
java-ver:
description: Java SDK ver to build. Skipped if not specified. Must start with v.
type: string
do-push:
description: If set, push the built images to Docker Hub.
type: boolean
Expand All @@ -23,6 +26,9 @@ on:
py-ver:
description: Python SDK ver to build. Skipped if not specified. Must start with v.
type: string
java-ver:
description: Java SDK ver to build. Skipped if not specified. Must start with v.
type: string
do-push:
description: If set, push the built images to Docker Hub.
type: boolean
Expand All @@ -47,3 +53,12 @@ jobs:
lang: py
sdk-version: ${{ inputs.py-ver }}
do-push: ${{ inputs.do-push }}

build-java-docker-images:
if: inputs.java-ver
uses: ./.github/workflows/docker-images.yml
secrets: inherit
with:
lang: java
sdk-version: ${{ inputs.java-ver }}
do-push: ${{ inputs.do-push }}
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ jobs:
- name: Run scenario against image
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

build-lint-test-java:
runs-on: ubuntu-latest
steps:
- name: Print build information
run: "echo head_ref: ${{ github.head_ref }}, ref: ${{ github.ref }}"
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '11'
- name: Set up Gradle
uses: gradle/gradle-build-action@v2
- name: Lint Java worker
run: cd workers/java && ./gradlew --no-daemon spotlessCheck
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: "^1.20"
- name: Build exe
run: go build -o temporal-omes ./cmd
- name: Run local scenario with worker
run: ./temporal-omes run-scenario-with-worker --scenario workflow_with_single_noop_activity --log-level debug --language java --embedded-server --iterations 5
- name: Build worker image
run: ./temporal-omes build-worker-image --language java --version 1.22.3 --tag-as-latest
- name: Run worker image
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
- name: Run scenario against image
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

build-lint-test-python:
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
go.work
go.work.sum
.idea/
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
workers/java/bin
workers/java/build

/loadgen/kitchen-sink-gen/target/
19 changes: 18 additions & 1 deletion cmd/prepare_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func (b *workerBuilder) build(ctx context.Context) (sdkbuild.Program, error) {
return b.buildGo(ctx, baseDir)
case "python":
return b.buildPython(ctx, baseDir)
case "java":
return b.buildJava(ctx, baseDir)
default:
return nil, fmt.Errorf("unrecognized language %v", lang)
}
Expand Down Expand Up @@ -144,14 +146,29 @@ func (b *workerBuilder) buildPython(ctx context.Context, baseDir string) (sdkbui
return prog, nil
}

func (b *workerBuilder) buildJava(ctx context.Context, baseDir string) (sdkbuild.Program, error) {
prog, err := sdkbuild.BuildJavaProgram(ctx, sdkbuild.BuildJavaProgramOptions{
BaseDir: baseDir,
DirName: b.dirName,
Version: b.version,
MainClass: "io.temporal.omes.Main",
HarnessDependency: "io.temporal:omes:0.1.0",
Build: true,
})
if err != nil {
return nil, fmt.Errorf("failed preparing: %w", err)
}
return prog, nil
}

func rootDir() string {
_, currFile, _, _ := runtime.Caller(0)
return filepath.Dir(filepath.Dir(currFile))
}

func normalizeLangName(lang string) (string, error) {
switch lang {
case "go", "python":
case "go", "python", "java":
case "py":
lang = "python"
default:
Expand Down
2 changes: 2 additions & 0 deletions cmd/run_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ func (r *workerRunner) run(ctx context.Context) error {
prog, err = sdkbuild.GoProgramFromDir(filepath.Join(baseDir, r.dirName))
case "python":
prog, err = sdkbuild.PythonProgramFromDir(filepath.Join(baseDir, r.dirName))
case "java":
prog, err = sdkbuild.JavaProgramFromDir(filepath.Join(baseDir, r.dirName))
default:
return fmt.Errorf("unrecognized language %v", lang)
}
Expand Down
45 changes: 45 additions & 0 deletions dockerfiles/java.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Build in a full featured container
FROM eclipse-temurin:11 as build

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install --no-install-recommends --assume-yes \
protobuf-compiler=3.12.4* git=1:2.34.1-1ubuntu1

# Get go compiler
ARG PLATFORM=amd64
RUN wget -q https://go.dev/dl/go1.20.4.linux-${PLATFORM}.tar.gz \
&& tar -C /usr/local -xzf go1.20.4.linux-${PLATFORM}.tar.gz

WORKDIR /app

# Copy CLI build dependencies
COPY cmd ./cmd
COPY loadgen ./loadgen
COPY scenarios ./scenarios
COPY workers ./workers
COPY go.mod go.sum ./

# Build the CLI
RUN CGO_ENABLED=0 /usr/local/go/bin/go build -o temporal-omes ./cmd

ARG SDK_VERSION

# Optional SDK dir to copy, defaults to unimportant file
ARG SDK_DIR=.gitignore
COPY ${SDK_DIR} ./repo

# Build the worker
ENV GRADLE_USER_HOME="/gradle"
RUN CGO_ENABLED=0 ./temporal-omes prepare-worker --language java --dir-name prepared --version "$SDK_VERSION"

# Copy the CLI and prepared feature to a "run" container. Distroless isn't used here since we run
# through Gradle and it's more annoying than it's worth to get its deps to line up
FROM eclipse-temurin:11
ENV GRADLE_USER_HOME="/gradle"

COPY --from=build /app/temporal-omes /app/temporal-omes
COPY --from=build /app/workers/java /app/workers/java

# Use entrypoint instead of command to "bake" the default command options
ENTRYPOINT ["/app/temporal-omes", "run-worker", "--language", "java", "--dir-name", "prepared"]
3 changes: 3 additions & 0 deletions loadgen/kitchen-sink-gen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let protoc = protoc_from_env();
for (lang, out_dir) in [
("python", "../../workers/python/protos"),
("java", "../../workers/java"),
("go", "../../loadgen/kitchensink"),
] {
let mut cmd = Command::new(protoc.clone());
Expand All @@ -52,6 +53,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if lang == "python" {
cmd.arg(format!("--python_out={out_dir}"));
cmd.arg(format!("--pyi_out={out_dir}"));
} else if lang == "java" {
cmd.arg(format!("--java_out={out_dir}"));
} else if lang == "go" {
cmd.arg("--go_opt=paths=source_relative");
cmd.arg(format!("--go_out={out_dir}"));
Expand Down
11 changes: 6 additions & 5 deletions loadgen/kitchensink/kitchen_sink.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions workers/java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
plugins {
id 'java'
id 'com.diffplug.spotless' version '6.18.0'
}

group 'io.temporal'
version '0.1.0'

java {
sourceCompatibility = JavaVersion.VERSION_1_10
targetCompatibility = JavaVersion.VERSION_1_10
}

repositories {
mavenCentral()
}

spotless {
java {
googleJavaFormat('1.16.0')
}
}

dependencies {
implementation 'ch.qos.logback:logback-classic:1.2.9'
implementation 'com.google.guava:guava:31.0.1-jre'
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'com.jayway.jsonpath:json-path:2.6.0'
implementation 'info.picocli:picocli:4.6.2'
implementation 'io.temporal:temporal-sdk:1.22.3'
implementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
implementation 'org.reflections:reflections:0.10.2'
implementation 'net.logstash.logback:logstash-logback-encoder:7.4'
implementation "io.micrometer:micrometer-registry-prometheus"

implementation(platform("com.fasterxml.jackson:jackson-bom:2.15.2"))
implementation "com.fasterxml.jackson.core:jackson-databind"
implementation "com.fasterxml.jackson.core:jackson-core"
implementation 'com.google.protobuf:protobuf-java:3.25.0'

}

sourceSets {
main {
java {
srcDirs = ['./']
}
}
}
Binary file added workers/java/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions workers/java/gradle/wrapper/gradle-wrapper.properties
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.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 789df24

Please sign in to comment.