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..b0ca1c2ab 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..7f50f2b07 100644 --- a/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt +++ b/run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt @@ -230,6 +230,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 +240,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..9806143f7 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.getRunnerDataObject(), runType) this.eventPublisher.publishEvent(startEvent) val runId = startEvent.response ?: throw IllegalStateException("Run Service did not respond") runnerInstance.setLastRunInfo(runId)