feat(xen-api/objects): buffer objects' events on initial fetch (#3994)

XO requires all objects to be available at the same time.
This commit is contained in:
Julien Fontanet 2019-02-26 15:03:33 +01:00 committed by Pierre Donias
parent d866bccf3b
commit 344e9e06d0

View File

@ -983,25 +983,30 @@ export class Xapi extends EventEmitter {
const types = this._watchedTypes || this._types const types = this._watchedTypes || this._types
// initial fetch // initial fetch
await Promise.all( const flush = this.objects.bufferEvents()
types.map(async type => { try {
try { await Promise.all(
// FIXME: use _transportCall to avoid auto-reconnection types.map(async type => {
forOwn( try {
await this._sessionCall(`${type}.get_all_records`), // FIXME: use _transportCall to avoid auto-reconnection
(record, ref) => { forOwn(
// we can bypass _processEvents here because they are all *add* await this._sessionCall(`${type}.get_all_records`),
// event and all objects are of the same type (record, ref) => {
this._addObject(type, ref, record) // we can bypass _processEvents here because they are all *add*
// event and all objects are of the same type
this._addObject(type, ref, record)
}
)
} catch (error) {
if (error == null || error.code !== 'MESSAGE_REMOVED') {
throw error
} }
)
} catch (error) {
if (error == null || error.code !== 'MESSAGE_REMOVED') {
throw error
} }
} })
}) )
) } finally {
flush()
}
this._resolveObjectsFetched() this._resolveObjectsFetched()
// event loop // event loop
@ -1060,22 +1065,28 @@ export class Xapi extends EventEmitter {
// It also has to manually get all objects first. // It also has to manually get all objects first.
_watchEventsLegacy() { _watchEventsLegacy() {
const getAllObjects = async () => { const getAllObjects = async () => {
return Promise.all( const flush = this.objects.bufferEvents()
this._types.map(type => try {
this._sessionCall(`${type}.get_all_records`).then( await Promise.all(
objects => { this._types.map(type =>
forEach(objects, (object, ref) => { this._sessionCall(`${type}.get_all_records`).then(
this._addObject(type, ref, object) objects => {
}) forEach(objects, (object, ref) => {
}, this._addObject(type, ref, object)
error => { })
if (error.code !== 'MESSAGE_REMOVED') { },
throw error error => {
if (error.code !== 'MESSAGE_REMOVED') {
throw error
}
} }
} )
) )
) )
).then(() => this._resolveObjectsFetched()) } finally {
flush()
}
this._resolveObjectsFetched()
} }
const watchEvents = () => const watchEvents = () =>