You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by au...@apache.org on 2022/08/10 17:23:54 UTC

[beam-starter-kotlin] branch main updated: Initial commit (#1)

This is an automated email from the ASF dual-hosted git repository.

austin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/beam-starter-kotlin.git


The following commit(s) were added to refs/heads/main by this push:
     new f933be2  Initial commit (#1)
f933be2 is described below

commit f933be2d53f085daef74de818119fbf33dcbdc02
Author: David Cavazos <dc...@google.com>
AuthorDate: Wed Aug 10 10:23:50 2022 -0700

    Initial commit (#1)
    
    * initial commit
---
 .github/PULL_REQUEST_TEMPLATE.md            | 12 +++++
 .github/dependabot.yml                      | 19 +++++++
 .github/workflows/test.yaml                 | 25 +++++++++
 .gitignore                                  | 12 +++++
 CONTRIBUTING.md                             | 69 ++++++++++++++++++++++++
 LICENSE                                     | 37 ++++++++++++-
 NOTICE                                      |  5 ++
 README.md                                   | 81 +++++++++++++++++++++++++++++
 app/build.gradle.kts                        | 48 +++++++++++++++++
 app/src/main/kotlin/beam/starter/App.kt     | 43 +++++++++++++++
 app/src/test/kotlin/beam/starter/AppTest.kt | 28 ++++++++++
 settings.gradle.kts                         | 11 ++++
 12 files changed, 389 insertions(+), 1 deletion(-)

diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 0000000..50a629d
--- /dev/null
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,12 @@
+**Please** add a meaningful description for your change here
+
+------------------------
+
+Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
+
+ - [ ] I agree that my contributions are licensed with both [Apache ASL2](../../LICENSE-APACHE) and [MIT](../../LICENSE-MIT).
+ - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
+ - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
+ - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
+
+See the [`CONTRIBUTING.md`](../../CONTRIBUTING.md) guide for more information.
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..d53722f
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,19 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+version: 2
+updates:
+  - package-ecosystem: "gradle"
+    directory: "/"
+    schedule:
+      interval: "daily"
+
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "daily"
diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
new file mode 100644
index 0000000..0cf14e4
--- /dev/null
+++ b/.github/workflows/test.yaml
@@ -0,0 +1,25 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+# option. This file may not be copied, modified, or distributed
+# except according to those terms.
+
+name: Test
+
+on: [push, pull_request]
+
+jobs:
+  Gradle:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v3
+    - uses: actions/setup-java@v3
+      with:
+        distribution: 'temurin'
+        java-version: '17'
+        cache: 'gradle'
+    - run: gradle assemble --info
+    - run: gradle test --info
+    - run: java -jar app/build/pipeline.jar --inputText="🎉"
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1cdbe8c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+# Build directories
+bin/
+build/
+
+# IDEs
+.classpath
+.project
+.settings/
+.vscode/
+
+# Gradle
+.gradle/
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..3dd8773
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,69 @@
+# Contributing
+
+🎉🎊 Thanks for taking the time to contribute! 🎉🎊
+
+There are many ways to contribute, here are some.
+
+## Filing an issue
+
+If there's any issue you encounter or anything that needs to be fixed, feel free to [create a GitHub issue](https://github.com/apache/beam-starter-kotlin/issues).
+
+## Contributing to this starter project
+
+If this is your first time contributing to a GitHub repo,
+we recommmend going through the
+[GitHub quickstart](https://docs.github.com/en/get-started/quickstart/hello-world).
+
+It's a good idea to discuss your plans with the Beam community through the dev@beam.apache.org mailing list before doing any changes.
+
+Here's a small overview of the process.
+
+1. [Fork the repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo).
+
+1. Clone the repo.
+
+    ```sh
+    export GITHUB_USERNAME="my-github-username"
+
+    git clone git@github.com:$GITHUB_USERNAME/beam-starter-kotlin.git
+    ```
+
+1. Set the [upstream remote branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/configuring-a-remote-for-a-fork).
+
+    ```sh
+    cd beam-starter-kotlin
+    git remote add upstream git@github.com:apache/beam-starter-kotlin.git
+    ```
+
+1. Create and change to a new branch.
+
+    ```sh
+    git checkout -B my-branch-name
+    ```
+
+1. Modify the code! 😱
+
+1. Run the tests. For steps on how to run them see the [`README.md`](README.md).
+
+1. Commit and push your changes to your branch in `origin`.
+
+    ```sh
+    git commit -m "one line description of your changes"
+    git push
+    ```
+
+1. [Create a Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
+
+1. Add reviewers, and [address review comments](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests).
+
+1. Once it's approved, we can merge the Pull Request.
+
+For more information about proposing changes to a GitHub repository, see the
+[Propose changes](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches)
+page in the GitHub docs.
+
+## Contributing to Apache Beam
+
+For information on how to contribute to
+[Apache Beam](https://github.com/apache/beam), see to the
+[Contribution guide](https://beam.apache.org/contribute/).
diff --git a/LICENSE b/LICENSE
index 261eeb9..c7e6385 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,3 +1,38 @@
+This software is distributed under the terms of both the MIT license and the
+Apache License (Version 2.0).
+
+
+MIT license
+
+Copyright 2022 Google LLC
+
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+
+Apache 2 license
+
                                  Apache License
                            Version 2.0, January 2004
                         http://www.apache.org/licenses/
@@ -198,4 +233,4 @@
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
-   limitations under the License.
+   limitations under the License.
\ No newline at end of file
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..454af2e
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Beam
+Copyright [2022-] The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..23f48f7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,81 @@
+# Apache Beam starter for Kotlin
+
+If you want to clone this repository to start your own project,
+you can choose the license you prefer and feel free to delete anything related to the license you are dropping.
+
+## Before you begin
+
+Make sure you have a [Java](https://en.wikipedia.org/wiki/Java_%28programming_language%29) development environment ready with
+[Gradle](https://gradle.org).
+If you don't, an easy way to install it is with [`sdkman`](https://sdkman.io).
+
+```sh
+# Install sdkman.
+curl -s "https://get.sdkman.io" | bash
+
+# Make sure you have Java 17 and Gradle installed.
+sdk install java 17.0.3-tem
+sdk install gradle
+```
+
+## Source file structure
+
+This is a very basic Apache Beam project to help you get started.
+
+There are only two source files:
+
+* [`app/src/main/kotlin/beam/starter/App.kt`](app/src/main/kotlin/beam/starter/App.kt): the application source file, containing the [`main` function](https://kotlinlang.org/docs/basic-syntax.html#program-entry-point).
+* [`app/src/test/kotlin/beam/starter/AppTest.kt`](app/src/test/kotlin/beam/starter/AppTest.kt): tests for the `App.kt` file.
+
+### Running the pipeline
+
+You can run your pipeline with Gradle.
+
+```sh
+# To do a simple run.
+gradle run
+
+# To run passing command line arguments.
+gradle run --args=--inputText="🎉"
+
+# To run the tests.
+gradle test --info
+```
+
+To build a self-contained jar file, we need to configure the [`jar`](https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html) task in the [`build.gradle`](build.gradle) file.
+
+```sh
+# Build a self-contained jar.
+gradle jar
+
+# Run the jar application.
+java -jar app/build/pipeline.jar --inputText="🎉"
+```
+
+## GitHub Actions automated testing
+
+This project already comes with automated testing via [GitHub Actions](https://github.com/features/actions).
+
+To configure it, look at the [`.github/workflows/test.yaml`](.github/workflows/test.yaml) file.
+
+## Using other runners
+
+To keep this template small, it only includes the [Direct Runner](https://beam.apache.org/documentation/runners/direct/).
+
+For a comparison of what each runner currently supports, look at the [Beam Capability Matrix](https://beam.apache.org/documentation/runners/capability-matrix/).
+
+To add a new runner, visit the runner's page for instructions on how to include it.
+
+## Contributing
+
+Thank you for your interest in contributing!
+All contributions are welcome! 🎉🎊
+
+Please refer to the [`CONTRIBUTING.md`](CONTRIBUTING.md) file for more information.
+
+# License
+
+This software is distributed under the terms of both the MIT license and the
+Apache License (Version 2.0).
+
+See [LICENSE](LICENSE) for details.
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
new file mode 100644
index 0000000..ee3e27c
--- /dev/null
+++ b/app/build.gradle.kts
@@ -0,0 +1,48 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ *
+ * This generated file contains a sample Kotlin application project to get you started.
+ * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
+ * User Manual available at https://docs.gradle.org/7.2/userguide/building_java_projects.html
+ */
+
+plugins {
+    application
+    id("org.jetbrains.kotlin.jvm") version "1.7.10"
+}
+
+repositories { mavenCentral() }
+
+val beamVersion = "2.40.0"
+
+dependencies {
+    // Kotlin dependencies.
+    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
+    implementation("org.jetbrains.kotlin:kotlin-stdlib")
+
+    // App dependencies.
+    implementation("org.apache.beam:beam-sdks-java-core:${beamVersion}")
+    implementation("org.apache.beam:beam-runners-direct-java:${beamVersion}")
+    implementation("org.slf4j:slf4j-jdk14:1.7.36")
+
+    // Test dependencies.
+    testImplementation("junit:junit:4.13.2")
+    testImplementation("org.hamcrest:hamcrest:2.2")
+}
+
+application { mainClass.set("beam.starter.AppKt") }
+
+// Test with JUnit 4.
+tasks.test { useJUnit() }
+
+// Package a self-contained jar file.
+tasks.jar {
+    archiveBaseName.set("pipeline")
+    destinationDirectory.set(file("build"))
+    manifest { attributes("Main-Class" to "beam.starter.AppKt") }
+    exclude("META-INF/*.SF")
+    exclude("META-INF/*.DSA")
+    exclude("META-INF/*.RSA")
+    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
+    from({ configurations.runtimeClasspath.get().map(::zipTree) })
+}
diff --git a/app/src/main/kotlin/beam/starter/App.kt b/app/src/main/kotlin/beam/starter/App.kt
new file mode 100644
index 0000000..c54ae17
--- /dev/null
+++ b/app/src/main/kotlin/beam/starter/App.kt
@@ -0,0 +1,43 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+package beam.starter
+
+import org.apache.beam.sdk.Pipeline
+import org.apache.beam.sdk.options.Default
+import org.apache.beam.sdk.options.Description
+import org.apache.beam.sdk.options.PipelineOptions
+import org.apache.beam.sdk.options.PipelineOptionsFactory
+import org.apache.beam.sdk.transforms.Create
+import org.apache.beam.sdk.transforms.MapElements
+import org.apache.beam.sdk.transforms.SimpleFunction
+import org.apache.beam.sdk.values.PCollection
+
+interface Options : PipelineOptions {
+    @get:Description("Input text to print.")
+    @get:Default.String("My input text")
+    var inputText: String
+}
+
+class PrintElement : SimpleFunction<String, String>() {
+    override fun apply(element: String): String {
+        println(element)
+        return element
+    }
+}
+
+fun buildPipeline(pipeline: Pipeline, inputText: String): PCollection<String> =
+        pipeline.apply("Create elements", Create.of("Hello", "World!", inputText))
+                .apply("Print elements", MapElements.via(PrintElement()))
+
+fun main(args: Array<String>) {
+    val options = PipelineOptionsFactory.fromArgs(*args).withValidation().`as`(Options::class.java)
+    val pipeline = Pipeline.create(options)
+    buildPipeline(pipeline, options.inputText)
+    pipeline.run().waitUntilFinish()
+}
diff --git a/app/src/test/kotlin/beam/starter/AppTest.kt b/app/src/test/kotlin/beam/starter/AppTest.kt
new file mode 100644
index 0000000..43f2f65
--- /dev/null
+++ b/app/src/test/kotlin/beam/starter/AppTest.kt
@@ -0,0 +1,28 @@
+// Copyright 2022 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+package beam.starter
+
+import org.apache.beam.sdk.testing.PAssert
+import org.apache.beam.sdk.testing.TestPipeline
+import org.junit.Rule
+import org.junit.Test
+
+class AppTest {
+    @Transient val pipeline = TestPipeline.create()
+    @Rule fun pipelineRule() = pipeline
+
+    @Test
+    fun appHasAGreeting() {
+        val elements = buildPipeline(pipeline, "Test")
+
+        // Note that the order of the elements doesn't matter.
+        PAssert.that(elements).containsInAnyOrder("Test", "Hello", "World!")
+        pipeline.run().waitUntilFinish()
+    }
+}
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..503eeed
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,11 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ *
+ * The settings file is used to specify which projects to include in your build.
+ *
+ * Detailed information about configuring a multi-project build in Gradle can be found
+ * in the user manual at https://docs.gradle.org/7.2/userguide/multi_project_builds.html
+ */
+
+rootProject.name = "beam-starter-kotlin"
+include("app")