From 7d9adb31fd7c4d79c4fac131d61058365f53edb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Al=C3=A9p=C3=A9e?= Date: Mon, 23 Mar 2026 10:35:50 +0100 Subject: [PATCH 1/3] add RunType to Run and start delete run on runner deletion --- .../main/kotlin/com/cosmotech/common/events/RunEvents.kt | 8 +++++++- .../main/kotlin/com/cosmotech/run/RunContainerFactory.kt | 6 ++++++ .../kotlin/com/cosmotech/run/service/RunServiceImpl.kt | 3 +++ .../com/cosmotech/runner/service/RunnerApiServiceImpl.kt | 4 +++- .../kotlin/com/cosmotech/runner/service/RunnerService.kt | 5 +++-- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt index 25941b822..da771df51 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt @@ -2,7 +2,13 @@ // Licensed under the MIT license. package com.cosmotech.common.events -class RunStart(publisher: Any, val runnerData: Any) : CsmRequestResponseEvent(publisher) +enum class RunType(val value: String) { + Run("run"), + Delete("delete"), +} + +class RunStart(publisher: Any, val runnerData: Any, val runType: RunType) : + CsmRequestResponseEvent(publisher) class RunStop(publisher: Any, val runnerData: Any) : CsmEvent(publisher) diff --git a/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt b/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt index 1980188fc..7f0021900 100644 --- a/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt +++ b/run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt @@ -4,6 +4,7 @@ package com.cosmotech.run import com.cosmotech.common.config.CsmPlatformProperties import com.cosmotech.common.containerregistry.ContainerRegistryService +import com.cosmotech.common.events.RunType import com.cosmotech.common.utils.sanitizeForKubernetes import com.cosmotech.organization.api.OrganizationApiService import com.cosmotech.organization.domain.Organization @@ -50,6 +51,7 @@ private const val PARAMETERS_RUNNER_VAR = "CSM_RUNNER_ID" private const val PARAMETERS_RUN_VAR = "CSM_RUN_ID" private const val RUN_TEMPLATE_ID_VAR = "CSM_RUN_TEMPLATE_ID" +private const val RUN_TYPE = "CSM_RUN_TYPE" private const val ENTRYPOINT_NAME = "entrypoint.py" private const val NODE_PARAM_NONE = "%NONE%" const val NODE_LABEL_DEFAULT = "basic" @@ -89,6 +91,7 @@ class RunContainerFactory( runnerId: String, workflowType: String, runId: String, + runType: RunType = RunType.Run, ): StartInfo { val organization = organizationService.getOrganization(organizationId) val workspace = workspaceService.getWorkspace(organizationId, workspaceId) @@ -113,6 +116,7 @@ class RunContainerFactory( runId, runId, workflowType, + runType, ), runner = runner, workspace = workspace, @@ -131,6 +135,7 @@ class RunContainerFactory( runId: String, csmSimulationId: String, workflowType: String, + runType: RunType = RunType.Run, ): RunStartContainers { check(runner.runTemplateId.isNotBlank()) { "Runner runTemplateId cannot be blank" } @@ -176,6 +181,7 @@ class RunContainerFactory( ) envVars[RUN_TEMPLATE_ID_VAR] = runTemplateId + envVars[RUN_TYPE] = runType.value val customSizing = runSizing ?: (runTemplateSizing ?: defaultSizing) diff --git a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt index 3dbc64ef3..e19aae9ae 100644 --- a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt +++ b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt @@ -6,6 +6,7 @@ import com.cosmotech.common.CsmPhoenixService import com.cosmotech.common.events.RunDeleted import com.cosmotech.common.events.RunStart import com.cosmotech.common.events.RunStop +import com.cosmotech.common.events.RunType import com.cosmotech.common.events.RunnerDeleted import com.cosmotech.common.events.UpdateRunnerStatus import com.cosmotech.common.exceptions.CsmResourceNotFoundException @@ -230,6 +231,7 @@ class RunServiceImpl( @EventListener(RunStart::class) fun onRunStart(runStartRequest: RunStart) { val runner = runStartRequest.runnerData as Runner + val runType = runStartRequest.runType val runId = generateId("run", prependPrefix = "run-") val startInfo = @@ -239,6 +241,7 @@ class RunServiceImpl( runner.id, WORKFLOW_TYPE_RUN, runId, + runType, ) val runRequest = workflowService.launchRun( diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt index edbd387ec..e0b0b57df 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt @@ -5,6 +5,7 @@ package com.cosmotech.runner.service import com.cosmotech.common.config.CsmPlatformProperties import com.cosmotech.common.events.GetRunnerAttachedToDataset import com.cosmotech.common.events.RunDeleted +import com.cosmotech.common.events.RunType import com.cosmotech.common.rbac.PERMISSION_CREATE_CHILDREN import com.cosmotech.common.rbac.PERMISSION_DELETE import com.cosmotech.common.rbac.PERMISSION_LAUNCH @@ -121,6 +122,7 @@ internal class RunnerApiServiceImpl( val runnerInstance = runnerService.getInstance(runnerId).userHasPermission(PERMISSION_DELETE) runnerService.deleteInstance(runnerInstance) + runnerService.startRunWith(runnerInstance, RunType.Delete) } override fun listRunners( @@ -142,7 +144,7 @@ internal class RunnerApiServiceImpl( val runnerInstance = runnerService.getInstance(runnerId).userHasPermission(PERMISSION_LAUNCH) - return runnerService.startRunWith(runnerInstance) + return runnerService.startRunWith(runnerInstance, RunType.Run) } override fun stopRun(organizationId: String, workspaceId: String, runnerId: String) { diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt index 57b599dad..0434cf991 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt @@ -6,6 +6,7 @@ import com.cosmotech.common.CsmPhoenixService import com.cosmotech.common.events.HasRunningRuns import com.cosmotech.common.events.RunStart import com.cosmotech.common.events.RunStop +import com.cosmotech.common.events.RunType import com.cosmotech.common.events.RunnerDeleted import com.cosmotech.common.events.UpdateRunnerStatus import com.cosmotech.common.exceptions.CsmClientException @@ -279,8 +280,8 @@ class RunnerService( return runners } - fun startRunWith(runnerInstance: RunnerInstance): CreatedRun { - val startEvent = RunStart(this, runnerInstance.getRunnerDataObject()) + fun startRunWith(runnerInstance: RunnerInstance, runType: RunType): CreatedRun { + val startEvent = RunStart(this, runnerInstance.getRunnerDataObjet(), runType) this.eventPublisher.publishEvent(startEvent) val runId = startEvent.response ?: throw IllegalStateException("Run Service did not respond") runnerInstance.setLastRunInfo(runId) From 3551021900103359407894c6f1cfdbff2834bc99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Al=C3=A9p=C3=A9e?= Date: Mon, 23 Mar 2026 11:07:29 +0100 Subject: [PATCH 2/3] fixup --- .../main/kotlin/com/cosmotech/runner/service/RunnerService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt index 0434cf991..9806143f7 100644 --- a/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt +++ b/runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt @@ -281,7 +281,7 @@ class RunnerService( } fun startRunWith(runnerInstance: RunnerInstance, runType: RunType): CreatedRun { - val startEvent = RunStart(this, runnerInstance.getRunnerDataObjet(), runType) + val startEvent = RunStart(this, runnerInstance.getRunnerDataObject(), runType) this.eventPublisher.publishEvent(startEvent) val runId = startEvent.response ?: throw IllegalStateException("Run Service did not respond") runnerInstance.setLastRunInfo(runId) From 58ce71733f1679d70bf7daf4e4976ff601f27d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Al=C3=A9p=C3=A9e?= Date: Mon, 23 Mar 2026 10:47:24 +0100 Subject: [PATCH 3/3] chore: spotlessApply --- .../src/main/kotlin/com/cosmotech/common/events/RunEvents.kt | 4 ++-- .../main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt index da771df51..b0ca1c2ab 100644 --- a/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt +++ b/common/src/main/kotlin/com/cosmotech/common/events/RunEvents.kt @@ -3,8 +3,8 @@ package com.cosmotech.common.events enum class RunType(val value: String) { - Run("run"), - Delete("delete"), + Run("run"), + Delete("delete"), } class RunStart(publisher: Any, val runnerData: Any, val runType: RunType) : diff --git a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt index e19aae9ae..7f50f2b07 100644 --- a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt +++ b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt @@ -6,7 +6,6 @@ import com.cosmotech.common.CsmPhoenixService import com.cosmotech.common.events.RunDeleted import com.cosmotech.common.events.RunStart import com.cosmotech.common.events.RunStop -import com.cosmotech.common.events.RunType import com.cosmotech.common.events.RunnerDeleted import com.cosmotech.common.events.UpdateRunnerStatus import com.cosmotech.common.exceptions.CsmResourceNotFoundException