~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/upgrader/error.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 2014 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package upgrader
 
5
 
 
6
import (
 
7
        "github.com/juju/version"
 
8
 
 
9
        "github.com/juju/juju/agent/tools"
 
10
)
 
11
 
 
12
// UpgradeReadyError is returned by an Upgrader to report that
 
13
// an upgrade is ready to be performed and a restart is due.
 
14
type UpgradeReadyError struct {
 
15
        AgentName string
 
16
        OldTools  version.Binary
 
17
        NewTools  version.Binary
 
18
        DataDir   string
 
19
}
 
20
 
 
21
func (e *UpgradeReadyError) Error() string {
 
22
        return "must restart: an agent upgrade is available"
 
23
}
 
24
 
 
25
// ChangeAgentTools does the actual agent upgrade.
 
26
// It should be called just before an agent exits, so that
 
27
// it will restart running the new tools.
 
28
func (e *UpgradeReadyError) ChangeAgentTools() error {
 
29
        agentTools, err := tools.ChangeAgentTools(e.DataDir, e.AgentName, e.NewTools)
 
30
        if err != nil {
 
31
                return err
 
32
        }
 
33
        logger.Infof("upgraded from %v to %v (%q)", e.OldTools, agentTools.Version, agentTools.URL)
 
34
        return nil
 
35
}