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

Allows to define custom mappings for devices and assets for a tenant group only #61

Merged
merged 35 commits into from
May 4, 2021

Conversation

Yoann-Abbes
Copy link
Contributor

@Yoann-Abbes Yoann-Abbes commented Apr 1, 2021

What this PR does

This PR allows to have custom mapping for each tenant group for the assets and devices collections
#28
They are meant to be loaded at application startup

For devices collection, only qos, measures, and metadata fields are meant to be customized.
For assets collection, only metadata field is meant to be customized.

How to test

  1. Functional tests.

  2. Clone KIoTP repo on branch add-custom-mappings
    Install plugins and switch to the add-custom-mappings branch on the device-plugin-manager
    Define your own mappings in lib/plugins/device-manager/mappings/
    Register it in lib/plugins/device-manager/index.ts with the provided methods
    Run KIoTP
    Create and engine kourou device-manager/engine:create -a group="groupTest" index="test"
    Verify the mappings are correctly added.

deviceManagerPlugin.devices.registerQos
deviceManagerPlugin.devices.registerMetadata
deviceManagerPlugin.devices.registerMeasure

deviceManagerPlugin.assets.registerMetadata

@Yoann-Abbes Yoann-Abbes self-assigned this Apr 1, 2021
@Yoann-Abbes Yoann-Abbes marked this pull request as draft April 1, 2021 15:36
Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

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

First round of reviews

@@ -10,27 +10,49 @@ const deviceManager = new DeviceManagerPlugin();
deviceManager.registerDecoder(new DummyTempDecoder());
deviceManager.registerDecoder(new DummyTempPositionDecoder());

deviceManager.mappings.devices.measures = {
deviceManager.devices.registerMeasures({
Copy link
Contributor

Choose a reason for hiding this comment

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

To me this method could take the measure name as first parameter and then the measure definition.

This could allows to avoid to register 2 times the same measure for example

value: { type: 'float' },
}
}
}, 'astronaut');
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's an option, it should be of this form { group: "astronaut" }

lib/DeviceManagerPlugin.ts Outdated Show resolved Hide resolved
this.config.mappings.set(tenantGroup, {
...this.config.mappings.get(tenantGroup),
assets,
'asset-history': assets
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this? This collection is not included by default in the device manager plugin

lib/DeviceManagerPlugin.ts Show resolved Hide resolved
})
}
}
console.log(this.config.mappings);
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug leftover

this.config.mappings.set(tenantGroup, {
...this.config.mappings.get(tenantGroup),
assets: this.config.mappings.get('shared').assets,
'asset-history': this.config.mappings.get('shared').assets
Copy link
Contributor

Choose a reason for hiding this comment

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

This collection does not exists in the device manager

@@ -52,7 +52,8 @@ export class EngineController {

async create (request: KuzzleRequest) {
const index = request.getIndex();
const { collections } = await this.engineService.create(index);
const tenantGroup = request.input.args.group;
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use a request params helper intsead

lib/models/CustomProperties.ts Outdated Show resolved Hide resolved
lib/models/CustomProperties.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

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

Please can you add proper comments to every function with also parameter explanation for developers but also maintainers

@Yoann-Abbes Yoann-Abbes marked this pull request as ready for review April 20, 2021 13:28
@Yoann-Abbes Yoann-Abbes requested a review from Aschen April 20, 2021 13:28
@Yoann-Abbes Yoann-Abbes changed the title Able to have custom mappings for each tenant kind Able to have custom mappings for each tenant group Apr 20, 2021
@Yoann-Abbes Yoann-Abbes requested a review from Leodau April 20, 2021 16:03
@Yoann-Abbes Yoann-Abbes requested a review from Leodau April 20, 2021 16:21
@Leodau
Copy link
Contributor

Leodau commented Apr 21, 2021

Why is the package.lock getting modified?

Copy link
Contributor

@Leodau Leodau left a comment

Choose a reason for hiding this comment

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

I would need an explanation on why was there the need to explode a functionality, into specific class methods.
Are we trying to build overkill setup functionalities on top of what should be templating?

register-measures
register-metadata
register-qos

Do these modifications imply that if we add new specific custom properties in the future OR new default collections with customizable properties, one would have to reconstruct/setup all this boilerplate by hand?

It seems to me at first glance, that a bad architectural choice was made somewhere.
@Yoann-Abbes @Aschen

@Yoann-Abbes Yoann-Abbes requested a review from Shiranuit April 23, 2021 01:24
@Leodau
Copy link
Contributor

Leodau commented Apr 23, 2021

A simple guide to be added and IMO all done!

@Yoann-Abbes Yoann-Abbes requested a review from Leodau April 29, 2021 15:31
doc/1/guides/mappings/index.md Outdated Show resolved Hide resolved
doc/1/guides/mappings/index.md Outdated Show resolved Hide resolved
doc/1/guides/mappings/index.md Outdated Show resolved Hide resolved
@Yoann-Abbes Yoann-Abbes requested a review from Leodau April 29, 2021 17:58
@Yoann-Abbes Yoann-Abbes changed the title Able to have custom mappings for each tenant group Allows to define custom mappings for devices and assets for a tenant group only Apr 30, 2021
@Leodau Leodau merged commit 65fca52 into 1-dev May 4, 2021
@Leodau Leodau deleted the add-custom-mappings branch May 4, 2021 12:23
@Yoann-Abbes Yoann-Abbes mentioned this pull request May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allows to define custom mappings for devices and assets for a tenant group only
5 participants