Skip to content

Commit

Permalink
Merge pull request #524 from telefonicaid/bug/fixAlamRaisedWithNull
Browse files Browse the repository at this point in the history
Capture MongoDB connection events
  • Loading branch information
AlvaroVega authored Nov 17, 2016
2 parents 637c2b7 + 9f201fa commit a6c8b03
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
- FIX Missing operations manual (#485)
- ADD a mechanism to share constants and error definitions between IoTAs (#386)
- Alarm raises with null error (#521)
- Capture mongo Connection Errors
28 changes: 28 additions & 0 deletions lib/model/dbConn.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
var mongoose = require('mongoose'),
config = require('../commonConfig'),
constants = require('../constants'),
alarms = require('../services/common/alarmManagement'),
logger = require('logops'),
async = require('async'),
errors = require('../errors'),
Expand Down Expand Up @@ -111,6 +112,33 @@ function init(host, db, port, username, password, options, callback) {
lastError = error;
} else {
defaultDb = candidateDb;

defaultDb.on('error', function(error) {
alarms.raise(constants.MONGO_ALARM, error);

logger.error(context, 'Mongo Driver error: %j', error);
});
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('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');
});
}

callback();
Expand Down
12 changes: 11 additions & 1 deletion lib/services/common/iotManagerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,17 @@ function register(callback) {
getServices,
sendRegistration,
handleRegistration
], callback);
], function registerHandler(error) {
if (error) {
logger.error(context, 'Error connecting to IoT Manager: %j', error);

alarms.raise(constants.IOTAM_ALARM, 'Unknown error connecting with the IoTAM');

callback(error);
} else {
callback();
}
});
} else {
callback();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"jison": "0.4.17",
"express": "^4.11.2",
"logops": "1.0.0",
"mongoose": "^4.1.5",
"mongoose": "4.6.8",
"mu2": "^0.5.20",
"mustache": "0.8.2",
"node-uuid": "^1.4.1",
Expand Down

0 comments on commit a6c8b03

Please sign in to comment.