Skip to content

Commit

Permalink
Merge pull request #1521 from telefonicaid/task/add_payloadType_devic…
Browse files Browse the repository at this point in the history
…e_group_model

Task/add payload type device group model
  • Loading branch information
fgalan authored Nov 15, 2023
2 parents 63d9bbd + 0aa6f31 commit 4528abd
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Add: payloadType to device and groups model to support NGSI-v2 and NGSI-LD formats in southbound measures (iotagent-json#778)
- Large refactor of IOTA Lib code to make it simpler
- Remove: time compression support
- Remove: autocast (including env var IOTA_AUTOCAST) (#1498)
Expand Down
2 changes: 2 additions & 0 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ Config group is represented by a JSON object with the following fields:
| `ngsiVersion` || string | | optional string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. Possible values are: `v2` or `ld`. The default is `v2`. When not running in mixed mode, this field is ignored. |
| `defaultEntityNameConjunction` || string | | optional string value to set default conjunction string used to compose a default `entity_name` when is not provided at device provisioning time. |
| `autoprovision` || bool | ✓? | optional boolean: If `false`, autoprovisioned devices (i.e. devices that are not created with an explicit provision operation but when the first measure arrives) are not allowed in this group. Default (in the case of omitting the field) is `true`. |
| `payloadType` || string | | optional string value used to switch between **IoTAgent**, **NGSI-v2** and **NGSI-LD** measure payloads types. Possible values are: `iotagent`, `ngsiv2` or `ngsild`. The default is `iotagent`. |

### Config group operations

Expand Down Expand Up @@ -1430,6 +1431,7 @@ the API resource fields and the same fields in the database model.
| `internal_attributes` || `array` | | List of internal attributes with free format for specific IoT Agent configuration. |
| `explicitAttrs` || `boolean` || Field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](#explicitly-defined-attributes-explicitattrs) |
| `ngsiVersion` || `string` | | string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. The default is `v2`. When not running in mixed mode, this field is ignored. |
| `payloadType` || `string` | | optional string value used to switch between **IoTAgent**, **NGSI-v2** and **NGSI-LD** measure payloads types. Possible values are: `iotagent`, `ngsiv2` or `ngsild`. The default is `iotagent`. |

### Device operations

Expand Down
3 changes: 2 additions & 1 deletion lib/model/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const Device = new Schema({
internalAttributes: Object,
autoprovision: Boolean,
explicitAttrs: Group.ExplicitAttrsType,
ngsiVersion: String
ngsiVersion: String,
payloadType: String
});

function load(db) {
Expand Down
3 changes: 2 additions & 1 deletion lib/model/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const Group = new Schema({
explicitAttrs: ExplicitAttrsType,
defaultEntityNameConjunction: String,
ngsiVersion: String,
entityNameExp: String
entityNameExp: String,
payloadType: String
});

function load(db) {
Expand Down
3 changes: 2 additions & 1 deletion lib/services/common/iotManagerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ function register(callback) {
explicitAttrs: service.explicitAttrs,
defaultEntityNameConjunction: service.defaultEntityNameConjunction,
ngsiVersion: service.ngsiVersion,
entityNameExp: service.entityNameExp
entityNameExp: service.entityNameExp,
payloadType: service.payloadType
};
}

Expand Down
4 changes: 3 additions & 1 deletion lib/services/devices/deviceRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const attributeList = [
'polling',
'timestamp',
'explicitAttrs',
'ngsiVersion'
'ngsiVersion',
'payloadType'
];

/**
Expand Down Expand Up @@ -316,6 +317,7 @@ function update(device, callback) {
data.explicitAttrs = device.explicitAttrs;
data.ngsiVersion = device.ngsiVersion;
data.timestamp = device.timestamp;
data.payloadType = device.payloadType;

/* eslint-disable-next-line new-cap */
const deviceObj = new Device.model(data);
Expand Down
3 changes: 3 additions & 0 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ function mergeDeviceWithConfiguration(fields, defaults, deviceData, configuratio
if (configuration && configuration.timestamp !== undefined && deviceData.timestamp === undefined) {
deviceData.timestamp = configuration.timestamp;
}
if (configuration && configuration.payloadType !== undefined && deviceData.payloadType === undefined) {
deviceData.payloadType = configuration.payloadType;
}
logger.debug(context, 'deviceData after merge with conf: %j', deviceData);
callback(null, deviceData);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/services/devices/devices-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ function updateRegisterDeviceNgsi2(deviceObj, entityInfoUpdated, callback) {
if ('apikey' in newDevice && newDevice.apikey !== undefined) {
oldDevice.apikey = newDevice.apikey;
}
if ('payloadType' in newDevice && newDevice.payloadType !== undefined) {
oldDevice.payloadType = newDevice.payloadType;
}
oldDevice.endpoint = newDevice.endpoint || oldDevice.endpoint;

callback(null, oldDevice);
Expand Down
39 changes: 20 additions & 19 deletions lib/services/groups/groupRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ const attributeList = [
'expressionLanguage',
'defaultEntityNameConjunction',
'ngsiVersion',
'entityNameExp'
'entityNameExp',
'payloadType'
];

/**
Expand Down Expand Up @@ -147,15 +148,15 @@ function listGroups(service, limit, offset, callback) {
query.skip(parseInt(offset, 10));
}

async.series([query.exec.bind(query), Group.model.countDocuments.bind(Group.model, condition)], function (
error,
results
) {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
});
async.series(
[query.exec.bind(query), Group.model.countDocuments.bind(Group.model, condition)],
function (error, results) {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
}
);
}

function getById(id, callback) {
Expand Down Expand Up @@ -201,15 +202,15 @@ function find(service, subservice, callback) {

const query = Group.model.find(condition).sort();

async.series([query.exec.bind(query), Group.model.countDocuments.bind(Group.model, condition)], function (
error,
results
) {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
});
async.series(
[query.exec.bind(query), Group.model.countDocuments.bind(Group.model, condition)],
function (error, results) {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
}
);
}

function findOneInMongoDB(queryObj, fields, callback) {
Expand Down
9 changes: 6 additions & 3 deletions lib/services/northBound/deviceProvisioningServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const provisioningAPITranslation = {
autoprovision: 'autoprovision',
explicitAttrs: 'explicitAttrs',
ngsiVersion: 'ngsiVersion',
entityNameExp: 'entityNameExp'
entityNameExp: 'entityNameExp',
payloadType: 'payloadType'
};

/**
Expand Down Expand Up @@ -141,7 +142,8 @@ function handleProvision(req, res, next) {
internalId: null,
autoprovision: body.autoprovision,
explicitAttrs: body.explicitAttrs,
ngsiVersion: body.ngsiVersion
ngsiVersion: body.ngsiVersion,
payloadType: body.payloadType
});
}

Expand Down Expand Up @@ -218,7 +220,8 @@ function toProvisioningAPIFormat(device) {
protocol: device.protocol,
autoprovision: device.autoprovision,
explicitAttrs: device.explicitAttrs,
ngsiVersion: device.ngsiVersion
ngsiVersion: device.ngsiVersion,
payloadType: device.payloadType
};
}

Expand Down
4 changes: 4 additions & 0 deletions lib/templates/createDevice.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"description": "NGSI Interface for this device",
"type": "string"
},
"payloadType": {
"description": "Payload type allowed for measures for this device",
"type": "string"
},
"lazy": {
"description": "list of lazy attributes of the devices",
"type": "array",
Expand Down
4 changes: 4 additions & 0 deletions lib/templates/createDeviceLax.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"description": "NGSI Interface for this device",
"type": "string"
},
"payloadType": {
"description": "Payload type allowed for measures for this device",
"type": "string"
},
"lazy": {
"description": "list of lazy attributes of the devices",
"type": "array",
Expand Down
4 changes: 4 additions & 0 deletions lib/templates/deviceGroup.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
"description": "NGSI Interface for this group of devices",
"type": "string"
},
"payloadType": {
"description": "Payload type allowed for measures for this group",
"type": "string"
},
"attributes": {
"description": "list of active attributes of the devices",
"type": "array"
Expand Down
4 changes: 4 additions & 0 deletions lib/templates/updateDevice.json
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@
"ngsiVersion": {
"description": "NGSI Interface for this device",
"type": "string"
},
"payloadType": {
"description": "Payload type allowed for measures for this device",
"type": "string"
}
}
}
4 changes: 4 additions & 0 deletions lib/templates/updateDeviceLax.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
"ngsiVersion": {
"description": "NGSI Interface for this device",
"type": "string"
},
"payloadType": {
"description": "Payload type allowed for measures for this device",
"type": "string"
}
}
}

0 comments on commit 4528abd

Please sign in to comment.