in dev-tools/v2tool/manager/manager.go [144:192]
func (in *InputManager) configFromObserved(started time.Time, obs *proto.CheckinObserved) []*proto.UnitExpected {
// any units not in this array will be removed by the server
units := []*proto.UnitExpected{}
for iter, v := range in.Units {
obsUnit, foundObs := findObserved(v.State.Id, obs.Units)
// Case, the unit has already been asked to stop
if v.done {
if foundObs {
if obsUnit.State == proto.State_STOPPED { // case: The unit has been marked as done, and now stopped
in.logger.Debugf("Unit %s marked as done by v2tool, found in state %; removing", v.State.Id, obsUnit.State.String())
continue
}
} else { // case: The unit is done, and has been completely removed
continue
}
}
if foundObs && obsUnit.State == proto.State_STOPPED {
in.logger.Warnf("Unit %s was not explicitly stopped, but is now stopped; removing")
continue
}
// unit has previously been sent to client
if foundObs {
if obsUnit.State == proto.State_FAILED {
in.logger.Debugf("Unit %s has been marked as failed; removing", v.State.Id)
continue
}
// Do we no want to stop?
// The check functions are responsible for checking the actual status of the state
if !v.done && v.Rules.Stop.Check.Check(started, obsUnit) {
in.logger.Debugf("Unit %s will be marked as STOPPED", v.State.Id)
in.Units[iter].State.State = proto.State_STOPPED
in.Units[iter].State.ConfigStateIdx++
units = append(units, in.Units[iter].State)
in.Units[iter].done = true
} else {
// unit will continue as normal
units = append(units, in.Units[iter].State)
}
} else {
// unit doesn't exist, do we want to start?
if v.Rules.Start.Check.Check(started, nil) {
in.logger.Debugf("Unit %s will be marked as STARTING")
units = append(units, in.Units[iter].State)
}
}
}
return units
}