From fb0525c574430d4a86dd8e03cd896c9d5534fc1c Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Wed, 14 Apr 2021 09:10:22 +0200
Subject: [PATCH] Catch additional exception while deletion of executions

---
 .../execution/operator/ExecutionEventHandler.kt | 17 +++++++++++++----
 .../execution/operator/TheodoliteController.kt  | 10 ++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt
index 1752ac112..0152cd7be 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/ExecutionEventHandler.kt
@@ -3,6 +3,7 @@ package theodolite.execution.operator
 import io.fabric8.kubernetes.client.informers.ResourceEventHandler
 import mu.KotlinLogging
 import theodolite.benchmark.BenchmarkExecution
+import java.lang.NullPointerException
 
 private val logger = KotlinLogging.logger {}
 
@@ -16,17 +17,25 @@ class ExecutionHandler(private val controller: TheodoliteController): ResourceEv
     override fun onUpdate(oldExecution: BenchmarkExecution, newExecution: BenchmarkExecution) {
         logger.info { "Add updated execution to queue." }
         newExecution.name = newExecution.metadata.name
-        this.controller.executionsQueue.removeIf { e -> e.name == newExecution.metadata.name }
+        try {
+            this.controller.executionsQueue.removeIf { e -> e.name == newExecution.metadata.name }
+        } catch(e: NullPointerException) {
+            logger.warn { "No execution found for deletion" }
+        }
         this.controller.executionsQueue.addFirst(newExecution)
-        if (this.controller.isInitialized() &&  this.controller.executor.getExecution().name == newExecution.metadata.name) {
+        if (this.controller.isInitialized() && this.controller.executor.getExecution().name == newExecution.metadata.name) {
             this.controller.isUpdated.set(true)
             this.controller.executor.executor.run.compareAndSet(true, false)
         }
     }
 
     override fun onDelete(execution: BenchmarkExecution, b: Boolean) {
-        logger.info { "Delete execution ${execution.metadata.name} from queue." }
-        this.controller.executionsQueue.removeIf { e -> e.name == execution.metadata.name }
+        try {
+            this.controller.executionsQueue.removeIf { e -> e.name == execution.metadata.name }
+            logger.info { "Delete execution ${execution.metadata.name} from queue." }
+        } catch(e: NullPointerException) {
+            logger.warn { "No execution found for deletion" }
+        }
         if (this.controller.isInitialized() && this.controller.executor.getExecution().name == execution.metadata.name) {
             this.controller.isUpdated.set(true)
             this.controller.executor.executor.run.compareAndSet(true, false)
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt
index 9e6280cf3..9f6cd6452 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt
@@ -70,9 +70,15 @@ class TheodoliteController(
         executor = TheodoliteExecutor(config = execution, kubernetesBenchmark = benchmark)
         executor.run()
 
-        if (!isUpdated.get()) {
-            client.customResource(executionContext).delete(client.namespace, execution.metadata.name)
+        try {
+            if (!isUpdated.get()) {
+                this.executionsQueue.removeIf { e -> e.name == execution.name }
+                client.customResource(executionContext).delete(client.namespace, execution.metadata.name)
+            }
+        } catch (e: Exception) {
+            logger.warn { "Deletion skipped." }
         }
+
         logger.info { "Execution of ${execution.name} is finally stopped." }
     }
 
-- 
GitLab