-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathDaemonTestDeploy.vue
More file actions
489 lines (480 loc) · 14.3 KB
/
Copy pathDaemonTestDeploy.vue
File metadata and controls
489 lines (480 loc) · 14.3 KB
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcModal :show="show" @close="closeModal">
<div class="test-deploy-dialog">
<h2>{{ t('app_api', 'Test deploy') }} - {{ daemon.display_name }}</h2>
<p>
{{ t('app_api', 'AppAPI will try to install small skeleton ExApp to verify Daemon configured correctly and deployment steps are passing.') }}
</p>
<p>
{{ t('app_api', 'The following Deploy test checks must be passed to succeed:') }}
({{ Object.values(statusChecks).reduce((acc, status_check) => acc + (status_check.passed ? 1 : 0), 0) }} / {{ Object.keys(statusChecks).length }})
</p>
<div class="status-checks">
<div v-for="statusCheck in statusChecks"
:key="statusCheck.id"
class="status-check">
<NcNoteCard
:type="getStatusCheckType(statusCheck)"
:heading="getStatusCheckTitle(statusCheck)"
style="margin: 0 0 10px 0;">
<template #icon>
<NcLoadingIcon v-if="statusCheck.loading && !statusCheck.error" :size="20" />
<Check v-else-if="statusCheck.passed" :size="20" />
</template>
{{ statusCheck.text }}
</NcNoteCard>
<p v-if="statusCheck.error && statusCheck.error_message !== ''" class="error">
{{ statusCheck.error_message }}
</p>
<div class="actions">
<NcButton
v-if="statusCheck.error"
type="tertiary"
:href="statusCheck.help_url"
target="_blank"
style="margin: 5px 0 15px 0;">
<template #icon>
<OpenInNew :size="20" />
</template>
{{ t('app_api', 'More info') }}
</NcButton>
</div>
</div>
</div>
<div class="actions">
<NcButton
v-tooltip="{ content: downloadLogsTooltip, placement: 'top' }"
:disabled="!canDownloadLogs"
type="tertiary"
:href="getDownloadLogsUrl()"
target="_blank"
style="margin-right: 10px;">
<template #icon>
<TrayArrowDown :size="20" />
</template>
{{ t('app_api', 'Download ExApp logs') }}
</NcButton>
<NcButton
v-if="!testRunning && hasTestDeployResults"
v-tooltip="{ content: t('app_api', 'Remove test ExApp'), placement: 'top' }"
:disabled="stoppingTest"
type="tertiary"
style="margin-right: 10px;"
@click="removeTestExApp">
<template #icon>
<TrashCanOutline v-if="!stoppingTest" :size="20" />
<NcLoadingIcon v-else :size="20" />
</template>
</NcButton>
<NcButton
v-if="!testRunning"
:disabled="startingTest"
type="primary"
@click="startDeployTest">
<template #icon>
<NcLoadingIcon v-if="startingTest" :size="20" />
</template>
{{ t('app_api', 'Start Deploy test') }}
</NcButton>
<NcButton
v-if="testRunning"
type="warning"
style="margin-left: 5px;"
:disabled="stoppingTest"
@click="stopDeployTest">
<template #icon>
<StopIcon v-if="!stoppingTest" :size="20" />
<NcLoadingIcon v-else :size="20" />
</template>
{{ t('app_api', 'Stop Deploy test') }}
</NcButton>
</div>
<p v-if="testRunning" class="warning-text">
{{ t('app_api', 'ExApp is unregistered and container is removed on "Stop deploy test"') }}
</p>
</div>
</NcModal>
</template>
<script>
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import Check from 'vue-material-design-icons/Check.vue'
import StopIcon from 'vue-material-design-icons/Stop.vue'
import OpenInNew from 'vue-material-design-icons/OpenInNew.vue'
import TrayArrowDown from 'vue-material-design-icons/TrayArrowDown.vue'
import TrashCanOutline from 'vue-material-design-icons/TrashCanOutline.vue'
export default {
name: 'DaemonTestDeploy',
components: {
NcModal,
NcNoteCard,
NcLoadingIcon,
NcButton,
Check,
StopIcon,
OpenInNew,
TrayArrowDown,
TrashCanOutline,
},
props: {
show: {
type: Boolean,
required: true,
default: false,
},
daemon: {
type: Object,
required: true,
default: () => null,
},
getAllDaemons: {
type: Function,
required: true,
},
},
data() {
return {
startingTest: false,
stoppingTest: false,
testRunning: false,
polling: null,
canDownloadLogs: false,
statusChecks: {
register: {
id: 'register',
title: t('app_api', 'Register ExApp in Nextcloud'),
text: t('app_api', 'Check if the ExApp is registered in Nextcloud before deployment'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#register',
},
image_pull: {
id: 'image_pull',
title: t('app_api', 'Image pull'),
text: t('app_api', 'Check if the image is successfully pulled'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#image-pull',
progress: null,
},
container_started: {
id: 'container_started',
title: t('app_api', 'Container started'),
text: t('app_api', 'Check if the image successfully pulled and container is created and started'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#container-started',
},
heartbeat: {
id: 'heartbeat',
title: t('app_api', 'Heartbeat'),
text: t('app_api', 'Check for the heartbeat is finished and healthy'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#heartbeat',
heartbeat_count: null,
},
init: {
id: 'init',
title: t('app_api', 'Init step'),
text: t('app_api', 'Wait for initialization step to finish'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#init',
progress: null,
},
enabled: {
id: 'enabled',
title: t('app_api', 'Enabled'),
text: t('app_api', 'Check if ExApp successfully handled the enabled event and registered all stuff properly'),
passed: false,
loading: false,
error: false,
error_message: '',
help_url: 'https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/TestDeploy.html#enabled',
},
},
}
},
computed: {
heartbeatCountHeadingProgress() {
return `${this.statusChecks.heartbeat.title} (heartbeat_count: ${this.statusChecks.heartbeat.heartbeat_count || 0})`
},
imagePullHeadingProgress() {
return `${this.statusChecks.image_pull.title} (${this.statusChecks.image_pull.progress}%)`
},
initHeadingProgress() {
return `${this.statusChecks.init.title} (${this.statusChecks.init.progress}%)`
},
downloadLogsTooltip() {
if (!this.canDownloadLogs) {
return t('app_api', 'Only if ExApp container is preset')
}
return null
},
hasTestDeployResults() {
return Object.values(this.statusChecks).some(statusCheck => statusCheck.passed || statusCheck.error)
},
},
beforeMount() {
this.fetchTestDeployStatus()
},
beforeDestroy() {
clearInterval(this.polling)
},
methods: {
closeModal() {
this.$emit('update:show', false)
},
_cleanupStatusChecks() {
Object.values(this.statusChecks).forEach(statusCheck => {
statusCheck.loading = false
statusCheck.passed = false
statusCheck.error = false
statusCheck.error_message = ''
if ('progress' in statusCheck) {
statusCheck.progress = null
}
if ('heartbeat_count' in statusCheck) {
statusCheck.heartbeat_count = null
}
})
},
startDeployTest() {
this.canDownloadLogs = false
this.startingTest = true
this._cleanupStatusChecks()
this._startDeployTest().then((res) => {
this.testRunning = true
if (this._detectCurrentStep(res.data.status) === 'register') {
this.statusChecks.register.passed = true
this.statusChecks.register.loading = false
}
}).catch((err) => {
if (err.response.data.error) {
showError(err.response.data.error)
}
this.stopDeployTest()
}).finally(() => {
this.startingTest = false
})
},
_startDeployTest() {
return axios.post(generateUrl(`/apps/app_api/daemons/${this.daemon.name}/test_deploy`))
.then(res => {
this.startDeployTestPolling()
return res
}).finally(() => {
this.getAllDaemons()
})
},
startDeployTestPolling() {
this.polling = setInterval(() => {
this.fetchTestDeployStatus()
}, 1000)
},
removeTestExApp() {
this._stopDeployTest().then(() => {
this.canDownloadLogs = false
this._cleanupStatusChecks()
})
},
stopDeployTest() {
this._stopDeployTest().then(() => {
Object.values(this.statusChecks).forEach(statusCheck => {
statusCheck.loading = false
})
this.clearTestRunning()
})
},
_stopDeployTest() {
this.stoppingTest = true
return axios.delete(generateUrl(`/apps/app_api/daemons/${this.daemon.name}/test_deploy`)).then(() => {
clearInterval(this.polling)
}).finally(() => {
this.stoppingTest = false
this.getAllDaemons()
})
},
fetchTestDeployStatus() {
return axios.get(generateUrl(`/apps/app_api/daemons/${this.daemon.name}/test_deploy/status`))
.then(res => {
this.handleTestDeployStatus(res.data)
}).catch(err => {
// test-deploy app is not registered, test is not running
if (err.status === 404) {
this.clearTestRunning()
}
})
},
handleTestDeployStatus(status) {
const currentStep = this._detectCurrentStep(status)
if (currentStep !== null && status.error === '') {
this.testRunning = true
if (this.polling === null) {
this.startDeployTestPolling()
}
}
Object.keys(this.statusChecks).forEach(step => {
const statusCheck = this.statusChecks[step]
statusCheck.loading = step === currentStep
if (statusCheck.id === 'image_pull' && statusCheck.loading) {
statusCheck.progress = status.deploy
}
if (statusCheck.id === 'init' && statusCheck.loading) {
statusCheck.progress = status.init
}
if (statusCheck.id === 'heartbeat' && 'heartbeat_count' in status) {
statusCheck.heartbeat_count = status.heartbeat_count
}
switch (step) {
case 'register':
statusCheck.passed = true // at this point we're reading app status, so it's already registered
break
case 'image_pull':
statusCheck.passed = status.deploy >= 94
break
case 'container_started':
statusCheck.passed = status.deploy >= 98
this.canDownloadLogs = true // at status.deploy = 97 container is already created
break
case 'heartbeat':
statusCheck.passed = status.deploy === 100
// update later 'image_pull' progress as well
this.statusChecks.image_pull.progress = status.deploy
this.canDownloadLogs = true
break
case 'init':
statusCheck.passed = status.init === 100
// update later 'image_pull' and 'init' progress as well
this.statusChecks.image_pull.progress = status.deploy
this.statusChecks.init.progress = status.init
this.canDownloadLogs = true
break
case 'enabled':
statusCheck.passed = status.init === 100 && status.deploy === 100 && status.action === '' && status.error === ''
// update later 'image_pull' and 'init' progress as well
this.statusChecks.image_pull.progress = status.deploy
this.statusChecks.init.progress = status.init
if (statusCheck.passed) {
showSuccess(t('app_api', 'Deploy test passed successfully!'))
this.clearTestRunning()
statusCheck.loading = false
}
break
}
if (status.error && step === currentStep) {
statusCheck.error = true
statusCheck.error_message = status.error
statusCheck.loading = false
statusCheck.passed = false
showError(t('app_api', 'Deploy test failed at step "{step}"', { step }))
}
})
if (status.error !== '') {
this.clearTestRunning()
}
},
_detectCurrentStep(status) {
if (status.action === '' && status.deploy === 0 && status.init === 0) {
return 'register'
}
if (status.action === 'deploy') {
if (status.deploy >= 0 && status.deploy < 94) {
return 'image_pull'
}
if (status.deploy >= 95 && status.deploy <= 97) {
return 'container_started'
}
if (status.deploy >= 98 && status.deploy <= 99) {
return 'heartbeat'
}
}
if (status.action === 'healthcheck') {
return 'heartbeat'
}
if (status.action === 'init') {
return 'init'
}
if (status.action === '' && status.deploy === 100 && status.init === 100) {
return 'enabled'
}
return null
},
getStatusCheckType(statusCheck) {
if (statusCheck.error || statusCheck.error_message !== '') {
return 'error'
}
if (statusCheck.passed) {
return 'success'
}
return 'info'
},
getStatusCheckTitle(statusCheck) {
if (statusCheck.id === 'heartbeat' && this.statusChecks.heartbeat.heartbeat_count) {
return this.heartbeatCountHeadingProgress
}
if (statusCheck.id === 'image_pull' && this.statusChecks.image_pull.progress) {
return this.imagePullHeadingProgress
}
if (statusCheck.id === 'init' && this.statusChecks.init.progress) {
return this.initHeadingProgress
}
return statusCheck.title
},
clearTestRunning() {
this.testRunning = false
clearInterval(this.polling)
this.polling = null
},
getDownloadLogsUrl() {
if (!this.canDownloadLogs) {
return null
}
return generateUrl('/apps/app_api/apps/logs/test-deploy')
},
},
}
</script>
<style scoped lang="scss">
.test-deploy-dialog {
padding: 20px;
.status-checks {
max-height: 50vh;
overflow-y: auto;
margin: 20px 0;
}
.actions {
display: flex;
justify-content: flex-end;
}
.error {
color: var(--color-error-text);
}
.warning-text {
display: flex;
justify-content: flex-end;
margin-top: 10px;
color: var(--color-warning-text);
}
}
</style>