Skip to content

Commit

Permalink
added debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdjulian committed Jun 7, 2023
1 parent 004a01e commit 894a79f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 174 deletions.
128 changes: 0 additions & 128 deletions kirc-core/src/main/resources/META-INF/native-image/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,134 +26,6 @@
}
]
},
{
"name": "de.cmdjulian.kirc.image.Digest",
"allDeclaredFields": true,
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"methods": [
{
"name": "<init>",
"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": "<init>",
"parameterTypes": [
"java.lang.String"
]
}
]
},
{
"name": "de.cmdjulian.kirc.image.Tag",
"allDeclaredFields": true,
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"methods": [
{
"name": "<init>",
"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": "<init>",
"parameterTypes": [
"java.lang.String"
]
}
]
},
{
"name": "de.cmdjulian.kirc.impl.response.Catalog",
"allDeclaredFields": true,
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"methods": [
{
"name": "<init>",
"parameterTypes": [
"java.util.List"
]
}
]
},
{
"name": "de.cmdjulian.kirc.impl.response.TagList",
"allDeclaredFields": true,
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"methods": [
{
"name": "<init>",
"parameterTypes": [
"java.lang.String",
"java.util.List"
]
}
]
},
{
"name": "de.cmdjulian.kirc.spec.Architecture",
"allDeclaredFields": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,62 @@
[
{
"name": "de.cmdjulian.kirc.image.Digest",
"allDeclaredFields": true,
"queryAllDeclaredMethods": true,
"queryAllDeclaredConstructors": true,
"methods": [
{
"name": "box-impl",
"name": "<init>",
"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": "<init>",
"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": "<init>",
"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
}
]
Original file line number Diff line number Diff line change
@@ -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 <reified T : Any> jacksonDeserializer() = object : ResponseDeserializable<T> {
override fun deserialize(content: String): T = JsonMapper.readValue(content)
class JacksonDeserializer<T : Any>(private val clazz: Class<T>) : ResponseDeserializable<T> {

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 <reified T : Any> jacksonDeserializer() = JacksonDeserializer(T::class.java)
Original file line number Diff line number Diff line change
Expand Up @@ -24,78 +24,64 @@ 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()
}
}

override suspend fun repositories(limit: Int?, last: Int?): List<Repository> =
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<Tag> =
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<DockerImageConfigV1>(config)
is OciManifestV1 -> JsonMapper.readValue<OciImageConfigV1>(config)
is DockerManifestV2 -> jacksonDeserializer<DockerImageConfigV1>().deserialize(config)
is OciManifestV1 -> jacksonDeserializer<DockerImageConfigV1>().deserialize(config)
}
}
.onError { logger.trace(it) { "error on image config retrieve" } }
.getOrElse { throw it.toRegistryClientError() }

override suspend fun toImageClient(repository: Repository, reference: Reference): SuspendingContainerImageClient =
Expand Down
Loading

0 comments on commit 894a79f

Please sign in to comment.