~ubuntu-branches/ubuntu/wily/juju-core/wily

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/upgrades/upgrade.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-28 16:53:15 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20140228165315-g8n1ds0jrtekhxq6
Tags: 1.17.4-0ubuntu1
* New upstream point release (LP: #1261628):
  - https://launchpad.net/juju-core/trunk/1.17.4
  - d/control: Prefer juju-mongodb over mongodb-server for juju-local
    package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
        AgentConfig() agent.Config
83
83
}
84
84
 
85
 
// UpgradeContext is a default Context implementation.
86
 
type UpgradeContext struct {
 
85
// upgradeContext is a default Context implementation.
 
86
type upgradeContext struct {
87
87
        // Work in progress........
88
88
        // Exactly what a context needs is to be determined as the
89
89
        // implementation evolves.
92
92
}
93
93
 
94
94
// APIState is defined on the Context interface.
95
 
func (c *UpgradeContext) APIState() *api.State {
 
95
func (c *upgradeContext) APIState() *api.State {
96
96
        return c.st
97
97
}
98
98
 
99
99
// AgentConfig is defined on the Context interface.
100
 
func (c *UpgradeContext) AgentConfig() agent.Config {
 
100
func (c *upgradeContext) AgentConfig() agent.Config {
101
101
        return c.agentConfig
102
102
}
103
103
 
 
104
// NewContext returns a new upgrade context.
 
105
func NewContext(agentConfig agent.Config, st *api.State) Context {
 
106
        return &upgradeContext{
 
107
                st:          st,
 
108
                agentConfig: agentConfig,
 
109
        }
 
110
}
 
111
 
104
112
// upgradeError records a description of the step being performed and the error.
105
113
type upgradeError struct {
106
114
        description string
113
121
 
114
122
// PerformUpgrade runs the business logic needed to upgrade the current "from" version to this
115
123
// version of Juju on the "target" type of machine.
116
 
func PerformUpgrade(from version.Number, target Target, context Context) *upgradeError {
 
124
func PerformUpgrade(from version.Number, target Target, context Context) error {
117
125
        // If from is not known, it is 1.16.
118
126
        if from == version.Zero {
119
127
                from = version.MustParse("1.16.0")
120
128
        }
121
129
        for _, upgradeOps := range upgradeOperations() {
 
130
                targetVersion := upgradeOps.TargetVersion()
122
131
                // Do not run steps for versions of Juju earlier or same as we are upgrading from.
123
 
                if upgradeOps.TargetVersion().Compare(from) < 1 {
 
132
                if targetVersion.Compare(from) <= 0 {
 
133
                        continue
 
134
                }
 
135
                // Do not run steps for versions of Juju later than we are upgrading to.
 
136
                if targetVersion.Compare(version.Current.Number) > 0 {
124
137
                        continue
125
138
                }
126
139
                if err := runUpgradeSteps(context, target, upgradeOps); err != nil {
150
163
                if !validTarget(target, step) {
151
164
                        continue
152
165
                }
 
166
                logger.Infof("Running upgrade step: %v", step.Description())
153
167
                if err := step.Run(context); err != nil {
 
168
                        logger.Errorf("upgrade step %q failed: %v", step.Description(), err)
154
169
                        return &upgradeError{
155
170
                                description: step.Description(),
156
171
                                err:         err,
157
172
                        }
158
173
                }
159
174
        }
 
175
        logger.Infof("All upgrade steps completed successfully")
160
176
        return nil
161
177
}
162
178