/
installation_states.go
281 lines (264 loc) · 11.9 KB
/
installation_states.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
package model
import mmv1alpha1 "github.com/mattermost/mattermost-operator/apis/mattermost/v1alpha1"
const (
// InstallationStateStable is an installation in a stable state and undergoing no changes.
InstallationStateStable = "stable"
// InstallationStateCreationRequested is an installation waiting to be created.
InstallationStateCreationRequested = "creation-requested"
// InstallationStateCreationPreProvisioning in an installation in the process
// of having managed services created along with any other preparation.
InstallationStateCreationPreProvisioning = "creation-pre-provisioning"
// InstallationStateCreationInProgress is an installation in the process of
// being created.
InstallationStateCreationInProgress = "creation-in-progress"
// InstallationStateCreationDNS is an installation in the process having configuring DNS.
InstallationStateCreationDNS = "creation-configuring-dns"
// InstallationStateCreationFailed is an installation that failed creation.
InstallationStateCreationFailed = "creation-failed"
// InstallationStateCreationNoCompatibleClusters is an installation that
// can't be fully created because there are no compatible clusters.
InstallationStateCreationNoCompatibleClusters = "creation-no-compatible-clusters"
// InstallationStateCreationFinalTasks is the final step of the installation creation.
InstallationStateCreationFinalTasks = "creation-final-tasks"
// InstallationStateHibernationRequested is an installation that is about
// to be put into hibernation.
InstallationStateHibernationRequested = "hibernation-requested"
// InstallationStateHibernationInProgress is an installation that is
// transitioning to hibernation.
InstallationStateHibernationInProgress = "hibernation-in-progress"
// InstallationStateHibernating is an installation that is hibernating.
InstallationStateHibernating = "hibernating"
// InstallationStateWakeUpRequested is an installation that is about to be
// woken up from hibernation.
InstallationStateWakeUpRequested = "wake-up-requested"
// InstallationStateUpdateRequested is an installation that is about to undergo an update.
InstallationStateUpdateRequested = "update-requested"
// InstallationStateUpdateInProgress is an installation that is being updated.
InstallationStateUpdateInProgress = "update-in-progress"
// InstallationStateUpdateFailed is an installation that failed to update.
InstallationStateUpdateFailed = "update-failed"
// InstallationStateImportInProgress is an installation into which a
// Workspace archive is being imported from another service or
// on-premise
InstallationStateImportInProgress = "import-in-progress"
// InstallationStateImportComplete is an installation whose import
// is complete but whose completion has not yet been noted by the
// AWAT. It is otherwise the same as a stable state.
InstallationStateImportComplete = "import-complete"
// InstallationStateDeletionPendingRequested is an installation that is marked
// to be moved to the deletion-pending state.
InstallationStateDeletionPendingRequested = "deletion-pending-requested"
// InstallationStateDeletionPendingInProgress is an installation that is being
// placed into a deletion-pending state.
InstallationStateDeletionPendingInProgress = "deletion-pending-in-progress"
// InstallationStateDeletionPending is an installation that is pending
// deletion.
InstallationStateDeletionPending = "deletion-pending"
// InstallationStateDeletionCancellationRequested is an installation that is
// requested to have its pending deletion cancelled.
InstallationStateDeletionCancellationRequested = "deletion-cancellation-requested"
// InstallationStateDeletionRequested is an installation that deletion has
// been requested on.
InstallationStateDeletionRequested = "deletion-requested"
// InstallationStateDeletionInProgress is an installation being deleted.
InstallationStateDeletionInProgress = "deletion-in-progress"
// InstallationStateDeletionFinalCleanup is the final step of installation deletion.
InstallationStateDeletionFinalCleanup = "deletion-final-cleanup"
// InstallationStateDeletionFailed is an installation that failed deletion.
InstallationStateDeletionFailed = "deletion-failed"
// InstallationStateDeleted is an installation that has been deleted
InstallationStateDeleted = "deleted"
// InstallationStateDBRestorationInProgress is an installation that is being restored from backup.
InstallationStateDBRestorationInProgress = "db-restoration-in-progress"
// InstallationStateDBMigrationInProgress is an installation that is being migrated to different database.
InstallationStateDBMigrationInProgress = "db-migration-in-progress"
// InstallationStateDBMigrationRollbackInProgress is an installation that is being migrated back to original database.
InstallationStateDBMigrationRollbackInProgress = "db-migration-rollback-in-progress"
// InstallationStateDBRestorationFailed is an installation for which database restoration failed.
InstallationStateDBRestorationFailed = "db-restoration-failed"
// InstallationStateDBMigrationFailed is an installation for which database migration failed.
InstallationStateDBMigrationFailed = "db-migration-failed"
// InstallationStateDNSMigrationHibernating is an hibernated installation that is being migrated to different cluster.
InstallationStateDNSMigrationHibernating = "dns-migration-hibernated"
)
const (
// InstallationDefaultSize is the default size for an installation.
InstallationDefaultSize = mmv1alpha1.Size100String
)
// AllInstallationStates is a list of all states an installation can be in.
// Warning:
// When creating a new installation state, it must be added to this list.
var AllInstallationStates = []string{
InstallationStateStable,
InstallationStateCreationRequested,
InstallationStateCreationPreProvisioning,
InstallationStateCreationInProgress,
InstallationStateCreationDNS,
InstallationStateCreationFailed,
InstallationStateCreationNoCompatibleClusters,
InstallationStateCreationFinalTasks,
InstallationStateHibernationRequested,
InstallationStateHibernationInProgress,
InstallationStateHibernating,
InstallationStateWakeUpRequested,
InstallationStateUpdateRequested,
InstallationStateUpdateInProgress,
InstallationStateUpdateFailed,
InstallationStateImportInProgress,
InstallationStateImportComplete,
InstallationStateDeletionPendingRequested,
InstallationStateDeletionPendingInProgress,
InstallationStateDeletionPending,
InstallationStateDeletionCancellationRequested,
InstallationStateDeletionRequested,
InstallationStateDeletionInProgress,
InstallationStateDeletionFinalCleanup,
InstallationStateDeletionFailed,
InstallationStateDeleted,
InstallationStateDBRestorationInProgress,
InstallationStateDBMigrationInProgress,
InstallationStateDBMigrationRollbackInProgress,
InstallationStateDBRestorationFailed,
InstallationStateDBMigrationFailed,
InstallationStateDNSMigrationHibernating,
}
// AllInstallationStatesPendingWork is a list of all installation states that
// the supervisor will attempt to transition towards stable on the next "tick".
// Warning:
// When creating a new installation state, it must be added to this list if the
// cloud installation supervisor should perform some action on its next work cycle.
var AllInstallationStatesPendingWork = []string{
InstallationStateCreationRequested,
InstallationStateCreationPreProvisioning,
InstallationStateCreationInProgress,
InstallationStateCreationNoCompatibleClusters,
InstallationStateCreationFinalTasks,
InstallationStateCreationDNS,
InstallationStateHibernationRequested,
InstallationStateHibernationInProgress,
InstallationStateWakeUpRequested,
InstallationStateUpdateRequested,
InstallationStateUpdateInProgress,
InstallationStateDNSMigrationHibernating,
InstallationStateDeletionPendingRequested,
InstallationStateDeletionPendingInProgress,
InstallationStateDeletionCancellationRequested,
InstallationStateDeletionRequested,
InstallationStateDeletionInProgress,
InstallationStateDeletionFinalCleanup,
}
// InstallationStateWorkPriority is a map of states to their priority. Default priority is 0.
// States with higher priority will be processed first.
var InstallationStateWorkPriority = map[string]int{
InstallationStateCreationRequested: 5,
InstallationStateCreationNoCompatibleClusters: 4,
InstallationStateCreationPreProvisioning: 3,
InstallationStateCreationInProgress: 2,
InstallationStateCreationDNS: 1,
}
// AllInstallationRequestStates is a list of all states that an installation can
// be put in via the API.
// Warning:
// When creating a new installation state, it must be added to this list if an
// API endpoint should put the installation in this state.
var AllInstallationRequestStates = []string{
InstallationStateCreationRequested,
InstallationStateHibernationRequested,
InstallationStateWakeUpRequested,
InstallationStateUpdateRequested,
InstallationStateDNSMigrationHibernating,
InstallationStateDeletionPendingRequested,
InstallationStateDeletionCancellationRequested,
InstallationStateDeletionRequested,
}
// ValidTransitionState returns whether an installation can be transitioned into
// the new state or not based on its current state.
func (i *Installation) ValidTransitionState(newState string) bool {
validStates, found := validInstallationTransitions[newState]
if !found {
return false
}
return contains(validStates, i.State)
}
var (
validInstallationTransitions = map[string][]string{
InstallationStateCreationRequested: {
InstallationStateCreationRequested,
InstallationStateCreationFailed,
},
InstallationStateHibernationRequested: {
InstallationStateStable,
},
InstallationStateWakeUpRequested: {
InstallationStateHibernating,
},
InstallationStateUpdateRequested: {
InstallationStateStable,
InstallationStateUpdateRequested,
InstallationStateUpdateInProgress,
InstallationStateUpdateFailed,
},
InstallationStateDeletionPendingRequested: {
InstallationStateStable,
InstallationStateUpdateRequested,
InstallationStateUpdateInProgress,
InstallationStateUpdateFailed,
InstallationStateHibernating,
InstallationStateDeletionPendingRequested,
InstallationStateDeletionPendingInProgress,
},
InstallationStateDeletionPending: {
InstallationStateDeletionPending,
},
InstallationStateDeletionCancellationRequested: {
InstallationStateDeletionPending,
},
InstallationStateDeletionRequested: {
InstallationStateCreationRequested,
InstallationStateCreationPreProvisioning,
InstallationStateCreationInProgress,
InstallationStateCreationDNS,
InstallationStateCreationNoCompatibleClusters,
InstallationStateCreationFinalTasks,
InstallationStateCreationFailed,
InstallationStateDeletionRequested,
InstallationStateDeletionInProgress,
InstallationStateDeletionFinalCleanup,
InstallationStateDeletionFailed,
},
InstallationStateDBRestorationInProgress: {
InstallationStateHibernating,
},
InstallationStateDBMigrationInProgress: {
InstallationStateHibernating,
},
InstallationStateDNSMigrationHibernating: {
InstallationStateHibernating,
},
}
)
// InstallationStateReport is a report of all installation requests states.
type InstallationStateReport []StateReportEntry
// GetInstallationRequestStateReport returns a InstallationStateReport based on
// the current model of installation states.
func GetInstallationRequestStateReport() InstallationStateReport {
report := InstallationStateReport{}
for _, requestState := range AllInstallationRequestStates {
entry := StateReportEntry{
RequestedState: requestState,
}
for _, newState := range AllInstallationStates {
i := Installation{State: newState}
if i.ValidTransitionState(requestState) {
entry.ValidStates = append(entry.ValidStates, newState)
} else {
entry.InvalidStates = append(entry.InvalidStates, newState)
}
}
report = append(report, entry)
}
return report
}