iotagent-node-lib 4.4.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +67 -272
  2. package/config.js +2 -1
  3. package/doc/README.md +1 -1
  4. package/doc/admin.md +19 -22
  5. package/doc/api.md +621 -155
  6. package/doc/deprecated.md +4 -0
  7. package/doc/devel/architecture.md +5 -135
  8. package/doc/devel/development.md +224 -12
  9. package/doc/getting-started.md +114 -53
  10. package/doc/requirements.txt +1 -1
  11. package/doc/roadmap.md +5 -5
  12. package/docker/Mosquitto/Dockerfile +2 -2
  13. package/docker/Mosquitto/README.md +14 -11
  14. package/lib/commonConfig.js +7 -1
  15. package/lib/constants.js +3 -0
  16. package/lib/fiware-iotagent-lib.js +12 -15
  17. package/lib/jexlTranformsMap.js +3 -1
  18. package/lib/model/dbConn.js +1 -4
  19. package/lib/services/common/alarmManagement.js +3 -0
  20. package/lib/services/devices/deviceRegistryMemory.js +1 -1
  21. package/lib/services/devices/deviceRegistryMongoDB.js +2 -2
  22. package/lib/services/devices/deviceService.js +4 -3
  23. package/lib/services/devices/devices-NGSI-LD.js +5 -5
  24. package/lib/services/devices/devices-NGSI-mixed.js +3 -3
  25. package/lib/services/devices/devices-NGSI-v2.js +5 -5
  26. package/lib/services/groups/groupService.js +1 -1
  27. package/lib/services/ngsi/entities-NGSI-LD.js +321 -571
  28. package/lib/services/ngsi/entities-NGSI-v2.js +348 -281
  29. package/lib/services/ngsi/ngsiService.js +3 -1
  30. package/lib/services/ngsi/subscription-NGSI-LD.js +2 -2
  31. package/lib/services/ngsi/subscription-NGSI-v2.js +2 -2
  32. package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
  33. package/lib/services/northBound/deviceProvisioningServer.js +5 -5
  34. package/lib/services/northBound/northboundServer.js +4 -2
  35. package/lib/services/stats/statsRegistry.js +128 -101
  36. package/lib/templates/createDevice.json +0 -24
  37. package/lib/templates/createDeviceLax.json +0 -23
  38. package/lib/templates/deviceGroup.json +1 -25
  39. package/lib/templates/updateDevice.json +0 -24
  40. package/lib/templates/updateDeviceLax.json +0 -23
  41. package/package.json +2 -2
  42. package/scripts/legacy_expression_tool/README.md +0 -1
  43. package/test/functional/README.md +75 -47
  44. package/test/functional/functional-tests-runner.js +9 -4
  45. package/test/functional/functional-tests.js +4 -4
  46. package/test/functional/testCases.js +1251 -257
  47. package/test/functional/testUtils.js +53 -20
  48. package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
  49. package/test/unit/examples/deviceProvisioningRequests/updateProvisionDeviceWithApikey.json +4 -0
  50. package/test/unit/examples/groupProvisioningRequests/multipleConfigGroupsCreation.json +44 -0
  51. package/test/unit/examples/groupProvisioningRequests/provisionDuplicateConfigGroup.json +35 -0
  52. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroup.json +36 -0
  53. package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroupAlternate.json +36 -0
  54. package/test/unit/general/deviceService-test.js +102 -0
  55. package/test/unit/general/statistics-service_test.js +1 -74
  56. package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
  57. package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -3
  58. package/test/unit/mongodb/mongodb-group-registry-test.js +34 -33
  59. package/test/unit/mongodb/mongodb-service-registry-test.js +477 -0
  60. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +4 -4
  61. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +22 -22
  62. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +4 -4
  63. package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +14 -15
  64. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +23 -23
  65. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +0 -5
  66. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +11 -16
  67. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +23 -28
  68. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +8 -13
  69. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
  70. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +24 -29
  71. package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +12 -17
  72. package/test/unit/ngsi-ld/examples/contextRequests/updateContextStaticLinkedAttributes.json +12 -10
  73. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -102
  74. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +4 -5
  75. package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +5 -5
  76. package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +0 -4
  77. package/test/unit/ngsiv2/general/deviceService-test.js +94 -1
  78. package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
  79. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +259 -0
  80. package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1189 -0
  81. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +6 -6
  82. package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +0 -4
  83. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +35 -0
  84. package/test/unit/statsRegistry/openmetrics-test.js +167 -0
  85. package/lib/templates/queryContext.json +0 -25
  86. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +0 -35
  87. package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json +0 -17
  88. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +0 -31
  89. package/test/unit/general/statistics-persistence_test.js +0 -121
  90. package/test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json +0 -17
  91. package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +0 -12
  92. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  93. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +0 -21
  94. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -17
  95. package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -23
  96. package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +0 -132
  97. package/test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json +0 -8
  98. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
  99. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -19
  100. package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -24
@@ -89,29 +89,6 @@
89
89
  "description": "Optional entity type for multientity updatess",
90
90
  "type": "string",
91
91
  "pattern": "^([^<>;'=\"]+)+$"
92
- },
93
- "reverse": {
94
- "description": "Define the attribute as bidirectional",
95
- "type": "array",
96
- "items": {
97
- "type": "object",
98
- "additionalProperties": false,
99
- "properties": {
100
- "object_id": {
101
- "description": "ID of the attribute in the device",
102
- "type": "string"
103
- },
104
- "type": {
105
- "description": "Type of the attribute in the target entity",
106
- "type": "string",
107
- "pattern": "^([^<>();'=\"]+)+$"
108
- },
109
- "expression": {
110
- "description": "Optional expression for measurement transformation",
111
- "type": "string"
112
- }
113
- }
114
- }
115
92
  }
116
93
  }
117
94
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "iotagent-node-lib",
3
3
  "license": "AGPL-3.0-only",
4
4
  "description": "IoT Agent library to interface with NGSI Context Broker",
5
- "version": "4.4.0",
5
+ "version": "4.6.0",
6
6
  "homepage": "https://github.com/telefonicaid/iotagent-node-lib",
7
7
  "keywords": [
8
8
  "fiware",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "async": "2.6.4",
47
- "body-parser": "~1.20.0",
47
+ "body-parser": "~1.20.3",
48
48
  "express": "~4.19.2",
49
49
  "got": "~11.8.5",
50
50
  "jexl": "2.3.0",
@@ -249,7 +249,6 @@ The script implements expression detection and translation in the following fiel
249
249
 
250
250
  - active.expression
251
251
  - active.entity_name
252
- - active.reverse
253
252
  - attributes.expression
254
253
  - attributes.entity_name
255
254
  - attributes.expression
@@ -21,8 +21,10 @@ pattern than the one supported by the test runner).
21
21
  Each test case is defined as a JSON object in the `testCases.js` file. This file is loaded by the test suite and the
22
22
  test cases are automatically generated. Each test case is defined as an object with the following elements:
23
23
 
24
- - `describeName`: The name of the `DESCRIBE` test case. This will be used to generate the test case name in the mocha. Note this name is prefixed by a pure number (e.g `0010 - Simple group without attributes`) which specifies the group to which the test belong (usually meaning a feature) or by a number preced by the `#` symbol to refer to an issue number (e.g. `#1234 - Bug foobar`).
25
- test suite.
24
+ - `describeName`: The name of the `DESCRIBE` test case. This will be used to generate the test case name in the mocha.
25
+ Note this name is prefixed by a pure number (e.g `0010 - Simple group without attributes`) which specifies the group
26
+ to which the test belong (usually meaning a feature) or by a number preced by the `#` symbol to refer to an issue
27
+ number (e.g. `#1234 - Bug foobar`). test suite.
26
28
  - `provision`: The JSON object that will be sent to the IoTA JSON provisioning API. This will be used to create the
27
29
  group. It contains the following elements:
28
30
  - `url`: The URL of the provisioning API (group)
@@ -30,17 +32,19 @@ test cases are automatically generated. Each test case is defined as an object w
30
32
  - `json`: The JSON object that defines the group
31
33
  - `headers`: The headers to send to the provisioning API. This should contain the `fiware-service` and
32
34
  `fiware-servicepath` headers.
33
- - `skip`: optional. Allow to skip test cases (at `describe` level). It allows diferent values: `false` (default, meaning that the test is not skipped in any circustance),
34
- `true` (meaning the test is always skipped), `"lib"` (meaning the test has to be skipped when running it in IoTA Node lib repo) and
35
- `"json"` (meaning the test has to be skipped when running it in IOTA JSON repo). The latter alternatives are useful to skip test cases that are not supported by
36
- the lib (I.E: all tests related to the transport) or by the IOTA. Combinations (e.g `"lib,json"`) and negation (e.g. `"!lib"`) are also supported.
35
+ - `skip`: optional. Allow to skip test cases (at `describe` level). It allows diferent values: `false` (default,
36
+ meaning that the test is not skipped in any circustance), `true` (meaning the test is always skipped), `"lib"`
37
+ (meaning the test has to be skipped when running it in IoTA Node lib repo) and `"json"` (meaning the test has to
38
+ be skipped when running it in IOTA JSON repo). The latter alternatives are useful to skip test cases that are
39
+ not supported by the lib (I.E: all tests related to the transport) or by the IOTA. Combinations (e.g
40
+ `"lib,json"`) and negation (e.g. `"!lib"`) are also supported.
37
41
  - `should`: The array of test cases to execute. Each test case is defined as an object with the following elements:
38
42
  - `transport`: The transport to use to send the measure. This can be `HTTP` or `MQTT`. It uses `HTTP` by default
39
43
  or if the `transport` element is not defined. See the "Advanced features" section for more information.
40
44
  - `shouldName`: The name of the `IT` test case. This will be used to generate the test case name in the mocha test
41
45
  suite.
42
- - `type`: The type of the test case. This can be `single` or `multientity`. See the "Advanced features" section
43
- for more information.
46
+ - `type`: The type of the test case. This can be `single`, `multimeasure` or `multientity`. See the "Advanced
47
+ features" section for more information.
44
48
  - `measure`: The JSON object that will be sent to the IoTA JSON measure API. This will be used to send the
45
49
  measure. It contains the following elements:
46
50
  - `url`: The URL of the measure API (group)
@@ -64,10 +68,10 @@ test cases are automatically generated. Each test case is defined as an object w
64
68
  {
65
69
  describeName: 'Basic group provision with attributes',
66
70
  provision: {
67
- url: 'http://localhost:' + config.iota.server.port + '/iot/services',
71
+ url: 'http://localhost:' + config.iota.server.port + '/iot/groups',
68
72
  method: 'POST',
69
73
  json: {
70
- services: [
74
+ groups: [
71
75
  {
72
76
  resource: '/iot/json',
73
77
  apikey: '123456',
@@ -199,41 +203,11 @@ as a batch operation (see the following example).
199
203
 
200
204
  #### Multimeasures
201
205
 
202
- It is also supported to test cases in which is sent more than one measure. To do so, you need to define the test case
203
- `expectation` as an array, with one object for each measurement. Then, the suite will recognize the array length and will
204
- expect the same number of NGSI requests. I.E:
206
+ It is also supported to test cases in which is sent more than one measure. To do so, you need to set add to the test
207
+ case the parameter `should.type` to the value `'multimeasure'`.
205
208
 
206
- ```js
207
- [
208
- {
209
- id: 'TheLightType2:MQTT_2',
210
- type: 'TheLightType2',
211
- temperature: {
212
- value: 10,
213
- type: 'Number'
214
- },
215
- status: {
216
- value: false,
217
- type: 'Boolean'
218
- }
219
- },
220
- {
221
- id: 'TheLightType2:MQTT_2',
222
- type: 'TheLightType2',
223
- temperature: {
224
- value: 20,
225
- type: 'Number'
226
- },
227
- status: {
228
- value: true,
229
- type: 'Boolean'
230
- }
231
- }
232
- ];
233
- ```
234
-
235
- You also should define the measure as multimeasure. This is done by defining the `measure` JSON element as an array of
236
- objects. Each object will be a measure that will be sent to the Context Broker in a different request. I.E:
209
+ You must define the measure as multimeasure. This is done by defining the `measure` JSON element as an array of objects.
210
+ I.E:
237
211
 
238
212
  ```javascript
239
213
  measure: {
@@ -246,16 +220,69 @@ measure: {
246
220
  json: [
247
221
  {
248
222
  s: false,
249
- t: 10
223
+ t: 21
250
224
  },
251
225
  {
252
226
  s: true,
253
- t: 20
227
+ t: 22
228
+ },
229
+ {
230
+ s: false,
231
+ t: 23
232
+ }
233
+ ]
234
+ }
235
+ ```
236
+
237
+ And you should define the test case `expectation` as an object, following a Context Broker batch operation. I.E:
238
+
239
+ ```js
240
+ expectation: {
241
+ actionType: 'append',
242
+ entities: [
243
+ {
244
+ id: 'TheLightType2:MQTT_2',
245
+ type: 'TheLightType2',
246
+ temperature: {
247
+ type: 'Number',
248
+ value: 21
249
+ },
250
+ status: {
251
+ type: 'Boolean',
252
+ value: false
253
+ }
254
+ },
255
+ {
256
+ id: 'TheLightType2:MQTT_2',
257
+ type: 'TheLightType2',
258
+ temperature: {
259
+ type: 'Number',
260
+ value: 22
261
+ },
262
+ status: {
263
+ type: 'Boolean',
264
+ value: true
265
+ }
266
+ },
267
+ {
268
+ id: 'TheLightType2:MQTT_2',
269
+ type: 'TheLightType2',
270
+ temperature: {
271
+ type: 'Number',
272
+ value: 23
273
+ },
274
+ status: {
275
+ type: 'Boolean',
276
+ value: false
277
+ }
254
278
  }
255
279
  ]
256
280
  }
257
281
  ```
258
282
 
283
+ Then, a batch request would be sent to the Context Broker containing the different measures. More information about how
284
+ the IoT Agent send multimeasures to the Context Broker [here](/doc/api.md#multimeasure-support).
285
+
259
286
  #### Transport
260
287
 
261
288
  The test suite supports using the internal node lib function `iotAgentLib.update`, `HTTP` or `MQTT` for measure sending.
@@ -309,7 +336,8 @@ the expectation as an empty object. I.E:
309
336
  ...
310
337
  ```
311
338
 
312
- Note that this means the CB *must not* receive any payload. In other words, if the CB would receive any payload, the test will fail.
339
+ Note that this means the CB _must not_ receive any payload. In other words, if the CB would receive any payload, the
340
+ test will fail.
313
341
 
314
342
  ### Debugging automated tests
315
343
 
@@ -63,12 +63,17 @@ describe('FUNCTIONAL TESTS AUTO', function () {
63
63
  if (testCase.loglevel) {
64
64
  logger.setLevel(testCase.loglevel);
65
65
  }
66
- let type = testUtils.groupToIoTAConfigType(
66
+ let confType = testUtils.groupToIoTAConfigType(
67
67
  testCase.provision.json.services[0],
68
- testCase.provision.headers.fiwareService,
69
- testCase.provision.headers.fiwareServicepath
68
+ testCase.provision.headers['fiware-service'],
69
+ testCase.provision.headers['fiware-servicepath']
70
70
  );
71
- config.iota.types[type.name] = type.type;
71
+ // Inject device id into config as real typeInformation
72
+ if (testCase.should[0] && testCase.should[0].measure.qs.i) {
73
+ confType.type['id'] = testCase.should[0].measure.qs.i;
74
+ }
75
+ config.iota.types[confType.name] = confType.type;
76
+
72
77
  iotAgentLib.activate(config.iota, function (error) {
73
78
  done(error);
74
79
  });
@@ -115,8 +115,8 @@ describe('FUNCTIONAL TESTS', function () {
115
115
  beforeEach(function (done) {
116
116
  let type = testUtils.groupToIoTAConfigType(
117
117
  provision.json.services[0],
118
- provision.headers.fiwareService,
119
- provision.headers.fiwareServicepath
118
+ provision.headers['fiware-service'],
119
+ provision.headers['fiware-servicepath']
120
120
  );
121
121
  config.iota.types[type.name] = type.type;
122
122
  iotAgentLib.activate(config.iota, function (error) {
@@ -214,8 +214,8 @@ describe('FUNCTIONAL TESTS', function () {
214
214
  beforeEach(function (done) {
215
215
  let type = testUtils.groupToIoTAConfigType(
216
216
  provision.json.services[0],
217
- provision.headers.fiwareService,
218
- provision.headers.fiwareServicepath
217
+ provision.headers['fiware-service'],
218
+ provision.headers['fiware-servicepath']
219
219
  );
220
220
  config.iota.types[type.name] = type.type;
221
221
  iotAgentLib.activate(config.iota, function (error) {