Skip to content
This repository was archived by the owner on Feb 15, 2021. It is now read-only.

Commit c662440

Browse files
authored
Not relying on erroneous count returned by findHostsForMigration (apache#774)
1 parent fad30a8 commit c662440

1 file changed

Lines changed: 45 additions & 21 deletions

File tree

src/views/compute/MigrateWizard.vue

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
:placeholder="$t('label.search')"
2222
v-model="searchQuery"
2323
style="margin-bottom: 10px;"
24-
@search="fetchData" />
24+
@search="handleSearch" />
2525
<a-table
2626
size="small"
2727
style="overflow-y: auto"
2828
:loading="loading"
2929
:columns="columns"
30-
:dataSource="hosts"
30+
:dataSource="items"
3131
:pagination="false"
3232
:rowKey="record => record.id">
3333
<div slot="suitability" slot-scope="record">
@@ -95,6 +95,7 @@ export default {
9595
return {
9696
loading: true,
9797
hosts: [],
98+
items: [],
9899
selectedHost: {},
99100
searchQuery: '',
100101
totalCount: 0,
@@ -129,23 +130,34 @@ export default {
129130
},
130131
methods: {
131132
fetchData () {
132-
this.loading = true
133-
api('findHostsForMigration', {
134-
virtualmachineid: this.resource.id,
135-
keyword: this.searchQuery,
136-
page: this.page,
137-
pagesize: this.pageSize
138-
}).then(response => {
139-
this.hosts = response.findhostsformigrationresponse.host
140-
this.totalCount = response.findhostsformigrationresponse.count
141-
if (this.totalCount > 0) {
142-
this.totalCount -= 1
143-
}
144-
}).catch(error => {
145-
this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`)
146-
}).finally(() => {
147-
this.loading = false
148-
})
133+
var page = 1
134+
const hosts = []
135+
const getNextPage = () => {
136+
this.loading = true
137+
api('findHostsForMigration', {
138+
virtualmachineid: this.resource.id,
139+
listAll: true,
140+
details: 'min',
141+
page: page,
142+
pageSize: 500
143+
}).then(response => {
144+
if (response && response.findhostsformigrationresponse && response.findhostsformigrationresponse.host) {
145+
hosts.push(...response.findhostsformigrationresponse.host)
146+
}
147+
if (response.findhostsformigrationresponse.host) {
148+
page++
149+
getNextPage()
150+
}
151+
}).catch(error => {
152+
this.$message.error(`${this.$t('message.load.host.failed')}: ${error}`)
153+
}).finally(() => {
154+
this.hosts = hosts
155+
this.totalCount = this.hosts.length
156+
this.items = this.hosts.slice(0, Math.min(this.totalCount, this.pageSize))
157+
this.loading = false
158+
})
159+
}
160+
getNextPage()
149161
},
150162
submitForm () {
151163
this.loading = true
@@ -181,15 +193,27 @@ export default {
181193
this.$message.error(`${this.$t('message.migrating.vm.to.host.failed')} ${this.selectedHost.name}`)
182194
})
183195
},
196+
handleSearch () {
197+
this.loading = true
198+
this.page = 1
199+
this.items = this.hosts.filter(x => x.name.toLowerCase().includes(this.searchQuery))
200+
this.totalCount = this.items.length
201+
this.items = this.items.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
202+
this.loading = false
203+
},
184204
handleChangePage (page, pageSize) {
205+
this.loading = true
185206
this.page = page
186207
this.pageSize = pageSize
187-
this.fetchData()
208+
this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
209+
this.loading = false
188210
},
189211
handleChangePageSize (currentPage, pageSize) {
212+
this.loading = true
190213
this.page = currentPage
191214
this.pageSize = pageSize
192-
this.fetchData()
215+
this.items = this.hosts.slice((this.page - 1) * this.pageSize, Math.min(this.totalCount, this.page * this.pageSize))
216+
this.loading = false
193217
}
194218
},
195219
filters: {

0 commit comments

Comments
 (0)