Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
Introduce the modelRepositoryInit for the KolasuClient and the LionWe…
Browse files Browse the repository at this point in the history
…bClient
  • Loading branch information
ftomassetti committed Feb 15, 2024
1 parent f18ff35 commit 75350c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ class LionWebClient(
}
}
}

/**
* To be called exactly once, to ensure the Model Repository is initialized.
* Note that it causes all content of the Model Repository to be lost!
*/
fun modelRepositoryInit() {
val url = "http://$hostname:$port/init"
val request: Request = Request.Builder()
.url(url)
.post("".toRequestBody())
.build()
OkHttpClient().newCall(request).execute().use { response ->
if (response.code != 200) {
throw RuntimeException("DB initialization failed, HTTP ${response.code}: ${response.body?.string()}")
}
}
}
}
8 changes: 8 additions & 0 deletions starlasu-client/src/main/kotlin/KolasuClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ class KolasuClient(val hostname: String = "localhost", val port: Int = 3005, val
val lwNode = lionWebClient.getPartition(nodeId)
return nodeConverter.importModelFromLionWeb(lwNode)
}

/**
* To be called exactly once, to ensure the Model Repository is initialized.
* Note that it causes all content of the Model Repository to be lost!
*/
fun modelRepositoryInit() {
lionWebClient.modelRepositoryInit()
}
}

0 comments on commit 75350c7

Please sign in to comment.