1
// Copyright 2012-2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
6
import "github.com/juju/juju/status"
8
// setAgentStatus sets the unit's status if it has changed since last time this method was called.
9
func setAgentStatus(u *Uniter, agentStatus status.Status, info string, data map[string]interface{}) error {
10
u.setStatusMutex.Lock()
11
defer u.setStatusMutex.Unlock()
12
if u.lastReportedStatus == agentStatus && u.lastReportedMessage == info {
15
u.lastReportedStatus = agentStatus
16
u.lastReportedMessage = info
17
logger.Debugf("[AGENT-STATUS] %s: %s", agentStatus, info)
18
return u.unit.SetAgentStatus(agentStatus, info, data)
21
// reportAgentError reports if there was an error performing an agent operation.
22
func reportAgentError(u *Uniter, userMessage string, err error) {
23
// If a non-nil error is reported (e.g. due to an operation failing),
24
// set the agent status to Failed.
28
err2 := setAgentStatus(u, status.StatusFailed, userMessage, nil)
30
logger.Errorf("updating agent status: %v", err2)