Skip to content

Commit

Permalink
Updated logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
deepal committed Feb 18, 2015
1 parent 6c16dbb commit 841abd0
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 145 deletions.
1 change: 1 addition & 0 deletions app.js
Expand Up @@ -46,6 +46,7 @@ var zabbixLoginCallback = function(data, res) {
app.post('/login', routes.login);

app.post('/request', function(req, res){
logger.info("GET /request received !");
routes.submitAPIRequest(req, res, sessID);
});

Expand Down
1 change: 1 addition & 0 deletions config/index.js
Expand Up @@ -17,6 +17,7 @@ ERROR = {
JVIRSH_SERVICE_ERROR: 'Error communicating with JVirsh Preemption Web Service',
INTERNAL_JVIRSH_ERROR: 'Internal Error occured in JVirsh',
NOT_LOGGED_IN: 'You are not logged in !',
REST_CLIENT_ERROR: 'Error occured calling an external REST API!',
REQUEST_PRIORITY_NOT_AUTHORIZED: 'You have no previleges to specify this priority level for the request',
REQUEST_QUEUED: 'Your request cannot be currently served due to insufficient resources! It has been queued and will be served later',
SESSION_KEY_MISSING_IN_REQUEST: 'Authentication failed! Session ID is missing in the request',
Expand Down
5 changes: 4 additions & 1 deletion core/scheduler/hostFilter.js
@@ -1,6 +1,8 @@
module.exports = function (resourceRequest) {

var unitconverter = require('../util/unitConverter')();
var bunyan = require('bunyan');
var logger = bunyan.createLogger({name: APP_NAME});

var cloudstack = new (require('csclient'))({
serverURL: CLOUDSTACK.API,
Expand Down Expand Up @@ -97,7 +99,7 @@ module.exports = function (resourceRequest) {
}

else{
callback(responseInfo.error(500,"Database Error!", err));
callback(responseInfo.error(500,"Database Error!", err));
}
});
};
Expand Down Expand Up @@ -353,6 +355,7 @@ module.exports = function (resourceRequest) {

cloudstack.execute('listConfigurations', {}, function(err, result){
if(err){
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
var cloudstackCpuOPFactor = 1;
var cloudstackMemOPFactor = 1;
var cloudstackStorageOPFactor = 1;
Expand Down
4 changes: 3 additions & 1 deletion core/scheduler/migrationScheduler.js
Expand Up @@ -87,7 +87,7 @@ module.exports = function () {

Hosts.findOne({ zabbixID: candidate.hostId }).exec(function (err, hostIds) {
if(err){
logger.error(ERROR.DB_CONNECTION_ERROR);
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.DB_CONNECTION_ERROR, err));
}
else{
Expand Down Expand Up @@ -247,6 +247,7 @@ module.exports = function () {

migrations.push({
vmId : vmList[i].vmID,
instanceName: vmList[i].detailedInfo.instancename,
migrationHostId: hostMemInfo[j].hostId
});
//tempUsedMemory = tempUsedMemory + vmMemory;
Expand Down Expand Up @@ -282,6 +283,7 @@ module.exports = function () {
callback(err);
}
});
logger.info("Migrating Virtual machine "+migrationAllocation[vmIndex].instanceName+" to host "+hostIds.ipAddress+" ...");
});

}
Expand Down
8 changes: 4 additions & 4 deletions core/scheduler/preemptiveScheduler.js
Expand Up @@ -48,7 +48,7 @@ module.exports = function(){

queuedRequest.save(function (err) {
if(err){
logger.error("Database error occured while saving queued request");
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
}
else{
logger.info("Queued Request Saved In database!");
Expand Down Expand Up @@ -139,14 +139,14 @@ module.exports = function(){

preemptedJob.save(function (err) {
if(err){
logger.error("Error occured when saving preempted request in database! ");
logger.error("Error occured when saving preempted request in database!. Error: "+JSON.stringify(err));
}
else{
Allocation.remove({
'VM.InstanceName': vmIDs[index]
}, function (err) {
if(err){
logger.error('Error removing allocation from database ! ');
logger.error('Error removing allocation from database !'+". Error: "+JSON.stringify(err));
}
else{
index++;
Expand Down Expand Up @@ -195,7 +195,7 @@ module.exports = function(){

highPriorityQueuedAlloc.save(function (err) {
if(err){
logger.error("Error occured saving request in database ! Error info: "+JSON.stringify(err));
logger.error("Error occured saving request in database !. Error: "+JSON.stringify(err));
}
else{
logger.error("Queued Request Saved In database! ");
Expand Down
162 changes: 85 additions & 77 deletions core/scheduler/vmScheduler.js
Expand Up @@ -116,7 +116,7 @@ module.exports = function (zSession) {
storagetype: 'shared'
}, function (err, res) {
if(err){
logger.error(ERROR.CLOUDSTACK_ERROR);
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.CLOUDSTACK_ERROR, err));
}
else{
Expand All @@ -128,7 +128,7 @@ module.exports = function (zSession) {
callback(null);
}
else{
logger.error(ERROR.CUSTOM_ERROR("Unsupported image format!"));
logger.error(ERROR.CUSTOM_ERROR("Unsupported image format specified in Resource Allocation Request!"));
callback(response.error(200, ERROR.CUSTOM_ERROR("Unsupported image format!"), null));
}

Expand All @@ -142,7 +142,7 @@ module.exports = function (zSession) {
//list all available zones, take the first zone's id and deploy vm there (zoneid is required when deploying a VM)
cloudstack.execute('listZones', {available: true}, function (err, result) { //list available zones to allocate VM
if(err){
logger.error(ERROR.CLOUDSTACK_ERROR);
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.CLOUDSTACK_ERROR, err));
}
else{
Expand Down Expand Up @@ -175,7 +175,7 @@ module.exports = function (zSession) {
else{
cloudstack.execute('createInstanceGroup', {}, function (err, res) { //if no group specified, create a group, this is specially for the first VM of a group
if(err){
logger.error(ERROR.CLOUDSTACK_ERROR);
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.CLOUDSTACK_ERROR, err));
}
else{
Expand Down Expand Up @@ -235,88 +235,96 @@ module.exports = function (zSession) {
hypervisor: HYPERVISOR
}, function (err, res) {
if(err){
logger.error(ERROR.CLOUDSTACK_ERROR);
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.CLOUDSTACK_ERROR, err)); //if error occured in cloudstack, return the error through callback
}
else{
logger.info('VM Deployment on host '+params.hostID+' in progress ...');
//console.log("VM Deploy request is being processed\n" +
//"\tService offering ID - "+params.serviceOfferingID+"\n" +
//"\tTemplate ID - "+params.templateID+"\n" +
//"\tDisk Offering ID - "+params.diskOfferingID+"\n" +
//"\tZone ID - "+params.zoneID+"\n" +
//"\tVM Group ID - "+params.vmGroupID+"\n" +
//"\tHost ID - "+params.hostID+"\n" +
//"\tHypervisor - "+HYPERVISOR);

callback(null, res);

var jobID = res.deployvirtualmachineresponse.jobid; // get the Asynchronous JobID of VM deploy. Job ID required to get the deployed VM's ID using queryAsyncJobResult API Method

logger.info('Waiting for VM deployment to complete...');

queryAsyncJobResultRecurs(jobID, function (err, res) {
// queryAsyncJobResult method recursively check whether VM deployment is complete and if complete,
// get the jobresult object and collect information about the VM including id, memory, cpucores, cpufreq etc.
DBHost.findOne({cloudstackID: params.hostID}).exec(function (err, host) {
if(err){
logger.error("Error occured while calling queryAsyncJobResult !\nError info: "+err);
callback(500, ERROR.DB_CONNECTION_ERROR, err);
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
}
else{
if(res.errorcode){
logger.error("VM deployment failed: "+ JSON.stringify(res)); //if an error code is returned, VM deployment has been failed, log the error.
}
else{
var VMId = res.virtualmachine.id;
var VMMemory = unitConverter.convertMemoryAndStorage(res.virtualmachine.memory,'mb', 'b');
var VMCores = res.virtualmachine.cpunumber;
var VMFreq = res.virtualmachine.cpuspeed;
var InstanceName = res.virtualmachine.instancename;

DBHost.findOne({cloudstackID:params.hostID}).exec(function (err, host) {
if(err){
logger.error(ERROR.DB_CONNECTION_ERROR);
callback(response.error(500, ERROR.DB_CONNECTION_ERROR, err));
logger.info('VM Deployment on host '+host.ipAddress+' in progress ...');
//console.log("VM Deploy request is being processed\n" +
//"\tService offering ID - "+params.serviceOfferingID+"\n" +
//"\tTemplate ID - "+params.templateID+"\n" +
//"\tDisk Offering ID - "+params.diskOfferingID+"\n" +
//"\tZone ID - "+params.zoneID+"\n" +
//"\tVM Group ID - "+params.vmGroupID+"\n" +
//"\tHost ID - "+params.hostID+"\n" +
//"\tHypervisor - "+HYPERVISOR);

callback(null, res);

var jobID = res.deployvirtualmachineresponse.jobid; // get the Asynchronous JobID of VM deploy. Job ID required to get the deployed VM's ID using queryAsyncJobResult API Method

logger.info('Waiting for VM deployment to complete...');

queryAsyncJobResultRecurs(jobID, function (err, res) {
// queryAsyncJobResult method recursively check whether VM deployment is complete and if complete,
// get the jobresult object and collect information about the VM including id, memory, cpucores, cpufreq etc.
if(err){
logger.error("Error occured while calling queryAsyncJobResult !\nError info: "+err);
}
else{
if(res.errorcode){
logger.error("VM deployment failed: "+ JSON.stringify(res)); //if an error code is returned, VM deployment has been failed, log the error.
}
else{
var allocation = new Allocation({ //create new resource allocation request model to save in the database
_id: params.allocationID,
VM: {
VMID: VMId,
InstanceName: InstanceName,
HostInfo: {
CloudStackID: host.cloudstackID,
ZabbixID: host.zabbixID,
IPAddr: host.ipAddress
},
GroupID: params.vmGroupID,
Memory: VMMemory,
CPUFreq : VMFreq,
CPUCount: VMCores
},
RequestContent: {
Content: params.authorizedRequest.requestContent.group,
Session: params.authorizedRequest.session
},
AllocationInfo: {
From: Date.now(),
To: null,
TimeStamp: Date.now(),
Priority: params.authorizedRequest.requestContent.group[0].priority[0]
}
});

allocation.save(function (err) { //save allocation in database
if (err) {
logger.error("Error saving allocation in the database\nError Info: "+err);
var VMId = res.virtualmachine.id;
var VMMemory = unitConverter.convertMemoryAndStorage(res.virtualmachine.memory,'mb', 'b');
var VMCores = res.virtualmachine.cpunumber;
var VMFreq = res.virtualmachine.cpuspeed;
var InstanceName = res.virtualmachine.instancename;

DBHost.findOne({cloudstackID:params.hostID}).exec(function (err, host) {
if(err){
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.DB_CONNECTION_ERROR, err));
}
else {
logger.info("Allocation saved in database !");
else{
var allocation = new Allocation({ //create new resource allocation request model to save in the database
_id: params.allocationID,
VM: {
VMID: VMId,
InstanceName: InstanceName,
HostInfo: {
CloudStackID: host.cloudstackID,
ZabbixID: host.zabbixID,
IPAddr: host.ipAddress
},
GroupID: params.vmGroupID,
Memory: VMMemory,
CPUFreq : VMFreq,
CPUCount: VMCores
},
RequestContent: {
Content: params.authorizedRequest.requestContent.group,
Session: params.authorizedRequest.session
},
AllocationInfo: {
From: Date.now(),
To: null,
TimeStamp: Date.now(),
Priority: params.authorizedRequest.requestContent.group[0].priority[0]
}
});

allocation.save(function (err) { //save allocation in database
if (err) {
logger.error("Error saving allocation in the database\nError Info: "+err);
}
else {
logger.info("Allocation saved in database !");
}
});
}
});
}
});

}
}
}
});
}
});

Expand All @@ -339,7 +347,7 @@ module.exports = function (zSession) {
cloudstack.execute('createInstanceGroup', {name: thisAllocationId}, function (err, result) {
var vmGroupID = result.createinstancegroupresponse.instancegroup.id;
if (err) {
logger.error(ERROR.CLOUDSTACK_ERROR);
logger.error(ERROR.CLOUDSTACK_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.CLOUDSTACK_ERROR, err));
}
else {
Expand Down Expand Up @@ -384,7 +392,7 @@ module.exports = function (zSession) {

getDBHostByZabbixId(filteredHostsInfo[0].hostId, function (err, dbHost) { //to query database using zabbix host id
if(err){
logger.error(ERROR.DB_CONNECTION_ERROR);
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.DB_CONNECTION_ERROR, err));
}
else{
Expand Down Expand Up @@ -417,7 +425,7 @@ module.exports = function (zSession) {

getDBHostByZabbixId(minMemoryHostInfo.hostId, function (err, dbHost) {
if(err){
logger.error(ERROR.DB_CONNECTION_ERROR);
logger.error(ERROR.DB_CONNECTION_ERROR+". Error: "+JSON.stringify(err));
callback(response.error(500, ERROR.DB_CONNECTION_ERROR, err));
}
else{
Expand Down

0 comments on commit 841abd0

Please sign in to comment.