Skip to content

Commit e97b3fc

Browse files
authored
Add missing transitionStatus to Environment Events (#738)
I consider transitionStatus as the status of the whole transition, i.e. even if the transition has multiple steps, OpStatus_STARTED and OpStatus_DONE_OK should be published just once, as the first and the last event for a transition. Fixes OCTRL-1038.
1 parent 1f512fb commit e97b3fc

File tree

2 files changed

+49
-12
lines changed

2 files changed

+49
-12
lines changed

core/environment/environment.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
173173
RunNumber: env.GetCurrentRunNumber(),
174174
Transition: e.Event,
175175
TransitionStep: trigger,
176+
TransitionStatus: pb.OpStatus_ONGOING,
176177
Message: "transition step starting",
177178
LastRequestUser: env.GetLastRequestUser(),
178179
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -189,6 +190,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
189190
Error: errHooks.Error(),
190191
Transition: e.Event,
191192
TransitionStep: trigger,
193+
TransitionStatus: pb.OpStatus_DONE_ERROR,
192194
Message: "transition step finished",
193195
WorkflowTemplateInfo: env.GetWorkflowInfo(),
194196
})
@@ -325,6 +327,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
325327
Message: "transition step finished",
326328
Transition: e.Event,
327329
TransitionStep: trigger,
330+
TransitionStatus: pb.OpStatus_ONGOING,
328331
LastRequestUser: env.GetLastRequestUser(),
329332
WorkflowTemplateInfo: env.GetWorkflowInfo(),
330333
})
@@ -339,6 +342,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
339342
Transition: e.Event,
340343
TransitionStep: trigger,
341344
Message: "transition step starting",
345+
TransitionStatus: pb.OpStatus_ONGOING,
342346
LastRequestUser: env.GetLastRequestUser(),
343347
WorkflowTemplateInfo: env.GetWorkflowInfo(),
344348
})
@@ -365,6 +369,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
365369
Error: errHooks.Error(),
366370
Transition: e.Event,
367371
TransitionStep: trigger,
372+
TransitionStatus: pb.OpStatus_DONE_ERROR,
368373
Message: "transition step finished",
369374
WorkflowTemplateInfo: env.GetWorkflowInfo(),
370375
})
@@ -389,6 +394,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
389394
Message: "transition step finished",
390395
Transition: e.Event,
391396
TransitionStep: trigger,
397+
TransitionStatus: pb.OpStatus_DONE_ERROR,
392398
LastRequestUser: env.GetLastRequestUser(),
393399
WorkflowTemplateInfo: env.GetWorkflowInfo(),
394400
})
@@ -404,16 +410,19 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
404410
Message: "transition step starting",
405411
Transition: e.Event,
406412
TransitionStep: fmt.Sprintf("tasks_%s", e.Event),
413+
TransitionStatus: pb.OpStatus_ONGOING,
407414
LastRequestUser: env.GetLastRequestUser(),
408415
WorkflowTemplateInfo: env.GetWorkflowInfo(),
409416
})
410417

411418
env.handlerFunc()(e)
412419

413420
eventState := e.Dst // we set the destination state here instead of the current for the event write, if the tasks have transitioned
421+
transitionStatus := pb.OpStatus_ONGOING
414422
if e.Err != nil {
415423
errorMsg = e.Err.Error()
416424
eventState = e.Src
425+
transitionStatus = pb.OpStatus_DONE_ERROR
417426
}
418427

419428
the.EventWriterWithTopic(topic.Environment).WriteEvent(&pb.Ev_EnvironmentEvent{
@@ -424,6 +433,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
424433
Message: "transition step finished",
425434
Transition: e.Event,
426435
TransitionStep: fmt.Sprintf("tasks_%s", e.Event),
436+
TransitionStatus: transitionStatus,
427437
LastRequestUser: env.GetLastRequestUser(),
428438
WorkflowTemplateInfo: env.GetWorkflowInfo(),
429439
})
@@ -437,6 +447,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
437447
RunNumber: env.currentRunNumber,
438448
Transition: e.Event,
439449
TransitionStep: trigger,
450+
TransitionStatus: pb.OpStatus_ONGOING,
440451
Message: "transition step starting",
441452
LastRequestUser: env.GetLastRequestUser(),
442453
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -454,8 +465,10 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
454465
}
455466

456467
errorMsg := ""
468+
transitionStatus := pb.OpStatus_ONGOING
457469
if e.Err != nil {
458470
errorMsg = e.Err.Error()
471+
transitionStatus = pb.OpStatus_DONE_ERROR
459472
}
460473

461474
the.EventWriterWithTopic(topic.Environment).WriteEvent(&pb.Ev_EnvironmentEvent{
@@ -466,6 +479,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
466479
Message: "transition step finished",
467480
Transition: e.Event,
468481
TransitionStep: trigger,
482+
TransitionStatus: transitionStatus,
469483
LastRequestUser: env.GetLastRequestUser(),
470484
WorkflowTemplateInfo: env.GetWorkflowInfo(),
471485
})
@@ -496,6 +510,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
496510
RunNumber: env.currentRunNumber,
497511
Transition: e.Event,
498512
TransitionStep: trigger,
513+
TransitionStatus: pb.OpStatus_ONGOING,
499514
Message: "transition step starting",
500515
LastRequestUser: env.GetLastRequestUser(),
501516
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -611,8 +626,10 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
611626
}
612627

613628
errorMsg := ""
629+
transitionStatus := pb.OpStatus_ONGOING
614630
if e.Err != nil {
615631
errorMsg = e.Err.Error()
632+
transitionStatus = pb.OpStatus_DONE_ERROR
616633
}
617634

618635
// publish transition step complete event
@@ -624,6 +641,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
624641
Message: "transition step finished",
625642
Transition: e.Event,
626643
TransitionStep: trigger,
644+
TransitionStatus: transitionStatus,
627645
LastRequestUser: env.GetLastRequestUser(),
628646
WorkflowTemplateInfo: env.GetWorkflowInfo(),
629647
})
@@ -990,6 +1008,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
9901008
RunNumber: env.currentRunNumber,
9911009
Message: "transition starting",
9921010
Transition: t.eventName(),
1011+
TransitionStatus: pb.OpStatus_STARTED,
9931012
LastRequestUser: env.GetLastRequestUser(),
9941013
WorkflowTemplateInfo: env.GetWorkflowInfo(),
9951014
})
@@ -1003,6 +1022,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
10031022
Error: err.Error(),
10041023
Message: "transition impossible",
10051024
Transition: t.eventName(),
1025+
TransitionStatus: pb.OpStatus_DONE_ERROR,
10061026
LastRequestUser: env.GetLastRequestUser(),
10071027
WorkflowTemplateInfo: env.GetWorkflowInfo(),
10081028
})
@@ -1018,6 +1038,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
10181038
Error: err.Error(),
10191039
Message: "transition error",
10201040
Transition: t.eventName(),
1041+
TransitionStatus: pb.OpStatus_DONE_ERROR,
10211042
LastRequestUser: env.GetLastRequestUser(),
10221043
WorkflowTemplateInfo: env.GetWorkflowInfo(),
10231044
})
@@ -1028,6 +1049,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
10281049
RunNumber: env.currentRunNumber,
10291050
Message: "transition completed successfully",
10301051
Transition: t.eventName(),
1052+
TransitionStatus: pb.OpStatus_DONE_OK,
10311053
LastRequestUser: env.GetLastRequestUser(),
10321054
WorkflowTemplateInfo: env.GetWorkflowInfo(),
10331055
})

core/environment/manager.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
226226
}
227227

228228
the.EventWriterWithTopic(topic.Environment).WriteEvent(&evpb.Ev_EnvironmentEvent{
229-
EnvironmentId: newId.String(),
230-
State: "PENDING",
231-
Transition: "CREATE",
232-
TransitionStep: "before_CREATE",
233-
Message: "instantiating",
234-
LastRequestUser: lastRequestUser,
229+
EnvironmentId: newId.String(),
230+
State: "PENDING",
231+
Transition: "CREATE",
232+
TransitionStep: "before_CREATE",
233+
TransitionStatus: evpb.OpStatus_STARTED,
234+
Message: "instantiating",
235+
LastRequestUser: lastRequestUser,
235236
WorkflowTemplateInfo: &evpb.WorkflowTemplateInfo{
236237
Path: workflowPath,
237238
Public: workflowPublicInfo.IsPublic,
@@ -322,6 +323,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
322323
State: "PENDING",
323324
Transition: "CREATE",
324325
TransitionStep: "before_CREATE",
326+
TransitionStatus: evpb.OpStatus_ONGOING,
325327
Message: "running hooks",
326328
LastRequestUser: lastRequestUser,
327329
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -339,6 +341,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
339341
State: "PENDING",
340342
Transition: "CREATE",
341343
TransitionStep: "CREATE",
344+
TransitionStatus: evpb.OpStatus_ONGOING,
342345
Message: "loading workflow",
343346
LastRequestUser: lastRequestUser,
344347
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -386,6 +389,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
386389
State: env.CurrentState(),
387390
Transition: "CREATE",
388391
TransitionStep: "after_CREATE",
392+
TransitionStatus: evpb.OpStatus_DONE_OK,
389393
Message: "workflow loaded",
390394
Vars: cvs, // we push the full var stack of the root role in the workflow loaded event
391395
LastRequestUser: lastRequestUser,
@@ -605,6 +609,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
605609
State: env.CurrentState(),
606610
Transition: "DESTROY",
607611
TransitionStep: "before_DESTROY",
612+
TransitionStatus: evpb.OpStatus_STARTED,
608613
Message: "workflow teardown started",
609614
LastRequestUser: env.GetLastRequestUser(),
610615
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -619,6 +624,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
619624
State: env.CurrentState(),
620625
Transition: "DESTROY",
621626
TransitionStep: "leave_" + env.CurrentState(),
627+
TransitionStatus: evpb.OpStatus_ONGOING,
622628
Message: "workflow teardown ongoing",
623629
LastRequestUser: env.GetLastRequestUser(),
624630
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -703,6 +709,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
703709
State: env.CurrentState(),
704710
Transition: "DESTROY",
705711
TransitionStep: "DESTROY",
712+
TransitionStatus: evpb.OpStatus_ONGOING,
706713
Message: "releasing tasks",
707714
LastRequestUser: env.GetLastRequestUser(),
708715
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -771,6 +778,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
771778
State: "DONE",
772779
Transition: "DESTROY",
773780
TransitionStep: "after_DESTROY",
781+
TransitionStatus: evpb.OpStatus_DONE_ERROR,
774782
Message: "environment teardown finished with error",
775783
Error: err.Error(),
776784
LastRequestUser: env.GetLastRequestUser(),
@@ -785,6 +793,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
785793
State: env.CurrentState(),
786794
Transition: "DESTROY",
787795
TransitionStep: "after_DESTROY",
796+
TransitionStatus: evpb.OpStatus_ONGOING,
788797
Message: "running DESTROY hooks",
789798
LastRequestUser: env.GetLastRequestUser(),
790799
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -855,6 +864,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
855864
State: "DONE",
856865
Transition: "DESTROY",
857866
TransitionStep: "after_DESTROY",
867+
TransitionStatus: evpb.OpStatus_DONE_ERROR,
858868
Message: "environment teardown finished with error",
859869
Error: err.Error(),
860870
LastRequestUser: env.GetLastRequestUser(),
@@ -883,6 +893,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
883893
State: "DONE",
884894
Transition: "DESTROY",
885895
TransitionStep: "after_DESTROY",
896+
TransitionStatus: evpb.OpStatus_DONE_OK,
886897
Message: "environment teardown complete",
887898
LastRequestUser: env.GetLastRequestUser(),
888899
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -1195,12 +1206,13 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
11951206
}
11961207

11971208
the.EventWriterWithTopic(topic.Environment).WriteEvent(&evpb.Ev_EnvironmentEvent{
1198-
EnvironmentId: newId.String(),
1199-
State: "PENDING",
1200-
Transition: "CREATE",
1201-
TransitionStep: "before_CREATE",
1202-
Message: "instantiating",
1203-
LastRequestUser: lastRequestUser,
1209+
EnvironmentId: newId.String(),
1210+
State: "PENDING",
1211+
Transition: "CREATE",
1212+
TransitionStep: "before_CREATE",
1213+
TransitionStatus: evpb.OpStatus_STARTED,
1214+
Message: "instantiating",
1215+
LastRequestUser: lastRequestUser,
12041216
WorkflowTemplateInfo: &evpb.WorkflowTemplateInfo{
12051217
Path: workflowPath,
12061218
Public: workflowPublicInfo.IsPublic,
@@ -1234,6 +1246,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
12341246
State: "PENDING",
12351247
Transition: "CREATE",
12361248
TransitionStep: "before_CREATE",
1249+
TransitionStatus: evpb.OpStatus_ONGOING,
12371250
Message: "running hooks",
12381251
LastRequestUser: lastRequestUser,
12391252
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -1254,6 +1267,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
12541267
State: "PENDING",
12551268
Transition: "CREATE",
12561269
TransitionStep: "CREATE",
1270+
TransitionStatus: evpb.OpStatus_ONGOING,
12571271
Message: "loading workflow",
12581272
LastRequestUser: lastRequestUser,
12591273
WorkflowTemplateInfo: env.GetWorkflowInfo(),
@@ -1272,6 +1286,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
12721286
State: env.CurrentState(),
12731287
Transition: "CREATE",
12741288
TransitionStep: "after_CREATE",
1289+
TransitionStatus: evpb.OpStatus_DONE_OK,
12751290
Message: "workflow loaded",
12761291
Vars: cvs, // we push the full var stack of the root role in the workflow loaded event
12771292
LastRequestUser: lastRequestUser,

0 commit comments

Comments
 (0)