From ee71da09f60089f0c78689bfd44dc992adf8c15b Mon Sep 17 00:00:00 2001 From: Dylan Meissner Date: Sat, 7 Oct 2023 08:16:36 -0700 Subject: [PATCH] Update standard examples --- embedded-example/build.gradle | 9 +---- embedded-example/protocols/build.gradle | 9 ++--- embedded-example/settings.gradle | 44 +++++++++++++++++++++ embedded-example/shopping/build.gradle | 51 ++++++++++++------------- remote-example/Dockerfile | 2 +- remote-example/Dockerfile.flink | 2 +- remote-example/README.md | 4 +- remote-example/requirements.txt | 6 +-- 8 files changed, 81 insertions(+), 46 deletions(-) diff --git a/embedded-example/build.gradle b/embedded-example/build.gradle index 2d860ce..758d698 100644 --- a/embedded-example/build.gradle +++ b/embedded-example/build.gradle @@ -1,14 +1,7 @@ plugins { - id 'org.jetbrains.kotlin.jvm' version "$kotlinVersion" apply false - id "org.jetbrains.kotlin.kapt" version "$kotlinVersion" apply false + id 'java' } allprojects { group 'embedded-example' } - -subprojects { - repositories { - mavenCentral() - } -} diff --git a/embedded-example/protocols/build.gradle b/embedded-example/protocols/build.gradle index 15b4914..3d350ed 100644 --- a/embedded-example/protocols/build.gradle +++ b/embedded-example/protocols/build.gradle @@ -1,18 +1,17 @@ plugins { + id 'idea' id 'java-library' - id 'com.google.protobuf' version "0.8.14" + id 'com.google.protobuf' } -apply plugin: 'idea' - dependencies { - compileOnly "com.google.protobuf:protobuf-java:$protobufVersion" + api libs.protobuf.java } protobuf { protoc { // The artifact spec for the Protobuf Compiler - artifact = "com.google.protobuf:protoc:$protobufVersion" + artifact = libs.protobuf.compiler.get().toString() } generatedFilesBaseDir = "$projectDir/src/generated" diff --git a/embedded-example/settings.gradle b/embedded-example/settings.gradle index 09007ad..af353c4 100644 --- a/embedded-example/settings.gradle +++ b/embedded-example/settings.gradle @@ -1,2 +1,46 @@ +pluginManagement { + plugins { + id 'org.jetbrains.kotlin.jvm' version '1.8.21' + id 'org.jetbrains.kotlin.kapt' version '1.8.21' + id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.21' + id 'com.google.protobuf' version '0.9.3' + id 'com.google.cloud.tools.jib' version '3.3.1' + } + repositories { + gradlePluginPortal() + } +} + +dependencyResolutionManagement { + versionCatalogs { + libs { + version('flink', '1.16.2') + version('protobuf', '3.21.9') + version('statefun', '3.3.0') + version('serialization', '1.3.2') + + library('asciitable', 'de.vandermeer', 'asciitable').version('0.3.2') + library('auto-service', 'com.google.auto.service', 'auto-service').version('1.0-rc6') + library('auto-service-annotations', 'com.google.auto.service', 'auto-service-annotations').version('1.0-rc6') + library('protobuf-compiler', 'com.google.protobuf', 'protoc').versionRef('protobuf') + library('protobuf-java', 'com.google.protobuf', 'protobuf-java').versionRef('protobuf') + library('protobuf-util', 'com.google.protobuf', 'protobuf-java-util').versionRef('protobuf') + library('serialization-core', 'org.jetbrains.kotlinx', 'kotlinx-serialization-core').versionRef('serialization') + library('serialization-json', 'org.jetbrains.kotlinx', 'kotlinx-serialization-json').versionRef('serialization') + library('statefun-distribution', 'org.apache.flink', 'statefun-flink-distribution').versionRef('statefun') + library('statefun-sdk', 'org.apache.flink', 'statefun-sdk-java').versionRef('statefun') + library('statefun-harness', 'org.apache.flink', 'statefun-flink-harness').versionRef('statefun') + library('slf4j-api', 'org.slf4j', 'slf4j-api').version('1.7.36') + library('slf4j-impl', 'org.apache.logging.log4j', 'log4j-slf4j-impl').version('2.17.2') + + bundle('serialization', ['serialization-core', 'serialization-json']) + bundle('protobuf', ['protobuf-java', 'protobuf-util']) + } + } + repositories { + mavenCentral() + } +} + rootProject.name = 'example' include 'protocols', 'shopping' diff --git a/embedded-example/shopping/build.gradle b/embedded-example/shopping/build.gradle index d7f28fb..1ec79a0 100644 --- a/embedded-example/shopping/build.gradle +++ b/embedded-example/shopping/build.gradle @@ -1,17 +1,25 @@ plugins { id 'application' - id "com.google.cloud.tools.jib" version "$jibVersion" - id "org.jetbrains.kotlin.plugin.serialization" version "$kotlinVersion" + id 'org.jetbrains.kotlin.jvm' + id 'org.jetbrains.kotlin.kapt' + id 'com.google.cloud.tools.jib' + id 'org.jetbrains.kotlin.plugin.serialization' } -apply plugin: 'idea' -apply plugin: 'kotlin' -apply plugin: "kotlin-kapt" - archivesBaseName = 'statefun-shopping' mainClassName = 'shopping.Harness' //mainClassName = 'org.apache.flink.statefun.flink.core.StatefulFunctionsJob' +java { + toolchain { + languageVersion = JavaLanguageVersion.of(11) + } +} + +kapt { + correctErrorTypes = true +} + configurations { provided statefunLib @@ -23,25 +31,22 @@ configurations { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion" + implementation 'org.jetbrains.kotlin:kotlin-stdlib' + implementation libs.bundles.serialization implementation project(':protocols') - implementation "de.vandermeer:asciitable:0.3.2" - - provided "com.google.protobuf:protobuf-java:$protobufVersion" - provided "com.google.protobuf:protobuf-java-util:$protobufVersion" - provided "org.apache.flink:statefun-sdk-java:$statefunVersion" - provided "org.apache.flink:statefun-flink-harness:$statefunVersion" + implementation libs.asciitable - provided 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2' - provided 'org.slf4j:slf4j-api:1.7.36' + provided libs.bundles.protobuf + provided libs.statefun.sdk + provided libs.statefun.harness + provided libs.slf4j.api + provided libs.slf4j.impl - compileOnly "com.google.auto.service:auto-service-annotations:1.0-rc6" - kapt "com.google.auto.service:auto-service:1.0-rc6" + kapt libs.auto.service + compileOnly libs.auto.service.annotations - statefunLib "org.apache.flink:statefun-flink-distribution:$statefunVersion" + statefunLib libs.statefun.distribution } sourceSets { @@ -56,12 +61,6 @@ sourceSets { } } -java { - toolchain { - languageVersion = JavaLanguageVersion.of(11) - } -} - run { applicationDefaultJvmArgs = [ "-Dlog4j2.configurationFile=log4j2.properties", diff --git a/remote-example/Dockerfile b/remote-example/Dockerfile index 03b8ffe..8358ced 100644 --- a/remote-example/Dockerfile +++ b/remote-example/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9-slim-buster +FROM python:3.11-slim-buster RUN mkdir -p /app WORKDIR /app diff --git a/remote-example/Dockerfile.flink b/remote-example/Dockerfile.flink index 9d11490..7a209ac 100644 --- a/remote-example/Dockerfile.flink +++ b/remote-example/Dockerfile.flink @@ -1,4 +1,4 @@ -FROM apache/flink-statefun:3.2.0-java11 +FROM apache/flink-statefun:3.3.0-java11 RUN mkdir -p /opt/statefun/modules/shopping ADD module.yaml /opt/statefun/modules/shopping diff --git a/remote-example/README.md b/remote-example/README.md index 608512a..36388f0 100644 --- a/remote-example/README.md +++ b/remote-example/README.md @@ -1,6 +1,6 @@ # Remote statefun example -Similar to the classic [shopping-cart](https://github.com/apache/flink-statefun-playground/tree/release-3.2) example, this example demonstrates two "statefun" functions: +Similar to the classic [shopping-cart](https://github.com/apache/flink-statefun-playground/tree/release-3.3) example, this example demonstrates two "statefun" functions: - `shopping/basket` represent users' shopping baskets - `shopping/supply` represents a finite supply of products @@ -15,7 +15,7 @@ Build the Flink images defined in the `docker-compose.yaml` file: `docker-compos Run the function and the accompanying Flink cluster: `docker-compose up`. _If the Kafka broker appears to crash, run `docker-compose restart kafka-broker` or restart this step._ Now we have our Flink Stateful function running, but we don't have any state. We'll use `harness.py` to create and interact with our `supply` data. -- Install a few requirements: `pip3 install beautifultable pluralizer` +- Install a few requirements: `pip3 install beautifultable kafka-python pluralizer` - In a new shell, run `python3 harness.py restock` to add to our supply of products. - In a new shell, run `python3 harness.py add-to-basket` to take from our supply of products. - In a new shell, run `python3 harness.py print-supply` to show a live-feed of changes to our supply of products. diff --git a/remote-example/requirements.txt b/remote-example/requirements.txt index 293f84e..cb8088a 100644 --- a/remote-example/requirements.txt +++ b/remote-example/requirements.txt @@ -1,7 +1,7 @@ aiohttp -flask==1.1.2 -gunicorn==20.0.4 -apache-flink-statefun==3.2.0 +flask==2.3.3 +gunicorn==21.2.0 +apache-flink-statefun==3.3.0 pluralizer==1.1.0 kafka-python==2.0.2 beautifultable