iotagent-node-lib 2.22.0 → 2.23.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.
- package/.nyc_output/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +1 -0
- package/.nyc_output/processinfo/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/CHANGES_NEXT_RELEASE +1 -0
- package/config +0 -0
- package/doc/advanced-topics.md +16 -5
- package/docker/Mosquitto/Dockerfile.debian +38 -0
- package/docker/Mosquitto/Dockerfile.debian~ +23 -0
- package/lib/plugins/multiEntity.js_avg2 +343 -0
- package/lib/services/ngsi/entities-NGSI-v2.js +56 -7
- package/package.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +12 -1
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +10 -8
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js_avg2 +1224 -0
- package/.nyc_output/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
- package/.nyc_output/processinfo/33364de2-1199-4ec2-b33c-cae063ef8cc4.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":14053,"argv":["/usr/bin/node","/home/avega/tid/fiware/iotagent-node-lib/node_modules/.bin/mocha","--recursive","test/**/*.js","--reporter","spec","--timeout","8000","--ui","bdd","--exit","--color","true"],"execArgv":[],"cwd":"/home/avega/tid/fiware/iotagent-node-lib","time":1658386273873,"ppid":14040,"coverageFilename":"/home/avega/tid/fiware/iotagent-node-lib/.nyc_output/6e3d7795-bf8c-4a50-bd2f-f8221f27aeae.json","externalId":"","uuid":"6e3d7795-bf8c-4a50-bd2f-f8221f27aeae","files":["/home/avega/tid/fiware/iotagent-node-lib/lib/fiware-iotagent-lib.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/ngsiService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/domain.js","/home/avega/tid/fiware/iotagent-node-lib/lib/constants.js","/home/avega/tid/fiware/iotagent-node-lib/lib/errors.js","/home/avega/tid/fiware/iotagent-node-lib/lib/commonConfig.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/ngsiUtils.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/genericMiddleware.js","/home/avega/tid/fiware/iotagent-node-lib/lib/model/dbConn.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/alarmManagement.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscriptionService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/stats/statsRegistry.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/iotManagerService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/request-shim.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/registrationUtils.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/restUtils.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/expressionPlugin.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/expressionParser.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/jexlParser.js","/home/avega/tid/fiware/iotagent-node-lib/lib/jexlTranformsMap.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/pluginUtils.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandService.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/northboundServer.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServerUtils.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/deviceProvisioningServer.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/deviceGroupAdministrationServer.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/compressTimestamp.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/attributeAlias.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/addEvent.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/timestampProcessPlugin.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/multiEntity.js","/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/bidirectionalData.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupRegistryMemory.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/securityServiceKeystone.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceRegistryMemory.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandRegistryMemory.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-v2.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-v2.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-v2.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-v2.js","/home/avega/tid/fiware/iotagent-node-lib/lib/model/Device.js","/home/avega/tid/fiware/iotagent-node-lib/lib/model/Group.js","/home/avega/tid/fiware/iotagent-node-lib/lib/model/Command.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceRegistryMongoDB.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupRegistryMongoDB.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandRegistryMongoDB.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-LD.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-LD.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-LD.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-LD.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/securityServiceOAuth2.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-mixed.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-mixed.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-mixed.js","/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-mixed.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"6e3d7795-bf8c-4a50-bd2f-f8221f27aeae":{"parent":null,"children":[]}},"files":{"/home/avega/tid/fiware/iotagent-node-lib/lib/fiware-iotagent-lib.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/ngsiService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/domain.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/constants.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/errors.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/commonConfig.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/ngsiUtils.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/genericMiddleware.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/model/dbConn.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/alarmManagement.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscriptionService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/stats/statsRegistry.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/iotManagerService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/request-shim.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/registrationUtils.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/restUtils.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/expressionPlugin.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/expressionParser.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/jexlParser.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/jexlTranformsMap.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/pluginUtils.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandService.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/northboundServer.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServerUtils.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/deviceProvisioningServer.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/deviceGroupAdministrationServer.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/compressTimestamp.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/attributeAlias.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/addEvent.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/timestampProcessPlugin.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/multiEntity.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/plugins/bidirectionalData.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupRegistryMemory.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/securityServiceKeystone.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceRegistryMemory.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandRegistryMemory.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-v2.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-v2.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-v2.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-v2.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/model/Device.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/model/Group.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/model/Command.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/deviceRegistryMongoDB.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/groups/groupRegistryMongoDB.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/commands/commandRegistryMongoDB.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-LD.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-LD.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-LD.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-LD.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/common/securityServiceOAuth2.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/devices/devices-NGSI-mixed.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-mixed.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-mixed.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"],"/home/avega/tid/fiware/iotagent-node-lib/lib/services/ngsi/entities-NGSI-mixed.js":["6e3d7795-bf8c-4a50-bd2f-f8221f27aeae"]},"externalIds":{}}
|
package/CHANGES_NEXT_RELEASE
CHANGED
package/config
ADDED
|
File without changes
|
package/doc/advanced-topics.md
CHANGED
|
@@ -305,7 +305,7 @@ stored in the Context Broker by adding a new attribute to the entity with the sa
|
|
|
305
305
|
element. By adding the field `explicitAttrs` with `true` value to device or group provision, the IoTAgent rejects the
|
|
306
306
|
measure elements that are not defined in the mappings of device or group provision, persisting only the one defined in
|
|
307
307
|
the mappings of the provision. If `explicitAttrs` is provided both at device and group level, the device level takes
|
|
308
|
-
precedence. Additionally `explicitAttrs` can be used to define which meassures (identified by their attribute names, not
|
|
308
|
+
precedence. Additionally `explicitAttrs` can be used to define which meassures (identified by their attribute names, not
|
|
309
309
|
by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface.
|
|
310
310
|
|
|
311
311
|
The different possibilities are summarized below:
|
|
@@ -332,11 +332,22 @@ Case 3:
|
|
|
332
332
|
"explicitAttrs": "['attr1','atrr2']"
|
|
333
333
|
```
|
|
334
334
|
|
|
335
|
-
just
|
|
336
|
-
propagated to NGSI interface (note that in this case the value of `explicitAttrs` is
|
|
335
|
+
just NGSI attributes defined in the array (identified by their attribute names, not by their object_id, plus
|
|
336
|
+
conditionally TimeInstant) will be propagated to NGSI interface (note that in this case the value of `explicitAttrs` is
|
|
337
|
+
not a JSON but a JEXL Array that looks likes a JSON).
|
|
337
338
|
|
|
338
339
|
Case 4:
|
|
339
340
|
|
|
341
|
+
```
|
|
342
|
+
"explicitAttrs": "['attr1','atrr2',{object_id:'active_id'}]"
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
just NGSI attributes defined in the array (identified by their attribute names and/or by their object_id) will be
|
|
346
|
+
propagated to NGSI interface (note that in this case the value of `explicitAttrs` is not a JSON but a JEXL Array/Object
|
|
347
|
+
that looks likes a JSON). This is necessary when same attribute names are used within multiple entities.
|
|
348
|
+
|
|
349
|
+
Case 5:
|
|
350
|
+
|
|
340
351
|
```
|
|
341
352
|
"explicitAtttr": "<JEXL expression resulting in bool or array>"
|
|
342
353
|
```
|
|
@@ -346,8 +357,8 @@ depending on the JEXL expression evaluation:
|
|
|
346
357
|
- If it evaluates to `true` every measure will be propagated to NGSI interface (as in case 1)
|
|
347
358
|
- If it evaluates to `false` just measures defined in active, static (plus conditionally TimeInstant) will be
|
|
348
359
|
propagated to NGSI interface (as in case 2)
|
|
349
|
-
- If it evaluates to an array just measures defined in the array (identified by their attribute names, not by their
|
|
350
|
-
will be will be propagated to NGSI interface (as in case 3)
|
|
360
|
+
- If it evaluates to an array just measures defined in the array (identified by their attribute names, not by their
|
|
361
|
+
object_id) will be will be propagated to NGSI interface (as in case 3)
|
|
351
362
|
|
|
352
363
|
### Configuring operation to persist the data in Context Broker (appendMode)
|
|
353
364
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
ARG IMAGE_TAG=11.2-slim
|
|
2
|
+
FROM debian:${IMAGE_TAG}
|
|
3
|
+
|
|
4
|
+
ARG CLEAN_DEV_TOOLS
|
|
5
|
+
ENV CLEAN_DEV_TOOLS ${CLEAN_DEV_TOOLS:-1}
|
|
6
|
+
|
|
7
|
+
ENV CONGIF_FROM_ENV true
|
|
8
|
+
|
|
9
|
+
COPY aclfile /root/
|
|
10
|
+
COPY startMosquitto.sh /bin
|
|
11
|
+
|
|
12
|
+
RUN \
|
|
13
|
+
# Install security updates
|
|
14
|
+
apt-get -y update && \
|
|
15
|
+
apt-get -y upgrade && \
|
|
16
|
+
# Install dependencies
|
|
17
|
+
apt-get -y install \
|
|
18
|
+
wget \
|
|
19
|
+
mosquitto && \
|
|
20
|
+
cp /etc/mosquitto/mosquitto.conf /etc/mosquitto/mosquitto.conf.orig && \
|
|
21
|
+
chmod 755 /bin/startMosquitto.sh && \
|
|
22
|
+
mkdir -p /var/log/mosquitto && \
|
|
23
|
+
chown mosquitto:mosquitto /var/log/mosquitto && \
|
|
24
|
+
echo "INFO: Cleaning unused software..." && \
|
|
25
|
+
apt-get clean && \
|
|
26
|
+
apt-get -y autoremove --purge && \
|
|
27
|
+
if [ ${CLEAN_DEV_TOOLS} -eq 0 ] ; then exit 0 ; fi && \
|
|
28
|
+
# remove the same packages we installed at the beginning to build Orch
|
|
29
|
+
apt-get -y autoremove --purge \
|
|
30
|
+
wget && \
|
|
31
|
+
# Don't need old log files inside docker images
|
|
32
|
+
rm -f /var/log/*log
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
EXPOSE 1883
|
|
36
|
+
EXPOSE 9001
|
|
37
|
+
|
|
38
|
+
ENTRYPOINT /bin/startMosquitto.sh
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
ARG IMAGE_TAG=11.2-slim
|
|
2
|
+
FROM debian:${IMAGE_TAG}
|
|
3
|
+
|
|
4
|
+
COPY aclfile /root/
|
|
5
|
+
COPY startMosquitto.sh /bin
|
|
6
|
+
|
|
7
|
+
ENV CONGIF_FROM_ENV true
|
|
8
|
+
|
|
9
|
+
RUN yum update -y && yum install -y wget \
|
|
10
|
+
&& yum install -y epel-release \
|
|
11
|
+
&& yum update -y epel-release \
|
|
12
|
+
&& yum install -y mosquitto \
|
|
13
|
+
&& cp /etc/mosquitto/mosquitto.conf /etc/mosquitto/mosquitto.conf.orig \
|
|
14
|
+
&& chmod 755 /bin/startMosquitto.sh \
|
|
15
|
+
&& mkdir /var/log/mosquitto \
|
|
16
|
+
&& chown mosquitto:mosquitto /var/log/mosquitto \
|
|
17
|
+
&& yum clean all
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
EXPOSE 1883
|
|
21
|
+
EXPOSE 9001
|
|
22
|
+
|
|
23
|
+
ENTRYPOINT /bin/startMosquitto.sh
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2016 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
+
*
|
|
4
|
+
* This file is part of fiware-iotagent-lib
|
|
5
|
+
*
|
|
6
|
+
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
+
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
+
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
+
* or (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
+
* See the GNU Affero General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU Affero General Public
|
|
17
|
+
* License along with fiware-iotagent-lib.
|
|
18
|
+
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
+
*
|
|
20
|
+
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
+
* please contact with::daniel.moranjimenez@telefonica.com
|
|
22
|
+
*
|
|
23
|
+
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/* eslint-disable no-prototype-builtins */
|
|
27
|
+
/* eslint-disable array-callback-return */
|
|
28
|
+
|
|
29
|
+
const _ = require('underscore');
|
|
30
|
+
const constants = require('../constants');
|
|
31
|
+
const legacyParser = require('./expressionParser');
|
|
32
|
+
const jexlParser = require('./jexlParser');
|
|
33
|
+
const config = require('../commonConfig');
|
|
34
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
35
|
+
const logger = require('logops');
|
|
36
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
37
|
+
const context = {
|
|
38
|
+
op: 'IoTAgentNGSI.MultiEntityPlugin'
|
|
39
|
+
};
|
|
40
|
+
const utils = require('./pluginUtils');
|
|
41
|
+
/* eslint-disable-next-line no-unused-vars */
|
|
42
|
+
const aliasPlugin = require('./attributeAlias');
|
|
43
|
+
|
|
44
|
+
function checkJexl(typeInformation) {
|
|
45
|
+
if (
|
|
46
|
+
config.getConfig().defaultExpressionLanguage === 'jexl' &&
|
|
47
|
+
typeInformation.expressionLanguage &&
|
|
48
|
+
typeInformation.expressionLanguage !== 'legacy'
|
|
49
|
+
) {
|
|
50
|
+
return true;
|
|
51
|
+
} else if (config.getConfig().defaultExpressionLanguage === 'jexl' && !typeInformation.expressionLanguage) {
|
|
52
|
+
return true;
|
|
53
|
+
} else if (
|
|
54
|
+
config.getConfig().defaultExpressionLanguage === 'legacy' &&
|
|
55
|
+
typeInformation.expressionLanguage &&
|
|
56
|
+
typeInformation.expressionLanguage === 'jexl'
|
|
57
|
+
) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function hasEntityName(item) {
|
|
64
|
+
return item.entity_name;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Return a list of all the attributes that don't have a multientity option. It considers NGSIv2.
|
|
69
|
+
*
|
|
70
|
+
* @param {Array} originalAttrs Array of original attributes coming from the single-entity device.
|
|
71
|
+
* @param {Array} meAttributes Array of all the multientity attributes.
|
|
72
|
+
* @return {Array} List of all the attrbiutes without multientity flag.
|
|
73
|
+
*/
|
|
74
|
+
function filterOutMultientitiesNgsi2(originalAttrs, meAttributes) {
|
|
75
|
+
|
|
76
|
+
function filterByEntityName() {
|
|
77
|
+
return function (item) {
|
|
78
|
+
return (item.entity_name !== undefined);
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result = {};
|
|
83
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 entity=originalAttrs: %j', originalAttrs);
|
|
84
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 meAttributes: %j', meAttributes);
|
|
85
|
+
const meNamesList = _.pluck(meAttributes, 'name');
|
|
86
|
+
//logger.debug(context, 'filterOutMultientitiesNgsi2 meNamesList: %j', meNamesList);
|
|
87
|
+
const meObjectsList = _.pluck(meAttributes, 'object_id');
|
|
88
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 meObjectsList: %j', meObjectsList);
|
|
89
|
+
const meEntityNamesList = _.pluck(meAttributes.filter(filterByEntityName()), 'name');
|
|
90
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 meEntityNamesList: %j', meEntityNamesList);
|
|
91
|
+
let toBeFilteredByObj = [];
|
|
92
|
+
|
|
93
|
+
for (const att in originalAttrs) {
|
|
94
|
+
if (originalAttrs.hasOwnProperty(att)) {
|
|
95
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 checking att: %j value %j', att, originalAttrs[att]);
|
|
96
|
+
//if (!_.contains(meNamesList, att)) {
|
|
97
|
+
if (!_.contains(meEntityNamesList, att)) {
|
|
98
|
+
result[att] = originalAttrs[att];
|
|
99
|
+
} else {
|
|
100
|
+
// TO DO: should be checked with meAttributes
|
|
101
|
+
// if (!originalAttrs[att].entity_name && !originalAttrs[att].entity_type) {
|
|
102
|
+
// result[att] = originalAttrs[att];
|
|
103
|
+
// }
|
|
104
|
+
}
|
|
105
|
+
if (originalAttrs[att].hasOwnProperty('multi')) {
|
|
106
|
+
let cleanAttributes = _.union([_.clone(originalAttrs[att])], originalAttrs[att].multi);
|
|
107
|
+
delete cleanAttributes[0].multi;
|
|
108
|
+
cleanAttributes = _.map(cleanAttributes, function (val) {
|
|
109
|
+
val['name'] = att;
|
|
110
|
+
return val;
|
|
111
|
+
});
|
|
112
|
+
toBeFilteredByObj = _.union(toBeFilteredByObj, cleanAttributes);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
for (const att in toBeFilteredByObj) {
|
|
118
|
+
if (!_.contains(meObjectsList, toBeFilteredByObj[att].object_id)) {
|
|
119
|
+
result[toBeFilteredByObj[att].name] = toBeFilteredByObj[att];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
logger.debug(context, 'filterOutMultientitiesNgsi2 result: %j', result);
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Generate new Context Elements for each new Entity, with the attributes of the original entity matching its
|
|
128
|
+
* entity_name. It considers Ngsiv2.
|
|
129
|
+
*
|
|
130
|
+
* @param {Object} entity The original entity
|
|
131
|
+
* @param {Array} newEntities List of the new entities that will be generated
|
|
132
|
+
* @param {Array} multiEntityAttributes List of attributes with multientity option
|
|
133
|
+
* @return {Array} List of the new Context Entities
|
|
134
|
+
*/
|
|
135
|
+
function generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes) {
|
|
136
|
+
const result = [];
|
|
137
|
+
let newEntityAttributes;
|
|
138
|
+
let newEntityAttributeNames;
|
|
139
|
+
let newEntityAttributeObjectIds;
|
|
140
|
+
function filterByEntityNameandType(entityNameType) {
|
|
141
|
+
return function (item) {
|
|
142
|
+
return (
|
|
143
|
+
item.entity_name === entityNameType.entity_name &&
|
|
144
|
+
(!item.entity_type || item.entity_type === entityNameType.entity_type)
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds) {
|
|
150
|
+
const result = {};
|
|
151
|
+
for (const att in entity) {
|
|
152
|
+
if (entity.hasOwnProperty(att)) {
|
|
153
|
+
if (_.contains(newEntityAttributeNames, att)) {
|
|
154
|
+
if (entity[att].object_id && _.contains(newEntityAttributeObjectIds, entity[att].object_id)) {
|
|
155
|
+
result[att] = entity[att];
|
|
156
|
+
delete entity[att].object_id;
|
|
157
|
+
} else if (entity[att].multi) {
|
|
158
|
+
for (const j in entity[att].multi) {
|
|
159
|
+
if (
|
|
160
|
+
entity[att].multi[j].object_id &&
|
|
161
|
+
_.contains(newEntityAttributeObjectIds, entity[att].multi[j].object_id)
|
|
162
|
+
) {
|
|
163
|
+
result[att] = entity[att].multi[j];
|
|
164
|
+
delete entity[att].multi[j].object_id;
|
|
165
|
+
break; // stop in first ocurrence (#635)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function filterNew(entity, multientityAttributes, name, type) {
|
|
176
|
+
logger.debug(context, 'filterNew: \n entity %j \n multientityAttribute %j \n name %j type %j',
|
|
177
|
+
entity, multientityAttributes, name, type);
|
|
178
|
+
const result = {};
|
|
179
|
+
for (const att in entity) {
|
|
180
|
+
if (entity.hasOwnProperty(att)) {
|
|
181
|
+
for (const j in multientityAttributes) {
|
|
182
|
+
if ( multientityAttributes[j].object_id && entity[att].object_id &&
|
|
183
|
+
multientityAttributes[j].object_id === entity[att].object_id &&
|
|
184
|
+
(multientityAttributes[j].entity_type ?
|
|
185
|
+
multientityAttributes[j].entity_type === type : true) &&
|
|
186
|
+
multientityAttributes[j].entity_name === name
|
|
187
|
+
) {
|
|
188
|
+
result[multientityAttributes[j].name] = {
|
|
189
|
+
type: entity[att].type,
|
|
190
|
+
value: entity[att].value
|
|
191
|
+
};
|
|
192
|
+
if (entity[att].metadata) {
|
|
193
|
+
result[multientityAttributes[j].name].metadata = entity[att].metadata;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (entity[att].multi){
|
|
197
|
+
for (const k in entity[att].multi) {
|
|
198
|
+
if ( multientityAttributes[j].object_id && entity[att].multi[k].object_id &&
|
|
199
|
+
multientityAttributes[j].object_id === entity[att].multi[k].object_id &&
|
|
200
|
+
(multientityAttributes[j].entity_type ?
|
|
201
|
+
multientityAttributes[j].entity_type === type : true) &&
|
|
202
|
+
multientityAttributes[j].entity_name === name
|
|
203
|
+
) {
|
|
204
|
+
result[multientityAttributes[j].name] = {
|
|
205
|
+
type: entity[att].multi[k].type,
|
|
206
|
+
value: entity[att].multi[k].value
|
|
207
|
+
};
|
|
208
|
+
if (entity[att].multi[k].metadata) {
|
|
209
|
+
result[multientityAttributes[j].name].metadata = entity[att].multi[k].metadata;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
logger.debug(context, 'filterNew result: %j', result);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// logger.debug(context, 'generateNewCEsNgsi2 entity: %j', entity); // measure
|
|
224
|
+
// entity: {"vol":{"type":"Number","value":0,"object_id":"v"},"id":"sh3","type":"ShareStation"}
|
|
225
|
+
// logger.debug(context, 'generateNewCEsNgsi2 multientityAttributes %j', multiEntityAttributes);
|
|
226
|
+
// multiEntityAttributes: [{"object_id":"v","name":"vol","type":"Number","entity_name":"WeatherStation1","entity_type":"Type1"},{"object_id":"v","name":"vol","type":"Number","entity_name":"WeatherStation1","entity_type":"Type2"},{"object_id":"v","name":"extravol","type":"Number","entity_name":"WeatherStation1","entity_type":"Type2"}]
|
|
227
|
+
//logger.debug(context, 'generateNewCEsNgsi2 newEntities %j', newEntities);
|
|
228
|
+
// newEntities [{"entity_name":"WeatherStation1","entity_type":"Type1"},{"entity_name":"WeatherStation1","entity_type":"Type2"}]
|
|
229
|
+
for (let i = 0; i < newEntities.length; i++) {
|
|
230
|
+
//logger.debug(context, 'generateNewCEsNgsi2 current newEntities: %j', newEntities[i]);
|
|
231
|
+
newEntityAttributeNames = _.pluck(
|
|
232
|
+
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
233
|
+
'name'
|
|
234
|
+
);
|
|
235
|
+
//logger.debug(context, 'generateNewCEsNgsi2 newEntityAttributeNames: %j', newEntityAttributeNames);
|
|
236
|
+
newEntityAttributeObjectIds = _.pluck(
|
|
237
|
+
multiEntityAttributes.filter(filterByEntityNameandType(newEntities[i])),
|
|
238
|
+
'object_id'
|
|
239
|
+
);
|
|
240
|
+
//logger.debug(context, 'generateNewCEsNgsi2 newEntityAttributeObjectIds: %j', newEntityAttributeObjectIds);
|
|
241
|
+
//newEntityAttributes = filterByAttributeObjectIds(entity, newEntityAttributeNames, newEntityAttributeObjectIds);
|
|
242
|
+
newEntityAttributes = filterNew(entity, multiEntityAttributes, newEntities[i].entity_name, newEntities[i].entity_type);
|
|
243
|
+
//logger.debug(context, 'generateNewCEsNgsi2 newEntityAttributes: %j', newEntityAttributes);
|
|
244
|
+
newEntityAttributes.type = newEntities[i].entity_type;
|
|
245
|
+
newEntityAttributes.id = newEntities[i].entity_name;
|
|
246
|
+
result.push(newEntityAttributes);
|
|
247
|
+
}
|
|
248
|
+
logger.debug(context, 'generateNewCEsNgsi2 result entities %j', result);
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function extractNewEntities(multiEntityAttributes, defaultType) {
|
|
253
|
+
let newEntitieswithDuplicates = multiEntityAttributes.map((elem) => {
|
|
254
|
+
return { entity_name: elem.entity_name, entity_type: elem.entity_type || defaultType };
|
|
255
|
+
});
|
|
256
|
+
let auxOverwriteTree = {};
|
|
257
|
+
for (let entityItem in newEntitieswithDuplicates) {
|
|
258
|
+
if (!auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name]) {
|
|
259
|
+
auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name] = {};
|
|
260
|
+
}
|
|
261
|
+
auxOverwriteTree[newEntitieswithDuplicates[entityItem].entity_name][
|
|
262
|
+
newEntitieswithDuplicates[entityItem].entity_type
|
|
263
|
+
] = null;
|
|
264
|
+
}
|
|
265
|
+
let flatNewEntities = [];
|
|
266
|
+
for (let entityItem in auxOverwriteTree) {
|
|
267
|
+
for (let typeItem in auxOverwriteTree[entityItem]) {
|
|
268
|
+
flatNewEntities.push({ entity_name: entityItem, entity_type: typeItem });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return flatNewEntities;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Propagates the same timestamp used in entity to entities. This is needed given that timestamp processing
|
|
275
|
+
* plugin runs before multientity plugin, so we could have issues as the one described here:
|
|
276
|
+
* https://github.com/telefonicaid/iotagent-node-lib/issues/748
|
|
277
|
+
*
|
|
278
|
+
* Note that this kind of timestamp propagation only works for NGSIv2. That is intentional: NGSIv1 is
|
|
279
|
+
* deprecated so we don't want to spend effort on it.
|
|
280
|
+
*
|
|
281
|
+
* @param entity entity which is the source of timestamp
|
|
282
|
+
* @param entities array to adjust
|
|
283
|
+
*
|
|
284
|
+
*/
|
|
285
|
+
function propagateTimestamp(entity, entities) {
|
|
286
|
+
const ts = entity[constants.TIMESTAMP_ATTRIBUTE];
|
|
287
|
+
if (!ts) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
entities.map(function (en) {
|
|
292
|
+
let att;
|
|
293
|
+
// Set timestamp metadata in attributes (except TimeInstant attribute itself)
|
|
294
|
+
for (att in en && att !== constants.TIMESTAMP_ATTRIBUTE) {
|
|
295
|
+
if (en.hasOwnProperty(att) && att !== 'id' && att !== 'type') {
|
|
296
|
+
if (!en[att].metadata) {
|
|
297
|
+
en[att].metadata = {};
|
|
298
|
+
}
|
|
299
|
+
en[att].metadata[constants.TIMESTAMP_ATTRIBUTE] = ts;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
// Set timestamp attribute inm the entity itself
|
|
303
|
+
en[constants.TIMESTAMP_ATTRIBUTE] = ts;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function updateAttribute(entity, typeInformation, callback) {
|
|
308
|
+
let parser = legacyParser;
|
|
309
|
+
if (checkJexl(typeInformation)) {
|
|
310
|
+
parser = jexlParser;
|
|
311
|
+
}
|
|
312
|
+
const attsArray = utils.extractAttributesArrayFromNgsi2Entity(entity);
|
|
313
|
+
const ctx = parser.extractContext(attsArray);
|
|
314
|
+
|
|
315
|
+
let entities = [entity];
|
|
316
|
+
if (typeInformation.active) {
|
|
317
|
+
const multiEntityAttributes = typeInformation.active.filter(hasEntityName);
|
|
318
|
+
for (let i in multiEntityAttributes) {
|
|
319
|
+
if (parser.contextAvailable(multiEntityAttributes[i].entity_name, ctx)) {
|
|
320
|
+
let entityName = parser.applyExpression(multiEntityAttributes[i].entity_name, ctx, typeInformation);
|
|
321
|
+
// An entity_name could not be null, but a result or expression could be null
|
|
322
|
+
if (entityName !== null) {
|
|
323
|
+
multiEntityAttributes[i].entity_name = entityName;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const newEntities = extractNewEntities(multiEntityAttributes, typeInformation.type);
|
|
328
|
+
|
|
329
|
+
if (multiEntityAttributes.length > 0) {
|
|
330
|
+
let resultAttributes = filterOutMultientitiesNgsi2(entity, multiEntityAttributes);
|
|
331
|
+
logger.debug(context, ' filterOutMultientitiesNgsi2 resultAttributes: %j', resultAttributes);
|
|
332
|
+
const newCes = generateNewCEsNgsi2(entity, newEntities, multiEntityAttributes);
|
|
333
|
+
entities = [resultAttributes].concat(newCes);
|
|
334
|
+
logger.debug(context, 'all entities: %j', entities);
|
|
335
|
+
propagateTimestamp(entity, entities);
|
|
336
|
+
} else {
|
|
337
|
+
entities = entity;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
callback(null, entities, typeInformation);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
exports.update = updateAttribute;
|