Skip to content

Commit

Permalink
Merge branch 'dev-operations' of github.com:nishant-jain-94/sro-ontol…
Browse files Browse the repository at this point in the history
…ogy-manager into dev-operations
  • Loading branch information
nishant-jain-94 committed Sep 1, 2017
2 parents f907454 + dede5bf commit d2a8264
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 13 deletions.
6 changes: 6 additions & 0 deletions meta-api/bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ app.set('port', port);

var server = http.createServer(app);

/**
* Turning the http connection to a websocket connection
* by attaching the socket.io server to http server
*/

var io = app.io;
io.attach(server);

/**
* Listen on provided port, on all network interfaces.
*/
Expand Down
12 changes: 12 additions & 0 deletions meta-api/config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// # Configuration and Settings

// ## config.js

// This file stores the configuration details like username, password
// of RabbitMQ, Neo4j etc.

//Declaring a config object
var config = {};

// Assigning values to some constants
const AMQP_HTTP_URL = process.env.AMQP_HTTP_URL || 'http://localhost:15672';
const NEO4J_HTTP_URL = process.env.NEO4J_HTTP_URL || 'http://localhost:7474';

// RabbitMQ Configuration
config.rabbitMQconfig = {
auth: {
"auth": {
Expand All @@ -13,6 +23,7 @@ config.rabbitMQconfig = {
url: `${AMQP_HTTP_URL}/api/`
};

// Neo4j Configuration
config.neo4jconfig = {
auth: {
"auth": {
Expand All @@ -23,4 +34,5 @@ config.neo4jconfig = {
url: `${NEO4J_HTTP_URL}/db/manage/`
};

// Exporting the config object
module.exports = config;
19 changes: 16 additions & 3 deletions meta-api/neo4j/neo4j.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var request = require('request');
// # Neo4j Conttroller

var controller = {};
// ## neo4j.controller.js

// The controller methods which are used by routes and sockets
// to fetch data from Neo4j HTTP API endpoints

// Imports the required dependencies
var request = require('request');
var config = require('../config');

//Declaring a controller object
var controller = {};

// `getNeo4jStatus` Get the health status of Neo4j by making an API
// call to the running instance of Neo4j
controller.getNeo4jStatus = (cb) => {

request.get( config.neo4jconfig.url, config.neo4jconfig.auth, (err, response) => {
Expand All @@ -16,7 +26,9 @@ controller.getNeo4jStatus = (cb) => {
});

}


// `getNeo4jData` Get the data about the number of nodes, relationships etc
// by making an API call to the running instance of Neo4j
controller.getNeo4jData = (cb) => {

const urlString = 'server/jmx/domain/org.neo4j/instance%3Dkernel%230%2Cname%3DPrimitive%20count?_=1342719685294';
Expand All @@ -32,4 +44,5 @@ controller.getNeo4jData = (cb) => {

}

// Exports the Neo4j controller object containing the methods
module.exports = controller;
17 changes: 16 additions & 1 deletion meta-api/neo4j/neo4j.io.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
const neo4jController = require('./neo4j.controller');
// # Neo4j Socket methods

// ## neo4j.io.js

// The socket methods that emit the data returned by the controller
// at regular intervals (at an interval of 5 seconds).


// Importing the Neo4j Controller methods
const neo4jController = require('./neo4j.controller');

// Listening for an incoming socket connection request upon which
// the socket methods are called
const neo4jio = (io) => {
io.on('connection', (socket) => {
console.log('neo4j connected');
Expand All @@ -9,6 +19,8 @@ const neo4jio = (io) => {
});
};

// `fetchNeo4jHealthStatus` Socket method that emits the Health Status of Neo4j
// every five seconds. If Neo4j instance is not running it emits a default value.
const fetchNeo4jHealthStatus = (socket) => {
setInterval(() => {
neo4jController.getNeo4jStatus((err, data) => {
Expand All @@ -19,6 +31,8 @@ const fetchNeo4jHealthStatus = (socket) => {
}, 5000);
};

// `fetchNeo4jData` Socket method that emits Neo4j data
// every five seconds
const fetchNeo4jData = (socket) => {
setInterval(() => {
neo4jController.getNeo4jData((err, data) => {
Expand All @@ -27,4 +41,5 @@ const fetchNeo4jData = (socket) => {
}, 5000);
}

// Exporting the neo4jio socket method
module.exports = neo4jio;
12 changes: 12 additions & 0 deletions meta-api/neo4j/neo4j.routes.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
// # Neo4j Router

// ## neo4j.routes.js

// The routes ued for API endpoints for Neo4j

// Imports the required dependencies
var express = require('express');
var router = express.Router();
var neo4jController = require('./neo4j.controller');

// GET `neo4jHealthStatus`
// To get the health status of Neo4j
router.get('/neo4jHealthStatus', function (req, res, next) {
neo4jController.getNeo4jStatus((err, data) => {
if(!err) res.json(data);
else next(err);
});
});

// GET `neo4jData`
// To get Neo4j data like number of nodes and number of relationships
router.get('/neo4jData', function (req, res, next) {
neo4jController.getNeo4jData((err, data) => {
if(!err) res.json(data);
else next(err);
});
});

// Exporting the router
module.exports = router;
21 changes: 19 additions & 2 deletions meta-api/rabbitmq/rabbitmq.controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
var request = require('request');
// # RabbitMQ Conttroller

var controller = {};
// ## rabbitmq.controller.js

// The controller methods which are used by routes and sockets
// to fetch data from RabbitMQ HTTP API endpoints

// Imports the required dependencies
var request = require('request');
var config = require('../config');

//Declaring a controller object
var controller = {};

// `getNoOfQueues` Get the number of queues by making an API call
// to the running instance of RabbitMQ
controller.getNoOfQueues = (cb) => {

request.get( config.rabbitMQconfig.url + 'queues', config.rabbitMQconfig.auth,(err, response, body) => {
Expand All @@ -17,6 +27,8 @@ controller.getNoOfQueues = (cb) => {

};

// `getHealthStatus` Get the health status of RabbitMQ by making an API
// call to the running instance of RabbitMQ
controller.getHealthStatus = (cb) => {

request.get( config.rabbitMQconfig.url + 'healthchecks/node', config.rabbitMQconfig.auth,function(err, response, body) {
Expand All @@ -30,6 +42,8 @@ controller.getHealthStatus = (cb) => {

};

// `getNoOfConsumers` Get the number of consumers by making an API
// call to the running instance of RabbitMQ
controller.getNoOfConsumers = (cb) => {

request.get( config.rabbitMQconfig.url + 'consumers', config.rabbitMQconfig.auth,function(err, response, body) {
Expand All @@ -43,6 +57,8 @@ controller.getNoOfConsumers = (cb) => {

};

// `getConsumerUtilisation` Get the consumerUtilisation of each queue and
// other related data by making an API call to the running instance of RabbitMQ
controller.getConsumerUtilisation = (cb) => {

request.get( config.rabbitMQconfig.url + 'queues', config.rabbitMQconfig.auth,(err, response, body) => {
Expand All @@ -56,4 +72,5 @@ controller.getConsumerUtilisation = (cb) => {

}

// Exports the RabbitMQ controller object containing the methods
module.exports = controller;
27 changes: 22 additions & 5 deletions meta-api/rabbitmq/rabbitmq.io.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
const rabbitmqController = require('./rabbitmq.controller');
// # RabbitMQ Socket methods

// ## rabbitmq.io.js

// The socket methods which emit the data returned by the controller
// at regular intervals (at an interval of 5 seconds).


// Importing the RabbitMQ Controller methods
const rabbitmqController = require('./rabbitmq.controller');

// Listening for an incoming socket connection request upon which
// the socket methods are called
const rabbitmqio = (io) => {
io.on('connection', (socket) => {
console.log('connected');
fetchNoOfQueuesAndEmitData(socket);
fetchNoOfQueues(socket);
fetchConsumerUtilisation(socket);
fetchHealthStatus(socket);
fetchNoOfConsumers(socket);
});
};

const fetchNoOfQueuesAndEmitData = (socket) => {
// `fetchNoOfQueuesAndEmitData` Socket method that emits the number of queues data
// of RabbitMQ every 5 seconds. If RabbitMQ instance is not running then it emits a default value.
const fetchNoOfQueues = (socket) => {
setInterval(() => {
rabbitmqController.getNoOfQueues((err, data) => {
let defaultValue = { count: 0 };
Expand All @@ -21,6 +33,8 @@ const fetchNoOfQueuesAndEmitData = (socket) => {
}, 5000);
};

// `fetchConsumerUtilisation` Socket method that emits the number of queues data
// of RabbitMQ every 5 seconds. If RabbitMQ instance is not running then it emits an empty value.
const fetchConsumerUtilisation = (socket) => {
setInterval(() => {
rabbitmqController.getConsumerUtilisation((err, data) => {
Expand All @@ -30,6 +44,8 @@ const fetchConsumerUtilisation = (socket) => {
}, 5000);
};

// `fetchHealthStatus` Socket method that emits the Health Status of RabbitMQ
// every five seconds. If RabbitMQ instance is not running then it emits a default value.
const fetchHealthStatus = (socket) => {
setInterval(() => {
rabbitmqController.getHealthStatus((err, data) => {
Expand All @@ -40,6 +56,8 @@ const fetchHealthStatus = (socket) => {
}, 5000);
};

// `fetchNoOfConsumers` Socket method that emits the number of consumers data
// from RabbitMQ every five seconds. If RabbitMQ is not running then it emits a default value.
const fetchNoOfConsumers = (socket) => {
setInterval(() => {
rabbitmqController.getNoOfConsumers((err, data) => {
Expand All @@ -50,6 +68,5 @@ const fetchNoOfConsumers = (socket) => {
}, 5000);
};



// Exporting the rabbitmqio socket method
module.exports = rabbitmqio;
20 changes: 18 additions & 2 deletions meta-api/rabbitmq/rabbitmq.routes.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
// # RabbitMQ Router

// ## rabbitmq.routes.js

// The routes used for API endpoints for RabbitMQ

// Imports the required dependencies
var express = require('express');
var router = express.Router();
var rabbitmqController = require('./rabbitmq.controller');

// GET `noOfQueues`
// To get the number of queues
router.get('/noOfQueues', function (req, res, next) {
rabbitmqController.getNoOfQueues((err, data) => {
if(!err) res.json(data);
else next(err);
});
})

})

// GET `healthStatus`
// To get the health status of RabbitMQ
router.get('/healthStatus', function (req, res, next) {
rabbitmqController.getHealthStatus((err, data) => {
if(!err) res.json(data);
else next(err);
});
})

// GET `noOfConsumers`
// To get the number of consumers
router.get('/noOfConsumers', function (req, res, next) {
rabbitmqController.getNoOfConsumers((err, data) => {
if(!err) res.json(data);
else next(err);
});
});

// GET `consumerUtilisation`
// To get the consumerUtilisation and other RabbitMQ data
router.get('/consumerUtilisation', function (req, res, next) {
rabbitmqController.getConsumerUtilisation((err, data) => {
if(!err) res.json(data);
else next(err);
});
});

// Exporting the router
module.exports = router;
8 changes: 8 additions & 0 deletions meta-api/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// # Main router object file

// ## index.js

// Aggregation of all routes

// Exporting the routes as an object.
// This is imported in app.js
module.exports = {
neo4j: require('../neo4j/neo4j.routes'),
rabbitmq: require('../rabbitmq/rabbitmq.routes')
Expand Down

0 comments on commit d2a8264

Please sign in to comment.