From 894a79f448e11dd8e8244eeec338a6eb4068d207 Mon Sep 17 00:00:00 2001 From: Julian Goede Date: Wed, 7 Jun 2023 20:17:47 +0200 Subject: [PATCH] added debug logging --- .../META-INF/native-image/reflect-config.json | 128 ------------------ .../META-INF/native-image/reflect-conf.json | 45 +++--- .../kirc/impl/JacksonDeserializer.kt | 23 +++- ...pendingContainerImageRegistryClientImpl.kt | 18 +-- .../META-INF/native-image/reflect-config.json | 70 ++++++++++ 5 files changed, 110 insertions(+), 174 deletions(-) create mode 100644 kirc-suspending/src/main/resources/META-INF/native-image/reflect-config.json diff --git a/kirc-core/src/main/resources/META-INF/native-image/reflect-config.json b/kirc-core/src/main/resources/META-INF/native-image/reflect-config.json index c8ff10c..1d00a8d 100644 --- a/kirc-core/src/main/resources/META-INF/native-image/reflect-config.json +++ b/kirc-core/src/main/resources/META-INF/native-image/reflect-config.json @@ -26,134 +26,6 @@ } ] }, - { - "name": "de.cmdjulian.kirc.image.Digest", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.lang.String" - ] - }, - { - "name": "getSeparator", - "parameterTypes": [] - } - ] - }, - { - "name": "de.cmdjulian.kirc.image.Digest$Companion" - }, - { - "name": "de.cmdjulian.kirc.image.Reference", - "queryAllDeclaredMethods": true - }, - { - "name": "de.cmdjulian.kirc.image.Repository", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.lang.String" - ] - } - ] - }, - { - "name": "de.cmdjulian.kirc.image.Tag", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.lang.String" - ] - }, - { - "name": "getSeparator", - "parameterTypes": [] - } - ] - }, - { - "name": "de.cmdjulian.kirc.image.Tag$Companion" - }, - { - "name": "de.cmdjulian.kirc.impl.ManifestListMixIn", - "queryAllDeclaredMethods": true - }, - { - "name": "de.cmdjulian.kirc.impl.ManifestMixIn", - "queryAllDeclaredMethods": true - }, - { - "name": "de.cmdjulian.kirc.impl.ManifestSingleMixIn", - "queryAllDeclaredMethods": true - }, - { - "name": "de.cmdjulian.kirc.impl.ResponseRetryWithAuthentication", - "methods": [ - { - "name": "resolveTokenAuth", - "parameterTypes": [ - "im.toss.http.parser.HttpAuthCredentials", - "com.github.kittinunf.fuel.core.Request", - "kotlin.coroutines.Continuation" - ] - } - ] - }, - { - "name": "de.cmdjulian.kirc.impl.ResponseRetryWithAuthentication$resolveTokenAuth$TokenResponse", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.lang.String" - ] - } - ] - }, - { - "name": "de.cmdjulian.kirc.impl.response.Catalog", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.util.List" - ] - } - ] - }, - { - "name": "de.cmdjulian.kirc.impl.response.TagList", - "allDeclaredFields": true, - "queryAllDeclaredMethods": true, - "queryAllDeclaredConstructors": true, - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.lang.String", - "java.util.List" - ] - } - ] - }, { "name": "de.cmdjulian.kirc.spec.Architecture", "allDeclaredFields": true, diff --git a/kirc-image/src/main/resources/META-INF/native-image/reflect-conf.json b/kirc-image/src/main/resources/META-INF/native-image/reflect-conf.json index 7d916dd..b4e4d4d 100644 --- a/kirc-image/src/main/resources/META-INF/native-image/reflect-conf.json +++ b/kirc-image/src/main/resources/META-INF/native-image/reflect-conf.json @@ -1,71 +1,62 @@ [ { "name": "de.cmdjulian.kirc.image.Digest", + "allDeclaredFields": true, "queryAllDeclaredMethods": true, "queryAllDeclaredConstructors": true, "methods": [ { - "name": "box-impl", + "name": "", "parameterTypes": [ "java.lang.String" ] }, { - "name": "constructor-impl", - "parameterTypes": [ - "java.lang.String" - ] - }, - { - "name": "unbox-impl", + "name": "getSeparator", "parameterTypes": [] } ] }, + { + "name": "de.cmdjulian.kirc.image.Digest$Companion" + }, { "name": "de.cmdjulian.kirc.image.Repository", + "allDeclaredFields": true, "queryAllDeclaredMethods": true, "queryAllDeclaredConstructors": true, "methods": [ { - "name": "box-impl", - "parameterTypes": [ - "java.lang.String" - ] - }, - { - "name": "constructor-impl", + "name": "", "parameterTypes": [ "java.lang.String" ] - }, - { - "name": "unbox-impl", - "parameterTypes": [] } ] }, { "name": "de.cmdjulian.kirc.image.Tag", + "allDeclaredFields": true, "queryAllDeclaredMethods": true, "queryAllDeclaredConstructors": true, "methods": [ { - "name": "box-impl", - "parameterTypes": [ - "java.lang.String" - ] - }, - { - "name": "constructor-impl", + "name": "", "parameterTypes": [ "java.lang.String" ] }, { - "name": "unbox-impl", + "name": "getSeparator", "parameterTypes": [] } ] + }, + { + "name": "de.cmdjulian.kirc.image.Tag$Companion" + }, + { + "name": "de.cmdjulian.kirc.image.Reference", + "queryAllDeclaredMethods": true } ] \ No newline at end of file diff --git a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/JacksonDeserializer.kt b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/JacksonDeserializer.kt index 7e761d0..d49611f 100644 --- a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/JacksonDeserializer.kt +++ b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/JacksonDeserializer.kt @@ -1,8 +1,25 @@ package de.cmdjulian.kirc.impl -import com.fasterxml.jackson.module.kotlin.readValue import com.github.kittinunf.fuel.core.ResponseDeserializable +import mu.KotlinLogging -internal inline fun jacksonDeserializer() = object : ResponseDeserializable { - override fun deserialize(content: String): T = JsonMapper.readValue(content) +class JacksonDeserializer(private val clazz: Class) : ResponseDeserializable { + + private val logger = KotlinLogging.logger { } + + override fun deserialize(content: String): T = try { + JsonMapper.readValue(content, clazz) + } catch (e: Exception) { + logger.error(e) { "unexpected error on json deserialization" } + throw e + } + + override fun deserialize(bytes: ByteArray): T = try { + JsonMapper.readValue(bytes, clazz) + } catch (e: Exception) { + logger.error(e) { "unexpected error on json deserialization" } + throw e + } } + +internal inline fun jacksonDeserializer() = JacksonDeserializer(T::class.java) diff --git a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/SuspendingContainerImageRegistryClientImpl.kt b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/SuspendingContainerImageRegistryClientImpl.kt index bff072c..6a29abf 100644 --- a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/SuspendingContainerImageRegistryClientImpl.kt +++ b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/impl/SuspendingContainerImageRegistryClientImpl.kt @@ -24,21 +24,16 @@ import de.cmdjulian.kirc.impl.response.Catalog import de.cmdjulian.kirc.impl.response.TagList import de.cmdjulian.kirc.spec.image.DockerImageConfigV1 import de.cmdjulian.kirc.spec.image.ImageConfig -import de.cmdjulian.kirc.spec.image.OciImageConfigV1 import de.cmdjulian.kirc.spec.manifest.DockerManifestV2 import de.cmdjulian.kirc.spec.manifest.Manifest import de.cmdjulian.kirc.spec.manifest.ManifestSingle import de.cmdjulian.kirc.spec.manifest.OciManifestV1 -import mu.KotlinLogging internal class SuspendingContainerImageRegistryClientImpl(private val api: ContainerRegistryApi) : SuspendingContainerImageRegistryClient { - private val logger = KotlinLogging.logger { } - override suspend fun testConnection() { api.ping().onError { - logger.trace(it) { "error on ping" } throw it.toRegistryClientError() } } @@ -46,56 +41,47 @@ internal class SuspendingContainerImageRegistryClientImpl(private val api: Conta override suspend fun repositories(limit: Int?, last: Int?): List = api.repositories(limit, last) .map(Catalog::repositories) - .onError { logger.trace(it) { "error on repositories retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun tags(repository: Repository, limit: Int?, last: Int?): List = api.tags(repository, limit, last) .map(TagList::tags) - .onError { logger.trace(it) { "error on tags retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun exists(repository: Repository, reference: Reference): Boolean = api.digest(repository, reference) .map { true } - .onError { logger.trace(it) { "error on exists" } } .getOrElse { if (it.response.statusCode == 404) false else throw it.toRegistryClientError() } override suspend fun manifest(repository: Repository, reference: Reference): Manifest = api.manifests(repository, reference) - .onError { logger.trace(it) { "error on manifest retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun manifestDelete(repository: Repository, reference: Reference): Digest = api.deleteManifest(repository, reference) - .onError { logger.trace(it) { "error on delete manifest" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun manifestDigest(repository: Repository, reference: Reference): Digest = api.digest(repository, reference) - .onError { logger.trace(it) { "error on manifest digest retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun blob(repository: Repository, digest: Digest): ByteArray = api.blob(repository, digest) - .onError { logger.trace(it) { "error on blob retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun config(repository: Repository, reference: Reference): ImageConfig = api.manifest(repository, reference) .map { config(repository, it) } - .onError { logger.trace(it) { "error on image config retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun config(repository: Repository, manifest: ManifestSingle): ImageConfig = api.blob(repository, manifest.config.digest) .map { config -> when (manifest) { - is DockerManifestV2 -> JsonMapper.readValue(config) - is OciManifestV1 -> JsonMapper.readValue(config) + is DockerManifestV2 -> jacksonDeserializer().deserialize(config) + is OciManifestV1 -> jacksonDeserializer().deserialize(config) } } - .onError { logger.trace(it) { "error on image config retrieve" } } .getOrElse { throw it.toRegistryClientError() } override suspend fun toImageClient(repository: Repository, reference: Reference): SuspendingContainerImageClient = diff --git a/kirc-suspending/src/main/resources/META-INF/native-image/reflect-config.json b/kirc-suspending/src/main/resources/META-INF/native-image/reflect-config.json new file mode 100644 index 0000000..c0dddd3 --- /dev/null +++ b/kirc-suspending/src/main/resources/META-INF/native-image/reflect-config.json @@ -0,0 +1,70 @@ +[ + { + "name": "de.cmdjulian.kirc.impl.ManifestListMixIn", + "queryAllDeclaredMethods": true + }, + { + "name": "de.cmdjulian.kirc.impl.ManifestMixIn", + "queryAllDeclaredMethods": true + }, + { + "name": "de.cmdjulian.kirc.impl.ManifestSingleMixIn", + "queryAllDeclaredMethods": true + }, + { + "name": "de.cmdjulian.kirc.impl.ResponseRetryWithAuthentication", + "methods": [ + { + "name": "resolveTokenAuth", + "parameterTypes": [ + "im.toss.http.parser.HttpAuthCredentials", + "com.github.kittinunf.fuel.core.Request", + "kotlin.coroutines.Continuation" + ] + } + ] + }, + { + "name": "de.cmdjulian.kirc.impl.ResponseRetryWithAuthentication$resolveTokenAuth$TokenResponse", + "allDeclaredFields": true, + "queryAllDeclaredMethods": true, + "queryAllDeclaredConstructors": true, + "methods": [ + { + "name": "", + "parameterTypes": [ + "java.lang.String" + ] + } + ] + }, + { + "name": "de.cmdjulian.kirc.impl.response.Catalog", + "allDeclaredFields": true, + "queryAllDeclaredMethods": true, + "queryAllDeclaredConstructors": true, + "methods": [ + { + "name": "", + "parameterTypes": [ + "java.util.List" + ] + } + ] + }, + { + "name": "de.cmdjulian.kirc.impl.response.TagList", + "allDeclaredFields": true, + "queryAllDeclaredMethods": true, + "queryAllDeclaredConstructors": true, + "methods": [ + { + "name": "", + "parameterTypes": [ + "java.lang.String", + "java.util.List" + ] + } + ] + } +]