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

Rename tenantGroup to group #89

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ registerMetadata (mappings: JSONObject, options: JSONObject);

| Properties | Type | Description |
|-----------|-----------------------|---------------------------------------------|
| `tenantGroup` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |
| `group` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |

## Usage

Expand All @@ -40,5 +40,5 @@ deviceManagerPlugin.assets.registerMetadata({
fields: {
text: { type: 'text' } }
}
}, { tenantGroup: 'water_management' });
}, { group: 'water_management' });
```
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ registerMeasure (measureName: string, mappings: JSONObject, options: JSONObject)

| Properties | Type | Description |
|-----------|-----------------------|---------------------------------------------|
| `tenantGroup` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition |
| `group` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition |

## Usage

Expand All @@ -44,7 +44,7 @@ deviceManagerPlugin.devices.registerMeasure(
celsius: { type: 'float' }
}
},
{ tenantGroup: 'water_management' });
{ group: 'water_management' });

deviceManagerPlugin.devices.registerMeasure(
'humidity',
Expand All @@ -58,5 +58,5 @@ deviceManagerPlugin.devices.registerMeasure(
}
}
},
{ tenantGroup: 'air_quality' });
{ group: 'air_quality' });
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ registerMetadata (mappings: JSONObject, options: JSONObject);

| Properties | Type | Description |
|-----------|-----------------------|---------------------------------------------|
| `tenantGroup` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |
| `group` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |

## Usage

Expand All @@ -40,5 +40,5 @@ deviceManagerPlugin.devices.registerMetadata({
fields: {
text: { type: 'text' } }
}
}, { tenantGroup: 'water_management' });
}, { group: 'water_management' });
```
4 changes: 2 additions & 2 deletions doc/1/classes/devices-custom-properties/register-qos/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ registerQos (mappings: JSONObject, options: JSONObject);

| Properties | Type | Description |
|-----------|-----------------------|---------------------------------------------|
| `tenantGroup` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |
| `group` | <pre>string</pre> | Name of the group for which the mappings should apply. If unspecified, mappings will apply to every group who does not have specific definition. |

## Usage

Expand All @@ -36,5 +36,5 @@ const deviceManagerPlugin = new DeviceManagerPlugin();

deviceManagerPlugin.devices.registerQos({
battery: { type: 'integer' }
}, { tenantGroup: 'water_management' });
}, { group: 'water_management' });
```
6 changes: 3 additions & 3 deletions doc/1/guides/mappings/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ deviceManager.assets.registerMetadata({

deviceManager.assets.registerMetadata({
stillAlive: { type: 'boolean' }
}, { tenantGroup: 'astronaut' }); // A tenant group is specified : 'astronaut'.
}, { group: 'astronaut' }); // A tenant group is specified : 'astronaut'.
// These are the mappings definition for the `metadata` field
// of the `assets` collection will only be applied for
// the 'astronaut' tenant.
Expand Down Expand Up @@ -206,7 +206,7 @@ deviceManager.devices.registerMeasure('gravity', {
},
value: { type: 'float' },
}
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

deviceManager.devices.registerQos({ // By default, every 'devices' tenant collection
battery: { type: 'integer' } // will have the 'battery' property with the provided
Expand All @@ -215,7 +215,7 @@ deviceManager.devices.registerQos({ // By default, every 'devices' ten

deviceManager.devices.registerQos({ // The 'devices' collection of the 'astronaut' tenant
durability: { type: 'float' } // will have the 'durability' property with the provided
}, { tenantGroup: 'astronaut' }); // mappings inside the 'qos' field.
}, { group: 'astronaut' }); // mappings inside the 'qos' field.

deviceManager.devices.registerMetadata({ // By default, every 'devices' tenant collection
group: { // will have the 'group' property with the provided
Expand Down
18 changes: 9 additions & 9 deletions features/fixtures/application/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ deviceManager.devices.registerMeasure('gravity', {
},
value: { type: 'float' },
}
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

deviceManager.devices.registerMeasure('acceleration', {
properties: {
Expand All @@ -71,34 +71,34 @@ deviceManager.devices.registerMeasure('acceleration', {
},
acceleration: { type: 'float' },
}
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });


deviceManager.devices.registerQos({
durability: { type: 'float' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

deviceManager.devices.registerQos({
signalStrenght: { type: 'float' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });


deviceManager.devices.registerMetadata({
awake: { type: 'boolean' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

deviceManager.devices.registerMetadata({
sleeping: { type: 'boolean' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });


deviceManager.assets.registerMetadata({
stillAlive: { type: 'boolean' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

deviceManager.assets.registerMetadata({
freezing: { type: 'boolean' }
}, { tenantGroup: 'astronaut' });
}, { group: 'astronaut' });

app.plugin.use(deviceManager);

Expand All @@ -113,7 +113,7 @@ app.config.set('plugins.kuzzle-plugin-logger.services.stdout.level', 'debug');
* Register pipe for scenario used to test the tenant specific event propagation
*/
app.pipe.register('tenant:tenant-ayse:device:new-payload', async eventParam => {
await app.sdk.realtime.publish('tests', 'messages', eventParam);
await app.sdk.realtime.publish('tests', 'messages', eventParam.result);

return eventParam;
});
Expand Down
22 changes: 11 additions & 11 deletions lib/DeviceManagerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ export class DeviceManagerPlugin extends Plugin {
const devicesProperties = this.devices.definitions.get('commons');

// Retrieve each group name which has custom properties definition
const tenantGroups = [...new Set(Array.from(this.devices.definitions.keys())
const groups = [...new Set(Array.from(this.devices.definitions.keys())
.concat(Array.from(this.assets.definitions.keys())))];

// Init each group with 'devices' and 'assets' commons properties definition
for (const tenantGroup of tenantGroups) {
this.config.mappings.set(tenantGroup, {
for (const group of groups) {
this.config.mappings.set(group, {
assets: {
dynamic: 'false',
properties: assetsProperties
Expand All @@ -210,9 +210,9 @@ export class DeviceManagerPlugin extends Plugin {
}

// Merge custom 'devices' properties with commons properties
for (const [tenantGroup, customProperties] of this.devices.definitions) {
this.config.mappings.set(tenantGroup, {
assets: this.config.mappings.get(tenantGroup).assets,
for (const [group, customProperties] of this.devices.definitions) {
this.config.mappings.set(group, {
assets: this.config.mappings.get(group).assets,
devices: {
dynamic: 'false',
properties: {
Expand All @@ -224,16 +224,16 @@ export class DeviceManagerPlugin extends Plugin {
}

// Merge custom 'assets' properties with commons properties
for (const [tenantGroup, customProperties] of this.assets.definitions) {
this.config.mappings.set(tenantGroup, {
for (const [group, customProperties] of this.assets.definitions) {
this.config.mappings.set(group, {
assets: {
dynamic: 'false',
properties: {
...assetsProperties,
...customProperties
}
},
devices: this.config.mappings.get(tenantGroup).devices,
devices: this.config.mappings.get(group).devices,
});

// Use "devices" mappings to generate "assets" collection mappings
Expand All @@ -244,7 +244,7 @@ export class DeviceManagerPlugin extends Plugin {
model: { type: 'keyword' },
};

const tenantMappings = this.config.mappings.get(tenantGroup);
const tenantMappings = this.config.mappings.get(group);

for (const [measureType, definition] of Object.entries(tenantMappings.devices.properties.measures.properties) as any) {
tenantMappings.assets.properties.measures.properties[measureType] = {
Expand All @@ -258,7 +258,7 @@ export class DeviceManagerPlugin extends Plugin {
}
};
}
this.config.mappings.set(tenantGroup, tenantMappings);
this.config.mappings.set(group, tenantMappings);
}

// Merge custom mappings from decoders for payloads collection
Expand Down
8 changes: 4 additions & 4 deletions lib/controllers/EngineController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ export class EngineController {

async create (request: KuzzleRequest) {
const index = request.getIndex();
const tenantGroup = request.getString('group', 'commons');
const group = request.getString('group', 'commons');

const { collections } = await this.engineService.create(index, tenantGroup);
const { collections } = await this.engineService.create(index, group);

return { index, collections };
}

async update (request: KuzzleRequest) {
const index = request.getIndex();
const tenantGroup = request.getString('group', 'commons');
const group = request.getString('group', 'commons');

const { collections } = await this.engineService.update(index, tenantGroup);
const { collections } = await this.engineService.update(index, group);

return { index, collections };
}
Expand Down
32 changes: 16 additions & 16 deletions lib/models/CustomProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class CustomProperties {
this.definitions.set('commons', defaultMappings.properties);
}

mergeMappings (propertyName: string, mappings: JSONObject, tenantGroup: string) {
const property = this.definitions.has(tenantGroup)
? this.definitions.get(tenantGroup)[propertyName] || {}
mergeMappings (propertyName: string, mappings: JSONObject, group: string) {
const property = this.definitions.has(group)
? this.definitions.get(group)[propertyName] || {}
: {};

property.properties = { ...property.properties, ...mappings }

this.definitions.set(tenantGroup, { ...this.definitions.get(tenantGroup), [propertyName]: property });
this.definitions.set(group, { ...this.definitions.get(group), [propertyName]: property });
}
}

Expand All @@ -30,10 +30,10 @@ export class AssetsCustomProperties extends CustomProperties {
*
* @param mappings Mappings definition of the "metadata" property
* @param options Additional options
* - `tenantGroup` Name of the group for which the mappings should apply
* - `group` Name of the group for which the mappings should apply
*/
registerMetadata (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) {
this.mergeMappings('metadata', mappings, tenantGroup);
registerMetadata (mappings: JSONObject, { group='commons' }: { group?: string } = {}) {
this.mergeMappings('metadata', mappings, group);
}
}

Expand All @@ -43,21 +43,21 @@ export class DevicesCustomProperties extends CustomProperties {
*
* @param mappings Mappings definition of the "qos" property
* @param options Additional options
* - `tenantGroup` Name of the group for which the mappings should apply
* - `group` Name of the group for which the mappings should apply
*/
registerQos (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) {
this.mergeMappings('qos', mappings, tenantGroup);
registerQos (mappings: JSONObject, { group='commons' }: { group?: string } = {}) {
this.mergeMappings('qos', mappings, group);
}

/**
* Define custom mappings for the "metadata" property
*
* @param mappings Mappings definition of the "metadata" property
* @param options Additional options
* - `tenantGroup` Name of the group for which the mappings should apply
* - `group` Name of the group for which the mappings should apply
*/
registerMetadata (mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) {
this.mergeMappings('metadata', mappings, tenantGroup);
registerMetadata (mappings: JSONObject, { group='commons' }: { group?: string } = {}) {
this.mergeMappings('metadata', mappings, group);
}

/**
Expand All @@ -66,9 +66,9 @@ export class DevicesCustomProperties extends CustomProperties {
* @param measureName Name of the measure property you mean to add (eg. 'temperature')
* @param mappings Mappings definition of the added measure property
* @param options Additional options
* - `tenantGroup` Name of the group for which the mappings should apply
* - `group` Name of the group for which the mappings should apply
*/
registerMeasure (measureName: string, mappings: JSONObject, { tenantGroup='commons' }: { tenantGroup?: string } = {}) {
this.mergeMappings('measures', { [measureName]: { ...mappings } }, tenantGroup);
registerMeasure (measureName: string, mappings: JSONObject, { group='commons' }: { group?: string } = {}) {
this.mergeMappings('measures', { [measureName]: { ...mappings } }, group);
}
}
12 changes: 6 additions & 6 deletions lib/services/EngineService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export class EngineService {
this.context = context;
}

async create (index: string, tenantGroup = 'commons') {
async create (index: string, group = 'commons') {
if (await this.exists(index)) {
throw new BadRequestError(`Tenant "${index}" already have a device-manager engine`);
}

const collections = [];
const promises = [];
const templates = this.config.mappings.get(tenantGroup)
? this.config.mappings.get(tenantGroup)
const templates = this.config.mappings.get(group)
? this.config.mappings.get(group)
: this.config.mappings.get('commons');

for (const [collection, mappings] of Object.entries(templates)) {
Expand All @@ -49,15 +49,15 @@ export class EngineService {
return { collections };
}

async update (index: string, tenantGroup = 'commons') {
async update (index: string, group = 'commons') {
if (! await this.exists(index)) {
throw new NotFoundError(`Tenant "${index}" does not have a device-manager engine`);
}

const collections = [];
const promises = [];
const templates = this.config.mappings.get(tenantGroup)
? this.config.mappings.get(tenantGroup)
const templates = this.config.mappings.get(group)
? this.config.mappings.get(group)
: this.config.mappings.get('commons');

for (const [collection, mappings] of Object.entries(templates)) {
Expand Down