-
Notifications
You must be signed in to change notification settings - Fork 0
/
job-scheduling.js
84 lines (79 loc) · 2.8 KB
/
job-scheduling.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { vmDetails } from './vm-details.js';
import { populateVMWeights } from './vm-resources.js';
import servers from './servers.json' assert {type: 'json'}
import task from './task.json' assert {type: 'json'}
import { serverDetails } from './server-details.js';
import { findRemainingResources, findWeight } from './server-resources.js';
export const findOptimalVm = async (task, servers) => {
try {
let task_length = task['taskLength'];
let communicationCost = task['communicationCost'];
let taskDeadline = task['taskDeadline'];
let res = { vm_id: null, weight: null };
// console.log(servers);
const Servers = servers.servers;
for (let server of Servers) {
let vms = await populateVMWeights(server);
for (let vm of vms['vms']) {
const currentTime = new Date();
const deadlineTime = new Date(taskDeadline);
// console.log(task_length);
let execTimeOfCurrTaskinMillSecond = (task_length / vm['vmMips']) + communicationCost;
// console.log(execTimeOfCurrTaskinMillSecond);
if ((deadlineTime.getTime() - currentTime.getTime()) >= execTimeOfCurrTaskinMillSecond) {
if (!res['vm_id']) {
res = vm;
}
else {
if (vm['weight'] < res['weight']) {
res = vm;
}
}
}
}
}
if (res['vm_id'])
return res;
else {
return { msg: "No optimal virtual machine found,Need scaling" };
}
}
catch (error) {
return error;
}
}
// console.log(await findOptimalVm(task, servers));
export const scaleVm = async (servers) => {
try {
const Servers = servers.servers;
let res = { vm_id: null };
for (let server of Servers) {
let vms = await populateVMWeights(server);
let remainingResources = await findRemainingResources(server);
for (let vm of vms['vms']) {
if (!res['vm_id']) {
res = vm;
}
else {
if (vm['weight'] > res['weight']) {
res = vm;
}
}
}
if (res['vm_id']) {
res['weight'] = res['weight'] + remainingResources;
}
}
if (res['vm_id']) {
return res;
}
else {
return { msg: "No optimal virtual machine can be scaled in this server " };
}
}
catch (error) {
return error;
}
}
// console.log(await populateVMWeights(servers['servers'][0]));
// console.log(await scaleVm(servers));