Skip to content

Commit

Permalink
Merge pull request telefonicaid#1503 from telefonicaid/task/remove_si…
Browse files Browse the repository at this point in the history
…ngle_configuration_mode

remove single configuration mode
  • Loading branch information
mapedraza authored Oct 9, 2023
2 parents 7899b00 + 31957c8 commit 14d065c
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 685 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: single configuration mode (along with IOTA_SINGLE_MODE env var) (#1469)
- Remove: extractVariables from jexl plugin (no needed anymore since the removal of bidireational plugin)
- Fix: ensure service and subservice in context of error handlers using req headers
- Fix: remove attribute of measures with name `id` or `type` to avoid collisions (#1485)
Expand Down
6 changes: 0 additions & 6 deletions doc/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
- [providerUrl](#providerurl)
- [iotaVersion](#iotaversion)
- [dieOnUnexpectedError](#dieonunexpectederror)
- [singleConfigurationMode](#singleconfigurationmode)
- [timestamp](#timestamp)
- [defaultResource](#defaultresource)
- [defaultKey](#defaultkey)
Expand Down Expand Up @@ -348,10 +347,6 @@ IoTA).

if this flag is activated, the IoTAgent will not capture global exception, thus dying upon any unexpected error.

#### `singleConfigurationMode`

enables the Single Configuration mode for backwards compatibility (see description in the Overview). Default to false.

#### `timestamp`

if this flag is activated:
Expand Down Expand Up @@ -483,7 +478,6 @@ overrides.
| IOTA_MONGO_RETRY_TIME | `mongodb.retryTime` |
| IOTA_MONGO_SSL | `mongodb.ssl` |
| IOTA_MONGO_EXTRAARGS | `mongodb.extraArgs` |
| IOTA_SINGLE_MODE | `singleConfigurationMode` |
| IOTA_POLLING_EXPIRATION | `pollingExpiration` |
| IOTA_POLLING_DAEMON_FREQ | `pollingDaemonFrequency` |
| IOTA_AUTOCAST | `autocast` |
Expand Down
12 changes: 0 additions & 12 deletions doc/devel/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,6 @@ configuration was assigned to a particular subservice and just one configuration
relation between a Device and a Configuration didn't need the type to discriminate between Configurations. That's why
for those agents, type was not a mandatory parameter.

In order to allow backward-compatibility with those agents, the IoT Agent Library now implement a compatibility mode:
the **Single Configuration Mode**, that makes the agent behave like the old agents. In this mode:

- Each Subservice can contain just one Configuration. If a second Configuration is created for a Subservice, an error
is raised.

- Each Device provisioned for a Subservice is automatically assigned to the Subservice one Configuration if there is
any.

This compatibility has to be set for the whole IoT Agent, and there is no option of having both modes simultaneously
running. Transitions from one mode to the other should be made with care, and may involve data migration.

#### Registration

Whenever a device is registered, the IoT Agent reads the device's entity information from the request or, if that
Expand Down
6 changes: 0 additions & 6 deletions lib/commonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ function processEnvironmentVariables() {
'IOTA_MONGO_RETRIES',
'IOTA_MONGO_USER',
'IOTA_MONGO_RETRY_TIME',
'IOTA_SINGLE_MODE',
'IOTA_POLLING_EXPIRATION',
'IOTA_POLLING_DAEMON_FREQ',
'IOTA_MULTI_CORE',
Expand Down Expand Up @@ -444,11 +443,6 @@ function processEnvironmentVariables() {
}
}

// Other configuration properties
if (process.env.IOTA_SINGLE_MODE) {
config.singleConfigurationMode = process.env.IOTA_SINGLE_MODE === 'true';
}

if (process.env.IOTA_POLLING_EXPIRATION) {
config.pollingExpiration = process.env.IOTA_POLLING_EXPIRATION;
}
Expand Down
25 changes: 10 additions & 15 deletions lib/services/devices/deviceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ function mergeDeviceWithConfiguration(fields, defaults, deviceData, configuratio
}

/**
* Find the configuration group belonging to a given device, with a different criteria depending on whether the
* agent is in single configuration mode or node.
* Find the configuration group belonging to a given device
*
* @param {Object} deviceObj Device data.
*/
Expand All @@ -206,19 +205,15 @@ function findConfigurationGroup(deviceObj, callback) {
callback(null, effectiveGroup);
}

if (config.getConfig().singleConfigurationMode === true) {
config.getGroupRegistry().find(deviceObj.service, deviceObj.subservice, handlerGroupFind);
} else {
config
.getGroupRegistry()
.findTypeSilently(
deviceObj.service,
deviceObj.subservice,
deviceObj.type,
deviceObj.apikey,
handlerGroupFindByType
);
}
config
.getGroupRegistry()
.findTypeSilently(
deviceObj.service,
deviceObj.subservice,
deviceObj.type,
deviceObj.apikey,
handlerGroupFindByType
);
}

/**
Expand Down
25 changes: 0 additions & 25 deletions lib/services/groups/groupRegistryMemory.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ let registeredGroups = {};
const logger = require('logops');
const intoTrans = require('../common/domain').intoTrans;
const errors = require('../../errors');
const config = require('../../commonConfig');
const _ = require('underscore');
const context = {
op: 'IoTAgentNGSI.InMemoryGroupRegister'
Expand Down Expand Up @@ -131,31 +130,7 @@ function clear(callback) {
callback();
}

function findSingleConfigurationMode(service, subservice, callback) {
let result;

for (const i in registeredGroups) {
if (
registeredGroups.hasOwnProperty(i) &&
registeredGroups[i].service === service &&
registeredGroups[i].subservice === subservice
) {
result = registeredGroups[i];
break;
}
}

if (result) {
callback(null, result);
} else {
callback(new errors.DeviceGroupNotFound(service, subservice));
}
}

function find(service, subservice, callback) {
if (config.getConfig().singleConfigurationMode === true) {
return findSingleConfigurationMode(service, subservice, callback);
}
const result = [];

for (const i in registeredGroups) {
Expand Down
17 changes: 3 additions & 14 deletions lib/services/groups/groupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ function validateGroup(group, callback) {
config.getGroupRegistry().getSilently(group.resource, group.apikey, generateDuplicateHandler(innerCb));
}

function checkServiceAndSubservice(innerCb) {
config.getGroupRegistry().find(group.service, group.subservice, generateDuplicateHandler(innerCb));
}

function checkMandatoryParams(innerCb) {
if (!group.service) {
innerCb(new errors.MissingConfigParams(['service']));
Expand All @@ -74,22 +70,15 @@ function validateGroup(group, callback) {
return;
}

if (config.getConfig().singleConfigurationMode === false) {
if (!group.type) {
innerCb(new errors.MissingConfigParams(['type']));
return;
}
if (!group.type) {
innerCb(new errors.MissingConfigParams(['type']));
return;
}

innerCb();
}

validations.push(checkApiKeyAndResource);

if (config.getConfig().singleConfigurationMode === true) {
validations.push(checkServiceAndSubservice);
}

validations.push(checkMandatoryParams);

async.series(validations, callback);
Expand Down
Loading

0 comments on commit 14d065c

Please sign in to comment.