Skip to content

Commit

Permalink
Merge pull request #1375 from KeshavSoni2511/Added_Feature_ConfigGroups
Browse files Browse the repository at this point in the history
Added feature config groups
  • Loading branch information
mapedraza authored Aug 7, 2024
2 parents c57d892 + bc1a1d4 commit e53d004
Show file tree
Hide file tree
Showing 24 changed files with 2,382 additions and 67 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: service header to use uppercase in case of update and delete (#1528)
- Fix: Allow to send to CB batch update for multimeasures for NGSI-LD (#1623)
- Add: new JEXL transformations for including into an array keys that have a certain value: valuePicker and valuePickerMulti
- Add /iot/configGroups API endpoints (as equivalent to /iot/services) (#752)
24 changes: 12 additions & 12 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ Config group is represented by a JSON object with the following fields:

The following actions are available under the config group endpoint:

#### Retrieve config groups `GET /iot/services`
#### Retrieve config groups GET `/iot/configGroups` or `GET /iot/services`

List all the config groups for the given `fiware-service` and `fiware-servicepath`. The config groups that match the
`fiware-servicepath` are returned in any other case.
Expand All @@ -1705,14 +1705,14 @@ Successful operations return `Content-Type` header with `application/json` value

_**Response payload**_

A JSON object with a services field that contains an array of services that match the request. See the
A JSON object with a configGroups or services field that contains an array of services that match the request. See the
[config group datamodel](#service-group-datamodel) for more information.

Example:

```json
{
"services": [
"configGroups": [
{
"resource": "/deviceTest",
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
Expand Down Expand Up @@ -1749,7 +1749,7 @@ Example:
}
```

#### Create config group `POST /iot/services`
#### Create config group `POST /iot/configGroups` or `POST /iot/services`

Creates a set of config groups for the given service and service path. The service and subservice information will taken
from the headers, overwritting any preexisting values.
Expand All @@ -1763,14 +1763,14 @@ _**Request headers**_

_**Request payload**_

A JSON object with a `services` field. The value is an array of config groups objects to create. See the
[config group datamodel](#service-group-datamodel) for more information.
A JSON object with a `configGroups` or `services` field. The value is an array of config groups objects to create. See
the [config group datamodel](#service-group-datamodel) for more information.

Example:

```json
{
"services": [
"configGroups": [
{
"resource": "/deviceTest",
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
Expand Down Expand Up @@ -1804,11 +1804,11 @@ _**Response headers**_

Successful operations return `Content-Type` header with `application/json` value.

#### Modify config group `PUT /iot/services`
#### Modify config group `PUT /iot/configGroups` or `PUT /iot/services`

Modifies the information of a config group, identified by the `resource` and `apikey` query parameters. Takes a service
group body as the payload. The body does not have to be complete: for incomplete bodies, just the attributes included in
the JSON body will be updated. The rest of the attributes will remain unchanged.
Modifies the information of a config group, identified by the `resource` and `apikey` query parameters. Takes a
configuration/service group body as the payload. The body does not have to be complete: for incomplete bodies, just the
attributes included in the JSON body will be updated. The rest of the attributes will remain unchanged.

_**Request query parameters**_

Expand Down Expand Up @@ -1844,7 +1844,7 @@ _**Response code**_
- 400 MISSING_HEADERS if any of the mandatory headers is not present.
- 500 SERVER ERROR if there was any error not contemplated above.:

#### Remove config group `DELETE /iot/services`
#### Remove config group `DELETE /iot/configGroups` or `DELETE /iot/services`

Removes a config group, identified by the `resource` and `apikey` query parameters.

Expand Down
40 changes: 26 additions & 14 deletions doc/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ product:
- cgroup literal in configuration groups management API (community)
- Refactor Append Mode & initial entity ([#1413](https://github.com/telefonicaid/iotagent-node-lib/issues/1413))
- Native support for NGSI-v2 and LD ingestion ([#1451](https://github.com/telefonicaid/iotagent-node-lib/issues/1451))
- Remove plugins structure (bidirectional plugin) ([#1413](https://github.com/telefonicaid/iotagent-node-lib/issues/1413))
- Remove plugins structure (bidirectional plugin)
([#1413](https://github.com/telefonicaid/iotagent-node-lib/issues/1413))
- Add init and improve log traces ([#1452](https://github.com/telefonicaid/iotagent-node-lib/issues/1452))
- Remove InMemory registry for Devices and Groups ([#1429](https://github.com/telefonicaid/iotagent-node-lib/issues/1429))
- Remove InMemory registry for Devices and Groups
([#1429](https://github.com/telefonicaid/iotagent-node-lib/issues/1429))

### Medium term

The following list of features are planned to be addressed in the medium term, typically within the subsequent
release(s) generated in the next 9 months after the next planned release:

- Allow to add metadata to attributes from measures ([#1453](https://github.com/telefonicaid/iotagent-node-lib/issues/1453))
- Allow to add metadata to attributes from measures
([#1453](https://github.com/telefonicaid/iotagent-node-lib/issues/1453))
- Cache support ([#1467](https://github.com/telefonicaid/iotagent-node-lib/issues/1467))
- MQTT per group advanced configuration (MQTT broker, topics) ([#1454](https://github.com/telefonicaid/iotagent-node-lib/issues/1454))
- MQTT per group advanced configuration (MQTT broker, topics)
([#1454](https://github.com/telefonicaid/iotagent-node-lib/issues/1454))
- Subscription based commands ([#1455](https://github.com/telefonicaid/iotagent-node-lib/issues/1455))
- Remove registration support ([#1456](https://github.com/telefonicaid/iotagent-node-lib/issues/1456))

Expand All @@ -49,29 +53,37 @@ The following list of features are proposals regarding the longer-term evolution
development of these features has not yet been scheduled for a release in the near future. Please feel free to contact
us if you wish to get involved in the implementation or influence the roadmap:

- Use the lightweight ingestion mechanism for connection oriented updates implemented in Context Broker (testing pending) ([#1457](https://github.com/telefonicaid/iotagent-node-lib/issues/1457))
- Add support to other transport protocols (BacNET, Modbus, etc) ([#1458](https://github.com/telefonicaid/iotagent-node-lib/issues/1458))
- Dynamic attribute generation (based on values array) ([#1459](https://github.com/telefonicaid/iotagent-node-lib/issues/1459))
- Use the lightweight ingestion mechanism for connection oriented updates implemented in Context Broker (testing
pending) ([#1457](https://github.com/telefonicaid/iotagent-node-lib/issues/1457))
- Add support to other transport protocols (BacNET, Modbus, etc)
([#1458](https://github.com/telefonicaid/iotagent-node-lib/issues/1458))
- Dynamic attribute generation (based on values array)
([#1459](https://github.com/telefonicaid/iotagent-node-lib/issues/1459))
- Incremental introduccion of ECMAScript6 syntax (previous analysis of which sub-set of interesting aspect we want to
take)

### Features already completed

The following list contains all features that were in the roadmap and have already been implemented.

- Refactor entities-NGSI-v2.js module ([#1166](https://github.com/telefonicaid/iotagent-node-lib/issues/1166)) ([3.0.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/3.0.0))
- Accept JEXL Expressions for entity name in autoprovisioned devices (entityNameExp) ([#1145](https://github.com/telefonicaid/iotagent-node-lib/issues/1145)) ([2.22.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.22.0))
- Improve command functionalities (binary data + expression + mapping) ([2.22.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.22.0))
- Refactor entities-NGSI-v2.js module ([#1166](https://github.com/telefonicaid/iotagent-node-lib/issues/1166))
([3.0.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/3.0.0))
- Accept JEXL Expressions for entity name in autoprovisioned devices (entityNameExp)
([#1145](https://github.com/telefonicaid/iotagent-node-lib/issues/1145))
([2.22.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.22.0))
- Improve command functionalities (binary data + expression + mapping)
([2.22.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.22.0))
- Support for "delta" measures (i.e. "temperature _increased_ in 5 degress" instead of "temperature _is_ 25")
- Allow to handle binary messages ([iota-ul#530](https://github.com/telefonicaid/iotagent-ul/issues/530))
- Removal support for NGSIv1 ([#966](https://github.com/telefonicaid/iotagent-node-lib/issues/966)) ([2.18.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.18.0))
- Removal support for NGSIv1 ([#966](https://github.com/telefonicaid/iotagent-node-lib/issues/966))
([2.18.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.18.0))
- Selectively ignore measure in the southbound interface
([iotagent-json#416](https://github.com/telefonicaid/iotagent-json/issues/416),
[iotagent-ul#372](https://github.com/telefonicaid/iotagent-ul/issues/372))
([2.13.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.13.0))
- JEXL support in expressions ([#801](https://github.com/telefonicaid/iotagent-node-lib/issues/801),
[#687](https://github.com/telefonicaid/iotagent-node-lib/issues/687),
[#868](https://github.com/telefonicaid/iotagent-node-lib/issues/868))
- JEXL support in expressions ([#801](https://github.com/telefonicaid/iotagent-node-lib/issues/801),
[#687](https://github.com/telefonicaid/iotagent-node-lib/issues/687),
[#868](https://github.com/telefonicaid/iotagent-node-lib/issues/868))
([2.13.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.13.0))
- Add MongoDB authentication support ([#844](https://github.com/telefonicaid/iotagent-node-lib/issues/844))
([2.12.0](https://github.com/telefonicaid/iotagent-node-lib/releases/tag/2.12.0))
2 changes: 2 additions & 0 deletions lib/fiware-iotagent-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ exports.setCommandHandler = contextServer.setCommandHandler;
exports.setMergePatchHandler = contextServer.setMergePatchHandler;
exports.setDataQueryHandler = contextServer.setQueryHandler;
exports.setConfigurationHandler = contextServer.setConfigurationHandler;
exports.setGroupConfigurationHandler = contextServer.setGroupConfigurationHandler;
exports.setRemoveConfigurationHandler = contextServer.setRemoveConfigurationHandler;
exports.setRemoveGroupConfigurationHandler = contextServer.setRemoveGroupConfigurationHandler;
exports.setProvisioningHandler = contextServer.setProvisioningHandler;
exports.setUpdatingHandler = contextServer.setUpdatingHandler;
exports.setRemoveDeviceHandler = contextServer.setRemoveDeviceHandler;
Expand Down
2 changes: 1 addition & 1 deletion lib/services/common/iotManagerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function register(callback) {
}

function getServices(callback) {
config.getGroupRegistry().list(null, null, null, function (error, results) {
config.getGroupRegistry().list(null, null, null, null, function (error, results) {
if (error) {
callback(error);
} else {
Expand Down
35 changes: 24 additions & 11 deletions lib/services/groups/groupRegistryMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function getConfigurationsByService(service) {
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listGroups(service, limit, offset, callback) {
function listGroups(endpoint, service, limit, offset, callback) {
const result = [];
let skipped = 0;
const filteredGroups = getConfigurationsByService(service);
Expand All @@ -113,11 +113,17 @@ function listGroups(service, limit, offset, callback) {
}
}
}

callback(null, {
count: filteredGroups.length,
services: result
});
if (endpoint != null && endpoint.includes('configgroups')) {
callback(null, {
count: filteredGroups.length,
configGroups: result
});
} else {
callback(null, {
count: filteredGroups.length,
services: result
});
}
}

function init(newConfig, callback) {
Expand All @@ -130,7 +136,7 @@ function clear(callback) {
callback();
}

function find(service, subservice, callback) {
function find(endpoint, service, subservice, callback) {
const result = [];

for (const i in registeredGroups) {
Expand All @@ -145,10 +151,17 @@ function find(service, subservice, callback) {

if (result.length > 0) {
logger.debug(context, 'groups found %j', result);
return callback(null, {
count: result.length,
services: result
});
if (endpoint.includes('configgroups')) {
return callback(null, {
count: result.length,
configGroups: result
});
} else {
return callback(null, {
count: result.length,
services: result
});
}
} else {
return callback(new errors.DeviceGroupNotFound(service, subservice));
}
Expand Down
34 changes: 24 additions & 10 deletions lib/services/groups/groupRegistryMongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function createGroup(group, callback) {
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listGroups(service, limit, offset, callback) {
function listGroups(endpoint, service, limit, offset, callback) {
const condition = {};

function toObjectFn(obj) {
Expand All @@ -153,10 +153,17 @@ function listGroups(service, limit, offset, callback) {
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)
});
if (endpoint.includes('configgroups')) {
callback(error, {
count: results[1],
configGroups: results[0].map(toObjectFn)
});
} else {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
}
}
);
}
Expand Down Expand Up @@ -192,7 +199,7 @@ function getById(id, callback) {
* @param {String} subservice Subservice used to filter the groups.
* @param {Function} callback The callback function.
*/
function find(service, subservice, callback) {
function find(endpoint, service, subservice, callback) {
const condition = {};

function toObjectFn(obj) {
Expand All @@ -207,10 +214,17 @@ function find(service, subservice, callback) {
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)
});
if (endpoint.includes('configgroups')) {
callback(error, {
count: results[1],
configGroups: results[0].map(toObjectFn)
});
} else {
callback(error, {
count: results[1],
services: results[0].map(toObjectFn)
});
}
}
);
}
Expand Down
34 changes: 23 additions & 11 deletions lib/services/groups/groupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const context = {
*
* @param {Object} group Validate the device group
*/
function validateGroup(group, callback) {
function validateGroup(endpoint, group, callback) {
const validations = [];
logger.debug(context, 'validateGroup %j', group);

Expand Down Expand Up @@ -94,12 +94,22 @@ function createGroup(groupSet, callback) {
const insertions = [];
const insertedGroups = [];

logger.debug(context, 'Creating new set of %d services', groupSet.services.length);
if (groupSet.configGroups) {
logger.debug(context, 'Creating new set of %d configGroups', groupSet.configGroups.length);

for (let i = 0; i < groupSet.services.length; i++) {
insertions.push(async.apply(validateGroup, groupSet.services[i]));
insertions.push(async.apply(config.getGroupRegistry().create, groupSet.services[i]));
insertedGroups.push(groupSet.services[i]);
for (let i = 0; i < groupSet.configGroups.length; i++) {
insertions.push(async.apply(validateGroup, 'configGroups', groupSet.configGroups[i]));
insertions.push(async.apply(config.getGroupRegistry().create, groupSet.configGroups[i]));
insertedGroups.push(groupSet.configGroups[i]);
}
} else {
logger.debug(context, 'Creating new set of %d services', groupSet.services.length);

for (let i = 0; i < groupSet.services.length; i++) {
insertions.push(async.apply(validateGroup, 'services', groupSet.services[i]));
insertions.push(async.apply(config.getGroupRegistry().create, groupSet.services[i]));
insertedGroups.push(groupSet.services[i]);
}
}

insertions.push(iotManagerService.register);
Expand All @@ -114,12 +124,13 @@ function createGroup(groupSet, callback) {
* @param {Number} limit Maximum number of entries to return.
* @param {Number} offset Number of entries to skip for pagination.
*/
function listGroups(service, limit, offset, callback) {
function listGroups(endpoint, service, limit, offset, callback) {
endpoint = endpoint.toLowerCase();
if (!callback) {
callback = service;
}

config.getGroupRegistry().list(service, limit, offset, callback);
config.getGroupRegistry().list(endpoint, service, limit, offset, callback);
}

function checkServiceIdentity(service, subservice, deviceGroup, callback) {
Expand Down Expand Up @@ -231,11 +242,12 @@ function update(service, subservice, resource, apikey, body, callback) {
* @param {String} subservice Group subservice name.
* @param {String} type Group type (optional).
*/
function find(service, subservice, type, callback) {
function find(endpoint, service, subservice, type, callback) {
endpoint = endpoint.toLowerCase();
if (type) {
config.getGroupRegistry().findType(service, subservice, type, callback);
} else {
config.getGroupRegistry().find(service, subservice, callback);
config.getGroupRegistry().find(endpoint, service, subservice, callback);
}
}

Expand Down Expand Up @@ -302,7 +314,7 @@ function getEffectiveApiKey(service, subservice, type, callback) {
}
}

find(service, subservice, type, handleFindGroup);
find('configGroups', service, subservice, type, handleFindGroup);
}

exports.create = intoTrans(context, createGroup);
Expand Down
1 change: 1 addition & 0 deletions lib/services/ngsi/entities-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ function sendUpdateValueNgsi2(entityName, originMeasures, originTypeInformation,
const currentIsoDate = new Date().toISOString();
const currentMoment = moment(currentIsoDate);
//Managing timestamp (mustInsertTimeInstant flag to decide if we should insert Timestamp later on)

const mustInsertTimeInstant =
originTypeInformation.timestamp !== undefined ? originTypeInformation.timestamp : false;

Expand Down
Loading

0 comments on commit e53d004

Please sign in to comment.