diff --git a/src/rest-server/package.json b/src/rest-server/package.json index a34f10bea6..ca6a70635e 100644 --- a/src/rest-server/package.json +++ b/src/rest-server/package.json @@ -42,6 +42,7 @@ "js-base64": "~2.4.8", "js-yaml": "~3.12.0", "jsonwebtoken": "~8.1.0", + "mathjs": "~5.4.0", "mocha": "~5.0.0", "morgan": "~1.9.0", "mustache": "~2.3.0", @@ -49,11 +50,11 @@ "node-cache": "~4.2.0", "node-etcd": "~5.1.0", "nyc": "~11.6.0", + "ssh-keygen": "~0.4.2", "statuses": "~1.5.0", "unirest": "~0.5.1", "winston": "~2.4.0", - "ssh-keygen": "~0.4.2", - "xml2js":"~0.4.19" + "xml2js": "~0.4.19" }, "scripts": { "coveralls": "nyc report --reporter=text-lcov | coveralls ..", diff --git a/src/rest-server/src/models/vc.js b/src/rest-server/src/models/vc.js index feeba68908..cd8afbcdcb 100644 --- a/src/rest-server/src/models/vc.js +++ b/src/rest-server/src/models/vc.js @@ -19,6 +19,7 @@ // module dependencies const unirest = require('unirest'); const xml2js = require('xml2js'); +const math = require('mathjs'); const yarnConfig = require('../config/yarn'); const createError = require('../util/error'); const logger = require('../config/logger'); @@ -31,8 +32,8 @@ class VirtualCluster { function traverse(queueInfo, queueDict) { if (queueInfo.type === 'capacitySchedulerLeafQueueInfo') { queueDict[queueInfo.queueName] = { - capacity: parseInt(queueInfo.absoluteCapacity), - maxCapacity: parseInt(queueInfo.absoluteMaxCapacity), + capacity: math.round(queueInfo.absoluteCapacity), + maxCapacity: math.round(queueInfo.absoluteMaxCapacity), usedCapacity: queueInfo.absoluteUsedCapacity, numActiveJobs: queueInfo.numActiveApplications, numJobs: queueInfo.numApplications, @@ -201,9 +202,9 @@ class VirtualCluster { } data['pendingUpdate']['default'] = defaultQuotaIfUpdated; - logger.debug('raw data to generate: ', data); + // logger.debug('raw data to generate: ', data); const vcdataXml = this.generateUpdateInfo(data); - logger.debug('Xml send to yarn: ', vcdataXml); + // logger.debug('Xml send to yarn: ', vcdataXml); this.sendUpdateInfo(vcdataXml, (err) => { if (err) { return callback(err); @@ -230,9 +231,9 @@ class VirtualCluster { let data = {'pendingStop': {}}; data['pendingStop'][vcName] = null; - logger.debug('raw data to generate: ', data); + // logger.debug('raw data to generate: ', data); const vcdataXml = this.generateUpdateInfo(data); - logger.debug('Xml send to yarn: ', vcdataXml); + // logger.debug('Xml send to yarn: ', vcdataXml); this.sendUpdateInfo(vcdataXml, (err) => { if (err) { return callback(err); @@ -247,7 +248,6 @@ class VirtualCluster { activeVc(vcName, callback) { this.getVcList((vcList, err) => { - logger.debug(err); if (err) { return callback(err); } else if (!vcList) { @@ -260,9 +260,9 @@ class VirtualCluster { let data = {'pendingActive': {}}; data['pendingActive'][vcName] = null; - logger.debug('raw data to generate: ', data); + // logger.debug('raw data to generate: ', data); const vcdataXml = this.generateUpdateInfo(data); - logger.debug('Xml send to yarn: ', vcdataXml); + // logger.debug('Xml send to yarn: ', vcdataXml); this.sendUpdateInfo(vcdataXml, (err) => { if (err) { return callback(err); diff --git a/src/rest-server/test/jobSubmission.js b/src/rest-server/test/jobSubmission.js index 1fdf854bae..b5845b2687 100644 --- a/src/rest-server/test/jobSubmission.js +++ b/src/rest-server/test/jobSubmission.js @@ -126,16 +126,24 @@ describe('Submit job: POST /api/v1/user/:username/jobs', () => { 'queueName': 'default', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "absoluteCapacity": 30.000002, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc1', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 50.000002, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc2', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 19.999996, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, } ] }, @@ -165,16 +173,24 @@ describe('Submit job: POST /api/v1/user/:username/jobs', () => { 'queueName': 'default', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "absoluteCapacity": 30.000002, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc1', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 50.000002, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc2', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 19.999996, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, } ] }, @@ -208,35 +224,43 @@ describe('Submit job: POST /api/v1/user/:username/jobs', () => { {} ); - nock(yarnUri) - .get('/ws/v1/cluster/scheduler') - .reply(200, { - 'scheduler': { - 'schedulerInfo': { - 'queues': { - 'queue': [ - { - 'queueName': 'default', - 'state': 'RUNNING', - 'type': 'capacitySchedulerLeafQueueInfo', - }, - { - 'queueName': 'vc1', - 'state': 'RUNNING', - 'type': 'capacitySchedulerLeafQueueInfo', - }, - { - 'queueName': 'vc2', - 'state': 'RUNNING', - 'type': 'capacitySchedulerLeafQueueInfo', - } - ] - }, - 'type': 'capacityScheduler', - 'usedCapacity': 0.0 - } + nock(yarnUri) + .get('/ws/v1/cluster/scheduler') + .reply(200, { + 'scheduler': { + 'schedulerInfo': { + 'queues': { + 'queue': [ + { + 'queueName': 'default', + 'state': 'RUNNING', + 'type': 'capacitySchedulerLeafQueueInfo', + "absoluteCapacity": 30.000002, + "absoluteMaxCapacity": 100, + }, + { + 'queueName': 'vc1', + 'state': 'RUNNING', + 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 50.000002, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, + }, + { + 'queueName': 'vc2', + 'state': 'RUNNING', + 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 19.999996, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, + } + ] + }, + 'type': 'capacityScheduler', + 'usedCapacity': 0.0 } - }); + } + }); // // Mock etcd return result diff --git a/src/rest-server/test/userManagement.js b/src/rest-server/test/userManagement.js index ec88f7d794..2e274476e1 100644 --- a/src/rest-server/test/userManagement.js +++ b/src/rest-server/test/userManagement.js @@ -100,16 +100,24 @@ describe('Add new user: put /api/v1/user', () => { 'queueName': 'default', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "absoluteCapacity": 30.000002, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc1', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 50.000002, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc2', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 19.999996, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, } ] }, @@ -587,16 +595,24 @@ describe('update user virtual cluster : put /api/v1/user/:username/virtualCluste 'queueName': 'default', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "absoluteCapacity": 30.000002, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc1', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 50.000002, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, }, { 'queueName': 'vc2', 'state': 'RUNNING', 'type': 'capacitySchedulerLeafQueueInfo', + "capacity": 19.999996, + "absoluteCapacity": 0, + "absoluteMaxCapacity": 100, } ] },