From 81c31f08ed4a7f158a4253b6702a4e69fc9c473e Mon Sep 17 00:00:00 2001 From: lorenz <stu203404@mail.uni-kiel.de> Date: Fri, 29 Jan 2021 17:45:04 +0100 Subject: [PATCH] Changed Nullable type and added execption for this in Yaml Loader --- .../kotlin/theodolite/execution/YamlLoader.kt | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/YamlLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/YamlLoader.kt index acdb75bfe..d52e7e392 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/YamlLoader.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/YamlLoader.kt @@ -20,18 +20,31 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @param path of the yaml file * @return service from fabric8 */ - fun loadService(path: String): Service? { + fun loadService(path: String): Service { val service = loadGenericRessource(path, { x: String -> client.services().load(x).get() }) return service } + + /** + * Parses a Service from a servive yaml + * @param path of the yaml file + * @return service from fabric8 + */ + fun loadService(path: String): Service { + + val service = loadGenericRessource(path, { x: String -> client.services().load(x).get() }) + return service + } + + /** * Parses a Deployment from a Deployment yaml * @param path of the yaml file * @return Deployment from fabric8 */ - fun loadDeployment(path: String): Deployment? { + fun loadDeployment(path: String): Deployment { val deployment = loadGenericRessource(path, { x: String -> client.apps().deployments().load(x).get() }) return deployment } @@ -41,7 +54,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @param path of the yaml file * @return ConfigMap from fabric8 */ - fun loadConfigmap(path: String): ConfigMap? { + fun loadConfigmap(path: String): ConfigMap { val configMap = loadGenericRessource(path, { x: String -> client.configMaps().load(x).get() }) return configMap } @@ -51,7 +64,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @param path of the resource * @param f fuction that shall be applied to the resource. */ - private fun <T> loadGenericRessource(path: String, f: (String) -> T): T? { + private fun <T> loadGenericRessource(path: String, f: (String) -> T): T { var resource: T? = null try { @@ -60,6 +73,11 @@ class YamlLoader(client: NamespacedKubernetesClient) { logger.info("You potentially misspelled the path: $path") logger.info("$e") } + + if (resource == null) { + throw NullPointerException("The Ressource at path: " + path + " could not be loaded") + } + return resource } } -- GitLab