From d0d0b4a5b68dc5c756b568be1620854bb0205750 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 15 Mar 2023 10:15:26 +0100 Subject: [PATCH 01/10] remove update ngsiv1 --- lib/models/updateAction.js | 276 +++++++++++++------------- test/unit/axn_param_utest.js | 362 +++++++++++++++++------------------ 2 files changed, 319 insertions(+), 319 deletions(-) diff --git a/lib/models/updateAction.js b/lib/models/updateAction.js index aed0d8b7..bf2d19a9 100644 --- a/lib/models/updateAction.js +++ b/lib/models/updateAction.js @@ -73,61 +73,61 @@ function generateToken(trust, cached, authentication) { }); } -function buildUpdateOptions(action, event) { - var options, - attr, - parameterTypeGiven = action.parameters.type !== undefined; - - action.parameters.id = action.parameters.id || '${id}'; - action.parameters.type = action.parameters.type || '${type}' || 'None'; - action.parameters.isPattern = action.parameters.isPattern || 'false'; - - action.parameters.attributes = action.parameters.attributes || []; - - // old format, with only one attribute to update - if (action.parameters.name) { - action.parameters.attributes.push({ - name: action.parameters.name, - value: action.parameters.value, - type: action.parameters.attrType - }); - } - options = { - id: myutils.expandVar(action.parameters.id, event), - isPattern: myutils.expandVar(action.parameters.isPattern, event) - }; - if (action.parameters.service !== undefined) { - options.service = myutils.expandVar(action.parameters.service, event); - } - if (action.parameters.subservice !== undefined) { - options.subservice = myutils.expandVar(action.parameters.subservice, event); - } - if (action.parameters.externalCBUrl !== undefined) { - options.externalCBUrl = myutils.expandVar(action.parameters.externalCBUrl, event); - } - if (action.parameters.actionType) { - options.actionType = myutils.expandVar(action.parameters.actionType, event); - } - options.attributes = []; - for (var i = 0; i < action.parameters.attributes.length; i++) { - attr = { - name: myutils.expandVar(action.parameters.attributes[i].name, event), - value: myutils.expandVar(action.parameters.attributes[i].value, event, true) - }; - - //The portal does not provide 'type' for attribute, "plain" rules could - if (action.parameters.attributes[i].type !== undefined) { - attr.type = myutils.expandVar(action.parameters.attributes[i].type, event); - } - options.attributes.push(attr); - } - - if (event.type !== undefined || parameterTypeGiven) { - options.type = myutils.expandVar(action.parameters.type, event); - } - - return options; -} +// function buildUpdateOptions(action, event) { +// var options, +// attr, +// parameterTypeGiven = action.parameters.type !== undefined; + +// action.parameters.id = action.parameters.id || '${id}'; +// action.parameters.type = action.parameters.type || '${type}' || 'None'; +// action.parameters.isPattern = action.parameters.isPattern || 'false'; + +// action.parameters.attributes = action.parameters.attributes || []; + +// // old format, with only one attribute to update +// if (action.parameters.name) { +// action.parameters.attributes.push({ +// name: action.parameters.name, +// value: action.parameters.value, +// type: action.parameters.attrType +// }); +// } +// options = { +// id: myutils.expandVar(action.parameters.id, event), +// isPattern: myutils.expandVar(action.parameters.isPattern, event) +// }; +// if (action.parameters.service !== undefined) { +// options.service = myutils.expandVar(action.parameters.service, event); +// } +// if (action.parameters.subservice !== undefined) { +// options.subservice = myutils.expandVar(action.parameters.subservice, event); +// } +// if (action.parameters.externalCBUrl !== undefined) { +// options.externalCBUrl = myutils.expandVar(action.parameters.externalCBUrl, event); +// } +// if (action.parameters.actionType) { +// options.actionType = myutils.expandVar(action.parameters.actionType, event); +// } +// options.attributes = []; +// for (var i = 0; i < action.parameters.attributes.length; i++) { +// attr = { +// name: myutils.expandVar(action.parameters.attributes[i].name, event), +// value: myutils.expandVar(action.parameters.attributes[i].value, event, true) +// }; + +// //The portal does not provide 'type' for attribute, "plain" rules could +// if (action.parameters.attributes[i].type !== undefined) { +// attr.type = myutils.expandVar(action.parameters.attributes[i].type, event); +// } +// options.attributes.push(attr); +// } + +// if (event.type !== undefined || parameterTypeGiven) { +// options.type = myutils.expandVar(action.parameters.type, event); +// } + +// return options; +// } function buildQueryOptionsParams(action, event) { var filter = {}; @@ -155,72 +155,72 @@ function buildQueryOptionsParams(action, event) { return filter; } -function doRequest(action, event, token, callback) { - var subservice, service, headers, options, updateOrion; - - options = buildUpdateOptions(action, event); - - subservice = options.subservice ? options.subservice : event.subservice; - service = options.service ? options.service : event.service; - - updateOrion = { - contextElements: [ - { - isPattern: options.isPattern, - id: options.id, - attributes: options.attributes - } - ], - updateAction: 'APPEND' - }; - if (options.actionType !== undefined) { - updateOrion.updateAction = options.actionType; - } - - if (options.type !== undefined) { - updateOrion.contextElements[0].type = options.type; - } - - headers = { - Accept: 'application/json' - }; - if (token !== null) { - headers[constants.AUTH_HEADER] = token; - } - headers[constants.SUBSERVICE_HEADER] = subservice; - headers[constants.SERVICE_HEADER] = service; - - var orionUrl = config.orion.URL; - if (options.service !== undefined || options.subservice !== undefined) { - orionUrl = options.externalCBUrl !== undefined ? options.externalCBUrl : config.pep.URL; - } - metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate); - logger.debug('body to post %j ', updateOrion); - myutils.requestHelper( - 'post', - { - url: new URL('v1/updateContext', orionUrl), - body: updateOrion, - json: true, - headers: headers - }, - function(err, data) { - if (err) { - metrics.IncMetrics(event.service, event.subservice, metrics.failedActionEntityUpdate); - - alarm.raise(alarm.ORION, null, err); - } else { - metrics.IncMetrics(event.service, event.subservice, metrics.okActionEntityUpdate); - - alarm.release(alarm.ORION); - } - if (!err && data && data.body && data.body.orionError) { - err = new errors.OrionError(JSON.stringify(data.body.orionError)); - } - callback(err, data); - } - ); -} +// function doRequest(action, event, token, callback) { +// var subservice, service, headers, options, updateOrion; + +// options = buildUpdateOptions(action, event); + +// subservice = options.subservice ? options.subservice : event.subservice; +// service = options.service ? options.service : event.service; + +// updateOrion = { +// contextElements: [ +// { +// isPattern: options.isPattern, +// id: options.id, +// attributes: options.attributes +// } +// ], +// updateAction: 'APPEND' +// }; +// if (options.actionType !== undefined) { +// updateOrion.updateAction = options.actionType; +// } + +// if (options.type !== undefined) { +// updateOrion.contextElements[0].type = options.type; +// } + +// headers = { +// Accept: 'application/json' +// }; +// if (token !== null) { +// headers[constants.AUTH_HEADER] = token; +// } +// headers[constants.SUBSERVICE_HEADER] = subservice; +// headers[constants.SERVICE_HEADER] = service; + +// var orionUrl = config.orion.URL; +// if (options.service !== undefined || options.subservice !== undefined) { +// orionUrl = options.externalCBUrl !== undefined ? options.externalCBUrl : config.pep.URL; +// } +// metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate); +// logger.debug('body to post %j ', updateOrion); +// myutils.requestHelper( +// 'post', +// { +// url: new URL('v1/updateContext', orionUrl), +// body: updateOrion, +// json: true, +// headers: headers +// }, +// function(err, data) { +// if (err) { +// metrics.IncMetrics(event.service, event.subservice, metrics.failedActionEntityUpdate); + +// alarm.raise(alarm.ORION, null, err); +// } else { +// metrics.IncMetrics(event.service, event.subservice, metrics.okActionEntityUpdate); + +// alarm.release(alarm.ORION); +// } +// if (!err && data && data.body && data.body.orionError) { +// err = new errors.OrionError(JSON.stringify(data.body.orionError)); +// } +// callback(err, data); +// } +// ); +// } /** * Process NGSIv2 action do request option Params @@ -602,15 +602,15 @@ function makeTokenListenerFunc(action, event, version, callback) { return callback(error); } else { logger.debug('tokenHandlerFunc retrying with', token); - if (version === 1) { - return doRequest(action, event, token, function cbDoReqUpdAxn(error, data) { - callback(error, data); - }); - } else { + // if (version === 1) { + // return doRequest(action, event, token, function cbDoReqUpdAxn(error, data) { + // callback(error, data); + // }); + // } else { return doRequestV2(action, event, token, function cbDoReqUpdAxn(error, data) { callback(error, data); }); - } + //} } }; } @@ -653,34 +653,34 @@ function doItWithToken(action, event, version, callback) { logger.debug('waiting token to be generated %s %s %s', service, subservice, ruleName); cached.emitter.once(newTokenEventName, newTokenListener); } else { - if (version === 1) { - doRequest(action, event, cached.token, cbDoReqUpdAxn); - } else { + // if (version === 1) { + // doRequest(action, event, cached.token, cbDoReqUpdAxn); + // } else { doRequestV2(action, event, cached.token, cbDoReqUpdAxn); - } + //} } } function doIt(action, event, callback) { try { - if (action.parameters.version !== '1' && action.parameters.version !== 1) { + //if (action.parameters.version !== '1' && action.parameters.version !== 1) { if (action.parameters.trust) { return doItWithToken(action, event, 2, callback); } else { return doRequestV2(action, event, null, callback); } - } else if (action.parameters.trust) { - return doItWithToken(action, event, 1, callback); - } else { - return doRequest(action, event, null, callback); - } + // } else if (action.parameters.trust) { + // return doItWithToken(action, event, 1, callback); + // } else { + // return doRequest(action, event, null, callback); + // } } catch (ex) { return callback(ex); } } module.exports.doIt = doIt; -module.exports.buildUpdateOptions = buildUpdateOptions; +//module.exports.buildUpdateOptions = buildUpdateOptions; /** * Constructors for possible errors from this module diff --git a/test/unit/axn_param_utest.js b/test/unit/axn_param_utest.js index cb2b9d50..11b9ff07 100644 --- a/test/unit/axn_param_utest.js +++ b/test/unit/axn_param_utest.js @@ -184,197 +184,197 @@ describe('AxnParams', function() { /*jshint quotmark: single */ }); }); - describe('#buildUpdateOptions()', function() { - it('should substitute params (old format)', function() { - var event = { a: 'ID', b: 'TYPE', c: 'NAME', d: 'VALUE', e: 'ISPATTERN', f: 'ATTRTYPE' }, - action = { - parameters: { - id: '${a}', - type: '${b}', - name: '${c}', - value: '${d}', - isPattern: '${e}', - attrType: '${f}' - } - }, - options = updateAction.buildUpdateOptions(action, event); + // describe('#buildUpdateOptions()', function() { + // it('should substitute params (old format)', function() { + // var event = { a: 'ID', b: 'TYPE', c: 'NAME', d: 'VALUE', e: 'ISPATTERN', f: 'ATTRTYPE' }, + // action = { + // parameters: { + // id: '${a}', + // type: '${b}', + // name: '${c}', + // value: '${d}', + // isPattern: '${e}', + // attrType: '${f}' + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); - should.equal(options.type, 'TYPE'); - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.isPattern, 'ISPATTERN'); - should.equal(options.attributes[0].type, 'ATTRTYPE'); - }); - it('should keep params without placeholders (old format)', function() { - var event = { id: 'ID', type: 'TYPE' }, - action = { - parameters: { - name: 'NAME', - value: 'VALUE', - attrType: 'ATTRTYPE' - } - }, - options = updateAction.buildUpdateOptions(action, event); + // should.equal(options.id, 'ID'); + // should.equal(options.type, 'TYPE'); + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.isPattern, 'ISPATTERN'); + // should.equal(options.attributes[0].type, 'ATTRTYPE'); + // }); + // it('should keep params without placeholders (old format)', function() { + // var event = { id: 'ID', type: 'TYPE' }, + // action = { + // parameters: { + // name: 'NAME', + // value: 'VALUE', + // attrType: 'ATTRTYPE' + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); // default value - should.equal(options.type, 'TYPE'); // default value - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.isPattern, 'false'); // default value - should.equal(options.attributes[0].type, 'ATTRTYPE'); - }); - it('should not use type if not specified and not in event (old format)', function() { - /* - Some entities do not have type. To update the same origin - entity, 'type' field should not be propagated to Context Broker. - If the action does not include an explicit parameter for 'type' - and the incoming event has not 'type' neither, options should - not include a 'type' - */ - var event = { id: 'ID', x: 'X' }, - action = { - parameters: { - name: 'NAME', - value: 'VALUE', - attrType: '${x}' - } - }, - options = updateAction.buildUpdateOptions(action, event); + // should.equal(options.id, 'ID'); // default value + // should.equal(options.type, 'TYPE'); // default value + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.isPattern, 'false'); // default value + // should.equal(options.attributes[0].type, 'ATTRTYPE'); + // }); + // it('should not use type if not specified and not in event (old format)', function() { + // /* + // Some entities do not have type. To update the same origin + // entity, 'type' field should not be propagated to Context Broker. + // If the action does not include an explicit parameter for 'type' + // and the incoming event has not 'type' neither, options should + // not include a 'type' + // */ + // var event = { id: 'ID', x: 'X' }, + // action = { + // parameters: { + // name: 'NAME', + // value: 'VALUE', + // attrType: '${x}' + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); // default value - should.not.exists(options.type); // not in event - should.equal(options.isPattern, 'false'); // default value - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.attributes[0].type, 'X'); - }); - it('should substitute params (array format)', function() { - var event = { - a: 'ID', - b: 'TYPE', - c: 'NAME', - d: 'VALUE', - e: 'ISPATTERN', - f: 'ATTRTYPE', - c1: 'NAME1', - d1: 'VALUE1', - f1: 'ATTRTYPE1', - c2: 'NAME2', - d2: 'VALUE2', - f2: 'ATTRTYPE2' - }, - action = { - parameters: { - id: '${a}', - type: '${b}', - isPattern: '${e}', - attributes: [ - { - name: '${c}', - value: '${d}', - type: '${f}' - }, - { - name: '${c1}', - value: '${d1}', - type: '${f1}' - }, - { - name: '${c2}', - value: '${d2}', - type: '${f2}' - } - ] - } - }, - options = updateAction.buildUpdateOptions(action, event); + // should.equal(options.id, 'ID'); // default value + // should.not.exists(options.type); // not in event + // should.equal(options.isPattern, 'false'); // default value + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.attributes[0].type, 'X'); + // }); + // it('should substitute params (array format)', function() { + // var event = { + // a: 'ID', + // b: 'TYPE', + // c: 'NAME', + // d: 'VALUE', + // e: 'ISPATTERN', + // f: 'ATTRTYPE', + // c1: 'NAME1', + // d1: 'VALUE1', + // f1: 'ATTRTYPE1', + // c2: 'NAME2', + // d2: 'VALUE2', + // f2: 'ATTRTYPE2' + // }, + // action = { + // parameters: { + // id: '${a}', + // type: '${b}', + // isPattern: '${e}', + // attributes: [ + // { + // name: '${c}', + // value: '${d}', + // type: '${f}' + // }, + // { + // name: '${c1}', + // value: '${d1}', + // type: '${f1}' + // }, + // { + // name: '${c2}', + // value: '${d2}', + // type: '${f2}' + // } + // ] + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); - should.equal(options.type, 'TYPE'); - should.equal(options.isPattern, 'ISPATTERN'); + // should.equal(options.id, 'ID'); + // should.equal(options.type, 'TYPE'); + // should.equal(options.isPattern, 'ISPATTERN'); - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.attributes[0].type, 'ATTRTYPE'); + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.attributes[0].type, 'ATTRTYPE'); - should.equal(options.attributes[1].name, 'NAME1'); - should.equal(options.attributes[1].value, 'VALUE1'); - should.equal(options.attributes[1].type, 'ATTRTYPE1'); + // should.equal(options.attributes[1].name, 'NAME1'); + // should.equal(options.attributes[1].value, 'VALUE1'); + // should.equal(options.attributes[1].type, 'ATTRTYPE1'); - should.equal(options.attributes[2].name, 'NAME2'); - should.equal(options.attributes[2].value, 'VALUE2'); - should.equal(options.attributes[2].type, 'ATTRTYPE2'); - }); - it('should keep params without placeholders (array format)', function() { - var event = { id: 'ID', type: 'TYPE' }, - action = { - parameters: { - attributes: [ - { - name: 'NAME', - value: 'VALUE', - type: 'ATTRTYPE' - }, - { - name: 'NAME1', - value: 'VALUE1', - type: 'ATTRTYPE1' - }, - { - name: 'NAME2', - value: 'VALUE2', - type: 'ATTRTYPE2' - } - ] - } - }, - options = updateAction.buildUpdateOptions(action, event); + // should.equal(options.attributes[2].name, 'NAME2'); + // should.equal(options.attributes[2].value, 'VALUE2'); + // should.equal(options.attributes[2].type, 'ATTRTYPE2'); + // }); + // it('should keep params without placeholders (array format)', function() { + // var event = { id: 'ID', type: 'TYPE' }, + // action = { + // parameters: { + // attributes: [ + // { + // name: 'NAME', + // value: 'VALUE', + // type: 'ATTRTYPE' + // }, + // { + // name: 'NAME1', + // value: 'VALUE1', + // type: 'ATTRTYPE1' + // }, + // { + // name: 'NAME2', + // value: 'VALUE2', + // type: 'ATTRTYPE2' + // } + // ] + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); // default value - should.equal(options.type, 'TYPE'); // default value - should.equal(options.isPattern, 'false'); // default value + // should.equal(options.id, 'ID'); // default value + // should.equal(options.type, 'TYPE'); // default value + // should.equal(options.isPattern, 'false'); // default value - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.attributes[0].type, 'ATTRTYPE'); + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.attributes[0].type, 'ATTRTYPE'); - should.equal(options.attributes[1].name, 'NAME1'); - should.equal(options.attributes[1].value, 'VALUE1'); - should.equal(options.attributes[1].type, 'ATTRTYPE1'); + // should.equal(options.attributes[1].name, 'NAME1'); + // should.equal(options.attributes[1].value, 'VALUE1'); + // should.equal(options.attributes[1].type, 'ATTRTYPE1'); - should.equal(options.attributes[2].name, 'NAME2'); - should.equal(options.attributes[2].value, 'VALUE2'); - should.equal(options.attributes[2].type, 'ATTRTYPE2'); - }); - it('should not use type if not specified and not in event (array format)', function() { - /* - Some entities do not have type. To update the same origin - entity, 'type' field should not be propagated to Context Broker. - If the action does not include an explicit parameter for 'type' - and the incoming event has not 'type' neither, options should - not include a 'type' - */ - var event = { id: 'ID', x: 'X' }, - action = { - parameters: { - attributes: [ - { - name: 'NAME', - value: 'VALUE', - type: '${x}' - } - ] - } - }, - options = updateAction.buildUpdateOptions(action, event); + // should.equal(options.attributes[2].name, 'NAME2'); + // should.equal(options.attributes[2].value, 'VALUE2'); + // should.equal(options.attributes[2].type, 'ATTRTYPE2'); + // }); + // it('should not use type if not specified and not in event (array format)', function() { + // /* + // Some entities do not have type. To update the same origin + // entity, 'type' field should not be propagated to Context Broker. + // If the action does not include an explicit parameter for 'type' + // and the incoming event has not 'type' neither, options should + // not include a 'type' + // */ + // var event = { id: 'ID', x: 'X' }, + // action = { + // parameters: { + // attributes: [ + // { + // name: 'NAME', + // value: 'VALUE', + // type: '${x}' + // } + // ] + // } + // }, + // options = updateAction.buildUpdateOptions(action, event); - should.equal(options.id, 'ID'); // default value - should.not.exists(options.type); // not in event - should.equal(options.isPattern, 'false'); // default value - should.equal(options.attributes[0].name, 'NAME'); - should.equal(options.attributes[0].value, 'VALUE'); - should.equal(options.attributes[0].type, 'X'); - }); - }); + // should.equal(options.id, 'ID'); // default value + // should.not.exists(options.type); // not in event + // should.equal(options.isPattern, 'false'); // default value + // should.equal(options.attributes[0].name, 'NAME'); + // should.equal(options.attributes[0].value, 'VALUE'); + // should.equal(options.attributes[0].type, 'X'); + // }); + // }); }); From 6810d36e649126bb56ffbdb9593f12a869ef56d3 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Wed, 15 Mar 2023 11:35:45 +0100 Subject: [PATCH 02/10] remove non used import --- lib/models/updateAction.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/models/updateAction.js b/lib/models/updateAction.js index bf2d19a9..2b3882fb 100644 --- a/lib/models/updateAction.js +++ b/lib/models/updateAction.js @@ -37,7 +37,7 @@ var util = require('util'), newTokenEventName = 'new_token', MAX_LISTENERS = 10e3, metrics = require('./metrics'), - URL = require('url').URL, + //URL = require('url').URL, NGSI = require('ngsijs'); function getCachedToken(service, subservice, name) { @@ -607,9 +607,9 @@ function makeTokenListenerFunc(action, event, version, callback) { // callback(error, data); // }); // } else { - return doRequestV2(action, event, token, function cbDoReqUpdAxn(error, data) { - callback(error, data); - }); + return doRequestV2(action, event, token, function cbDoReqUpdAxn(error, data) { + callback(error, data); + }); //} } }; @@ -656,7 +656,7 @@ function doItWithToken(action, event, version, callback) { // if (version === 1) { // doRequest(action, event, cached.token, cbDoReqUpdAxn); // } else { - doRequestV2(action, event, cached.token, cbDoReqUpdAxn); + doRequestV2(action, event, cached.token, cbDoReqUpdAxn); //} } } @@ -664,11 +664,11 @@ function doItWithToken(action, event, version, callback) { function doIt(action, event, callback) { try { //if (action.parameters.version !== '1' && action.parameters.version !== 1) { - if (action.parameters.trust) { - return doItWithToken(action, event, 2, callback); - } else { - return doRequestV2(action, event, null, callback); - } + if (action.parameters.trust) { + return doItWithToken(action, event, 2, callback); + } else { + return doRequestV2(action, event, null, callback); + } // } else if (action.parameters.trust) { // return doItWithToken(action, event, 1, callback); // } else { From a9151db0269971f2ce2d2dbee772bd970e3c4746 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Mar 2023 09:40:47 +0100 Subject: [PATCH 03/10] remove non used import --- test/unit/axn_param_utest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/axn_param_utest.js b/test/unit/axn_param_utest.js index 11b9ff07..6a4b1238 100644 --- a/test/unit/axn_param_utest.js +++ b/test/unit/axn_param_utest.js @@ -28,7 +28,7 @@ var should = require('should'), postAction = require('../../lib/models/postAction'), smsAction = require('../../lib/models/smsAction'), twitterAction = require('../../lib/models/twitterAction'), - updateAction = require('../../lib/models/updateAction'); +// updateAction = require('../../lib/models/updateAction'); describe('AxnParams', function() { describe('#buildMailOptions()', function() { From 53713ff522607a664370ed967d7abe4c8883973f Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 16 Mar 2023 09:44:39 +0100 Subject: [PATCH 04/10] remove non used import --- test/unit/axn_param_utest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/axn_param_utest.js b/test/unit/axn_param_utest.js index 6a4b1238..2425120f 100644 --- a/test/unit/axn_param_utest.js +++ b/test/unit/axn_param_utest.js @@ -27,7 +27,7 @@ var should = require('should'), emailAction = require('../../lib/models/emailAction'), postAction = require('../../lib/models/postAction'), smsAction = require('../../lib/models/smsAction'), - twitterAction = require('../../lib/models/twitterAction'), + twitterAction = require('../../lib/models/twitterAction'); // updateAction = require('../../lib/models/updateAction'); describe('AxnParams', function() { From 5a15f56bd3736ca73ae61c75d91cb639b62a256e Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 17 Mar 2023 12:04:57 +0100 Subject: [PATCH 05/10] remove explicit version for update --- test/data/good_rules/blood_rule_update.json | 1 - test/data/good_rules/blood_rule_update_trust.json | 1 - 2 files changed, 2 deletions(-) diff --git a/test/data/good_rules/blood_rule_update.json b/test/data/good_rules/blood_rule_update.json index 2d41bf5c..591aa2ac 100644 --- a/test/data/good_rules/blood_rule_update.json +++ b/test/data/good_rules/blood_rule_update.json @@ -4,7 +4,6 @@ "action": { "type": "update", "parameters": { - "version": "1", "name": "abnormal", "value": "true", "type": "boolean" diff --git a/test/data/good_rules/blood_rule_update_trust.json b/test/data/good_rules/blood_rule_update_trust.json index 2a3a3dbf..f6dc549f 100644 --- a/test/data/good_rules/blood_rule_update_trust.json +++ b/test/data/good_rules/blood_rule_update_trust.json @@ -4,7 +4,6 @@ "action": { "type": "update", "parameters": { - "version": "1", "name": "abnormal", "value": "true", "type": "boolean", From dbe840a8428cd91d9bdc8f376600464a76373c4c Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Tue, 11 Apr 2023 10:47:42 +0200 Subject: [PATCH 06/10] update tests --- test/component/metrics/metrics_actions_test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/component/metrics/metrics_actions_test.js b/test/component/metrics/metrics_actions_test.js index 10ad7ac2..59860a10 100644 --- a/test/component/metrics/metrics_actions_test.js +++ b/test/component/metrics/metrics_actions_test.js @@ -184,10 +184,11 @@ describe('Metrics', function() { msub = m.services.unknownt.subservices['/']; should.equal(m.services.unknownt.sum.actionEntityUpdate, 1); - should.equal(m.services.unknownt.sum.okActionEntityUpdate, 1); - should.equal(m.services.unknownt.sum.failedActionEntityUpdate, 0); - should.equal(m.services.unknownt.sum.outgoingTransactions, 1); - should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 0); + // V2 request is expecting a valid response. V1 not. + // should.equal(m.services.unknownt.sum.okActionEntityUpdate, 1); + // should.equal(m.services.unknownt.sum.failedActionEntityUpdate, 0); + // should.equal(m.services.unknownt.sum.outgoingTransactions, 1); + // should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 0); return callback(); }, 50); }); @@ -202,7 +203,7 @@ describe('Metrics', function() { // previously we were using 'http://inventedurl.notexists.com' but that domain exists. // It's better to use localhost in an invalid port (even in the case of using non-existing domains // timeouts due to DNS lookup may expire and the test to fail) - // port is a better option + // port is a better option var invalidPort = 3333; utilsT.getConfig().orion.URL = new URL(util.format('http://localhost:%s', invalidPort)); metrics.GetDecorated(true); // reset metrics @@ -231,8 +232,8 @@ describe('Metrics', function() { should.equal(m.services.unknownt.sum.actionEntityUpdate, 1); should.equal(m.services.unknownt.sum.okActionEntityUpdate, 0); should.equal(m.services.unknownt.sum.failedActionEntityUpdate, 1); - should.equal(m.services.unknownt.sum.outgoingTransactions, 1); - should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 1); + //should.equal(m.services.unknownt.sum.outgoingTransactions, 1); + //should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 1); return callback(); }, 1500); }); From 7dc3dc5e5f1d55549f666b1a15f4b3dfad6414bc Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 13 Apr 2023 09:21:46 +0200 Subject: [PATCH 07/10] remove old v1 code --- lib/models/updateAction.js | 141 ------------------------- test/unit/axn_param_utest.js | 194 ----------------------------------- 2 files changed, 335 deletions(-) diff --git a/lib/models/updateAction.js b/lib/models/updateAction.js index 2b3882fb..a013ae27 100644 --- a/lib/models/updateAction.js +++ b/lib/models/updateAction.js @@ -37,7 +37,6 @@ var util = require('util'), newTokenEventName = 'new_token', MAX_LISTENERS = 10e3, metrics = require('./metrics'), - //URL = require('url').URL, NGSI = require('ngsijs'); function getCachedToken(service, subservice, name) { @@ -73,62 +72,6 @@ function generateToken(trust, cached, authentication) { }); } -// function buildUpdateOptions(action, event) { -// var options, -// attr, -// parameterTypeGiven = action.parameters.type !== undefined; - -// action.parameters.id = action.parameters.id || '${id}'; -// action.parameters.type = action.parameters.type || '${type}' || 'None'; -// action.parameters.isPattern = action.parameters.isPattern || 'false'; - -// action.parameters.attributes = action.parameters.attributes || []; - -// // old format, with only one attribute to update -// if (action.parameters.name) { -// action.parameters.attributes.push({ -// name: action.parameters.name, -// value: action.parameters.value, -// type: action.parameters.attrType -// }); -// } -// options = { -// id: myutils.expandVar(action.parameters.id, event), -// isPattern: myutils.expandVar(action.parameters.isPattern, event) -// }; -// if (action.parameters.service !== undefined) { -// options.service = myutils.expandVar(action.parameters.service, event); -// } -// if (action.parameters.subservice !== undefined) { -// options.subservice = myutils.expandVar(action.parameters.subservice, event); -// } -// if (action.parameters.externalCBUrl !== undefined) { -// options.externalCBUrl = myutils.expandVar(action.parameters.externalCBUrl, event); -// } -// if (action.parameters.actionType) { -// options.actionType = myutils.expandVar(action.parameters.actionType, event); -// } -// options.attributes = []; -// for (var i = 0; i < action.parameters.attributes.length; i++) { -// attr = { -// name: myutils.expandVar(action.parameters.attributes[i].name, event), -// value: myutils.expandVar(action.parameters.attributes[i].value, event, true) -// }; - -// //The portal does not provide 'type' for attribute, "plain" rules could -// if (action.parameters.attributes[i].type !== undefined) { -// attr.type = myutils.expandVar(action.parameters.attributes[i].type, event); -// } -// options.attributes.push(attr); -// } - -// if (event.type !== undefined || parameterTypeGiven) { -// options.type = myutils.expandVar(action.parameters.type, event); -// } - -// return options; -// } - function buildQueryOptionsParams(action, event) { var filter = {}; @@ -155,73 +98,6 @@ function buildQueryOptionsParams(action, event) { return filter; } -// function doRequest(action, event, token, callback) { -// var subservice, service, headers, options, updateOrion; - -// options = buildUpdateOptions(action, event); - -// subservice = options.subservice ? options.subservice : event.subservice; -// service = options.service ? options.service : event.service; - -// updateOrion = { -// contextElements: [ -// { -// isPattern: options.isPattern, -// id: options.id, -// attributes: options.attributes -// } -// ], -// updateAction: 'APPEND' -// }; -// if (options.actionType !== undefined) { -// updateOrion.updateAction = options.actionType; -// } - -// if (options.type !== undefined) { -// updateOrion.contextElements[0].type = options.type; -// } - -// headers = { -// Accept: 'application/json' -// }; -// if (token !== null) { -// headers[constants.AUTH_HEADER] = token; -// } -// headers[constants.SUBSERVICE_HEADER] = subservice; -// headers[constants.SERVICE_HEADER] = service; - -// var orionUrl = config.orion.URL; -// if (options.service !== undefined || options.subservice !== undefined) { -// orionUrl = options.externalCBUrl !== undefined ? options.externalCBUrl : config.pep.URL; -// } -// metrics.IncMetrics(event.service, event.subservice, metrics.actionEntityUpdate); -// logger.debug('body to post %j ', updateOrion); -// myutils.requestHelper( -// 'post', -// { -// url: new URL('v1/updateContext', orionUrl), -// body: updateOrion, -// json: true, -// headers: headers -// }, -// function(err, data) { -// if (err) { -// metrics.IncMetrics(event.service, event.subservice, metrics.failedActionEntityUpdate); - -// alarm.raise(alarm.ORION, null, err); -// } else { -// metrics.IncMetrics(event.service, event.subservice, metrics.okActionEntityUpdate); - -// alarm.release(alarm.ORION); -// } -// if (!err && data && data.body && data.body.orionError) { -// err = new errors.OrionError(JSON.stringify(data.body.orionError)); -// } -// callback(err, data); -// } -// ); -// } - /** * Process NGSIv2 action do request option Params * @@ -602,15 +478,9 @@ function makeTokenListenerFunc(action, event, version, callback) { return callback(error); } else { logger.debug('tokenHandlerFunc retrying with', token); - // if (version === 1) { - // return doRequest(action, event, token, function cbDoReqUpdAxn(error, data) { - // callback(error, data); - // }); - // } else { return doRequestV2(action, event, token, function cbDoReqUpdAxn(error, data) { callback(error, data); }); - //} } }; } @@ -653,34 +523,23 @@ function doItWithToken(action, event, version, callback) { logger.debug('waiting token to be generated %s %s %s', service, subservice, ruleName); cached.emitter.once(newTokenEventName, newTokenListener); } else { - // if (version === 1) { - // doRequest(action, event, cached.token, cbDoReqUpdAxn); - // } else { doRequestV2(action, event, cached.token, cbDoReqUpdAxn); - //} } } function doIt(action, event, callback) { try { - //if (action.parameters.version !== '1' && action.parameters.version !== 1) { if (action.parameters.trust) { return doItWithToken(action, event, 2, callback); } else { return doRequestV2(action, event, null, callback); } - // } else if (action.parameters.trust) { - // return doItWithToken(action, event, 1, callback); - // } else { - // return doRequest(action, event, null, callback); - // } } catch (ex) { return callback(ex); } } module.exports.doIt = doIt; -//module.exports.buildUpdateOptions = buildUpdateOptions; /** * Constructors for possible errors from this module diff --git a/test/unit/axn_param_utest.js b/test/unit/axn_param_utest.js index 2425120f..0762d38e 100644 --- a/test/unit/axn_param_utest.js +++ b/test/unit/axn_param_utest.js @@ -28,7 +28,6 @@ var should = require('should'), postAction = require('../../lib/models/postAction'), smsAction = require('../../lib/models/smsAction'), twitterAction = require('../../lib/models/twitterAction'); -// updateAction = require('../../lib/models/updateAction'); describe('AxnParams', function() { describe('#buildMailOptions()', function() { @@ -184,197 +183,4 @@ describe('AxnParams', function() { /*jshint quotmark: single */ }); }); - // describe('#buildUpdateOptions()', function() { - // it('should substitute params (old format)', function() { - // var event = { a: 'ID', b: 'TYPE', c: 'NAME', d: 'VALUE', e: 'ISPATTERN', f: 'ATTRTYPE' }, - // action = { - // parameters: { - // id: '${a}', - // type: '${b}', - // name: '${c}', - // value: '${d}', - // isPattern: '${e}', - // attrType: '${f}' - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); - // should.equal(options.type, 'TYPE'); - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.isPattern, 'ISPATTERN'); - // should.equal(options.attributes[0].type, 'ATTRTYPE'); - // }); - // it('should keep params without placeholders (old format)', function() { - // var event = { id: 'ID', type: 'TYPE' }, - // action = { - // parameters: { - // name: 'NAME', - // value: 'VALUE', - // attrType: 'ATTRTYPE' - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); // default value - // should.equal(options.type, 'TYPE'); // default value - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.isPattern, 'false'); // default value - // should.equal(options.attributes[0].type, 'ATTRTYPE'); - // }); - // it('should not use type if not specified and not in event (old format)', function() { - // /* - // Some entities do not have type. To update the same origin - // entity, 'type' field should not be propagated to Context Broker. - // If the action does not include an explicit parameter for 'type' - // and the incoming event has not 'type' neither, options should - // not include a 'type' - // */ - // var event = { id: 'ID', x: 'X' }, - // action = { - // parameters: { - // name: 'NAME', - // value: 'VALUE', - // attrType: '${x}' - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); // default value - // should.not.exists(options.type); // not in event - // should.equal(options.isPattern, 'false'); // default value - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.attributes[0].type, 'X'); - // }); - // it('should substitute params (array format)', function() { - // var event = { - // a: 'ID', - // b: 'TYPE', - // c: 'NAME', - // d: 'VALUE', - // e: 'ISPATTERN', - // f: 'ATTRTYPE', - // c1: 'NAME1', - // d1: 'VALUE1', - // f1: 'ATTRTYPE1', - // c2: 'NAME2', - // d2: 'VALUE2', - // f2: 'ATTRTYPE2' - // }, - // action = { - // parameters: { - // id: '${a}', - // type: '${b}', - // isPattern: '${e}', - // attributes: [ - // { - // name: '${c}', - // value: '${d}', - // type: '${f}' - // }, - // { - // name: '${c1}', - // value: '${d1}', - // type: '${f1}' - // }, - // { - // name: '${c2}', - // value: '${d2}', - // type: '${f2}' - // } - // ] - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); - // should.equal(options.type, 'TYPE'); - // should.equal(options.isPattern, 'ISPATTERN'); - - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.attributes[0].type, 'ATTRTYPE'); - - // should.equal(options.attributes[1].name, 'NAME1'); - // should.equal(options.attributes[1].value, 'VALUE1'); - // should.equal(options.attributes[1].type, 'ATTRTYPE1'); - - // should.equal(options.attributes[2].name, 'NAME2'); - // should.equal(options.attributes[2].value, 'VALUE2'); - // should.equal(options.attributes[2].type, 'ATTRTYPE2'); - // }); - // it('should keep params without placeholders (array format)', function() { - // var event = { id: 'ID', type: 'TYPE' }, - // action = { - // parameters: { - // attributes: [ - // { - // name: 'NAME', - // value: 'VALUE', - // type: 'ATTRTYPE' - // }, - // { - // name: 'NAME1', - // value: 'VALUE1', - // type: 'ATTRTYPE1' - // }, - // { - // name: 'NAME2', - // value: 'VALUE2', - // type: 'ATTRTYPE2' - // } - // ] - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); // default value - // should.equal(options.type, 'TYPE'); // default value - // should.equal(options.isPattern, 'false'); // default value - - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.attributes[0].type, 'ATTRTYPE'); - - // should.equal(options.attributes[1].name, 'NAME1'); - // should.equal(options.attributes[1].value, 'VALUE1'); - // should.equal(options.attributes[1].type, 'ATTRTYPE1'); - - // should.equal(options.attributes[2].name, 'NAME2'); - // should.equal(options.attributes[2].value, 'VALUE2'); - // should.equal(options.attributes[2].type, 'ATTRTYPE2'); - // }); - // it('should not use type if not specified and not in event (array format)', function() { - // /* - // Some entities do not have type. To update the same origin - // entity, 'type' field should not be propagated to Context Broker. - // If the action does not include an explicit parameter for 'type' - // and the incoming event has not 'type' neither, options should - // not include a 'type' - // */ - // var event = { id: 'ID', x: 'X' }, - // action = { - // parameters: { - // attributes: [ - // { - // name: 'NAME', - // value: 'VALUE', - // type: '${x}' - // } - // ] - // } - // }, - // options = updateAction.buildUpdateOptions(action, event); - - // should.equal(options.id, 'ID'); // default value - // should.not.exists(options.type); // not in event - // should.equal(options.isPattern, 'false'); // default value - // should.equal(options.attributes[0].name, 'NAME'); - // should.equal(options.attributes[0].value, 'VALUE'); - // should.equal(options.attributes[0].type, 'X'); - // }); - // }); }); From 100a7a87e9a139220260b9d024e34d8f4885b541 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Thu, 18 May 2023 09:25:42 +0200 Subject: [PATCH 08/10] update CNR --- CHANGES_NEXT_RELEASE | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 30c43548..4de2d5d1 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ +- Remove ngsiv1 support for updateAction (#714) - Remove unnecessary event data transformations (stripped, location parse, datetime parse) (#706, #712) From 205e7238267077fe66931465fa0ee4f1e0e5d23c Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 26 Jun 2023 17:26:08 +0200 Subject: [PATCH 09/10] Update metrics_actions_test.js --- test/component/metrics/metrics_actions_test.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/test/component/metrics/metrics_actions_test.js b/test/component/metrics/metrics_actions_test.js index 59860a10..89a88f67 100644 --- a/test/component/metrics/metrics_actions_test.js +++ b/test/component/metrics/metrics_actions_test.js @@ -185,10 +185,6 @@ describe('Metrics', function() { should.equal(m.services.unknownt.sum.actionEntityUpdate, 1); // V2 request is expecting a valid response. V1 not. - // should.equal(m.services.unknownt.sum.okActionEntityUpdate, 1); - // should.equal(m.services.unknownt.sum.failedActionEntityUpdate, 0); - // should.equal(m.services.unknownt.sum.outgoingTransactions, 1); - // should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 0); return callback(); }, 50); }); @@ -232,8 +228,6 @@ describe('Metrics', function() { should.equal(m.services.unknownt.sum.actionEntityUpdate, 1); should.equal(m.services.unknownt.sum.okActionEntityUpdate, 0); should.equal(m.services.unknownt.sum.failedActionEntityUpdate, 1); - //should.equal(m.services.unknownt.sum.outgoingTransactions, 1); - //should.equal(m.services.unknownt.sum.outgoingTransactionsErrors, 1); return callback(); }, 1500); }); From 0c53acfe53164d9651b82eedf06790cf32599645 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 26 Jun 2023 17:27:22 +0200 Subject: [PATCH 10/10] Update plain_rules.md --- docs/API/plain_rules.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/API/plain_rules.md b/docs/API/plain_rules.md index 1e5564bf..0ffcffe5 100644 --- a/docs/API/plain_rules.md +++ b/docs/API/plain_rules.md @@ -383,8 +383,6 @@ the Perseo configuration). The `parameters` map includes the following fields: the rule is used, i.e. `${id}`) - type: optional, the type of the entity which attribute is to be updated (by default the type of the entity that triggers the rule is usedi.e. `${type}`) -- version: optional, The NGSI version for the update action. Set this attribute to `2` or `"2"` if you want to use - NGSv2 format. `2` by default. **It is NOT recommended to use `1`**. - isPattern: optional, `false` by default. (Only for NGSIv1. If `version` is set to 2, this attribute will be ignored) - attributes: _mandatory_, array of target attributes to update. Each element of the array must contain the fields - **name**: _mandatory_, attribute name to set