1 package at.ac.tuwien.lsdc.management;
3 import java.util.Collection;
4 import java.util.HashMap;
7 import at.ac.tuwien.lsdc.exception.VMsRunningException;
8 import at.ac.tuwien.lsdc.types.PhysicalMachine;
11 * This class is responsible to start and stop PMs & VMs
12 * also it will be used to put an application on a VM
13 * move an application and get utilization data
16 public class MachineManager {
18 private HashMap<Integer, PhysicalMachine> PMs = new HashMap<Integer, PhysicalMachine>();
22 public MachineManager(int maxPMs) {
28 * Start a physical machine
29 * @return the PM that was started, null if all machines already running
31 public PhysicalMachine startPhysicalMachine() {
32 if(PMs.size() < maxPMs) {
33 PhysicalMachine pm = new PhysicalMachine();
34 PMs.put(pm.getId(), pm);
42 * Stops a physical machine with the given id
43 * @param id the id of the PM to stop
44 * @throws VMsRunningException is thrown when there are still VMs running on this PM
46 public void stopPhysicalMachine(int id) throws VMsRunningException {
47 if(PMs.containsKey(id)) {
54 * Returns all running physical machines
55 * @return the currently active PMs
57 public Collection<PhysicalMachine> getPMs () {
62 * Returns the maximum number of available physical machines
63 * @return the maximum number of PMs
65 public int getMaxPMs() {
70 * Gets the total power consumption summed up from each PM
71 * @return the total power consumption
73 public double getTotalConsumption() {
74 double consumption = 0;
75 for (PhysicalMachine pm : PMs.values()) {
77 consumption = consumption + pm.getConsumption();