]> git.somenet.org - pub/jan/lsdc.git/blob - src/at/ac/tuwien/lsdc/management/MachineManager.java
start MachineManager from Scheduler, add more logging info
[pub/jan/lsdc.git] / src / at / ac / tuwien / lsdc / management / MachineManager.java
1 package at.ac.tuwien.lsdc.management;
2
3 import java.util.HashMap;
4
5 import at.ac.tuwien.lsdc.types.PhysicalMachine;
6
7 public class MachineManager {
8         // this class is responsible to start and stop PMs & VMs
9         // also it will be used to put an application on a VM
10         // move an application and get utilization data
11
12         private HashMap<Integer, PhysicalMachine> PMs = new HashMap<Integer, PhysicalMachine>();
13
14         public MachineManager(int numPMs) {
15                 init(numPMs);
16         }
17
18         private void init(int numPMs) {
19                 for (int i = 0; i < numPMs; i++) {
20                         PhysicalMachine pm = new PhysicalMachine();
21                         PMs.put(pm.getId(), pm);
22                 }
23         }
24
25         public double getCurrentConsumption() {
26                 double consumption = 0;
27                 for (PhysicalMachine pm : PMs.values()) {
28                         if (pm.isRunning())
29                                 consumption = consumption + pm.getConsumption();
30                 }
31                 return consumption;
32         }
33
34         public int countCurrentlyRunningPMs() {
35                 int running = 0;
36                 for (PhysicalMachine pm : PMs.values()) {
37                         if (pm.isRunning())
38                                 running++;
39                 }
40                 return running;
41         }
42         
43         public int countCurrentlyRunningVMs() {
44                 int running = 0;
45                 for (PhysicalMachine pm : PMs.values()) {
46                         if (pm.isRunning()) {
47                                 running += pm.countCurrentlyRunningVMs();
48                         }
49                 }
50                 return running;
51         }
52 }