summaryrefslogtreecommitdiff
path: root/simulator/opendc-workflows
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-09 12:57:12 +0100
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-03-09 13:03:20 +0100
commit970f5c6f653c8442ecd9b73b208a53a2dbb9a150 (patch)
treeaa5724ee239cb831e48d45aef8327d7b487e2ad1 /simulator/opendc-workflows
parente97774dbf274fcb57b9d173f9d674a2ef1b982af (diff)
compute: Add lifecycle methods for Server instances
This change adds more methods for controlling the lifecycle of Server instances.
Diffstat (limited to 'simulator/opendc-workflows')
-rw-r--r--simulator/opendc-workflows/src/main/kotlin/org/opendc/workflows/service/StageWorkflowService.kt12
1 files changed, 9 insertions, 3 deletions
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()
}
}