Skip to content
Merged
9 changes: 9 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"singleQuote": true,
"parser": "flow",
"printWidth": 120,
"trailingComma": "es5",
"tabWidth": 4
}
66 changes: 30 additions & 36 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@ var config = {};
*/
config.logLevel = 'INFO';


/**
* Configures the exposed API.
*/
config.endpoint = {
host: 'localhost',
port: 9090,
rulesPath : '/rules',
actionsPath : '/actions/do',
noticesPath : '/notices',
vrPath : '/m2m/vrules',
checkPath : '/check',
versionPath : '/version',
rulesPath: '/rules',
actionsPath: '/actions/do',
noticesPath: '/notices',
vrPath: '/m2m/vrules',
checkPath: '/check',
versionPath: '/version',
logPath: '/admin/log',
metricsPath: '/admin/metrics'
metricsPath: '/admin/metrics',
};

/**
Expand All @@ -58,38 +57,36 @@ config.isMaster = true;
*/
config.slaveDelay = 500;


/**
* DB Configuration.
*/
config.mongo = {
// The URI to use for the database connection. It supports replica set URIs.
// mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
// I.e.: 'mongodb://user:pass@host1:27017,host2:27018,host3:27019/cep?replicaSet=myrep'
url : 'mongodb://localhost:27017/cep'
url: 'mongodb://localhost:27017/cep',
};

/**
* OrionDB Configuration.
*/
config.orionDb = {
url : 'mongodb://localhost:27017/orion',
collection : 'entities',
prefix : 'orion',
batchSize: 500
url: 'mongodb://localhost:27017/orion',
collection: 'entities',
prefix: 'orion',
batchSize: 500,
};


/**
* EPL core options
*
* interval is the time in milliseconds between refreshing rules
* at core. Each <<interval>> ms, the rules are sent to core.
*/
config.perseoCore = {
rulesURL : 'http://localhost:8080/perseo-core/rules',
noticesURL : 'http://localhost:8080/perseo-core/events',
interval: 60e3*5
rulesURL: 'http://localhost:8080/perseo-core/rules',
noticesURL: 'http://localhost:8080/perseo-core/events',
interval: 60e3 * 5,
};
/**
* NEXT EPL core options (with HA)
Expand All @@ -104,37 +101,34 @@ config.nextCore = {
*/
};


/**
* SMTP endpoint options
*/
config.smtp = {
port: 25,
host: 'smtpserver',
secure: false
secure: false,
/*
,
auth: {
user: 'abc',
pass: 'xyz'
}
*/
,
tls: {
// keep rejectUnauthorized to false when secure is also false
rejectUnauthorized: false
}

// keep rejectUnauthorized to false when secure is also false
rejectUnauthorized: false,
},
};

/**
* SMS endpoint options
*/
config.sms = {
URL : 'http://sms-endpoint/smsoutbound',
API_KEY : '',
URL: 'http://sms-endpoint/smsoutbound',
API_KEY: '',
API_SECRET: '',
from: 'tel:22012;phone-context=+34'
from: 'tel:22012;phone-context=+34',
};

/**
Expand All @@ -146,14 +140,14 @@ config.smpp = {
systemid: '',
password: '',
from: '346666666',
enabled: false
enabled: false,
};

/**
* Orion (Context Broker) endpoint options
*/
config.orion = {
URL : 'http://orion-endpoint:1026/NGSI10/updateContext'
URL: 'http://orion-endpoint:1026/NGSI10/updateContext',
};

/**
Expand All @@ -163,16 +157,16 @@ config.authentication = {
host: 'keystone',
port: '5001',
user: 'user',
password: 'password'
password: 'password',
};

/**
* Collections
* @type {{}}
*/
config.collections = {
rules : 'rules',
executions: 'executions'
rules: 'rules',
executions: 'executions',
};

/**
Expand All @@ -190,8 +184,8 @@ config.executionsTTL = 1 * 24 * 60 * 60;
*
* @type {{}}
*/
config.DEFAULT_SUBSERVICE= '/';
config.DEFAULT_SERVICE= 'unknownt';
config.DEFAULT_SUBSERVICE = '/';
config.DEFAULT_SERVICE = 'unknownt';

/**
* CheckDB configuration
Expand All @@ -206,7 +200,7 @@ config.checkDB = {
delay: 5e3,
reconnectTries: 1e3,
reconnectInterval: 5e3,
bufferMaxEntries: 5
bufferMaxEntries: 5,
};

/**
Expand Down
20 changes: 10 additions & 10 deletions ghpages/javascripts/scale.fix.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
for (i = 0; i < metas.length; i++) {
if (metas[i].name == 'viewport') {
metas[i].content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0';
}
}
}
document.addEventListener("gesturestart", gestureStart, false);
document.addEventListener('gesturestart', gestureStart, false);
}
function gestureStart() {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
for (i = 0; i < metas.length; i++) {
if (metas[i].name == 'viewport') {
metas[i].content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}
}
}
}
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./lib/perseo');
module.exports = require('./lib/perseo');
1 change: 0 additions & 1 deletion lib/alarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var util = require('util'),
logger = require('logops'),
alarms = {};


function raise(alarm, context, message) {
var state = alarms[alarm];
context = (process.domain && process.domain.context) || {};
Expand Down
5 changes: 1 addition & 4 deletions lib/appContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*/
'use strict';

var
database,
orionDatabase;
var database, orionDatabase;

function SetDB(db) {
database = db;
Expand Down Expand Up @@ -67,4 +65,3 @@ module.exports.SetOrionDB = SetOrionDB;
* @return {Object} db connection
*/
module.exports.OrionDb = OrionDB;

3 changes: 1 addition & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ module.exports = {
CORRELATOR_HEADER: 'fiware-correlator',
AUTH_HEADER: 'X-Auth-Token',
REALIP_HEADER: 'X-Real-IP',
COMPONENT_NAME: 'perseo-fe'
COMPONENT_NAME: 'perseo-fe',
};

90 changes: 50 additions & 40 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ var async = require('async'),
database,
orionDb,
delay = config.checkDB.delay,
context = {comp: constants.COMPONENT_NAME, op: 'checkDB'};
context = { comp: constants.COMPONENT_NAME, op: 'checkDB' };

function pingAux(db, component, callback) {
db.command({ping: 1}, function(err, result) {
db.command({ ping: 1 }, function(err, result) {
if (err) {
alarm.raise(component, context, err.message);
}
else {
} else {
alarm.release(component, context, result);
}
return callback(err, result);
Expand All @@ -49,39 +48,43 @@ function pingAux(db, component, callback) {
function getDbAux(url, component, callback) {
var client = require('mongodb').MongoClient,
checkDbHealthFunc;
client.connect(url, {
db: {
bufferMaxEntries: config.checkDB.bufferMaxEntries,
domainsEnabled: true
client.connect(
url,
{
db: {
bufferMaxEntries: config.checkDB.bufferMaxEntries,
domainsEnabled: true,
},
server: {
reconnectTries: config.checkDB.reconnectTries,
reconnectInterval: config.checkDB.reconnectInterval,
domainsEnabled: true,
},
},
server: {
reconnectTries: config.checkDB.reconnectTries,
reconnectInterval: config.checkDB.reconnectInterval,
domainsEnabled: true
}
}, function(err, db) {
if (err) {
myutils.logErrorIf(err, 'connect', context);
return callback(err, null);
}
function(err, db) {
if (err) {
myutils.logErrorIf(err, 'connect', context);
return callback(err, null);
}

// This event is emitted only by Server topology (standalone)
// The driver has given up getting a connection, so we will die (restart perseo usually)
// and re-try from scratch.
// The ReplSet does not emit 'reconnectFailed'
db.serverConfig.on('reconnectFailed', function() {
logger.fatal('too many tries to reconnect to database, dying ...');
process.exit(-2);
});

checkDbHealthFunc = function checkDbHealth() {
pingAux(db, component, function(err, result) {
logger.debug('ping (%s) %j', component, err || result);
// This event is emitted only by Server topology (standalone)
// The driver has given up getting a connection, so we will die (restart perseo usually)
// and re-try from scratch.
// The ReplSet does not emit 'reconnectFailed'
db.serverConfig.on('reconnectFailed', function() {
logger.fatal('too many tries to reconnect to database, dying ...');
process.exit(-2);
});
};
setInterval(checkDbHealthFunc, delay);
return callback(null, db);
});

checkDbHealthFunc = function checkDbHealth() {
pingAux(db, component, function(err, result) {
logger.debug('ping (%s) %j', component, err || result);
});
};
setInterval(checkDbHealthFunc, delay);
return callback(null, db);
}
);
}
function getDb(callback) {
getDbAux(config.mongo.url, alarm.DATABASE, function cb(err, db) {
Expand All @@ -99,7 +102,7 @@ function getOrionDb(callback) {
function ensureIndex(collection, fields, callback) {
database.collection(collection, function(err, collection) {
myutils.logErrorIf(err, collection, context);
collection.ensureIndex(fields, {unique: true}, function(err, indexName) {
collection.ensureIndex(fields, { unique: true }, function(err, indexName) {
myutils.logErrorIf(err, 'ensureIndex ' + collection, context);
callback(err, indexName);
});
Expand All @@ -108,18 +111,25 @@ function ensureIndex(collection, fields, callback) {
function ensureIndexTTL(collection, fields, ttl, callback) {
database.collection(collection, function(err, collection) {
myutils.logErrorIf(err, collection);
collection.ensureIndex(fields, {expireAfterSeconds: ttl}, function(err, indexName) {
collection.ensureIndex(fields, { expireAfterSeconds: ttl }, function(err, indexName) {
myutils.logErrorIf(err, 'ensureIndex ' + collection, context);
callback(err, indexName);
});
});
}

function setUp(cbSU) {
async.parallel([
ensureIndex.bind(null, rulesCollection, {name: 1, subservice: 1, service: 1}),
ensureIndexTTL.bind(null, executionsCollection, {lastTime: 1}, config.executionsTTL)
], cbSU);
async.parallel(
[
ensureIndex.bind(null, rulesCollection, {
name: 1,
subservice: 1,
service: 1,
}),
ensureIndexTTL.bind(null, executionsCollection, { lastTime: 1 }, config.executionsTTL),
],
cbSU
);
}

function closeAux(db, callback) {
Expand Down
Loading