From 40505a0f4cab363be97a8b5f3a5cbf3c82c3838a Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 24 Nov 2023 12:21:44 +0100 Subject: [PATCH 1/5] step 4.0.0 -> 4.0.0-next --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48d38ddc6..c4b6f4b52 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "iotagent-node-lib", "license": "AGPL-3.0-only", "description": "IoT Agent library to interface with NGSI Context Broker", - "version": "4.0.0", + "version": "4.0.0-next", "homepage": "https://github.com/telefonicaid/iotagent-node-lib", "keywords": [ "fiware", From 5d34f317002d5efebfab1557ada9dc46d927529d Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 29 Nov 2023 11:20:02 +0100 Subject: [PATCH 2/5] log detail when badTimestamp --- lib/errors.js | 4 ++-- lib/services/ngsi/entities-NGSI-LD.js | 2 +- lib/services/ngsi/entities-NGSI-v2.js | 30 ++++++++++++--------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index 268ef3f96..6eb23e5e7 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -229,9 +229,9 @@ class BadAnswer { } } class BadTimestamp { - constructor(payload) { + constructor(payload, entityName) { this.name = 'BAD_TIMESTAMP'; - this.message = 'Invalid ISO8601 timestamp [' + payload + ']'; + this.message = 'Invalid ISO8601 timestamp [' + payload + '] in [' + entityName + ']'; this.code = 400; } } diff --git a/lib/services/ngsi/entities-NGSI-LD.js b/lib/services/ngsi/entities-NGSI-LD.js index 36cb8a629..79c20a535 100644 --- a/lib/services/ngsi/entities-NGSI-LD.js +++ b/lib/services/ngsi/entities-NGSI-LD.js @@ -1015,7 +1015,7 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c } else if (!utils.IsValidTimestampedNgsi2(payload[n])) { // legacy check needed? logger.error(context, 'Invalid timestamp:%s', JSON.stringify(payload[0])); - callback(new errors.BadTimestamp(payload)); + callback(new errors.BadTimestamp(payload, entityName)); return; } } diff --git a/lib/services/ngsi/entities-NGSI-v2.js b/lib/services/ngsi/entities-NGSI-v2.js index 3e98d1059..529af9c98 100644 --- a/lib/services/ngsi/entities-NGSI-v2.js +++ b/lib/services/ngsi/entities-NGSI-v2.js @@ -311,7 +311,7 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call if (moment(plainMeasures[constants.TIMESTAMP_ATTRIBUTE], moment.ISO_8601, true).isValid()) { timestamp.value = plainMeasures[constants.TIMESTAMP_ATTRIBUTE]; } else { - callback(new errors.BadTimestamp(null, entityName)); + callback(new errors.BadTimestamp(plainMeasures[constants.TIMESTAMP_ATTRIBUTE], entityName)); } } else if (!typeInformation.timezone) { timestamp.value = new Date().toISOString(); @@ -387,10 +387,11 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call typeof currentAttr.entity_name == 'string' ) { try { - logger.debug(context, + logger.debug( + context, 'Evaluating attribute: %j, for entity_name(exp):%j, with ctxt: %j', - currentAttr.name, - currentAttr.entity_name, + currentAttr.name, + currentAttr.entity_name, jexlctxt ); attrEntityName = jexlParser.applyExpression(currentAttr.entity_name, jexlctxt, typeInformation); @@ -451,10 +452,11 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call } catch (e) { valueExpression = null; } - logger.debug(context, - 'Evaluated attr: %j, with expression: %j, and ctxt: %j resulting: %j', + logger.debug( + context, + 'Evaluated attr: %j, with expression: %j, and ctxt: %j resulting: %j', currentAttr.name, - currentAttr.expression, + currentAttr.expression, jexlctxt, valueExpression ); @@ -564,7 +566,7 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call } } } - + let url = '/v2/op/update'; let options = NGSIUtils.createRequestObject(url, typeInformation, token); options.json = payload; @@ -607,15 +609,9 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call } // else: keep current options object created for a batch update //Send the NGSI request - logger.debug(context, - 'Updating device value in the Context Broker at: %j', - options.url - ); - logger.debug(context, - 'Using the following NGSI v2 request: %j', - options - ); - + logger.debug(context, 'Updating device value in the Context Broker at: %j', options.url); + logger.debug(context, 'Using the following NGSI v2 request: %j', options); + request( options, generateNGSI2OperationHandler('update', entityName, typeInformation, token, options, callback) From 0e215b1ece3fdc5714fe40d33cf39371833ceb66 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 29 Nov 2023 11:26:43 +0100 Subject: [PATCH 3/5] update CNR --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index e69de29bb..c6a609765 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -0,0 +1 @@ +- Log device id when BadTimestamp error From 063eafeff240e028b8ef806286c45ceb6686b520 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 29 Nov 2023 12:10:21 +0100 Subject: [PATCH 4/5] bump 4.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4b6f4b52..bf6f00588 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "iotagent-node-lib", "license": "AGPL-3.0-only", "description": "IoT Agent library to interface with NGSI Context Broker", - "version": "4.0.0-next", + "version": "4.0.1", "homepage": "https://github.com/telefonicaid/iotagent-node-lib", "keywords": [ "fiware", From 358650482bc489a89bf66ec7d739591f0e164e03 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 29 Nov 2023 12:10:51 +0100 Subject: [PATCH 5/5] bump 4.0.1 --- CHANGES_NEXT_RELEASE | 1 - 1 file changed, 1 deletion(-) delete mode 100644 CHANGES_NEXT_RELEASE diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE deleted file mode 100644 index c6a609765..000000000 --- a/CHANGES_NEXT_RELEASE +++ /dev/null @@ -1 +0,0 @@ -- Log device id when BadTimestamp error