Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TH2-5179] Implemented value formatter related to JDBC database type #24

Merged
merged 17 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
9f41f82
[TH2-5179] added FullReadDbOracleIntegrationTest
Nikita-Smirnov-Exactpro Mar 29, 2024
6be0b41
[TH2-5179] Added logic to convert date/time in ISO format to sql Time…
Nikita-Smirnov-Exactpro Apr 1, 2024
7655f67
[TH2-5179] Corrected test
Nikita-Smirnov-Exactpro Apr 1, 2024
b20506a
[TH2-5179] Corrected after review
Nikita-Smirnov-Exactpro Apr 1, 2024
35aaa04
[TH2-5179] Updated README.md
Nikita-Smirnov-Exactpro Apr 1, 2024
597f434
[TH2-5179] Implemented ValueTransformProvider
Nikita-Smirnov-Exactpro Apr 3, 2024
74aa1db
[TH2-5179] Corrected after review
Nikita-Smirnov-Exactpro Apr 3, 2024
7e3589e
[TH2-5179] added oracle-extension module
Nikita-Smirnov-Exactpro Apr 3, 2024
aeaf1c2
[TH2-5179] corrected app build.gradle.kts
Nikita-Smirnov-Exactpro Apr 3, 2024
e3096ac
[TH2-5179] corrected after review
Nikita-Smirnov-Exactpro Apr 3, 2024
9784bd2
Update core/src/test/kotlin/com/exactpro/th2/read/db/app/FullReadDbOr…
Nikita-Smirnov-Exactpro Apr 4, 2024
07f227a
[TH2-5179] corrected after review
Nikita-Smirnov-Exactpro Apr 4, 2024
d2f56df
[TH2-5179] corrected readme
Nikita-Smirnov-Exactpro Apr 4, 2024
09e3a1f
Merge remote-tracking branch 'origin/TH2-5179' into TH2-5179-value-fo…
Nikita-Smirnov-Exactpro Apr 4, 2024
af4c43a
[TH2-5179] corrected workflow
Nikita-Smirnov-Exactpro Apr 4, 2024
f704e92
[TH2-5179] Reduced severity of transformToString method
Nikita-Smirnov-Exactpro Apr 4, 2024
5dc5ad9
Merge remote-tracking branch 'origin/master' into TH2-5179-value-form…
Nikita-Smirnov-Exactpro Apr 8, 2024
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
46 changes: 44 additions & 2 deletions .github/workflows/build-dev-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
app: ${{ steps.filter.outputs.app }}
grpc: ${{ steps.filter.outputs.grpc }}
core: ${{ steps.filter.outputs.core }}
oracle: ${{ steps.filter.outputs.oracle }}
steps:
- uses: actions/checkout@v3
- uses: dorny/paths-filter@v2
Expand All @@ -41,6 +42,8 @@ jobs:
- 'grpc/gradle.properties'
core:
- 'core/gradle.properties'
oracle:
- 'oracle/gradle.properties'
grpc-version:
name: Extract grpc version
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
Expand All @@ -51,6 +54,11 @@ jobs:
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
with:
project-path: app
oracle-version:
name: Extract oracle version
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
with:
project-path: oracle

build-and-publish-grpc-java:
name: Build and publish Java gRPC distributions
Expand Down Expand Up @@ -114,6 +122,32 @@ jobs:
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}

build-and-publish-oracle-extension-java:
name: Build and publish Java oracle extension distributions
runs-on: 'ubuntu-20.04'
needs:
- build-and-publish-core-java
- changes
if: |
always() &&
(needs.changes.outputs.oracle == 'true' || needs.changes.outputs.core == 'true')
steps:
- uses: actions/checkout@v4
- name: Set up JDK 'zulu' '11'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Build with Gradle
run: ./gradlew --info -Pversion_suffix='dev' clean build :read-db-oracle-extension:publish closeAndReleaseSonatypeStagingRepository
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
owasp-scan:
needs:
- build-and-publish-core-java
Expand All @@ -125,12 +159,12 @@ jobs:
publish-docker:
name: Build and publish docker image
needs:
- build-and-publish-core-java
- build-and-publish-oracle-extension-java
- app-version
- changes
if: |
always() &&
(needs.changes.outputs.app == 'true' || needs.changes.outputs.grpc == 'true' || needs.changes.outputs.core == 'true')
(needs.changes.outputs.app == 'true' || needs.changes.outputs.grpc == 'true' || needs.changes.outputs.core == 'true' || needs.changes.outputs.oracle == 'true')
uses: th2-net/.github/.github/workflows/compaund-java-docker-push.yml@main
with:
docker-username: ${{ github.actor }}
Expand Down Expand Up @@ -159,6 +193,14 @@ jobs:
with:
runsOn: ${{ inputs.runsOn }}
tagName: ${{ needs.grpc-version.outputs.version }}-grpc-dev
create-oracle-tag:
if: needs.build-and-publish-oracle-extension-java.result == 'success'&& !cancelled()
name: Create and push oracle extension tag
needs: [ build-and-publish-oracle-extension-java ]
uses: th2-net/.github/.github/workflows/compaund-git-tag-push.yml@main
with:
runsOn: ${{ inputs.runsOn }}
tagName: ${{ needs.oracle-version.outputs.version }}-oracle-dev
create-app-tag:
if: needs.publish-docker.result == 'success' && needs.build-and-publish-core-java.result == 'success' && !cancelled()
name: Create and push app tag
Expand Down
35 changes: 34 additions & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ jobs:
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
with:
project-path: grpc
oracle-version:
name: Extract app version
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
with:
project-path: oracle
app-version:
name: Extract app version
uses: th2-net/.github/.github/workflows/compound-prebuild-java-workflow.yml@main
Expand All @@ -20,6 +25,7 @@ jobs:
app: ${{ steps.filter.outputs.app }}
grpc: ${{ steps.filter.outputs.grpc }}
core: ${{ steps.filter.outputs.core }}
oracle: ${{ steps.filter.outputs.oracle }}
steps:
- uses: dorny/paths-filter@v2
id: filter
Expand All @@ -31,6 +37,8 @@ jobs:
- 'grpc/gradle.properties'
core:
- 'core/gradle.properties'
oracle:
- 'oracle/gradle.properties'
build-and-publish-grpc-java:
name: Build and publish Java gRPC distributions
needs:
Expand Down Expand Up @@ -72,6 +80,22 @@ jobs:
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
build-and-publish-oracle-extension-java:
name: Build and publish Java oracle extension distributions
needs:
- changes
- build-and-publish-core-java
if: ${{ needs.changes.outputs.oracle == 'true' }}
uses: th2-net/.github/.github/workflows/compaund-java-multi-project-build-release.yml@main
with:
projectPath: oracle
release: true
additionalTasks: '["publish"]'
secrets:
sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
owasp-scan:
needs:
- build-and-publish-core-java
Expand All @@ -84,11 +108,12 @@ jobs:
name: Build and publish docker image
if: |
always() &&
(needs.changes.outputs.app == 'true' || needs.changes.outputs.grpc == 'true' || needs.changes.outputs.core == 'true')
(needs.changes.outputs.app == 'true' || needs.changes.outputs.grpc == 'true' || needs.changes.outputs.core == 'true' || needs.changes.outputs.oracle == 'true')
needs:
- build-and-publish-grpc-python
- build-and-publish-grpc-java
- build-and-publish-core-java
- build-and-publish-oracle-extension-java
- app-version
uses: th2-net/.github/.github/workflows/compaund-java-docker-push.yml@main
with:
Expand Down Expand Up @@ -118,6 +143,14 @@ jobs:
with:
runsOn: ${{ inputs.runsOn }}
tagName: ${{ needs.grpc-version.outputs.version }}-grpc
create-oracle-tag:
if: needs.build-and-publish-oracle-extension-java.result == 'success' && !cancelled()
name: Create and push oracle extension tag
needs: [ build-and-publish-oracle-extension-java ]
uses: th2-net/.github/.github/workflows/compaund-git-tag-push.yml@main
with:
runsOn: ${{ inputs.runsOn }}
tagName: ${{ needs.oracle-version.outputs.version }}-oracle
create-app-tag:
if: needs.publish-docker.result == 'success' && needs.build-and-publish-core-java.result == 'success' && !cancelled()
name: Create and push app tag
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/build-sanpshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,19 @@ jobs:
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
build-and-publish-oracle-extension-java:
name: Build and publish Java oracle extension distributions
uses: th2-net/.github/.github/workflows/compaund-java-multi-project-build.yml@main
with:
projectPath: oracle
additionalTasks: '["publish"]'
release: false
secrets:
sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }}
sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }}
sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }}
sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
owasp-scan:
needs:
- build-and-publish-core-java
uses: th2-net/.github/.github/workflows/owasp-gradle-scan.yml@main
with:
multiproject: true
Expand Down
14 changes: 13 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@ configurations.all {
dependencies {
implementation(project(":read-db-core"))

//region Drivers
//region postgresql
runtimeOnly("org.postgresql:postgresql:42.7.3") {
because("prostresql support")
}
//endregion

//region mysql
runtimeOnly("com.mysql:mysql-connector-j:8.3.0") {
because("mysql support")
}
//endregion

//region oracle
runtimeOnly("com.oracle.database.jdbc:ojdbc11:23.3.0.23.09") {
because("oracle support")
}
runtimeOnly(project(":read-db-oracle-extension")) {
because("oracle support")
}
//endregion

//region mssql
runtimeOnly("com.microsoft.sqlserver:mssql-jdbc:12.4.0.jre11") {
because("mssql support")
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("com.exactpro.th2.gradle.publish") version "0.0.4"

kotlin("jvm") version "1.8.22" apply false
kotlin("kapt") version "1.8.22" apply false
id("com.exactpro.th2.gradle.grpc") version "0.0.4" apply false
id("com.exactpro.th2.gradle.component") version "0.0.4" apply false
}
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ dependencies {
testImplementation("io.grpc:grpc-inprocess")

testImplementation("com.exactpro.th2:junit-jupiter-integration:0.0.1")
testImplementation("org.awaitility:awaitility:4.2.1")

testRuntimeOnly("com.mysql:mysql-connector-j:8.3.0") {
because("mysql support")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.exactpro.th2.read.db.core.RowListener
import com.exactpro.th2.read.db.core.TableRow
import com.exactpro.th2.read.db.core.TaskId
import com.exactpro.th2.read.db.core.UpdateListener
import com.exactpro.th2.read.db.core.ValueTransformProvider
import com.exactpro.th2.read.db.core.impl.DataBaseMonitorServiceImpl
import com.exactpro.th2.read.db.core.impl.DataBaseServiceImpl
import com.exactpro.th2.read.db.core.impl.BaseDataSourceProvider
Expand Down Expand Up @@ -210,7 +211,8 @@ class DataBaseReader(
): DataBaseReader {
val sourceProvider: DataSourceProvider = BaseDataSourceProvider(configuration.dataSources)
val queryProvider: QueryProvider = BaseQueryProvider(configuration.queries)
val dataBaseService: DataBaseService = DataBaseServiceImpl(sourceProvider, queryProvider)
val transformProvider: ValueTransformProvider = ValueTransformProvider.create(configuration.dataSources)
val dataBaseService: DataBaseService = DataBaseServiceImpl(sourceProvider, queryProvider, transformProvider)
val hashService: HashService = BaseHashServiceImpl(sourceProvider, queryProvider)
val monitorService: DataBaseMonitorService = DataBaseMonitorServiceImpl(dataBaseService, hashService, clock)
return DataBaseReader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ResourceRegister: AutoCloseable {

}

internal fun setupApp(
fun setupApp(
factory: CommonFactory,
closeResource: (name: String, resource: () -> Unit) -> Unit,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data class QueryId(val id: String)
data class TaskId(val id: String)

data class TableRow(
val columns: Map<String, Any?>,
val columns: Map<String, String?>,
val associatedMessageType: String? = null,
val executionId: Long? = null
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2024 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.read.db.core

import com.exactpro.th2.read.db.core.impl.DefaultValueTransform
import java.net.URI
import java.sql.Connection
import java.util.ServiceLoader.load

/**
* This method transforms an instance of JDBC class to general th2 string format.
* Some vendor's JDBC classes use connection / session parameters (for example time zone of db or session)
* for transformation their instances to general java classes.
*/
typealias ToNullableStringTransformer = (Any?, Connection) -> String?
private typealias ToStringTransformer = (Any, Connection) -> String

class ValueTransformProvider private constructor(
private val transforms: Map<DataSourceId, ToStringTransformer>
) {
fun transformer(dataSourceId: DataSourceId): ToNullableStringTransformer {
val func: ToStringTransformer = transforms[dataSourceId] ?: DEFAULT_TRANSFORM
return { source, connection -> source?.let { func(it, connection) } }
}

companion object {
@JvmField
val DEFAULT_TRANSFORM: ToStringTransformer = DefaultValueTransform.transformToString()

fun create(dataSources: Map<DataSourceId, DataSourceConfiguration>): ValueTransformProvider {
val dbVendorToFactory = load(ValueTransformerFactory::class.java)
.associateBy(ValueTransformerFactory::dbVendor)
return ValueTransformProvider(
dataSources.asSequence().associate { (sourceId, config) ->
sourceId to findTransform(config.url, dbVendorToFactory)
}
)
}

private infix fun (ValueTransform).orTransform(after: ValueTransform): ValueTransform {
return { source, connection ->
when (val result = this(source, connection)) {
is String -> result
else -> after(result, connection)
}
}
}

private fun (ValueTransform).transformToString(): ToStringTransformer =
{ source, connection -> this(source, connection).toString() }

private fun findTransform(url: String, dbTypeToFactory: Map<String, ValueTransformerFactory>): ToStringTransformer {
val dbType = URI.create(url).schemeSpecificPart.split(":").first()
return dbTypeToFactory[dbType]?.let {
(DefaultValueTransform orTransform it.transformer).transformToString()
} ?: DEFAULT_TRANSFORM
}
}
}

operator fun ValueTransformProvider.get(dataSourceId: DataSourceId): ToNullableStringTransformer = transformer(dataSourceId)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Exactpro (Exactpro Systems Limited)
* Copyright 2024 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.
Expand All @@ -14,9 +14,16 @@
* limitations under the License.
*/

package com.exactpro.th2.read.db.containers
package com.exactpro.th2.read.db.core

import org.testcontainers.containers.OracleContainer
import org.testcontainers.utility.DockerImageName
import java.sql.Connection

class OracleContainer : OracleContainer(DockerImageName.parse("gvenzl/oracle-xe:21-slim-faststart"))
typealias ValueTransform = (Any, Connection) -> Any

interface ValueTransformerFactory {
/**
* Holds database vendor of JDBC URI protocol
*/
val dbVendor: String
val transformer: ValueTransform
}
Loading
Loading