|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <div class="form-layout"> |
| 20 | + <a-spin :spinning="loading"> |
| 21 | + <a-form :form="form" @submit="handleSubmit" layout="vertical"> |
| 22 | + <a-form-item |
| 23 | + :label="$t('migrate.from')"> |
| 24 | + <a-select |
| 25 | + v-decorator="['srcpool', { |
| 26 | + initialValue: selectedStore, |
| 27 | + rules: [ |
| 28 | + { |
| 29 | + required: true, |
| 30 | + message: $t('message.error.select'), |
| 31 | + }] |
| 32 | + }]" |
| 33 | + :loading="loading" |
| 34 | + @change="val => { selectedStore = val }" |
| 35 | + > |
| 36 | + <a-select-option |
| 37 | + v-for="store in imageStores" |
| 38 | + :key="store.id" |
| 39 | + >{{ store.name || opt.url }}</a-select-option> |
| 40 | + </a-select> |
| 41 | + </a-form-item> |
| 42 | + <a-form-item |
| 43 | + :label="$t('migrate.to')"> |
| 44 | + <a-select |
| 45 | + v-decorator="['destpools', { |
| 46 | + rules: [ |
| 47 | + { |
| 48 | + required: true, |
| 49 | + message: $t('message.select.destination.image.stores'), |
| 50 | + }] |
| 51 | + }]" |
| 52 | + mode="multiple" |
| 53 | + :loading="loading" |
| 54 | + > |
| 55 | + <a-select-option |
| 56 | + v-for="store in imageStores" |
| 57 | + v-if="store.id !== selectedStore" |
| 58 | + :key="store.id" |
| 59 | + >{{ store.name || opt.url }}</a-select-option> |
| 60 | + </a-select> |
| 61 | + </a-form-item> |
| 62 | + <a-form-item :label="$t('migrationPolicy')"> |
| 63 | + <a-select |
| 64 | + v-decorator="['migrationtype', { |
| 65 | + initialValue: 'Complete', |
| 66 | + rules: [ |
| 67 | + { |
| 68 | + required: true, |
| 69 | + message: $t('message.select.migration.policy'), |
| 70 | + }] |
| 71 | + }]" |
| 72 | + :loading="loading" |
| 73 | + > |
| 74 | + <a-select-option value="Complete">Complete</a-select-option> |
| 75 | + <a-select-option value="Balance">Balance</a-select-option> |
| 76 | + </a-select> |
| 77 | + </a-form-item> |
| 78 | + <div :span="24" class="action-button"> |
| 79 | + <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button> |
| 80 | + <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button> |
| 81 | + </div> |
| 82 | + </a-form> |
| 83 | + </a-spin> |
| 84 | + </div> |
| 85 | +</template> |
| 86 | +<script> |
| 87 | +import { api } from '@/api' |
| 88 | +export default { |
| 89 | + name: 'MigrateData', |
| 90 | + inject: ['parentFetchData'], |
| 91 | + data () { |
| 92 | + return { |
| 93 | + imageStores: [], |
| 94 | + loading: false, |
| 95 | + selectedStore: '' |
| 96 | + } |
| 97 | + }, |
| 98 | + beforeCreate () { |
| 99 | + this.form = this.$form.createForm(this) |
| 100 | + }, |
| 101 | + mounted () { |
| 102 | + this.fetchImageStores() |
| 103 | + }, |
| 104 | + methods: { |
| 105 | + fetchImageStores () { |
| 106 | + this.loading = true |
| 107 | + api('listImageStores').then(json => { |
| 108 | + this.imageStores = json.listimagestoresresponse.imagestore || [] |
| 109 | + this.selectedStore = this.imageStores[0].id || '' |
| 110 | + }).finally(() => { |
| 111 | + this.loading = false |
| 112 | + }) |
| 113 | + }, |
| 114 | + handleSubmit (e) { |
| 115 | + e.preventDefault() |
| 116 | + this.form.validateFields((err, values) => { |
| 117 | + if (err) { |
| 118 | + return |
| 119 | + } |
| 120 | + const params = {} |
| 121 | + for (const key in values) { |
| 122 | + const input = values[key] |
| 123 | + if (input === undefined) { |
| 124 | + continue |
| 125 | + } |
| 126 | + if (key === 'destpools') { |
| 127 | + params[key] = input.join(',') |
| 128 | + } else { |
| 129 | + params[key] = input |
| 130 | + } |
| 131 | + } |
| 132 | +
|
| 133 | + const title = 'Data Migration' |
| 134 | + this.loading = true |
| 135 | +
|
| 136 | + const result = this.migrateData(params, title) |
| 137 | + result.then(json => { |
| 138 | + const result = json.jobresult |
| 139 | + const success = result.imagestore.success || false |
| 140 | + const message = result.imagestore.message || '' |
| 141 | + if (success) { |
| 142 | + this.$notification.success({ |
| 143 | + message: title, |
| 144 | + description: message |
| 145 | + }) |
| 146 | + } else { |
| 147 | + this.$notification.error({ |
| 148 | + message: title, |
| 149 | + description: message, |
| 150 | + duration: 0 |
| 151 | + }) |
| 152 | + } |
| 153 | + }).catch(error => { |
| 154 | + console.log(error) |
| 155 | + }) |
| 156 | + this.loading = false |
| 157 | + this.parentFetchData() |
| 158 | + this.closeAction() |
| 159 | + }) |
| 160 | + }, |
| 161 | + migrateData (args, title) { |
| 162 | + return new Promise((resolve, reject) => { |
| 163 | + api('migrateSecondaryStorageData', args).then(async json => { |
| 164 | + const jobId = json.migratesecondarystoragedataresponse.jobid |
| 165 | + if (jobId) { |
| 166 | + const result = await this.pollJob(jobId, title) |
| 167 | + if (result.jobstatus === 2) { |
| 168 | + reject(result.jobresult.errortext) |
| 169 | + return |
| 170 | + } |
| 171 | + resolve(result) |
| 172 | + } |
| 173 | + }).catch(error => { |
| 174 | + reject(error) |
| 175 | + }) |
| 176 | + }) |
| 177 | + }, |
| 178 | + async pollJob (jobId, title) { |
| 179 | + return new Promise(resolve => { |
| 180 | + const asyncJobInterval = setInterval(() => { |
| 181 | + api('queryAsyncJobResult', { jobId }).then(async json => { |
| 182 | + const result = json.queryasyncjobresultresponse |
| 183 | + if (result.jobstatus === 0) { |
| 184 | + return |
| 185 | + } |
| 186 | + this.$store.dispatch('AddAsyncJob', { |
| 187 | + title: title, |
| 188 | + jobid: jobId, |
| 189 | + description: 'imagestore', |
| 190 | + status: 'progress', |
| 191 | + silent: true |
| 192 | + }) |
| 193 | + clearInterval(asyncJobInterval) |
| 194 | + resolve(result) |
| 195 | + }) |
| 196 | + }, 1000) |
| 197 | + }) |
| 198 | + }, |
| 199 | + closeAction () { |
| 200 | + this.$emit('close-action') |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | +</script> |
| 205 | +<style lang="scss" scoped> |
| 206 | +.form-layout { |
| 207 | + width: 85vw; |
| 208 | +
|
| 209 | + @media (min-width: 1000px) { |
| 210 | + width: 40vw; |
| 211 | + } |
| 212 | +} |
| 213 | +
|
| 214 | +.action-button { |
| 215 | + text-align: right; |
| 216 | +
|
| 217 | + button { |
| 218 | + margin-right: 5px; |
| 219 | + } |
| 220 | +} |
| 221 | +</style> |
0 commit comments