~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/uniter/agent.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2012-2015 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package uniter
 
5
 
 
6
import "github.com/juju/juju/status"
 
7
 
 
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 {
 
13
                return nil
 
14
        }
 
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)
 
19
}
 
20
 
 
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.
 
25
        if err == nil {
 
26
                return
 
27
        }
 
28
        err2 := setAgentStatus(u, status.StatusFailed, userMessage, nil)
 
29
        if err2 != nil {
 
30
                logger.Errorf("updating agent status: %v", err2)
 
31
        }
 
32
}