-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.go
114 lines (100 loc) · 3.57 KB
/
operations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package upgrades
import (
"github.com/juju/version"
jujuversion "github.com/juju/juju/version"
)
// stateUpgradeOperations returns an ordered slice of sets of
// state-based operations needed to upgrade Juju to particular
// version. The slice is ordered by target version, so that the sets
// of operations are executed in order from oldest version to most
// recent.
//
// All state-based operations are run before API-based operations
// (below).
var stateUpgradeOperations = func() []Operation {
steps := []Operation{
upgradeToVersion{version.MustParse("2.0.0"), stateStepsFor20()},
upgradeToVersion{version.MustParse("2.1.0"), stateStepsFor21()},
upgradeToVersion{version.MustParse("2.2.0"), stateStepsFor22()},
upgradeToVersion{version.MustParse("2.2.1"), stateStepsFor221()},
upgradeToVersion{version.MustParse("2.2.2"), stateStepsFor222()},
upgradeToVersion{version.MustParse("2.2.3"), stateStepsFor223()},
upgradeToVersion{version.MustParse("2.3.0"), stateStepsFor23()},
upgradeToVersion{version.MustParse("2.3.1"), stateStepsFor231()},
upgradeToVersion{version.MustParse("2.3.2"), stateStepsFor232()},
upgradeToVersion{version.MustParse("2.3.4"), stateStepsFor234()},
upgradeToVersion{version.MustParse("2.3.6"), stateStepsFor236()},
upgradeToVersion{version.MustParse("2.3.7"), stateStepsFor237()},
upgradeToVersion{version.MustParse("2.4.0"), stateStepsFor24()},
upgradeToVersion{version.MustParse("2.5.0"), stateStepsFor25()},
}
return steps
}
// upgradeOperations returns an ordered slice of sets of API-based
// operations needed to upgrade Juju to particular version. As per the
// state-based operations above, ordering is important.
var upgradeOperations = func() []Operation {
steps := []Operation{
upgradeToVersion{version.MustParse("2.0.0"), stepsFor20()},
upgradeToVersion{version.MustParse("2.2.0"), stepsFor22()},
upgradeToVersion{version.MustParse("2.4.0"), stepsFor24()},
upgradeToVersion{version.MustParse("2.4.5"), stepsFor245()},
}
return steps
}
type opsIterator struct {
from version.Number
to version.Number
allOps []Operation
current int
}
func newStateUpgradeOpsIterator(from version.Number) *opsIterator {
return newOpsIterator(from, jujuversion.Current, stateUpgradeOperations())
}
func newUpgradeOpsIterator(from version.Number) *opsIterator {
return newOpsIterator(from, jujuversion.Current, upgradeOperations())
}
func newOpsIterator(from, to version.Number, ops []Operation) *opsIterator {
// If from is not known, it is 1.16.
if from == version.Zero {
from = version.MustParse("1.16.0")
}
// Clear the version tag of the target release to ensure that all
// upgrade steps for the release are run for alpha and beta
// releases.
// ...but only do this if the agent version has actually changed,
// lest we trigger upgrade mode unnecessarily for non-final
// versions.
if from.Compare(to) != 0 {
to.Tag = ""
}
return &opsIterator{
from: from,
to: to,
allOps: ops,
current: -1,
}
}
func (it *opsIterator) Next() bool {
for {
it.current++
if it.current >= len(it.allOps) {
return false
}
targetVersion := it.allOps[it.current].TargetVersion()
// Do not run steps for versions of Juju earlier or same as we are upgrading from.
if targetVersion.Compare(it.from) <= 0 {
continue
}
// Do not run steps for versions of Juju later than we are upgrading to.
if targetVersion.Compare(it.to) > 0 {
continue
}
return true
}
}
func (it *opsIterator) Get() Operation {
return it.allOps[it.current]
}