Skip to content

Commit f698506

Browse files
claireguyotteo
authored andcommitted
[OCTRL-649][core] Corrections after PR review.
1 parent 1a11c4f commit f698506

File tree

4 files changed

+41
-33
lines changed

4 files changed

+41
-33
lines changed

core/environment/manager.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,22 @@ func NewEnvManager(tm *task.Manager, incomingEventCh <-chan event.Event) *Manage
8282

8383
case *event.TasksReleasedEvent:
8484
// If we got a TasksReleasedEvent, it must be matched with a pending
85-
// environment teardown if the task is critical.
85+
// environment teardown.
8686
if thisEnvCh, ok := instance.pendingTeardownsCh[typedEvent.GetEnvironmentId()]; ok {
8787
thisEnvCh <- typedEvent
8888
close(thisEnvCh)
8989
delete(instance.pendingTeardownsCh, typedEvent.GetEnvironmentId())
9090
} else {
91+
// If there is no pending environment teardown, it means that the released task stopped
92+
// unexpectedly. In that case, the environment should get torn-down only if the task
93+
// is critical.
9194
var releaseCriticalTask = false
9295
for _, v := range typedEvent.GetTaskIds() {
93-
if tm.GetTask(v).GetTraits().Critical == true || tm.GetTask(v).GetParent().GetTaskTraits().Critical == true {
94-
releaseCriticalTask = true
96+
if tm.GetTask(v) != nil {
97+
if tm.GetTask(v).GetTraits().Critical == true {
98+
//|| tm.GetTask(v).GetParent().GetTaskTraits().Critical == true
99+
releaseCriticalTask = true
100+
}
95101
}
96102
}
97103
if releaseCriticalTask {
@@ -103,14 +109,19 @@ func NewEnvManager(tm *task.Manager, incomingEventCh <-chan event.Event) *Manage
103109

104110
case *event.TasksStateChangedEvent:
105111
// If we got a TasksStateChangedEvent, it must be matched with a pending
106-
// environment transition if the task is critical.
112+
// environment transition.
107113
if thisEnvCh, ok := instance.pendingStateChangeCh[typedEvent.GetEnvironmentId()]; ok {
108114
thisEnvCh <- typedEvent
109115
} else {
116+
// If there is no pending environment transition, it means that the changed task did so
117+
// unexpectedly. In that case, the environment should transition only if the task
118+
// is critical.
110119
var changeCriticalTask = false
111120
for _, v := range typedEvent.GetTaskIds() {
112-
if tm.GetTask(v).GetTraits().Critical == true || tm.GetTask(v).GetParent().GetTaskTraits().Critical == true {
113-
changeCriticalTask = true
121+
if tm.GetTask(v) != nil {
122+
if tm.GetTask(v).GetTraits().Critical == true {
123+
changeCriticalTask = true
124+
}
114125
}
115126
}
116127
if changeCriticalTask {

core/task/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ type TasksDeploymentError struct {
8282
}
8383

8484
func (r TasksDeploymentError) Error() string {
85-
return fmt.Sprintf("deployment failed for %d critical tasks [%s], and %d non-critical tasks [%s]", len(r.failedCriticalDescriptors), r.failedCriticalDescriptors.String(), len(r.failedNonCriticalDescriptors), r.failedNonCriticalDescriptors.String())
85+
return fmt.Sprintf("deployment failed for %d critical tasks, and %d non-critical tasks; critical tasks: [%s]; non-critical tasks: [%s]", len(r.failedCriticalDescriptors), len(r.failedNonCriticalDescriptors), r.failedCriticalDescriptors.String(), r.failedNonCriticalDescriptors.String())
8686
}
8787

8888
type TaskAlreadyReleasedError taskErrorBase

core/task/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,10 @@ func (m *Manager) configureTasks(envId uid.ID, tasks Tasks) error {
690690

691691
if len(taskNonCriticalErrors) > 0 {
692692
log.WithField("partition", envId).
693-
Warnf("non-critical task configuration failure, errors: %s", strings.Join(taskNonCriticalErrors, "; "))
693+
Warnf("CONFIGURE could not complete for non-critical tasks, errors: %s", strings.Join(taskNonCriticalErrors, "; "))
694694
}
695695
if len(taskCriticalErrors) > 0 {
696-
return fmt.Errorf("CONFIGURE could not complete, errors: %s", strings.Join(taskCriticalErrors, "; "))
696+
return fmt.Errorf("CONFIGURE could not complete for critical tasks, errors: %s", strings.Join(taskCriticalErrors, "; "))
697697
}
698698
return nil
699699
} else {
@@ -768,10 +768,10 @@ func (m *Manager) transitionTasks(envId uid.ID, tasks Tasks, src string, event s
768768

769769
if len(taskNonCriticalErrors) > 0 {
770770
log.WithField("partition", envId).
771-
Warnf("non-critical task transition failure, errors: %s", strings.Join(taskNonCriticalErrors, "; "))
771+
Warnf("%s could not complete for non-critical tasks, errors: %s", event, strings.Join(taskNonCriticalErrors, "; "))
772772
}
773773
if len(taskCriticalErrors) > 0 {
774-
return fmt.Errorf("transition could not complete, errors: %s", strings.Join(taskCriticalErrors, "; "))
774+
return fmt.Errorf("%s could not complete for critical tasks, errors: %s", event, strings.Join(taskCriticalErrors, "; "))
775775
}
776776
return nil
777777
} else {

core/workflow/safestate.go

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,30 @@ type SafeState struct {
3434
state task.State
3535
}
3636

37-
func aggregateState(roles []Role, s task.State) (state task.State) {
37+
func aggregateState(roles []Role) (state task.State) {
38+
state = task.INVARIANT
3839
if len(roles) == 0 {
39-
state = task.INVARIANT
4040
return
4141
}
42-
state = s
43-
if len(roles) > 1 {
44-
for _, c := range roles[1:] {
45-
taskR, isTaskRole := c.(*taskRole)
46-
callR, isCallRole := c.(*callRole)
47-
if isTaskRole {
48-
if !taskR.Critical {
49-
continue
50-
}
51-
} else if isCallRole {
52-
if !callR.Critical {
53-
continue
54-
}
42+
for _, c := range roles {
43+
taskR, isTaskRole := c.(*taskRole)
44+
callR, isCallRole := c.(*callRole)
45+
if isTaskRole {
46+
if !taskR.Critical {
47+
continue
5548
}
56-
if state == task.MIXED {
57-
return
49+
} else if isCallRole {
50+
if !callR.Critical {
51+
continue
5852
}
59-
if state == task.ERROR {
60-
return
61-
}
62-
state = state.X(c.GetState())
6353
}
54+
if state == task.MIXED {
55+
return
56+
}
57+
if state == task.ERROR {
58+
return
59+
}
60+
state = state.X(c.GetState())
6461
}
6562
return
6663
}
@@ -88,7 +85,7 @@ func (t *SafeState) merge(s task.State, r Role) {
8885
return
8986
default:
9087
allRoles := r.GetRoles()
91-
t.state = aggregateState(allRoles, s)
88+
t.state = aggregateState(allRoles)
9289
}
9390
}
9491

0 commit comments

Comments
 (0)