diff --git a/theodolite/build.gradle b/theodolite/build.gradle index 8bf4d92059c08399607944788bc3025cf24f3814..58c9de232b3287b7bfdabf0ebeb09a39a717277a 100644 --- a/theodolite/build.gradle +++ b/theodolite/build.gradle @@ -22,8 +22,7 @@ dependencies { implementation 'org.bouncycastle:bcprov-ext-jdk15on:1.69' implementation 'org.bouncycastle:bcpkix-jdk15on:1.69' - - implementation 'com.google.code.gson:gson:2.8.9' + implementation 'org.slf4j:slf4j-simple:1.7.32' implementation 'io.github.microutils:kotlin-logging:2.1.16' implementation 'org.apache.kafka:kafka-clients:2.8.0' diff --git a/theodolite/src/main/kotlin/rocks/theodolite/core/IOHandler.kt b/theodolite/src/main/kotlin/rocks/theodolite/core/IOHandler.kt index e70779afb34c4e7cecd561a2c4d64b09c9933ad5..6c5323764a49a62f6472a3ecddae89d21770bd84 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/core/IOHandler.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/core/IOHandler.kt @@ -1,6 +1,6 @@ package rocks.theodolite.core -import com.google.gson.GsonBuilder +import com.fasterxml.jackson.databind.ObjectMapper import mu.KotlinLogging import java.io.File import java.io.PrintWriter @@ -56,8 +56,9 @@ class IOHandler { * @param fileURL the URL of the file */ fun <T> writeToJSONFile(objectToSave: T, fileURL: String) { - val gson = GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create() - writeStringToTextFile(fileURL, gson.toJson(objectToSave)) + val outputFile = File(fileURL) + ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(outputFile, objectToSave) + logger.info { "Wrote txt file: $fileURL to ${outputFile.absolutePath}." } } /** diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandler.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandler.kt index 884606b13783d85ae41c1a8f4c1e5a1980c0e1b0..950ad7e2a87d030835b4a5b6448d5ae5df121e76 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandler.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/operator/ExecutionEventHandler.kt @@ -1,7 +1,6 @@ package rocks.theodolite.kubernetes.operator -import com.google.gson.Gson -import com.google.gson.GsonBuilder +import com.fasterxml.jackson.databind.ObjectMapper import io.fabric8.kubernetes.client.informers.ResourceEventHandler import mu.KotlinLogging import rocks.theodolite.kubernetes.model.BenchmarkExecution @@ -22,8 +21,7 @@ class ExecutionEventHandler( private val controller: TheodoliteController, private val stateHandler: ExecutionStateHandler ) : ResourceEventHandler<ExecutionCRD> { - - private val gson: Gson = GsonBuilder().enableComplexMapKeySerialization().create() + private val mapper: ObjectMapper = ObjectMapper() /** * Adds an execution to the end of the queue of the TheodoliteController. @@ -60,7 +58,7 @@ class ExecutionEventHandler( override fun onUpdate(oldExecution: ExecutionCRD, newExecution: ExecutionCRD) { newExecution.spec.name = newExecution.metadata.name oldExecution.spec.name = oldExecution.metadata.name - if (gson.toJson(oldExecution.spec) != gson.toJson(newExecution.spec)) { + if (mapper.writeValueAsString(oldExecution.spec) != mapper.writeValueAsString(newExecution.spec)) { logger.info { "Receive update event for execution ${oldExecution.metadata.name}." } when (this.stateHandler.getExecutionState(newExecution.metadata.name)) { ExecutionState.RUNNING -> { diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/MetricFetcher.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/MetricFetcher.kt index 58c83909ae6f7d8b87ceab2bbb6a2977ec8c470a..cda2c3bac2b1599d8e995c504b24924ca294aef2 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/MetricFetcher.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/MetricFetcher.kt @@ -1,6 +1,6 @@ package rocks.theodolite.kubernetes.slo -import com.google.gson.Gson +import com.fasterxml.jackson.databind.ObjectMapper import khttp.get import khttp.responses.Response import mu.KotlinLogging @@ -67,7 +67,7 @@ class MetricFetcher(private val prometheusURL: String, private val offset: Durat * @return a [PrometheusResponse] */ private fun parseValues(values: Response): PrometheusResponse { - return Gson().fromJson<PrometheusResponse>( + return ObjectMapper().readValue<PrometheusResponse>( values.jsonObject.toString(), PrometheusResponse::class.java ) diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloJson.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloJson.kt index d91696ee98eac26325e88b58efeda1c47355b197..cd3b463037e007fa77ac1e4342b734802223de1f 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloJson.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloJson.kt @@ -1,6 +1,6 @@ package rocks.theodolite.kubernetes.slo -import com.google.gson.Gson +import com.fasterxml.jackson.databind.ObjectMapper class SloJson constructor( val results: List<List<PromResult>>, @@ -8,7 +8,7 @@ class SloJson constructor( ) { fun toJson(): String { - return Gson().toJson( + return ObjectMapper().writeValueAsString( mapOf( "results" to this.results, "metadata" to this.metadata diff --git a/theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt index e54bf7851b195927f69666caa2fd3b33fb3673d7..809b43332f39f67814dbf731385c0695d2988e4c 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/core/IOHandlerTest.kt @@ -1,6 +1,6 @@ package rocks.theodolite.core -import com.google.gson.GsonBuilder +import com.fasterxml.jackson.databind.ObjectMapper import io.quarkus.test.junit.QuarkusTest import org.hamcrest.CoreMatchers.containsString import org.hamcrest.MatcherAssert.assertThat @@ -121,7 +121,7 @@ internal class IOHandlerTest { objectToSave = testContentResource ) - val expected = GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create().toJson(testContentResource) + val expected = ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(testContentResource) assertEquals( expected, diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/BenchmarkStateCheckerTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/BenchmarkStateCheckerTest.kt index 465233a5d47e0c3963371a1fd0cc891aac74a42a..162308df4fe5e5082ddef44b00559b7f188005f0 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/BenchmarkStateCheckerTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/BenchmarkStateCheckerTest.kt @@ -1,6 +1,6 @@ package rocks.theodolite.kubernetes.operator -import com.google.gson.Gson +import com.fasterxml.jackson.databind.ObjectMapper import io.fabric8.kubernetes.api.model.ConfigMapBuilder import io.fabric8.kubernetes.api.model.Pod import io.fabric8.kubernetes.api.model.PodBuilder @@ -10,16 +10,16 @@ import io.fabric8.kubernetes.client.server.mock.KubernetesServer import io.fabric8.kubernetes.client.server.mock.OutputStreamMessage import io.fabric8.kubernetes.client.utils.Utils import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.Assertions.* -import rocks.theodolite.kubernetes.model.crd.BenchmarkState -import rocks.theodolite.kubernetes.model.KubernetesBenchmark -import rocks.theodolite.kubernetes.model.crd.BenchmarkCRDummy import rocks.theodolite.kubernetes.ConfigMapResourceSet import rocks.theodolite.kubernetes.ExecActionSelector import rocks.theodolite.kubernetes.PodSelector import rocks.theodolite.kubernetes.ResourceSets +import rocks.theodolite.kubernetes.model.KubernetesBenchmark +import rocks.theodolite.kubernetes.model.crd.BenchmarkCRDummy +import rocks.theodolite.kubernetes.model.crd.BenchmarkState internal class BenchmarkStateCheckerTest { private val server = KubernetesServer(false, false) @@ -128,7 +128,7 @@ internal class BenchmarkStateCheckerTest { val resource = resourceBuilder.build() resource.metadata.name = "test-deployment" resource.metadata.labels = mutableMapOf("app" to "pod1") - val resourceString = Gson().toJson(resource) + val resourceString = ObjectMapper().writeValueAsString(resource) // create and deploy configmap val configMap1 = ConfigMapBuilder() diff --git a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ControllerTest.kt b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ControllerTest.kt index 301580bf3f84faaef8df22555d22a33dff0d2acd..3e665423edd75d1cef781076b28d458f917aa004 100644 --- a/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ControllerTest.kt +++ b/theodolite/src/test/kotlin/rocks/theodolite/kubernetes/operator/ControllerTest.kt @@ -1,7 +1,6 @@ package rocks.theodolite.kubernetes.operator -import com.google.gson.Gson -import com.google.gson.GsonBuilder +import com.fasterxml.jackson.databind.ObjectMapper import io.fabric8.kubernetes.client.CustomResourceList import io.fabric8.kubernetes.client.server.mock.KubernetesServer import io.quarkus.test.junit.QuarkusTest @@ -19,7 +18,7 @@ import rocks.theodolite.kubernetes.model.crd.* class ControllerTest { private final val server = KubernetesServer(false, false) lateinit var controller: TheodoliteController - private val gson: Gson = GsonBuilder().enableComplexMapKeySerialization().create() + private val mapper = ObjectMapper() private var benchmark = KubernetesBenchmark() private var execution = BenchmarkExecution() @@ -118,8 +117,8 @@ class ControllerTest { assertEquals(2, result.size) assertEquals( - gson.toJson(benchmark), - gson.toJson(result.firstOrNull()?.spec) + mapper.writeValueAsString(benchmark), + mapper.writeValueAsString(result.firstOrNull()?.spec) ) } @@ -133,8 +132,8 @@ class ControllerTest { val result = method.invoke(controller) as BenchmarkExecution? assertEquals( - gson.toJson(this.execution), - gson.toJson(result) + mapper.writeValueAsString(this.execution), + mapper.writeValueAsString(result) ) } } \ No newline at end of file