Skip to content

Commit a6c8b03

Browse files
authored
Merge pull request #524 from telefonicaid/bug/fixAlamRaisedWithNull
Capture MongoDB connection events
2 parents 637c2b7 + 9f201fa commit a6c8b03

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

CHANGES_NEXT_RELEASE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
- FIX Missing operations manual (#485)
2424
- ADD a mechanism to share constants and error definitions between IoTAs (#386)
2525
- Alarm raises with null error (#521)
26+
- Capture mongo Connection Errors

lib/model/dbConn.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
var mongoose = require('mongoose'),
3131
config = require('../commonConfig'),
3232
constants = require('../constants'),
33+
alarms = require('../services/common/alarmManagement'),
3334
logger = require('logops'),
3435
async = require('async'),
3536
errors = require('../errors'),
@@ -111,6 +112,33 @@ function init(host, db, port, username, password, options, callback) {
111112
lastError = error;
112113
} else {
113114
defaultDb = candidateDb;
115+
116+
defaultDb.on('error', function(error) {
117+
alarms.raise(constants.MONGO_ALARM, error);
118+
119+
logger.error(context, 'Mongo Driver error: %j', error);
120+
});
121+
defaultDb.on('connecting', function(error) {
122+
logger.debug(context, 'Mongo Driver connecting');
123+
});
124+
defaultDb.on('connected', function() {
125+
logger.debug(context, 'Mongo Driver connected');
126+
});
127+
defaultDb.on('reconnected', function() {
128+
logger.debug(context, 'Mongo Driver reconnected');
129+
});
130+
defaultDb.on('disconnected', function() {
131+
logger.debug(context, 'Mongo Driver disconnected');
132+
});
133+
defaultDb.on('disconnecting', function() {
134+
logger.debug(context, 'Mongo Driver disconnecting');
135+
});
136+
defaultDb.on('open', function() {
137+
logger.debug(context, 'Mongo Driver open');
138+
});
139+
defaultDb.on('close', function() {
140+
logger.debug(context, 'Mongo Driver close');
141+
});
114142
}
115143

116144
callback();

lib/services/common/iotManagerService.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,17 @@ function register(callback) {
123123
getServices,
124124
sendRegistration,
125125
handleRegistration
126-
], callback);
126+
], function registerHandler(error) {
127+
if (error) {
128+
logger.error(context, 'Error connecting to IoT Manager: %j', error);
129+
130+
alarms.raise(constants.IOTAM_ALARM, 'Unknown error connecting with the IoTAM');
131+
132+
callback(error);
133+
} else {
134+
callback();
135+
}
136+
});
127137
} else {
128138
callback();
129139
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"jison": "0.4.17",
4040
"express": "^4.11.2",
4141
"logops": "1.0.0",
42-
"mongoose": "^4.1.5",
42+
"mongoose": "4.6.8",
4343
"mu2": "^0.5.20",
4444
"mustache": "0.8.2",
4545
"node-uuid": "^1.4.1",

0 commit comments

Comments
 (0)