~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/worker/upgradesteps/worker.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
        "github.com/juju/juju/agent"
17
17
        "github.com/juju/juju/api"
18
 
        "github.com/juju/juju/apiserver/params"
19
18
        cmdutil "github.com/juju/juju/cmd/jujud/util"
20
19
        "github.com/juju/juju/mongo"
21
20
        "github.com/juju/juju/state"
22
21
        "github.com/juju/juju/state/multiwatcher"
 
22
        "github.com/juju/juju/status"
23
23
        "github.com/juju/juju/upgrades"
24
 
        "github.com/juju/juju/version"
 
24
        jujuversion "github.com/juju/juju/version"
25
25
        "github.com/juju/juju/worker"
26
26
        "github.com/juju/juju/worker/gate"
27
27
        "github.com/juju/juju/wrench"
 
28
        "github.com/juju/version"
28
29
)
29
30
 
30
31
var logger = loggo.GetLogger("juju.worker.upgradesteps")
68
69
        err := a.ChangeConfig(func(agentConfig agent.ConfigSetter) error {
69
70
                if !upgrades.AreUpgradesDefined(agentConfig.UpgradedToVersion()) {
70
71
                        logger.Infof("no upgrade steps required or upgrade steps for %v "+
71
 
                                "have already been run.", version.Current)
 
72
                                "have already been run.", jujuversion.Current)
72
73
                        lock.Unlock()
73
74
 
74
75
                        // Even if no upgrade is required the version number in
75
76
                        // the agent's config still needs to be bumped.
76
 
                        agentConfig.SetUpgradedToVersion(version.Current)
 
77
                        agentConfig.SetUpgradedToVersion(jujuversion.Current)
77
78
                }
78
79
                return nil
79
80
        })
86
87
// StatusSetter defines the single method required to set an agent's
87
88
// status.
88
89
type StatusSetter interface {
89
 
        SetStatus(status params.Status, info string, data map[string]interface{}) error
 
90
        SetStatus(setableStatus status.Status, info string, data map[string]interface{}) error
90
91
}
91
92
 
92
93
// NewWorker returns a new instance of the upgradesteps worker. It
97
98
        agent agent.Agent,
98
99
        apiConn api.Connection,
99
100
        jobs []multiwatcher.MachineJob,
100
 
        openState func() (*state.State, func(), error),
 
101
        openState func() (*state.State, error),
101
102
        preUpgradeSteps func(st *state.State, agentConf agent.Config, isController, isMasterServer bool) error,
102
103
        machine StatusSetter,
103
104
) (worker.Worker, error) {
128
129
        agent           agent.Agent
129
130
        apiConn         api.Connection
130
131
        jobs            []multiwatcher.MachineJob
131
 
        openState       func() (*state.State, func(), error)
 
132
        openState       func() (*state.State, error)
132
133
        preUpgradeSteps func(st *state.State, agentConf agent.Config, isController, isMaster bool) error
133
134
        machine         StatusSetter
134
135
 
175
176
        }
176
177
 
177
178
        w.fromVersion = w.agent.CurrentConfig().UpgradedToVersion()
178
 
        w.toVersion = version.Current
 
179
        w.toVersion = jujuversion.Current
179
180
        if w.fromVersion == w.toVersion {
180
181
                logger.Infof("upgrade to %v already completed.", w.toVersion)
181
182
                w.upgradeComplete.Unlock()
194
195
        // of StateWorker, because we have no guarantees about when
195
196
        // and how often StateWorker might run.
196
197
        if w.isController {
197
 
                var closer func()
198
198
                var err error
199
 
                if w.st, closer, err = w.openState(); err != nil {
 
199
                if w.st, err = w.openState(); err != nil {
200
200
                        return err
201
201
                }
202
 
                defer closer()
 
202
                defer w.st.Close()
203
203
 
204
204
                if w.isMaster, err = IsMachineMaster(w.st, w.tag.Id()); err != nil {
205
205
                        return errors.Trace(err)
223
223
        } else {
224
224
                // Upgrade succeeded - signal that the upgrade is complete.
225
225
                logger.Infof("upgrade to %v completed successfully.", w.toVersion)
226
 
                w.machine.SetStatus(params.StatusStarted, "", nil)
 
226
                w.machine.SetStatus(status.StatusStarted, "", nil)
227
227
                w.upgradeComplete.Unlock()
228
228
        }
229
229
        return nil
343
343
// designed to be called via a machine agent's ChangeConfig method.
344
344
func (w *upgradesteps) runUpgradeSteps(agentConfig agent.ConfigSetter) error {
345
345
        var upgradeErr error
346
 
        w.machine.SetStatus(params.StatusStarted, fmt.Sprintf("upgrading to %v", w.toVersion), nil)
 
346
        w.machine.SetStatus(status.StatusStarted, fmt.Sprintf("upgrading to %v", w.toVersion), nil)
347
347
 
348
348
        context := upgrades.NewContext(agentConfig, w.apiConn, w.st)
349
349
        logger.Infof("starting upgrade from %v to %v for %q", w.fromVersion, w.toVersion, w.tag)
377
377
        }
378
378
        logger.Errorf("upgrade from %v to %v for %q failed (%s): %v",
379
379
                w.fromVersion, w.toVersion, w.tag, retryText, err)
380
 
        w.machine.SetStatus(params.StatusError,
 
380
        w.machine.SetStatus(status.StatusError,
381
381
                fmt.Sprintf("upgrade to %v failed (%s): %v", w.toVersion, retryText, err), nil)
382
382
}
383
383