-
Notifications
You must be signed in to change notification settings - Fork 89
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
Added feature config groups #1375
Changes from 7 commits
4aa64c5
1016def
ab1d728
0b0973d
1ea983f
5c686c0
5899a2b
a4db57a
4fad7ea
a07215c
207cbb5
5174f01
92340d4
2abd610
06bcc74
7483358
c0100be
8f91d13
1178705
7320d9a
407c156
bc1a1d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Add /iot/configGroups API endpoints (as equivalent to /iot/services) (#752) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1172,7 +1172,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`. If the `fiware-servicepath` header | ||
has the wildcard expression, `/*`, all the config groups for that `fiware-service` are returned. The config groups that | ||
|
@@ -1197,11 +1197,50 @@ 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 | ||
{ | ||
"configGroups": [ | ||
{ | ||
"resource": "/deviceTest", | ||
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732", | ||
"type": "Light", | ||
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS", | ||
"cbHost": "http://orion:1026", | ||
"commands": [{ "name": "wheel1", "type": "Wheel" }], | ||
"attributes": [ | ||
{ | ||
"name": "luminescence", | ||
"type": "Integer", | ||
"metadata": { | ||
"unitCode": { "type": "Text", "value": "CAL" } | ||
} | ||
} | ||
], | ||
"lazy": [{ "name": "status", "type": "Boolean" }] | ||
}, | ||
{ | ||
"resource": "/deviceTest2", | ||
"apikey": "A21323ASDG12312ASDN21LWQEJPO2J123", | ||
"type": "Switch", | ||
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS", | ||
"cbHost": "http://orion:1026", | ||
"commands": [{ "name": "on", "type": "order" }], | ||
"attributes": [ | ||
{ | ||
"name": "swithc_status", | ||
"type": "boolean" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
```json | ||
{ | ||
"services": [ | ||
|
@@ -1241,7 +1280,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. | ||
|
@@ -1255,11 +1294,38 @@ _**Request headers**_ | |
|
||
_**Request payload**_ | ||
|
||
A JSON object with a `services` field. The value is an array of config groups objects to create. See the | ||
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 | ||
{ | ||
"configGroups": [ | ||
{ | ||
"resource": "/deviceTest", | ||
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732", | ||
"type": "Light", | ||
"trust": "8970A9078A803H3BL98PINEQRW8342HBAMS", | ||
"cbHost": "http://orion:1026", | ||
"commands": [{ "name": "wheel1", "type": "Wheel" }], | ||
"attributes": [ | ||
{ | ||
"name": "luminescence", | ||
"type": "Integer", | ||
"metadata": { | ||
"unitCode": { "type": "Text", "value": "CAL" } | ||
} | ||
} | ||
], | ||
"lazy": [{ "name": "status", "type": "Boolean" }] | ||
} | ||
] | ||
} | ||
``` | ||
OR | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should replace the existing example, not adding a new one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
```json | ||
{ | ||
"services": [ | ||
|
@@ -1296,9 +1362,9 @@ _**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 | ||
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. | ||
|
||
|
@@ -1336,7 +1402,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. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,40 @@ function getConfigurationsByService(service) { | |
}); | ||
} | ||
|
||
/** | ||
* List all the configGroups created in the IoT Agent. The result, passed as a parameter in the callback | ||
* will be an object with two attributes: the services array with the list of groups; and a count | ||
* attribute with the total number of groups in the collection. | ||
* | ||
* @param {Number} service Service for wich all the configurations want to be retrieved. | ||
* @param {Number} limit Maximum number of entries to return. | ||
* @param {Number} offset Number of entries to skip for pagination. | ||
*/ | ||
function listConfigGroups(service, limit, offset, callback) { | ||
const result = []; | ||
let skipped = 0; | ||
const filteredGroups = getConfigurationsByService(service); | ||
|
||
for (const i in filteredGroups) { | ||
if (registeredGroups.hasOwnProperty(filteredGroups[i])) { | ||
if (offset && skipped < parseInt(offset, 10)) { | ||
skipped++; | ||
} else { | ||
result.push(registeredGroups[filteredGroups[i]]); | ||
} | ||
|
||
if (limit && result.length === parseInt(limit, 10)) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
callback(null, { | ||
count: filteredGroups.length, | ||
configGroups: result | ||
}); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated, same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
/** | ||
* List all the groups created in the IoT Agent. The result, passed as a parameter in the callback | ||
* will be an object with two attributes: the services array with the list of groups; and a count | ||
|
@@ -152,6 +186,32 @@ function findSingleConfigurationMode(service, subservice, callback) { | |
} | ||
} | ||
|
||
function findConfigGroups(service, subservice, callback) { | ||
if (config.getConfig().singleConfigurationMode === true) { | ||
return findSingleConfigurationMode(service, subservice, callback); | ||
} | ||
const result = []; | ||
|
||
for (const i in registeredGroups) { | ||
if ( | ||
registeredGroups.hasOwnProperty(i) && | ||
registeredGroups[i].service === service && | ||
registeredGroups[i].subservice === subservice | ||
) { | ||
result.push(registeredGroups[i]); | ||
} | ||
} | ||
|
||
if (result.length > 0) { | ||
return callback(null, { | ||
count: result.length, | ||
configGroups: result | ||
}); | ||
} else { | ||
return callback(new errors.DeviceGroupNotFound(service, subservice)); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated, same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
function find(service, subservice, callback) { | ||
if (config.getConfig().singleConfigurationMode === true) { | ||
return findSingleConfigurationMode(service, subservice, callback); | ||
|
@@ -284,8 +344,10 @@ function remove(id, callback) { | |
|
||
exports.create = intoTrans(context, createGroup); | ||
exports.list = intoTrans(context, listGroups); | ||
exports.listConfigGroups = intoTrans(context, listConfigGroups); | ||
exports.init = intoTrans(context, init); | ||
exports.find = intoTrans(context, find); | ||
exports.findConfigGroups = intoTrans(context, findConfigGroups); | ||
exports.findBy = intoTrans(context, findBy); | ||
exports.findType = intoTrans(context, findBy(['service', 'subservice', 'type'])); | ||
exports.findTypeSilently = intoTrans(context, findBy(['service', 'subservice', 'type'])); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,45 @@ function createGroup(group, callback) { | |
}); | ||
} | ||
|
||
/** | ||
* List all the configGroups created in the IoT Agent. | ||
* | ||
* @param {Number} service Service for wich all the configurations want to be retrieved. | ||
* @param {Number} limit Maximum number of entries to return. | ||
* @param {Number} offset Number of entries to skip for pagination. | ||
*/ | ||
function listConfigGroups(service, limit, offset, callback) { | ||
const condition = {}; | ||
|
||
function toObjectFn(obj) { | ||
return obj.toObject(); | ||
} | ||
|
||
if (service) { | ||
condition.service = service; | ||
} | ||
|
||
const query = Group.model.find(condition).sort(); | ||
|
||
if (limit) { | ||
query.limit(parseInt(limit, 10)); | ||
} | ||
|
||
if (offset) { | ||
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], | ||
configGroups: results[0].map(toObjectFn) | ||
}); | ||
}); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code, same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
/** | ||
* List all the groups created in the IoT Agent. | ||
* | ||
|
@@ -182,6 +221,36 @@ function getById(id, callback) { | |
}); | ||
} | ||
|
||
/** | ||
* List all the configGroups created in the IoT Agent for a service and a subservice. | ||
* | ||
* @param {String} service Service used to filter the groups. | ||
* @param {String} subservice Subservice used to filter the groups. | ||
* @param {Function} callback The callback function. | ||
*/ | ||
function findConfigGroups(service, subservice, callback) { | ||
const condition = {}; | ||
|
||
function toObjectFn(obj) { | ||
return obj.toObject(); | ||
} | ||
|
||
condition.service = service; | ||
condition.subservice = subservice; | ||
|
||
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], | ||
configGroups: results[0].map(toObjectFn) | ||
}); | ||
}); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicated code, same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
/** | ||
* List all the groups created in the IoT Agent for a service and a subservice. | ||
* | ||
|
@@ -302,8 +371,10 @@ function clear(callback) { | |
|
||
exports.create = alarmsInt(constants.MONGO_ALARM + '_01', intoTrans(context, createGroup)); | ||
exports.list = alarmsInt(constants.MONGO_ALARM + '_02', intoTrans(context, listGroups)); | ||
exports.listConfigGroups = alarmsInt(constants.MONGO_ALARM + '_12', intoTrans(context, listConfigGroups)); | ||
exports.init = alarmsInt(constants.MONGO_ALARM + '_03', intoTrans(context, init)); | ||
exports.find = alarmsInt(constants.MONGO_ALARM + '_04', intoTrans(context, find)); | ||
exports.findConfigGroups = alarmsInt(constants.MONGO_ALARM + '_13', intoTrans(context, findConfigGroups)); | ||
exports.findType = alarmsInt( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exporting duplicated functions, not required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1178705 |
||
constants.MONGO_ALARM + '_05', | ||
intoTrans(context, findBy(['service', 'subservice', 'type', 'apikey'])) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should replace the existing example, not adding a new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1178705