From e277db10d09c17dc275795725b88cb384859aa8c Mon Sep 17 00:00:00 2001 From: Roman Zabaluev Date: Fri, 29 Mar 2024 03:04:16 +0700 Subject: [PATCH] Fix init (#1) --- .github/release_drafter.yaml | 47 +++++++++++++++++++ .github/workflows/pr.yaml | 28 +++++++++++ .github/workflows/release.yaml | 6 +-- .github/workflows/release_drafter.yml | 19 ++++++++ .gitignore | 43 ++++++++++++++++- README.md | 2 +- docker-compose/setup-example.yaml | 8 ++-- pom.xml | 16 ++++--- .../kafbat/serde}/smile/SmileSerde.java | 45 ++++++++---------- .../kafbat/serde}/smile/SmileSerdeTest.java | 11 +++-- 10 files changed, 179 insertions(+), 46 deletions(-) create mode 100644 .github/release_drafter.yaml create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/release_drafter.yml rename src/main/java/{com/provectus/kafka/ui/serdes => io/kafbat/serde}/smile/SmileSerde.java (62%) rename src/test/java/{com/provectus/kafka/ui/serdes => io/kafbat/serde}/smile/SmileSerdeTest.java (94%) diff --git a/.github/release_drafter.yaml b/.github/release_drafter.yaml new file mode 100644 index 0000000..9e2f5d0 --- /dev/null +++ b/.github/release_drafter.yaml @@ -0,0 +1,47 @@ +name-template: '$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +template: | + ## Changes + $CHANGES + ## Contributors + $CONTRIBUTORS + +exclude-labels: + - 'scope/infrastructure' + - 'scope/QA' + - 'scope/AQA' + - 'type/dependencies' + - 'type/chore' + - 'type/documentation' + - 'type/refactoring' + +categories: + - title: '⚙️Features' + labels: + - 'type/feature' + - title: '🪛Enhancements' + labels: + - 'type/enhancement' + - title: '🔨Bug Fixes' + labels: + - 'type/bug' + - title: 'Security' + labels: + - 'type/security' + - title: '⎈ Helm/K8S Changes' + labels: + - 'scope/k8s' + +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' + +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: patch \ No newline at end of file diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..ff991ca --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,28 @@ +name: Pull Request Build + +on: + + pull_request: + types: [ "opened", "reopened", "synchronize", ] + +jobs: + release: + runs-on: ubuntu-latest + outputs: + version: ${{steps.build.outputs.version}} + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'zulu' + cache: 'maven' + + - name: Build with Maven + id: build + run: | + mvn -B -V -ntp clean package diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6c3b5b7..370ef61 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -36,11 +36,11 @@ jobs: uses: svenstaro/upload-release-action@2.3.0 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: target/kafka-ui-smile-serde-${{ steps.build.outputs.version }}-jar-with-dependencies.jar + file: target/serde-smile-${{ steps.build.outputs.version }}-jar-with-dependencies.jar tag: ${{ github.event.release.tag_name }} - name: Archive JAR uses: actions/upload-artifact@v3 with: - name: kafka-ui-smile-serde-${{ steps.build.outputs.version }} - path: target/kafka-ui-smile-serde-${{ steps.build.outputs.version }}-jar-with-dependencies.jar + name: serde-smile-${{ steps.build.outputs.version }}.jar + path: target/serde-smile-${{ steps.build.outputs.version }}-jar-with-dependencies.jar diff --git a/.github/workflows/release_drafter.yml b/.github/workflows/release_drafter.yml new file mode 100644 index 0000000..f9fafba --- /dev/null +++ b/.github/workflows/release_drafter.yml @@ -0,0 +1,19 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - main + workflow_dispatch: + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + with: + config-name: release_drafter.yaml + disable-autolabeler: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a1c2a23..b2a7af8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,44 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/** +!**/src/test/** + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ + +### VS Code ### +.vscode/ +/kafka-ui-api/app/node + +.DS_Store +*.code-workspace + + +*.tar.gz +*.tgz + +/docker/*.override.yaml +======= # Compiled class file *.class @@ -20,4 +61,4 @@ *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* +hs_err_pid* \ No newline at end of file diff --git a/README.md b/README.md index 3a824be..cb52738 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Smile serde plugin for kafka-ui -This is sample pluggable serde implementation for [kafka-ui](https://github.com/provectus/kafka-ui/). +This is sample pluggable serde implementation for [kafka-ui](https://github.com/kafbat/kafka-ui/). This serde uses [Jackson library](https://github.com/FasterXML/jackson-dataformats-binary) as a [Smile](https://github.com/FasterXML/smile-format-specification) format parser/generator implementation. diff --git a/docker-compose/setup-example.yaml b/docker-compose/setup-example.yaml index fb1a119..366b9b4 100644 --- a/docker-compose/setup-example.yaml +++ b/docker-compose/setup-example.yaml @@ -4,7 +4,7 @@ services: kafka-ui: container_name: kafka-ui - image: provectuslabs/kafka-ui:latest + image: ghcr.io/kafbat/kafka-ui:latest ports: - 8080:8080 depends_on: @@ -16,11 +16,11 @@ services: kafka.clusters.0.serde.0.name: Smile (Default) kafka.clusters.0.serde.0.filePath: /smile-serde/kafka-ui-smile-serde-0.0.1-SNAPSHOT-jar-with-dependencies.jar - kafka.clusters.0.serde.0.className: com.provectus.kafka.ui.serdes.smile.SmileSerde + kafka.clusters.0.serde.0.className: io.kafbat.serde.smile.SmileSerde kafka.clusters.0.serde.1.name: Smile (Without header) kafka.clusters.0.serde.1.filePath: /smile-serde/kafka-ui-smile-serde-0.0.1-SNAPSHOT-jar-with-dependencies.jar - kafka.clusters.0.serde.1.className: com.provectus.kafka.ui.serdes.smile.SmileSerde + kafka.clusters.0.serde.1.className: io.kafbat.serde.smile.SmileSerde # you can enable/disable parsers's and generator's features: kafka.clusters.0.serde.1.properties.generator.WRITE_HEADER: "false" kafka.clusters.0.serde.1.properties.parser.REQUIRE_HEADER: "false" @@ -28,7 +28,7 @@ services: # you can also use upper-cased variables like that: # KAFKA_CLUSTERS_0_SERDE_1_NAME: Smile # KAFKA_CLUSTERS_0_SERDE_1_FILE_PATH: /smile-serde -# KAFKA_CLUSTERS_0_SERDE_1_CLASS_NAME: com.provectus.kafka.ui.serdes.smile.SmileSerde +# KAFKA_CLUSTERS_0_SERDE_1_CLASS_NAME: io.kafbat.serde.smile.SmileSerde # KAFKA_CLUSTERS_0_SERDE_1_PROPERTIES_PARSER_REQUIRE_HEADER: "false" # KAFKA_CLUSTERS_0_SERDE_1_PROPERTIES_GENERATOR_WRITE_HEADER: "false" volumes: diff --git a/pom.xml b/pom.xml index 39f520e..23f5bf4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,10 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - com.provectus - 0.0.1-SNAPSHOT 4.0.0 - kafka-ui-smile-serde + + io.kafbat.ui.serde + serde-smile + kafbat-ui-serde-glue + + 1.0-SNAPSHOT jar @@ -17,11 +20,12 @@ - com.provectus - kafka-ui-serde-api - 1.1.0 + io.kafbat.ui + serde-api + 1.0.0 provided + com.fasterxml.jackson.dataformat jackson-dataformat-smile diff --git a/src/main/java/com/provectus/kafka/ui/serdes/smile/SmileSerde.java b/src/main/java/io/kafbat/serde/smile/SmileSerde.java similarity index 62% rename from src/main/java/com/provectus/kafka/ui/serdes/smile/SmileSerde.java rename to src/main/java/io/kafbat/serde/smile/SmileSerde.java index 0a9bbef..7ab2982 100644 --- a/src/main/java/com/provectus/kafka/ui/serdes/smile/SmileSerde.java +++ b/src/main/java/io/kafbat/serde/smile/SmileSerde.java @@ -1,4 +1,4 @@ -package com.provectus.kafka.ui.serdes.smile; +package io.kafbat.serde.smile; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; @@ -7,11 +7,10 @@ import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import com.fasterxml.jackson.dataformat.smile.SmileParser; import com.fasterxml.jackson.dataformat.smile.databind.SmileMapper; -import com.provectus.kafka.ui.serde.api.DeserializeResult; -import com.provectus.kafka.ui.serde.api.PropertyResolver; -import com.provectus.kafka.ui.serde.api.RecordHeaders; -import com.provectus.kafka.ui.serde.api.SchemaDescription; -import com.provectus.kafka.ui.serde.api.Serde; +import io.kafbat.ui.serde.api.DeserializeResult; +import io.kafbat.ui.serde.api.PropertyResolver; +import io.kafbat.ui.serde.api.SchemaDescription; +import io.kafbat.ui.serde.api.Serde; import java.io.IOException; import java.util.Collections; import java.util.Optional; @@ -59,32 +58,26 @@ public boolean canSerialize(String topic, Target target) { @Override public Serializer serializer(String topic, Target target) { - return new Serializer() { - @Override - public byte[] serialize(String inputString) { - try { - JsonNode jsonNode = JSON_MAPPER.readTree(inputString); - return smileMapper.writeValueAsBytes(jsonNode); - } catch (JsonProcessingException e) { - throw new RuntimeException("Serialization error", e); - } + return inputString -> { + try { + JsonNode jsonNode = JSON_MAPPER.readTree(inputString); + return smileMapper.writeValueAsBytes(jsonNode); + } catch (JsonProcessingException e) { + throw new RuntimeException("Serialization error", e); } }; } @Override public Deserializer deserializer(String topic, Target target) { - return new Deserializer() { - @Override - public DeserializeResult deserialize(RecordHeaders recordHeaders, byte[] bytes) { - try { - return new DeserializeResult( - smileMapper.readTree(bytes).toString(), - DeserializeResult.Type.JSON, - Collections.emptyMap()); - } catch (IOException e) { - throw new RuntimeException("Deserialization error", e); - } + return (recordHeaders, bytes) -> { + try { + return new DeserializeResult( + smileMapper.readTree(bytes).toString(), + DeserializeResult.Type.JSON, + Collections.emptyMap()); + } catch (IOException e) { + throw new RuntimeException("Deserialization error", e); } }; } diff --git a/src/test/java/com/provectus/kafka/ui/serdes/smile/SmileSerdeTest.java b/src/test/java/io/kafbat/serde/smile/SmileSerdeTest.java similarity index 94% rename from src/test/java/com/provectus/kafka/ui/serdes/smile/SmileSerdeTest.java rename to src/test/java/io/kafbat/serde/smile/SmileSerdeTest.java index 6c7c67c..1597e03 100644 --- a/src/test/java/com/provectus/kafka/ui/serdes/smile/SmileSerdeTest.java +++ b/src/test/java/io/kafbat/serde/smile/SmileSerdeTest.java @@ -1,18 +1,19 @@ -package com.provectus.kafka.ui.serdes.smile; +package io.kafbat.serde.smile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import com.fasterxml.jackson.dataformat.smile.SmileParser; -import com.provectus.kafka.ui.serde.api.DeserializeResult; -import com.provectus.kafka.ui.serde.api.PropertyResolver; -import com.provectus.kafka.ui.serde.api.Serde; +import io.kafbat.ui.serde.api.DeserializeResult; +import io.kafbat.ui.serde.api.PropertyResolver; +import io.kafbat.ui.serde.api.Serde; import java.util.Map; import java.util.Optional; import org.junit.jupiter.api.BeforeEach;