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

Fix schemaretriever #164

Merged
merged 2 commits into from
Jun 10, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/snyk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- master
- dev

jobs:
security:
Expand Down
12 changes: 6 additions & 6 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ object Versions {
}

const val java = 17
const val slf4j = "2.0.9"
const val confluent = "7.5.0"
const val kafka = "7.5.0-ce"
const val slf4j = "2.0.13"
const val confluent = "7.6.0"
const val kafka = "${confluent}-ce"
const val avro = "1.11.3"
const val jackson = "2.15.2"
const val okhttp = "4.11.0"
const val jackson = "2.15.3"
const val okhttp = "4.12.0"
const val junit = "5.10.0"
const val mockito = "5.5.0"
const val mockitoKotlin = "5.1.0"
const val hamcrest = "2.2"
const val radarSchemas = "0.8.4"
const val radarSchemas = "0.8.8"
const val opencsv = "5.8"
const val ktor = "2.3.4"
const val coroutines = "1.7.3"
Expand Down
15 changes: 7 additions & 8 deletions radar-commons-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,17 @@ object Versions {
}

const val java = 17
const val slf4j = "2.0.9"
const val confluent = "7.5.0"
const val kafka = "7.5.0-ce"
const val slf4j = "2.0.13"
const val confluent = "7.6.0"
const val kafka = "${confluent}-ce"
const val avro = "1.11.3"
const val jackson = "2.15.2"
const val okhttp = "4.11.0"
const val junit = "5.10.0"
const val jackson = "2.15.3"
const val okhttp = "4.12.0"
const val junit = "5.10.3"
const val mockito = "5.5.0"
const val mockitoKotlin = "5.1.0"
const val hamcrest = "2.2"
const val radarSchemas = "0.8.4"
const val radarSchemas = "0.8.8"
const val opencsv = "5.8"
const val ktor = "2.3.4"
const val coroutines = "1.7.3"
Expand All @@ -210,4 +210,3 @@ object Versions {
const val gradleVersionsPlugin = "0.50.0"
const val ktlint = "12.0.3"
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package org.radarbase.producer.schema

import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.plugins.auth.*
import io.ktor.client.plugins.auth.providers.*
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.defaultRequest
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.accept
import io.ktor.client.request.request
import io.ktor.client.request.setBody
import io.ktor.client.request.url
import io.ktor.client.request.*
import io.ktor.http.ContentType
import io.ktor.http.HttpMethod
import io.ktor.http.contentType
Expand All @@ -21,13 +18,15 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import org.apache.avro.Schema
import org.radarbase.producer.rest.RestException.Companion.toRestException
import org.slf4j.LoggerFactory
import java.io.IOException
import java.net.URI
import kotlin.coroutines.CoroutineContext

/** REST client for Confluent schema registry. */
class SchemaRestClient(
httpClient: HttpClient,
baseUrl: String,
private val baseUrl: String,
private val ioContext: CoroutineContext = Dispatchers.IO,
) {
private val httpClient: HttpClient = httpClient.config {
Expand All @@ -39,10 +38,6 @@ class SchemaRestClient(
},
)
}
defaultRequest {
url(baseUrl)
accept(ContentType.Application.Json)
}
}

suspend inline fun <reified T> request(
Expand Down Expand Up @@ -88,7 +83,7 @@ class SchemaRestClient(
@Throws(IOException::class)
suspend fun schemaGet(path: String): SchemaMetadata = request {
method = HttpMethod.Get
url(path)
url(URI(baseUrl).resolve(path).toString())
}

@Throws(IOException::class)
Expand All @@ -97,7 +92,7 @@ class SchemaRestClient(
schema: Schema,
): SchemaMetadata = request {
method = HttpMethod.Post
url(path)
url(URI(baseUrl).resolve(path).toString())
contentType(ContentType.Application.Json)
setBody(SchemaMetadata(schema = schema.toString()))
}
Expand Down Expand Up @@ -132,4 +127,8 @@ class SchemaRestClient(
schemaGet("/schemas/ids/$id")
.toParsedSchemaMetadata(id)
.schema

companion object {
private val logger = LoggerFactory.getLogger(SchemaRestClient::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ open class SchemaRetriever(config: Config) {
@RadarProducerDsl
class Config(
val baseUrl: String,
var httpClient: HttpClient? = null,
) {
var httpClient: HttpClient? = null
var schemaTimeout: CacheConfig = DEFAULT_SCHEMA_TIMEOUT_CONFIG
var ioContext: CoroutineContext = Dispatchers.IO
fun httpClient(config: HttpClientConfig<*>.() -> Unit) {
Expand Down
Loading