From 970f5c6f653c8442ecd9b73b208a53a2dbb9a150 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 9 Mar 2021 12:57:12 +0100 Subject: compute: Add lifecycle methods for Server instances This change adds more methods for controlling the lifecycle of Server instances. --- .../org/opendc/workflows/service/StageWorkflowService.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'simulator/opendc-workflows/src') diff --git a/simulator/opendc-workflows/src/main/kotlin/org/opendc/workflows/service/StageWorkflowService.kt b/simulator/opendc-workflows/src/main/kotlin/org/opendc/workflows/service/StageWorkflowService.kt index 6b348ed4..5ae503a7 100644 --- a/simulator/opendc-workflows/src/main/kotlin/org/opendc/workflows/service/StageWorkflowService.kt +++ b/simulator/opendc-workflows/src/main/kotlin/org/opendc/workflows/service/StageWorkflowService.kt @@ -261,13 +261,14 @@ public class StageWorkflowService( val flavor = Flavor(cores, 1000) // TODO How to determine memory usage for workflow task val image = instance.task.image coroutineScope.launch { - val server = computeClient.newServer(instance.task.name, image, flavor) + val server = computeClient.newServer(instance.task.name, image, flavor, start = false) instance.state = TaskStatus.ACTIVE instance.server = server taskByServer[server] = instance server.watch(this@StageWorkflowService) + server.start() } activeTasks += instance @@ -278,7 +279,8 @@ public class StageWorkflowService( public override fun onStateChanged(server: Server, newState: ServerState) { when (newState) { - ServerState.ACTIVE -> { + ServerState.PROVISIONING -> {} + ServerState.RUNNING -> { val task = taskByServer.getValue(server) task.startedAt = clock.millis() tracer.commit( @@ -290,8 +292,11 @@ public class StageWorkflowService( ) rootListener.taskStarted(task) } - ServerState.SHUTOFF, ServerState.ERROR -> { + ServerState.TERMINATED, ServerState.ERROR -> { val task = taskByServer.remove(server) ?: throw IllegalStateException() + + coroutineScope.launch { server.delete() } + val job = task.job task.state = TaskStatus.FINISHED task.finishedAt = clock.millis() @@ -322,6 +327,7 @@ public class StageWorkflowService( requestCycle() } + ServerState.DELETED -> {} else -> throw IllegalStateException() } } -- cgit v1.2.3