Skip to content

Commit a884c74

Browse files
committed
Revert "Remove state, lastRun, parentLastRun, rootLastRun on Runner + add lastRunId instead"
This reverts commit 681ea40
1 parent 16283e8 commit a884c74

File tree

6 files changed

+131
-30
lines changed

6 files changed

+131
-30
lines changed

run/src/main/kotlin/com/cosmotech/run/service/RunServiceImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,12 @@ class RunServiceImpl(
570570
@EventListener(RunStop::class)
571571
fun onRunStop(runStopRequest: RunStop) {
572572
val runner = runStopRequest.runnerData as Runner
573-
val run = getRun(runner.organizationId!!, runner.workspaceId!!, runner.id!!, runner.lastRunId!!)
573+
val run =
574+
getRun(
575+
runner.organizationId!!,
576+
runner.workspaceId!!,
577+
runner.id!!,
578+
runner.lastRun!!.runnerRunId!!)
574579
run.hasPermission(PERMISSION_WRITE)
575580
if (run.state!!.isTerminal()) {
576581
throw IllegalStateException(

runner/src/integrationTest/kotlin/com/cosmotech/runner/service/RunnerServiceIntegrationTest.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ import com.cosmotech.organization.domain.Organization
3737
import com.cosmotech.organization.domain.OrganizationAccessControl
3838
import com.cosmotech.organization.domain.OrganizationSecurity
3939
import com.cosmotech.runner.RunnerApiServiceInterface
40-
import com.cosmotech.runner.domain.*
40+
import com.cosmotech.runner.domain.Runner
41+
import com.cosmotech.runner.domain.RunnerAccessControl
42+
import com.cosmotech.runner.domain.RunnerJobState
43+
import com.cosmotech.runner.domain.RunnerLastRun
4144
import com.cosmotech.runner.domain.RunnerRole
4245
import com.cosmotech.solution.api.SolutionApiService
4346
import com.cosmotech.solution.domain.*
@@ -538,7 +541,7 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
538541

539542
@Test
540543
fun `test deleting a running runner`() {
541-
runnerSaved.lastRunId = "run-genid12345"
544+
runnerSaved.state = RunnerJobState.Running
542545
runnerApiService.updateRunner(
543546
organizationSaved.id!!, workspaceSaved.id!!, runnerSaved.id!!, runnerSaved)
544547

@@ -848,21 +851,22 @@ class RunnerServiceIntegrationTest : CsmRedisTestBase() {
848851

849852
@Test
850853
fun `startRun send event and save lastRun info`() {
851-
val expectedRunId = "run-genid12345"
854+
val mockRunId = "run-genid12345"
855+
val expectedRunInfo = RunnerLastRun(runnerRunId = mockRunId)
852856
every { eventPublisher.publishEvent(any<RunStart>()) } answers
853857
{
854-
firstArg<RunStart>().response = expectedRunId
858+
firstArg<RunStart>().response = mockRunId
855859
}
856860

857-
val runId =
861+
val runInfo =
858862
runnerApiService.startRun(organizationSaved.id!!, workspaceSaved.id!!, runnerSaved.id!!)
859-
assertEquals(expectedRunId, runId)
863+
assertEquals(expectedRunInfo, runInfo)
860864

861-
val lastRunId =
865+
val lastRunInfo =
862866
runnerApiService
863867
.getRunner(organizationSaved.id!!, workspaceSaved.id!!, runnerSaved.id!!)
864-
.lastRunId
865-
assertEquals(expectedRunId, lastRunId)
868+
.lastRun
869+
assertEquals(expectedRunInfo, lastRunInfo)
866870
}
867871

868872
@Test

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerApiServiceImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.cosmotech.api.utils.constructPageRequest
1515
import com.cosmotech.runner.RunnerApiServiceInterface
1616
import com.cosmotech.runner.domain.Runner
1717
import com.cosmotech.runner.domain.RunnerAccessControl
18+
import com.cosmotech.runner.domain.RunnerLastRun
1819
import com.cosmotech.runner.domain.RunnerRole
1920
import com.cosmotech.runner.domain.RunnerSecurity
2021
import org.springframework.context.event.EventListener
@@ -81,7 +82,11 @@ internal class RunnerApiServiceImpl(
8182
return runnerService.listInstances(pageRequest)
8283
}
8384

84-
override fun startRun(organizationId: String, workspaceId: String, runnerId: String): String {
85+
override fun startRun(
86+
organizationId: String,
87+
workspaceId: String,
88+
runnerId: String
89+
): RunnerLastRun {
8590
val runnerService = getRunnerService().inOrganization(organizationId).inWorkspace(workspaceId)
8691

8792
val runnerInstance = runnerService.getInstance(runnerId).userHasPermission(PERMISSION_LAUNCH)

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerEventServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RunnerEventServiceImpl(private val runnerApiService: RunnerApiService) :
1515
val workspaceId = triggerEvent.workspaceId
1616
val runnerId = triggerEvent.runnerId
1717

18-
val runId = runnerApiService.startRun(organizationId, workspaceId, runnerId)
19-
triggerEvent.response = runId
18+
val runInfo = runnerApiService.startRun(organizationId, workspaceId, runnerId)
19+
triggerEvent.response = runInfo.runnerRunId
2020
}
2121
}

runner/src/main/kotlin/com/cosmotech/runner/service/RunnerService.kt

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import com.cosmotech.organization.domain.Organization
3232
import com.cosmotech.runner.domain.Runner
3333
import com.cosmotech.runner.domain.RunnerAccessControl
3434
import com.cosmotech.runner.domain.RunnerRunTemplateParameterValue
35+
import com.cosmotech.runner.domain.RunnerJobState
36+
import com.cosmotech.runner.domain.RunnerLastRun
3537
import com.cosmotech.runner.domain.RunnerSecurity
3638
import com.cosmotech.runner.repository.RunnerRepository
3739
import com.cosmotech.solution.SolutionApiServiceInterface
@@ -156,26 +158,36 @@ class RunnerService(
156158
return runners
157159
}
158160

159-
fun startRunWith(runnerInstance: RunnerInstance): String {
161+
fun startRunWith(runnerInstance: RunnerInstance): RunnerLastRun {
160162
val startEvent = RunStart(this, runnerInstance.getRunnerDataObjet())
161163
this.eventPublisher.publishEvent(startEvent)
164+
162165
val runId = startEvent.response ?: throw IllegalStateException("Run Service did not respond")
163-
runnerInstance.setLastRunId(runId)
166+
val runInfo = RunnerLastRun(runnerRunId = runId)
167+
runnerInstance.setLastRun(runInfo)
168+
164169
runnerRepository.save(runnerInstance.getRunnerDataObjet())
165-
return runId
170+
171+
return runInfo
166172
}
167173

168174
fun stopLastRunOf(runnerInstance: RunnerInstance) {
169175
val runner = runnerInstance.getRunnerDataObjet()
170-
runner.lastRunId
171-
?: throw IllegalArgumentException("Runner ${runner.id} doesn't have a last run")
176+
val runId =
177+
runner.lastRun?.runnerRunId
178+
?: throw IllegalArgumentException("Runner ${runner.id} doesn't have a last run")
179+
172180
this.eventPublisher.publishEvent(RunStop(this, runner))
173181
}
174182

175183
@Suppress("TooManyFunctions")
176184
inner class RunnerInstance(var runner: Runner = Runner()) {
177185
private val roleDefinition: RolesDefinition = getScenarioRolesDefinition()
178186

187+
fun isRunning(): Boolean {
188+
return this.runner.state == RunnerJobState.Running
189+
}
190+
179191
fun initialize(): RunnerInstance = apply {
180192
val now = Instant.now().toEpochMilli()
181193
this.runner =
@@ -225,8 +237,8 @@ class RunnerService(
225237
}
226238
}
227239

228-
fun setLastRunId(runInfo: String) {
229-
this.runner.lastRunId = runInfo
240+
fun setLastRun(runInfo: RunnerLastRun) {
241+
this.runner.lastRun = runInfo
230242
}
231243

232244
fun initSecurity(runner: Runner): RunnerInstance = apply {

runner/src/main/openapi/runner.yaml

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ paths:
215215
content:
216216
text/plain:
217217
schema:
218-
type: string
219-
example: r-p75189n1m43k
218+
$ref: '#/components/schemas/RunnerLastRun'
220219
"404":
221220
description: the Runner specified is unknown or you don't have access to it
222221

@@ -634,6 +633,8 @@ components:
634633
x-field-extra-annotation: "@com.redis.om.spring.annotations.Indexed"
635634
readOnly: true
636635
description: the associated Workspace Id
636+
state:
637+
$ref: '#/components/schemas/RunnerJobState'
637638
creationDate:
638639
type: integer
639640
format: int64
@@ -669,9 +670,21 @@ components:
669670
description: the list of Solution Run Template parameters values
670671
items:
671672
$ref: '#/components/schemas/RunnerRunTemplateParameterValue'
672-
lastRunId:
673-
description: last run id from current runner
674-
type: string
673+
lastRun:
674+
allOf:
675+
- $ref: '#/components/schemas/RunnerLastRun'
676+
- type: object
677+
description: the last Runner Run for this Runner
678+
parentLastRun:
679+
allOf:
680+
- $ref: '#/components/schemas/RunnerLastRun'
681+
- type: object
682+
description: the last Runner Run for the parent of this Runner
683+
rootLastRun:
684+
allOf:
685+
- $ref: '#/components/schemas/RunnerLastRun'
686+
- type: object
687+
description: the last Runner Run for the root (master) of Runner
675688
validationStatus:
676689
x-field-extra-annotation: "@com.redis.om.spring.annotations.Searchable"
677690
allOf:
@@ -748,6 +761,21 @@ components:
748761
required:
749762
- cpu
750763
- memory
764+
RunnerLastRun:
765+
type: object
766+
properties:
767+
runnerRunId:
768+
type: string
769+
description: the last Runner Run id
770+
csmSimulationRun:
771+
type: string
772+
description: the last Cosmo Tech Simulation Run id
773+
workflowId:
774+
type: string
775+
description: the last Workflow Id
776+
workflowName:
777+
type: string
778+
description: the last Workflow name
751779
RunnerRunTemplateParameterValue:
752780
type: object
753781
description: the value of a Solution Run Template parameter for a Runner
@@ -814,6 +842,8 @@ components:
814842
type: string
815843
readOnly: true
816844
description: the Runner Data Download URL
845+
state:
846+
$ref: '#/components/schemas/RunnerJobState'
817847
RunnerDataDownloadJob:
818848
type: object
819849
description: Runner data download job
@@ -822,6 +852,23 @@ components:
822852
type: string
823853
readOnly: true
824854
description: the Runner Data Download job identifier
855+
RunnerJobState:
856+
type: string
857+
readOnly: true
858+
description: the Runner job state
859+
enum:
860+
- Created
861+
- Running
862+
- Successful
863+
- Failed
864+
# PROD-7888 : When requesting the runner state right after a run has been submitted,
865+
# the runner run service (e.g., Argo Workflow) might not have scheduled the run
866+
# effectively yet.
867+
# Furthermore, temporary communication errors might occur anytime when remotely
868+
# fetching last runner run statuses.
869+
- Unknown
870+
# PROD-7420 : return data ingestion status
871+
- DataIngestionInProgress
825872
RunnerValidationStatus:
826873
type: string
827874
description: the validation status of the runner
@@ -878,6 +925,7 @@ components:
878925
solutionName: Brewery Solution
879926
runTemplateId: "hundred"
880927
runTemplateName: Full simulation 100 steps
928+
state: Running
881929
ownerName: Bob
882930
creationDate: "2021-04-21T17:32:28Z"
883931
lastUpdate: "2021-04-21T17:32:28Z"
@@ -887,7 +935,11 @@ components:
887935
- parameterId: prefix
888936
varType: string
889937
value: ""
890-
lastRunId: "run-bDMr5lM9Vp"
938+
lastRun:
939+
csmSimulationRun: "ae8d1959-7a71-48ec-9f33-3fae53358cf1"
940+
runnerRunId: "SR-V9EYbbOE0"
941+
workflowId: "c7cd3f15-8a3b-4bcd-b3ca-62ee24c13d67"
942+
workflowName: "workflow-s-dwpxbzmdxn-zkvd7"
891943
security:
892944
default: "viewer"
893945
accessControlList:
@@ -909,6 +961,7 @@ components:
909961
solutionName: Brewery Solution
910962
runTemplateId: "hundred"
911963
runTemplateName: Full simulation 100 steps
964+
state: Created
912965
ownerName: Bob
913966
creationDate: "2021-04-21T17:32:28Z"
914967
lastUpdate: "2021-04-21T17:32:28Z"
@@ -936,6 +989,7 @@ components:
936989
solutionName: Brewery Solution
937990
runTemplateId: "hundred"
938991
runTemplateName: Full simulation 100 steps
992+
state: Running
939993
ownerName: Bob
940994
creationDate: "2021-04-21T17:32:28Z"
941995
lastUpdate: "2021-04-21T17:32:28Z"
@@ -945,7 +999,11 @@ components:
945999
- parameterId: prefix
9461000
varType: string
9471001
value: example
948-
lastRunId: "run-bDMr5lM9Vp"
1002+
lastRun:
1003+
csmSimulationRun: "ae8d1959-7a71-48ec-9f33-3fae53358cf1"
1004+
runnerRunId: "SR-V9EYbbOE0"
1005+
workflowId: "c7cd3f15-8a3b-4bcd-b3ca-62ee24c13d67"
1006+
workflowName: "workflow-s-dwpxbzmdxn-zkvd7"
9491007
security:
9501008
default: "viewer"
9511009
accessControlList:
@@ -963,6 +1021,7 @@ components:
9631021
solutionName: Brewery Solution
9641022
runTemplateId: "hundred"
9651023
runTemplateName: Full simulation 100 steps
1024+
state: Failed
9661025
ownerName: Alice
9671026
creationDate: "2021-04-21T17:32:28Z"
9681027
lastUpdate: "2021-04-21T17:32:28Z"
@@ -973,7 +1032,11 @@ components:
9731032
varType: string
9741033
value: ""
9751034
inherited: true
976-
lastRunId: "run-bDMr5lM9Vp"
1035+
lastRun:
1036+
csmSimulationRun: "ae8d1959-7a71-48ec-9f33-3fae53358cf1"
1037+
runnerRunId: "SR-V9EYbbOE0"
1038+
workflowId: "c7cd3f15-8a3b-4bcd-b3ca-62ee24c13d67"
1039+
workflowName: "workflow-s-dwpxbzmdxn-zkvd7"
9771040
security:
9781041
default: "viewer"
9791042
accessControlList:
@@ -1000,6 +1063,7 @@ components:
10001063
solutionName: Brewery Solution
10011064
runTemplateId: "hundred"
10021065
runTemplateName: Full simulation 100 steps
1066+
state: Created
10031067
ownerName: Bob
10041068
creationDate: "2021-04-21T17:32:28Z"
10051069
lastUpdate: "2021-04-21T17:32:28Z"
@@ -1038,6 +1102,7 @@ components:
10381102
- reference
10391103
ownerId: "1"
10401104
worskspaceId: "1"
1105+
state: Created
10411106
creationDate: "2021-04-21T17:32:28Z"
10421107
lastUpdate: "2021-04-21T17:32:28Z"
10431108
ownerName: Alice
@@ -1064,6 +1129,7 @@ components:
10641129
parentId: "1"
10651130
ownerId: "1"
10661131
worskspaceId: "1"
1132+
state: Running
10671133
creationDate: "2021-04-21T17:32:28Z"
10681134
lastUpdate: "2021-04-21T17:32:28Z"
10691135
ownerName: Alice
@@ -1076,7 +1142,11 @@ components:
10761142
varType: string
10771143
value: ""
10781144
inherited: true
1079-
lastRunId: "run-bDMr5lM9Vp"
1145+
lastRun:
1146+
csmSimulationRun: "ae8d1959-7a71-48ec-9f33-3fae53358cf1"
1147+
runnerRunId: "SR-V9EYbbOE0"
1148+
workflowId: "c7cd3f15-8a3b-4bcd-b3ca-62ee24c13d67"
1149+
workflowName: "workflow-s-dwpxbzmdxn-zkvd7"
10801150
security:
10811151
default: "viewer"
10821152
accessControlList:
@@ -1090,6 +1160,7 @@ components:
10901160
parentId: "1"
10911161
ownerId: "2"
10921162
worskspaceId: "1"
1163+
state: Failed
10931164
creationDate: "2021-04-21T17:32:28Z"
10941165
lastUpdate: "2021-04-21T17:32:28Z"
10951166
ownerName: Alice
@@ -1102,7 +1173,11 @@ components:
11021173
varType: string
11031174
value: ""
11041175
inherited: true
1105-
lastRunId: "run-bDMr5lM9Vp"
1176+
lastRun:
1177+
csmSimulationRun: "ae8d1959-7a71-48ec-9f33-3fae53358cf1"
1178+
runnerRunId: "SR-V9EYbbOE0"
1179+
workflowId: "c7cd3f15-8a3b-4bcd-b3ca-62ee24c13d67"
1180+
workflowName: "workflow-s-dwpxbzmdxn-zkvd7"
11061181
security:
11071182
default: "viewer"
11081183
accessControlList:

0 commit comments

Comments
 (0)