From 1106f400823106a0c36a1ac5852cbbc418d0a3ed Mon Sep 17 00:00:00 2001 From: Nikolai Sviridov Date: Wed, 6 Dec 2023 19:40:03 +0100 Subject: [PATCH] feat: add not found, deserialize error cases, refactor gradle kts --- build.gradle.kts | 16 +++++++++++ cli/build.gradle.kts | 9 +++--- core/build.gradle.kts | 6 +--- .../kotlin/loader/gerrit/LoaderChanges.kt | 28 ++++++++++++++++++- run.sh | 2 -- 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 build.gradle.kts delete mode 100755 run.sh diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..9295b2d --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,16 @@ +plugins { + kotlin("jvm") version "1.9.21" +} + +repositories { + mavenCentral() +} + +subprojects { + group = "org.jetbrains.research.ictl" + version = "0.0.2" + + apply { + apply(plugin = "org.jetbrains.kotlin.jvm") + } +} \ No newline at end of file diff --git a/cli/build.gradle.kts b/cli/build.gradle.kts index bca5c9f..54af231 100644 --- a/cli/build.gradle.kts +++ b/cli/build.gradle.kts @@ -1,11 +1,10 @@ -val version = "0.0.1" - plugins { - kotlin("jvm") version "1.9.21" id("application") id("com.google.cloud.tools.jib") version "3.4.0" } +val projectVersion = version as String + tasks { jib { container { @@ -22,8 +21,8 @@ tasks { } } to { - image = "ghcr.io/jetbrains-research/mr-loader/${rootProject.name}:$version" - tags = setOf("latest", version) + image = "ghcr.io/jetbrains-research/mr-loader/${rootProject.name}:$projectVersion" + tags = setOf("latest", projectVersion) } } diff --git a/core/build.gradle.kts b/core/build.gradle.kts index d298b98..8b258be 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,12 +1,8 @@ plugins { - kotlin("jvm") version "1.9.21" id("io.ktor.plugin") version "2.2.4" - kotlin("plugin.serialization").version("1.9.21") + kotlin("plugin.serialization") version "1.9.21" } -group = "org.jetbrains.research.ictl" -version = "0.0.1" - val ktorVersion = "2.2.4" repositories { diff --git a/core/src/main/kotlin/loader/gerrit/LoaderChanges.kt b/core/src/main/kotlin/loader/gerrit/LoaderChanges.kt index 84f6da8..6a9d0f4 100644 --- a/core/src/main/kotlin/loader/gerrit/LoaderChanges.kt +++ b/core/src/main/kotlin/loader/gerrit/LoaderChanges.kt @@ -46,6 +46,9 @@ class LoaderChanges( // TODO: needs check private val IGNORE_PROJECTS = setOf("All-Projects", "All-Users") + private const val NOT_FOUND = "Not found:" + private const val DESERIALIZE_ERROR = + "Deserialize error : There seems to be a change in response from the server side. Please report." fun baseUrlToDomain(baseUrl: String) = baseUrl .removePrefix("http://") @@ -56,6 +59,7 @@ class LoaderChanges( // TODO: replace private val logger = run { val result = Logger.getLogger("loader") + resultDir.mkdirs() val fh = FileHandler(File(resultDir, "loader.log").absolutePath) result.addHandler(fh) val formatter = SimpleFormatter() @@ -169,7 +173,19 @@ class LoaderChanges( val callable = Callable { runBlocking { - wrapIgnoringErrors { client.getChangeRaw(baseUrl, id) }?.let { rawJson -> + wrapIgnoringErrors { + val rawJson = client.getChangeRaw(baseUrl, id) + + if (rawJson.startsWith(NOT_FOUND)) { + throw Exception(rawJson) + } + + try { + decodeRawJson(rawJson) + } catch (e: Exception) { + throw Exception("$DESERIALIZE_ERROR : ChangeId $id") + } + jsonObjectBuffer.addEntry(rawJson, id) } logger.info("Loaded changes for $id") @@ -232,6 +248,16 @@ class LoaderChanges( continue } + errMsg.contains(NOT_FOUND) -> { + logger.warning(errMsg) + return null + } + + errMsg.contains(DESERIALIZE_ERROR) -> { + logger.severe("$DESERIALIZE_ERROR : $msg") + return null + } + numOfErrors > maxNumOfErrors -> { logger.severe("Number of errors for task exceeded threshold=$maxNumOfErrors : $msg : $errMsg") return null diff --git a/run.sh b/run.sh deleted file mode 100755 index 3239b0b..0000000 --- a/run.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -java -jar ./cli/build/libs/shadow-*.jar "$@"