-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(deviceManagerEngine): free devices after engine deletion #382
base: 2-dev
Are you sure you want to change the base?
Changes from 7 commits
9437217
66ca578
beffd03
d3f055d
53b18fc
b9164b2
2497436
580e868
cc511e9
77039ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -327,15 +327,14 @@ export class DeviceManagerEngine extends AbstractEngine<DeviceManagerPlugin> { | |
InternalCollection.DEVICES, | ||
InternalCollection.MEASURES, | ||
]; | ||
|
||
await Promise.all( | ||
collections.map(async (collection) => { | ||
if (await this.sdk.collection.exists(index, collection)) { | ||
await this.sdk.collection.delete(index, collection); | ||
} | ||
}), | ||
); | ||
|
||
await this.detachDevicesFromAdminIndex(index); | ||
return { | ||
collections, | ||
}; | ||
|
@@ -654,4 +653,40 @@ export class DeviceManagerEngine extends AbstractEngine<DeviceManagerPlugin> { | |
|
||
return result.hits.map((elt) => elt._source); | ||
} | ||
|
||
/** | ||
* Detach all devices of an index in the admin index | ||
* | ||
* @param engineId The target engine Id | ||
* @returns {any} | ||
*/ | ||
private async detachDevicesFromAdminIndex(engineId: string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like this method should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think tenantIndex could lead to confusion as this functions is related only to the 'platform' index which is referred as adminIndex in KDM. |
||
const devices = []; | ||
|
||
let result = await this.sdk.document.search( | ||
this.adminIndex, | ||
"devices", | ||
{ | ||
_source: false, | ||
query: { bool: { must: { term: { engineId } } } }, | ||
}, | ||
{ | ||
scroll: "2s", | ||
size: 100, | ||
}, | ||
); | ||
while (result !== null) { | ||
devices.push(...result.hits); | ||
result = await result.next(); | ||
} | ||
if (devices.length > 0) { | ||
void this.sdk.document.mUpdate( | ||
this.adminIndex, | ||
"devices", | ||
devices.map((device) => { | ||
return { _id: device._id, body: { assetId: null, engineId: null } }; | ||
}), | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this should not be done inside the kuzzle-device-manager plugins because here you create a dependency with the multi-tenancy plugin witch is not the purpose of this plugin. It is suppose to be autonomous. You should put this behaviour in the iot platform backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this was the first implementation but supposed to be removed for the reason you gave
My bad, I messed up my last commit...