Skip to content

Commit

Permalink
Merge pull request telefonicaid#1501 from telefonicaid/task/remove_au…
Browse files Browse the repository at this point in the history
…tocast2

 remove autocast feature
  • Loading branch information
fgalan authored Oct 11, 2023
2 parents 913f53d + f866dbd commit 87f9ee7
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 1,660 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Remove: autocast (including env var IOTA_AUTOCAST) (#1498)
- Fix: use but not store timestamp and explicitAttrs from group with autoprovisioned devices (#1504, partially)
- Fix: MongoDB connection authentication (user and password were not actually used) (#1510)
- Fix: add static attributes when use explicitAttrs (#1506)
Expand Down
6 changes: 0 additions & 6 deletions doc/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
- [componentName](#componentname)
- [pollingExpiration](#pollingexpiration)
- [pollingDaemonFrequency](#pollingdaemonfrequency)
- [autocast](#autocast)
- [multiCore](#multicore)
- [fallbackTenant](#fallbacktenant)
- [fallbackPath](#fallbackpath)
Expand Down Expand Up @@ -378,10 +377,6 @@ amount of time without being collected by the device, the expiration daemon will
time between collection of expired commands in milliseconds. This attribute is optional (if this parameter doesn't exist
the polling daemon won't be started).

#### `autocast`

When enabled, the IoT Agents will try to cast attribute's values considering the JSON native type (only for NGSI v2).

#### `multiCore`

When enabled, the IoT Agents runs in multi-thread environment to take advantage of multi-core systems. It allows two
Expand Down Expand Up @@ -480,7 +475,6 @@ overrides.
| IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
| IOTA_POLLING_EXPIRATION | `pollingExpiration` |
| IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
| IOTA_AUTOCAST | `autocast` |
| IOTA_MULTI_CORE | `multiCore` |
| IOTA_JSON_LD_CONTEXT | `jsonLdContext` |
| IOTA_FALLBACK_TENANT | `fallbackTenant` |
Expand Down
5 changes: 0 additions & 5 deletions lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ function processEnvironmentVariables() {
'IOTA_MONGO_PORT',
'IOTA_MONGO_DB',
'IOTA_MONGO_REPLICASET',
'IOTA_AUTOCAST',
'IOTA_MONGO_PASSWORD',
'IOTA_MONGO_AUTH_SOURCE',
'IOTA_MONGO_RETRIES',
Expand Down Expand Up @@ -451,10 +450,6 @@ function processEnvironmentVariables() {
config.pollingDaemonFrequency = process.env.IOTA_POLLING_DAEMON_FREQ;
}

if (process.env.IOTA_AUTOCAST) {
config.autocast = process.env.IOTA_AUTOCAST === 'true';
}

if (process.env.IOTA_MULTI_CORE) {
config.multiCore = process.env.IOTA_MULTI_CORE === 'true';
} else {
Expand Down
3 changes: 1 addition & 2 deletions lib/services/ngsi/entities-NGSI-LD.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,9 +955,8 @@ function sendUpdateValueNgsiLD(entityName, attributes, typeInformation, token, c
delete payload[m][key].object_id;
}
}
payload[m] = NGSIUtils.castJsonNativeAttributes(payload[m]); // native types
}
logger.debug(context, 'sendUpdateValueNgsiLD \n payload with native types and without object_id %j', payload);
logger.debug(context, 'sendUpdateValueNgsiLD \n payload and without object_id %j', payload);

options.json = payload;
try {
Expand Down
3 changes: 1 addition & 2 deletions lib/services/ngsi/entities-NGSI-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,8 @@ function sendUpdateValueNgsi2(entityName, measures, typeInformation, token, call
delete payload.entities[m][key].object_id;
}
}
payload.entities[m] = NGSIUtils.castJsonNativeAttributes(payload.entities[m]); // native types
}
logger.debug(context, 'sendUpdateValueNgsi2 payload with native types and without object_id=%j', payload);
logger.debug(context, 'sendUpdateValueNgsi2 payload without object_id=%j', payload);

options.json = payload;

Expand Down
30 changes: 0 additions & 30 deletions lib/services/ngsi/ngsiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,6 @@ function isFloat(value) {
return !isNaN(value) && value.toString().indexOf('.') !== -1;
}

/**
* It casts attribute values which are reported using JSON parsing
*
* @param {String} payload The payload
* @return {String} New payload where attributes's values are casted to the corresponding JSON values
*/
function castJsonNativeAttributes(payload) {
if (!config.getConfig().autocast) {
return payload;
}

for (const key in payload) {
if (
/* eslint-disable-next-line no-prototype-builtins */
payload.hasOwnProperty(key) &&
payload[key].value &&
typeof payload[key].value === 'string'
) {
try {
const parsedValue = JSON.parse(payload[key].value);
payload[key].value = parsedValue;
} catch (e) {
// Keep value as is
}
}
}
return payload;
}

/**
* Create the request object used to communicate with the Context Broker, adding security and service information.
*
Expand Down Expand Up @@ -230,7 +201,6 @@ exports.createRequestObject = createRequestObject;
exports.applyMiddlewares = applyMiddlewares;
exports.getMetaData = getMetaData;
exports.getLngLats = getLngLats;
exports.castJsonNativeAttributes = castJsonNativeAttributes;
exports.isFloat = isFloat;
exports.updateMiddleware = updateMiddleware;
exports.queryMiddleware = queryMiddleware;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
{
"@context": "http://context.json-ld",
"id": "urn:ngsi-ld:Light:light1",
"type": "Light"
"type": "Light",
"keep_alive": {
"type": "Property",
"value": {
"@type": "None",
"@value": "null"
}
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"type": "Property",
"value": {
"@type": "Array",
"@value": [
"iot",
"device"
]
"@value": "[\"iot\",\"device\"]"
}
},
"type": "Light"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
"type": "Property",
"value": {
"@type": "Object",
"@value": {
"firmware": {
"hash": "cf23df2207d99a74fbe169e3eba035e633b65d94",
"version": "1.1.0"
}
}
"@value": "{\"firmware\": {\"version\": \"1.1.0\",\"hash\": \"cf23df2207d99a74fbe169e3eba035e633b65d94\"}}"
}
},
"id": "urn:ngsi-ld:Light:light1",
Expand Down
Loading

0 comments on commit 87f9ee7

Please sign in to comment.