示例#1
0
文件: status.go 项目: imoapps/juju
// processUnitLost determines whether the given unit should be marked as lost.
// TODO(fwereade/wallyworld): this is also model-level code and should sit in
// between state and this package.
func processUnitLost(unit *state.Unit, status *params.UnitStatus) {
	if !canBeLost(status) {
		// The status is allocating or installing - there's no point
		// in enquiring about the agent liveness.
		return
	}
	agentAlive, err := unit.AgentPresence()
	if err != nil {
		return
	}

	if unit.Life() != state.Dead && !agentAlive {
		// If the unit is in error, it would be bad to throw away
		// the error information as when the agent reconnects, that
		// error information would then be lost.
		if status.Workload.Status != params.StatusError {
			status.Workload.Status = params.StatusUnknown
			status.Workload.Info = fmt.Sprintf("agent is lost, sorry! See 'juju status-history %s'", unit.Name())
		}
		status.UnitAgent.Status = params.StatusLost
		status.UnitAgent.Info = "agent is not communicating with the server"
	}
}