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
22 changes: 22 additions & 0 deletions core/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
RunNumber: env.GetCurrentRunNumber(),
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_ONGOING,
Message: "transition step starting",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -189,6 +190,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Error: errHooks.Error(),
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_DONE_ERROR,
Message: "transition step finished",
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand Down Expand Up @@ -325,6 +327,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step finished",
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_ONGOING,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -339,6 +342,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Transition: e.Event,
TransitionStep: trigger,
Message: "transition step starting",
TransitionStatus: pb.OpStatus_ONGOING,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -365,6 +369,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Error: errHooks.Error(),
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_DONE_ERROR,
Message: "transition step finished",
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -389,6 +394,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step finished",
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_DONE_ERROR,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -404,16 +410,19 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step starting",
Transition: e.Event,
TransitionStep: fmt.Sprintf("tasks_%s", e.Event),
TransitionStatus: pb.OpStatus_ONGOING,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})

env.handlerFunc()(e)

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

the.EventWriterWithTopic(topic.Environment).WriteEvent(&pb.Ev_EnvironmentEvent{
Expand All @@ -424,6 +433,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step finished",
Transition: e.Event,
TransitionStep: fmt.Sprintf("tasks_%s", e.Event),
TransitionStatus: transitionStatus,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -437,6 +447,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
RunNumber: env.currentRunNumber,
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_ONGOING,
Message: "transition step starting",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -454,8 +465,10 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
}

errorMsg := ""
transitionStatus := pb.OpStatus_ONGOING
if e.Err != nil {
errorMsg = e.Err.Error()
transitionStatus = pb.OpStatus_DONE_ERROR
}

the.EventWriterWithTopic(topic.Environment).WriteEvent(&pb.Ev_EnvironmentEvent{
Expand All @@ -466,6 +479,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step finished",
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: transitionStatus,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand Down Expand Up @@ -496,6 +510,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
RunNumber: env.currentRunNumber,
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: pb.OpStatus_ONGOING,
Message: "transition step starting",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -611,8 +626,10 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
}

errorMsg := ""
transitionStatus := pb.OpStatus_ONGOING
if e.Err != nil {
errorMsg = e.Err.Error()
transitionStatus = pb.OpStatus_DONE_ERROR
}

// publish transition step complete event
Expand All @@ -624,6 +641,7 @@ func newEnvironment(userVars map[string]string, newId uid.ID) (env *Environment,
Message: "transition step finished",
Transition: e.Event,
TransitionStep: trigger,
TransitionStatus: transitionStatus,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand Down Expand Up @@ -990,6 +1008,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
RunNumber: env.currentRunNumber,
Message: "transition starting",
Transition: t.eventName(),
TransitionStatus: pb.OpStatus_STARTED,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -1003,6 +1022,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
Error: err.Error(),
Message: "transition impossible",
Transition: t.eventName(),
TransitionStatus: pb.OpStatus_DONE_ERROR,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -1018,6 +1038,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
Error: err.Error(),
Message: "transition error",
Transition: t.eventName(),
TransitionStatus: pb.OpStatus_DONE_ERROR,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand All @@ -1028,6 +1049,7 @@ func (env *Environment) TryTransition(t Transition) (err error) {
RunNumber: env.currentRunNumber,
Message: "transition completed successfully",
Transition: t.eventName(),
TransitionStatus: pb.OpStatus_DONE_OK,
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
})
Expand Down
39 changes: 27 additions & 12 deletions core/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,13 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
}

the.EventWriterWithTopic(topic.Environment).WriteEvent(&evpb.Ev_EnvironmentEvent{
EnvironmentId: newId.String(),
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
Message: "instantiating",
LastRequestUser: lastRequestUser,
EnvironmentId: newId.String(),
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
TransitionStatus: evpb.OpStatus_STARTED,
Message: "instantiating",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: &evpb.WorkflowTemplateInfo{
Path: workflowPath,
Public: workflowPublicInfo.IsPublic,
Expand Down Expand Up @@ -322,6 +323,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "running hooks",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -339,6 +341,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
State: "PENDING",
Transition: "CREATE",
TransitionStep: "CREATE",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "loading workflow",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -386,6 +389,7 @@ func (envs *Manager) CreateEnvironment(workflowPath string, userVars map[string]
State: env.CurrentState(),
Transition: "CREATE",
TransitionStep: "after_CREATE",
TransitionStatus: evpb.OpStatus_DONE_OK,
Message: "workflow loaded",
Vars: cvs, // we push the full var stack of the root role in the workflow loaded event
LastRequestUser: lastRequestUser,
Expand Down Expand Up @@ -605,6 +609,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: env.CurrentState(),
Transition: "DESTROY",
TransitionStep: "before_DESTROY",
TransitionStatus: evpb.OpStatus_STARTED,
Message: "workflow teardown started",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -619,6 +624,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: env.CurrentState(),
Transition: "DESTROY",
TransitionStep: "leave_" + env.CurrentState(),
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "workflow teardown ongoing",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -703,6 +709,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: env.CurrentState(),
Transition: "DESTROY",
TransitionStep: "DESTROY",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "releasing tasks",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -771,6 +778,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: "DONE",
Transition: "DESTROY",
TransitionStep: "after_DESTROY",
TransitionStatus: evpb.OpStatus_DONE_ERROR,
Message: "environment teardown finished with error",
Error: err.Error(),
LastRequestUser: env.GetLastRequestUser(),
Expand All @@ -785,6 +793,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: env.CurrentState(),
Transition: "DESTROY",
TransitionStep: "after_DESTROY",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "running DESTROY hooks",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -855,6 +864,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: "DONE",
Transition: "DESTROY",
TransitionStep: "after_DESTROY",
TransitionStatus: evpb.OpStatus_DONE_ERROR,
Message: "environment teardown finished with error",
Error: err.Error(),
LastRequestUser: env.GetLastRequestUser(),
Expand Down Expand Up @@ -883,6 +893,7 @@ func (envs *Manager) TeardownEnvironment(environmentId uid.ID, force bool) error
State: "DONE",
Transition: "DESTROY",
TransitionStep: "after_DESTROY",
TransitionStatus: evpb.OpStatus_DONE_OK,
Message: "environment teardown complete",
LastRequestUser: env.GetLastRequestUser(),
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand Down Expand Up @@ -1195,12 +1206,13 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
}

the.EventWriterWithTopic(topic.Environment).WriteEvent(&evpb.Ev_EnvironmentEvent{
EnvironmentId: newId.String(),
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
Message: "instantiating",
LastRequestUser: lastRequestUser,
EnvironmentId: newId.String(),
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
TransitionStatus: evpb.OpStatus_STARTED,
Message: "instantiating",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: &evpb.WorkflowTemplateInfo{
Path: workflowPath,
Public: workflowPublicInfo.IsPublic,
Expand Down Expand Up @@ -1234,6 +1246,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
State: "PENDING",
Transition: "CREATE",
TransitionStep: "before_CREATE",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "running hooks",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -1254,6 +1267,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
State: "PENDING",
Transition: "CREATE",
TransitionStep: "CREATE",
TransitionStatus: evpb.OpStatus_ONGOING,
Message: "loading workflow",
LastRequestUser: lastRequestUser,
WorkflowTemplateInfo: env.GetWorkflowInfo(),
Expand All @@ -1272,6 +1286,7 @@ func (envs *Manager) CreateAutoEnvironment(workflowPath string, userVars map[str
State: env.CurrentState(),
Transition: "CREATE",
TransitionStep: "after_CREATE",
TransitionStatus: evpb.OpStatus_DONE_OK,
Message: "workflow loaded",
Vars: cvs, // we push the full var stack of the root role in the workflow loaded event
LastRequestUser: lastRequestUser,
Expand Down
Loading