-
Notifications
You must be signed in to change notification settings - Fork 91
add mongo uri #1742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+89
−84
Merged
add mongo uri #1742
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
78f32cc
add mongo uri
AlvaroVega 2ecfcbe
add mongo uri env var
AlvaroVega c895c6a
fix linter
AlvaroVega 271ebd9
add IOTA_MONGO_URI to mongoVariables
AlvaroVega ba0105e
update doc and CNR
AlvaroVega 53df1be
Update lib/commonConfig.js
AlvaroVega 27e7480
Merge branch 'master' into task/add_mongo_uri
AlvaroVega ba23c0b
Apply suggestion from @fgalan
AlvaroVega e93d996
Apply suggestion from @fgalan
AlvaroVega 7fe0d06
update doc
AlvaroVega b9a3442
Merge branch 'master' into task/add_mongo_uri
AlvaroVega 3e32f66
fix word
AlvaroVega 13cae21
Revise deprecated features and MongoDB config details
fgalan 6f0ea7b
Update doc/deprecated.md
fgalan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| - Add IOTA_MONGO_URI env var | ||
| - Deprecated: IOTA_MONGO_ different from IOTA_MONGO_URI (use IOTA_MONGO_URI instead) | ||
| - Fix: broken notification command mode (it was not working without providing targetEntityId and targetEntityType in the notification, which belongs to another command mode: advancedNotification) | ||
| - Fix: use normalized in attrsFormat for commands subscriptions (#1743) | ||
| - Add: locale string number jexl function (#1737) | ||
| - Add: locale string number jexl function (#1737) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ | |
| * please contact with::[email protected] | ||
| */ | ||
|
|
||
| /** | ||
| /* | ||
| * This module sets up the connection with the mongodb through mongoose. This connection will be used | ||
| * in mongoose schemas to persist objects. | ||
| */ | ||
|
|
@@ -49,8 +49,7 @@ function loadModels() { | |
| * | ||
| * @this Reference to the dbConn module itself. | ||
| */ | ||
|
|
||
| function init(host, db, port, options, callback) { | ||
| function init(host, db, port, options, callback, fullUri = null) { | ||
| let url; | ||
| let retries = 0; | ||
| let lastError; | ||
|
|
@@ -60,21 +59,25 @@ function init(host, db, port, options, callback) { | |
| return `${item}:${port}`; | ||
| } | ||
|
|
||
| url = 'mongodb://'; | ||
| if (fullUri) { | ||
| url = fullUri; | ||
| } else { | ||
| url = 'mongodb://'; | ||
|
|
||
| if (options.auth) { | ||
| url += `${encodeURIComponent(options.auth.user)}:${encodeURIComponent(options.auth.password)}@`; | ||
| } | ||
| if (options.auth) { | ||
| url += `${encodeURIComponent(options.auth.user)}:${encodeURIComponent(options.auth.password)}@`; | ||
| } | ||
|
|
||
| const hosts = host.split(',').map(addPort).join(','); | ||
| url += `${hosts}/${db}`; | ||
| const hosts = host.split(',').map(addPort).join(','); | ||
| url += `${hosts}/${db}`; | ||
|
|
||
| if (options.extraArgs) { | ||
| const query = new URLSearchParams(options.extraArgs).toString(); | ||
| if (query) { | ||
| url += `?${query}`; | ||
| if (options.extraArgs) { | ||
| const query = new URLSearchParams(options.extraArgs).toString(); | ||
| if (query) { | ||
| url += `?${query}`; | ||
| } | ||
| delete options.extraArgs; | ||
| } | ||
| delete options.extraArgs; | ||
| } | ||
|
|
||
| function connectionAttempt(callback) { | ||
|
|
@@ -91,32 +94,17 @@ function init(host, db, port, options, callback) { | |
| lastError = error; | ||
| alarms.raise(constants.MONGO_ALARM, error); | ||
| }); | ||
| /* eslint-disable-next-line no-unused-vars */ | ||
| defaultDb.on('connecting', function (error) { | ||
| logger.debug(context, 'Mongo Driver connecting'); | ||
| }); | ||
| defaultDb.on('connected', function () { | ||
| logger.debug(context, 'Mongo Driver connected'); | ||
| }); | ||
| defaultDb.on('reconnected', function () { | ||
| logger.debug(context, 'Mongo Driver reconnected'); | ||
| }); | ||
| defaultDb.on('disconnected', function () { | ||
| logger.debug(context, 'Mongo Driver disconnected'); | ||
| }); | ||
| defaultDb.on('reconnectFailed', function () { | ||
| defaultDb.on('connecting', () => logger.debug(context, 'Mongo Driver connecting')); | ||
| defaultDb.on('connected', () => logger.debug(context, 'Mongo Driver connected')); | ||
| defaultDb.on('reconnected', () => logger.debug(context, 'Mongo Driver reconnected')); | ||
| defaultDb.on('disconnected', () => logger.debug(context, 'Mongo Driver disconnected')); | ||
| defaultDb.on('reconnectFailed', () => { | ||
| logger.error(context, 'MONGODB-004: MongoDB connection was lost'); | ||
| process.exit(1); | ||
| }); | ||
| defaultDb.on('disconnecting', function () { | ||
| logger.debug(context, 'Mongo Driver disconnecting'); | ||
| }); | ||
| defaultDb.on('open', function () { | ||
| logger.debug(context, 'Mongo Driver open'); | ||
| }); | ||
| defaultDb.on('close', function () { | ||
| logger.debug(context, 'Mongo Driver close'); | ||
| }); | ||
| defaultDb.on('disconnecting', () => logger.debug(context, 'Mongo Driver disconnecting')); | ||
| defaultDb.on('open', () => logger.debug(context, 'Mongo Driver open')); | ||
| defaultDb.on('close', () => logger.debug(context, 'Mongo Driver close')); | ||
| callback(); | ||
| }) | ||
| .catch((err) => { | ||
|
|
@@ -144,34 +132,45 @@ function init(host, db, port, options, callback) { | |
|
|
||
| function configureDb(callback) { | ||
| const currentConfig = config.getConfig(); | ||
|
|
||
| if (currentConfig.deviceRegistry?.type === 'mongodb') { | ||
| if (!currentConfig.mongodb?.host) { | ||
| logger.fatal(context, 'MONGODB-003: No host found for MongoDB driver.'); | ||
| callback(new errors.BadConfiguration('No host found for MongoDB driver')); | ||
| } else { | ||
| const dbName = currentConfig.mongodb.db || DEFAULT_DB_NAME; | ||
| const port = currentConfig.mongodb.port || 27017; | ||
| const mongoCfg = currentConfig.mongodb; | ||
|
|
||
| if (mongoCfg?.uri) { | ||
| const options = {}; | ||
| logger.info(context, `Using full MongoDB URI from configuration`); | ||
| init(null, null, null, options, callback, mongoCfg.uri); | ||
| return; | ||
| } | ||
|
|
||
| if (currentConfig.mongodb.replicaSet) options.replicaSet = currentConfig.mongodb.replicaSet; | ||
| if (currentConfig.mongodb.ssl) options.ssl = currentConfig.mongodb.ssl; | ||
| if (currentConfig.mongodb.extraArgs) options.extraArgs = currentConfig.mongodb.extraArgs; | ||
| if (!mongoCfg?.host) { | ||
| logger.fatal(context, 'MONGODB-003: No host found for MongoDB driver.'); | ||
| callback(new errors.BadConfiguration('No host found for MongoDB driver')); | ||
| return; | ||
| } | ||
|
|
||
| if (currentConfig.mongodb.user && currentConfig.mongodb.password) { | ||
| options.auth = { | ||
| user: currentConfig.mongodb.user, | ||
| password: currentConfig.mongodb.password | ||
| const dbName = mongoCfg.db || DEFAULT_DB_NAME; | ||
| const port = mongoCfg.port || 27017; | ||
| const options = {}; | ||
|
|
||
| if (mongoCfg.replicaSet) options.replicaSet = mongoCfg.replicaSet; | ||
| if (mongoCfg.ssl) options.ssl = mongoCfg.ssl; | ||
| if (mongoCfg.extraArgs) options.extraArgs = mongoCfg.extraArgs; | ||
|
|
||
| if (mongoCfg.user && mongoCfg.password) { | ||
| options.auth = { | ||
| user: mongoCfg.user, | ||
| password: mongoCfg.password | ||
| }; | ||
| if (mongoCfg.authSource) { | ||
| options.extraArgs = { | ||
| ...options.extraArgs, | ||
| authSource: mongoCfg.authSource | ||
| }; | ||
| if (currentConfig.mongodb.authSource) { | ||
| options.extraArgs = { | ||
| ...options.extraArgs, | ||
| authSource: currentConfig.mongodb.authSource | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| init(currentConfig.mongodb.host, dbName, port, options, callback); | ||
| } | ||
|
|
||
| init(mongoCfg.host, dbName, port, options, callback); | ||
| } else { | ||
| callback(); | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the other IOTA_MONGO_X env var should be declared deprecated and removed from the documentation.
Similar to what we did in Orion
https://github.com/telefonicaid/fiware-orion/releases/tag/3.12.0
https://github.com/telefonicaid/fiware-orion/releases/tag/4.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in ba0105e