Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Licensed under the MIT license.
package com.cosmotech.common.events

class RunStart(publisher: Any, val runnerData: Any) : CsmRequestResponseEvent<String>(publisher)
enum class RunType(val value: String) {
Run("run"),
Delete("delete"),
}

class RunStart(publisher: Any, val runnerData: Any, val runType: RunType) :
CsmRequestResponseEvent<String>(publisher)

class RunStop(publisher: Any, val runnerData: Any) : CsmEvent(publisher)

Expand Down
6 changes: 6 additions & 0 deletions run/src/main/kotlin/com/cosmotech/run/RunContainerFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -113,6 +116,7 @@ class RunContainerFactory(
runId,
runId,
workflowType,
runType,
),
runner = runner,
workspace = workspace,
Expand All @@ -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" }
Expand Down Expand Up @@ -176,6 +181,7 @@ class RunContainerFactory(
)

envVars[RUN_TEMPLATE_ID_VAR] = runTemplateId
envVars[RUN_TYPE] = runType.value

val customSizing = runSizing ?: (runTemplateSizing ?: defaultSizing)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -239,6 +240,7 @@ class RunServiceImpl(
runner.id,
WORKFLOW_TYPE_RUN,
runId,
runType,
)
val runRequest =
workflowService.launchRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down