Skip to content
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

Open
wants to merge 13 commits into
base: 2-dev
Choose a base branch
from

Conversation

QuentinRousselet
Copy link
Contributor

@QuentinRousselet QuentinRousselet commented Nov 22, 2024

What does this PR do ?

Unassign all the devices from their engineId and assetId in the admin index when the deviceManagerEngine is deleted after the deletion of its collections.

How should this be manually tested?

  • Step 1 : Create a device-manager-engine
  • Step 2 : Add attach several devices to it and assign them to some assets
  • Step 3 : Delete the engine
  • Step 4 : Check in the admin index in the device collection that all former devices don't have any engineId or assetId anymore.

KZLPRD-511

* On deletion of a tenant, remove association for all of
* its formerly linked devices in the admin index.
*/
this.app.hook.register(
Copy link
Contributor

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

Copy link
Contributor Author

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...

* @param engineId The target engine Id
* @returns {any}
*/
private async detachDevicesFromAdminIndex(engineId: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this method should be named detachDevicesFromTenantIndex

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@Juiced66
Copy link
Contributor

Juiced66 commented Nov 26, 2024

It could be so cool to implement a dependancies property at model level that registers cleaning hooks itself. That way user can register is own dependancies and clean all business deps + system deps
Could be done for all entities of KDM

@rolljee
Copy link
Contributor

rolljee commented Nov 26, 2024

It could be so cool to implement a dependancies property at model level that registers cleaning hooks itself. That way user can register is own dependancies and clean all business deps + system deps Could be done for all entities of KDM

Could you elaborate on this ? i think i didn't get it properly

@Juiced66
Copy link
Contributor

Juiced66 commented Nov 26, 2024

It could be so cool to implement a dependancies property at model level that registers cleaning hooks itself. That way user can register is own dependancies and clean all business deps + system deps Could be done for all entities of KDM

Could you elaborate on this ? i think i didn't get it properly

It could be a kind of service wich we can pass a trigger (create, delete ...) and a callback wich is invoke when the action is trigger. That way we structurate system cleaning and we will be able to easily open it to user with a registerDependancy method
The idea is if an asset for example should add a workflow on create, we can register there dependancy and register also a cleaning callback when asset is removed for example.

that's fully possible to do it manually for now but it could structure the process and be easier for developpers IMHO

For me we address a sytem dependancy in this PR

Copy link
Contributor

@rolljee rolljee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add a test for this :) otherwise look good to me

@QuentinRousselet QuentinRousselet force-pushed the KZLPRD-511-free-devices-after-tenant-deletion branch from 77039ad to 1aa6b54 Compare December 18, 2024 10:28
Copy link
Contributor

@rolljee rolljee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the state of this PR ?

@QuentinRousselet
Copy link
Contributor Author

What is the state of this PR ?

Waiting for other reviews now that I added tests as requested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants