Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 12 additions & 38 deletions .github/workflows/dev-docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,17 @@ name: Dev build and publish Docker distributions to Github Container Registry gh
on:
push:
branches-ignore:
- master
- version-*
- master
- version-*
- dependabot**
paths-ignore:
- README.md

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
# Prepare custom build version
- name: Get branch name
id: branch
run: echo ::set-output name=branch_name::${GITHUB_REF#refs/*/}
- name: Get release_version
id: ver
uses: christian-draeger/read-properties@1.0.1
with:
path: gradle.properties
property: release_version
- name: Build custom release version
id: release_ver
run: echo ::set-output name=value::"${{ steps.ver.outputs.value }}-${{ steps.branch.outputs.branch_name }}-${{ github.run_id }}"
- name: Show custom release version
run: echo ${{ steps.release_ver.outputs.value }}
# Build and publish image
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- run: echo "::set-output name=REPOSITORY_NAME::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')"
id: meta
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.release_ver.outputs.value }}
labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.ver.outputs.value }}
build-job:
uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main
with:
build-target: 'Docker'
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}
41 changes: 13 additions & 28 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,18 @@ name: Build and publish Docker distributions to Github Container Registry ghcr.i
on:
push:
branches:
- master
- version-*
- master
- version-*
paths:
- gradle.properties
# - package_info.json

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- run: echo "::set-output name=REPOSITORY_NAME::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')"
id: meta
- name: Read version from gradle.properties
id: read_property
uses: christian-draeger/read-properties@1.0.1
with:
path: ./gradle.properties
property: release_version
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/${{ github.repository }}:${{ steps.read_property.outputs.value }}
labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.read_property.outputs.value }}
build-job:
uses: th2-net/.github/.github/workflows/compound-java.yml@main
with:
build-target: 'Docker'
docker-username: ${{ github.actor }}
secrets:
docker-password: ${{ secrets.GITHUB_TOKEN }}

65 changes: 48 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Csv codec (3.2.1)
# Csv codec (4.0.0)
## Description
Designed for decode csv raw messages from csv reader to the parsed messages.
It is based on [th2-codec](https://github.com/th2-net/th2-codec).
You can find additional information [here](https://github.com/th2-net/th2-codec/blob/master/README.md)

## Decoding

The codec decodes each raw message in the received batch.
Each raw message might contains several line in CSV format.
Each raw message might contain several line in CSV format.
If the default header parameter is not set the codec trites the first line from the raw message as a header.
Otherwise, the default header will be used for decoding the rest of data.
Output message type is taken from `th2.csv.override_message_type` property in input message.
If the property missing, the default value (`Csv_Message`) for output message type is used.

If no data was decoded from raw message, the message will be skipped, and an error event will be reported.

**NOTE: the encoding is not supported**.

## Decode Example

Simple example:
Expand Down Expand Up @@ -53,14 +59,15 @@ into
```

## Settings
Csv codec has following parameters:
Csv codec has the following parameters:

```yaml
default-header: [A, B, C]
delimiter: ','
encoding: UTF-8
display-name: CodecCsv
validate-length: true
publish-header: false
```
**default-header** - the default header for this codec. It will be used if no header found in the received batch.

Expand All @@ -71,40 +78,64 @@ validate-length: true
**display-name** - the name to set in the root event sent to the event store. All errors during decoding will be attached to that root event.
The default value for the name is `CodecCsv`.

**validate-length** - check if csv have different count of values against header's count

## Pins

The CSV codec requires at leas one pin with the following attributes:
1. `decode_in` and `subscribe` - to receive raw data.
2. `decode_out` and `publish` - to send decoded data.
**validate-length** - check if csv have different count of values against header's count.

The number of pins with each set of attributes is not limited. **Pins can use filters**.
**publish-header** - set to publish decoded header. The default value is `false`.

## Full configuration example

```yaml
apiVersion: th2.exactpro.com/v1
kind: Th2GenericBox
kind: Th2Box
metadata:
name: codec-csv
spec:
image-name: ghcr.io/th2-net/th2-codec-csv
image-version: 4.0.0
custom-config:
default-header: [A, B, C]
delimiter: ','
encoding: UTF-8
codecSettings:
default-header: [A, B, C]
delimiter: ','
encoding: UTF-8
pins:
# encoder
- name: in_codec_encode
connection-type: mq
attributes: [ 'encoder_in', 'parsed', 'subscribe' ]
- name: out_codec_encode
connection-type: mq
attributes: [ 'encoder_out', 'raw', 'publish' ]
# decoder
- name: in_codec_decode
connection-type: mq
attributes: ['decode_in', 'subscribe', 'group']
attributes: ['decoder_in', 'raw', 'subscribe']
- name: out_codec_decode
connection-type: mq
attributes: ['decode_out', 'publish', 'parsed']
attributes: ['decoder_out', 'parsed', 'publish']
# encoder general (technical)
- name: in_codec_general_encode
connection-type: mq
attributes: ['general_encoder_in', 'parsed', 'subscribe']
- name: out_codec_general_encode
connection-type: mq
attributes: ['general_encoder_out', 'raw', 'publish']
# decoder general (technical)
- name: in_codec_general_decode
connection-type: mq
attributes: ['general_decoder_in', 'raw', 'subscribe']
- name: out_codec_general_decode
connection-type: mq
attributes: ['general_decoder_out', 'parsed', 'publish']
```

## Release notes

### 4.0.0

+ Migrated to `th2-codec` core part. Uses the standard configuration format and pins for th2-codec
+ Updated `bom`: `3.1.0` -> `4.1.0`
+ Updated `common`: `3.37.1` -> `3.44.0`

### 3.2.1

+ fixed: last array-field as simple value
Expand Down
21 changes: 14 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ plugins {
id 'java-library'
id 'application'
id 'com.palantir.docker' version '0.25.0'
id "org.owasp.dependencycheck" version "7.4.4"
}

dependencyCheck {
format='HTML'
}

ext {
Expand Down Expand Up @@ -50,14 +55,16 @@ jar {
}

dependencies {
api platform('com.exactpro.th2:bom:3.1.0')
api platform('com.exactpro.th2:bom:4.1.0')

implementation 'com.exactpro.th2:common:3.37.1'

implementation "org.slf4j:slf4j-log4j12"
implementation "org.slf4j:slf4j-api"
implementation 'com.exactpro.th2:common:3.44.0'
implementation 'com.exactpro.th2:codec:4.7.4'

implementation 'net.sourceforge.javacsv:javacsv:2.0'
implementation 'org.jetbrains:annotations:23.0.0'

compileOnly 'com.google.auto.service:auto-service-annotations:1.0.1'
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'

testImplementation 'org.mockito:mockito-core:3.5.15'
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
Expand All @@ -68,13 +75,13 @@ test {
}

application {
mainClassName 'com.exactpro.th2.codec.csv.Main'
mainClassName 'com.exactpro.th2.codec.MainKt'
}

applicationName = 'service'

distTar {
archiveName "${applicationName}.tar"
archiveFileName.set("${applicationName}.tar")
}

dockerPrepare {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release_version = 3.2.1
release_version = 4.0.0

docker_image_name=
76 changes: 76 additions & 0 deletions src/main/java/com/exactpro/th2/codec/csv/CodecFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2023 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* 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.
*/

package com.exactpro.th2.codec.csv;

import java.io.InputStream;
import java.util.Collections;
import java.util.Set;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.exactpro.th2.codec.api.IPipelineCodec;
import com.exactpro.th2.codec.api.IPipelineCodecContext;
import com.exactpro.th2.codec.api.IPipelineCodecFactory;
import com.exactpro.th2.codec.api.IPipelineCodecSettings;
import com.exactpro.th2.codec.csv.cfg.CsvCodecConfiguration;
import com.google.auto.service.AutoService;

@AutoService(IPipelineCodecFactory.class)
public class CodecFactory implements IPipelineCodecFactory {
public static final String PROTOCOL = "csv";
private static final Set<String> PROTOCOLS = Collections.singleton(PROTOCOL);

@NotNull
@Override
public String getProtocol() {
return PROTOCOL;
}

@NotNull
@Override
public Set<String> getProtocols() {
return PROTOCOLS;
}

@NotNull
@Override
public Class<? extends IPipelineCodecSettings> getSettingsClass() {
return CsvCodecConfiguration.class;
}

@NotNull
@Override
public IPipelineCodec create(@Nullable IPipelineCodecSettings settings) {
if (settings instanceof CsvCodecConfiguration) {
return new CsvCodec((CsvCodecConfiguration)settings);
}
throw new IllegalArgumentException("Unexpected setting type: " + (settings == null ? "null" : settings.getClass()));
}

@Override
public void init(@NotNull IPipelineCodecContext iPipelineCodecContext) {
}

@Override
public void init(@NotNull InputStream inputStream) {
}

@Override
public void close() {
}
}
Loading