Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
replace parseint with math.round, fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mzmssg committed Dec 10, 2018
1 parent 42c17db commit 9714940
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 39 deletions.
5 changes: 3 additions & 2 deletions src/rest-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@
"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",
"nock": "~9.1.6",
"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 ..",
Expand Down
18 changes: 9 additions & 9 deletions src/rest-server/src/models/vc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -247,7 +248,6 @@ class VirtualCluster {

activeVc(vcName, callback) {
this.getVcList((vcList, err) => {
logger.debug(err);
if (err) {
return callback(err);
} else if (!vcList) {
Expand All @@ -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);
Expand Down
80 changes: 52 additions & 28 deletions src/rest-server/test/jobSubmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
]
},
Expand Down Expand Up @@ -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,
}
]
},
Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/rest-server/test/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
]
},
Expand Down Expand Up @@ -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,
}
]
},
Expand Down

0 comments on commit 9714940

Please sign in to comment.