Commit 2a72d522 authored by Anton Beloglazov's avatar Anton Beloglazov

- Added: collecting state data for hosts and VMs

parent bd09bbc0
......@@ -46,7 +46,7 @@ public class Host {
private VmScheduler vmScheduler;
/** The vm list. */
private List<? extends Vm> vmList;
private final List<? extends Vm> vmList = new ArrayList<Vm>();
/** The pe list. */
private List<? extends Pe> peList;
......@@ -55,7 +55,7 @@ public class Host {
private boolean failed;
/** The vms migrating in. */
private List<Vm> vmsMigratingIn;
private final List<Vm> vmsMigratingIn = new ArrayList<Vm>();
/** The datacenter where the host is placed. */
private Datacenter datacenter;
......@@ -83,7 +83,6 @@ public class Host {
setVmScheduler(vmScheduler);
setPeList(peList);
setVmList(new ArrayList<Vm>());
setFailed(false);
}
......@@ -323,7 +322,7 @@ public class Host {
* @return the free pes number
*/
public int getFreePesNumber() {
return PeList.getFreePesNumber((List<Pe>) getPeList());
return PeList.getFreePesNumber(getPeList());
}
/**
......@@ -332,7 +331,7 @@ public class Host {
* @return the total mips
*/
public int getTotalMips() {
return PeList.getTotalMips((List<Pe>) getPeList());
return PeList.getTotalMips(getPeList());
}
/**
......@@ -545,16 +544,6 @@ public class Host {
return (List<T>) vmList;
}
/**
* Sets the vm list.
*
* @param <T> the generic type
* @param vmList the new vm list
*/
protected <T extends Vm> void setVmList(List<T> vmList) {
this.vmList = vmList;
}
/**
* Sets the storage.
*
......@@ -588,7 +577,7 @@ public class Host {
public boolean setFailed(String resName, boolean failed) {
// all the PEs are failed (or recovered, depending on fail)
this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), resName, getId(), failed);
PeList.setStatusFailed(getPeList(), resName, getId(), failed);
return true;
}
......@@ -602,7 +591,7 @@ public class Host {
public boolean setFailed(boolean failed) {
// all the PEs are failed (or recovered, depending on fail)
this.failed = failed;
PeList.setStatusFailed((List<Pe>) getPeList(), failed);
PeList.setStatusFailed(getPeList(), failed);
return true;
}
......@@ -617,7 +606,7 @@ public class Host {
* @post $none
*/
public boolean setPeStatus(int peId, int status) {
return PeList.setPeStatus((List<Pe>) getPeList(), peId, status);
return PeList.setPeStatus(getPeList(), peId, status);
}
/**
......@@ -629,15 +618,6 @@ public class Host {
return vmsMigratingIn;
}
/**
* Sets the vms migrating in.
*
* @param vmsMigratingIn the new vms migrating in
*/
protected void setVmsMigratingIn(List<Vm> vmsMigratingIn) {
this.vmsMigratingIn = vmsMigratingIn;
}
/**
* Gets the data center.
* @return the data center where the host runs
......
......@@ -9,9 +9,8 @@
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.lists.PeList;
......@@ -32,8 +31,8 @@ public class HostDynamicWorkload extends Host {
/** The previous utilization mips. */
private double previousUtilizationMips;
/** The under allocated mips. */
private Map<String, List<List<Double>>> underAllocatedMips;
/** The state history. */
private final List<HostStateHistoryEntry> stateHistory = new LinkedList<HostStateHistoryEntry>();
/**
* Instantiates a new host.
......@@ -55,8 +54,6 @@ public class HostDynamicWorkload extends Host {
super(id, ramProvisioner, bwProvisioner, storage, peList, vmScheduler);
setUtilizationMips(0);
setPreviousUtilizationMips(0);
setUnderAllocatedMips(new HashMap<String, List<List<Double>>>());
setVmsMigratingIn(new ArrayList<Vm>());
}
/* (non-Javadoc)
......@@ -67,6 +64,7 @@ public class HostDynamicWorkload extends Host {
double smallerTime = super.updateVmsProcessing(currentTime);
setPreviousUtilizationMips(getUtilizationMips());
setUtilizationMips(0);
double hostTotalRequestedMips = 0;
for (Vm vm : getVmList()) {
getVmScheduler().deallocatePesForVm(vm);
......@@ -97,6 +95,8 @@ public class HostDynamicWorkload extends Host {
Log.formatLine("%.2f: [Host #" + getId() + "] MIPS for VM #" + vm.getId() + " by PEs (" + getPesNumber() + " * " + getVmScheduler().getPeCapacity() + ")." + pesString, CloudSim.clock());
}
vm.addStateHistoryEntry(currentTime, totalAllocatedMips, totalRequestedMips, (vm.isInMigration() && !getVmsMigratingIn().contains(vm)));
if (getVmsMigratingIn().contains(vm)) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is being migrated to Host #" + getId(), CloudSim.clock());
} else {
......@@ -104,8 +104,6 @@ public class HostDynamicWorkload extends Host {
Log.formatLine("%.2f: [Host #" + getId() + "] Under allocated MIPS for VM #" + vm.getId() + ": %.2f", CloudSim.clock(), totalRequestedMips - totalAllocatedMips);
}
updateUnderAllocatedMips(vm, totalRequestedMips, totalAllocatedMips);
if (vm.isInMigration()) {
Log.formatLine("%.2f: [Host #" + getId() + "] VM #" + vm.getId() + " is in migration", CloudSim.clock());
totalAllocatedMips /= 0.9; // performance degradation due to migration - 10%
......@@ -113,8 +111,11 @@ public class HostDynamicWorkload extends Host {
}
setUtilizationMips(getUtilizationMips() + totalAllocatedMips);
hostTotalRequestedMips += totalRequestedMips;
}
addStateHistoryEntry(currentTime, getUtilizationMips(), hostTotalRequestedMips, (getUtilizationMips() > 0));
return smallerTime;
}
......@@ -175,29 +176,6 @@ public class HostDynamicWorkload extends Host {
return getBwProvisioner().getUsedBw();
}
/**
* Update under allocated mips.
*
* @param vm the vm
* @param requested the requested
* @param allocated the allocated
*/
protected void updateUnderAllocatedMips(Vm vm, double requested, double allocated) {
List<List<Double>> underAllocatedMipsArray;
List<Double> underAllocatedMips = new ArrayList<Double>();
underAllocatedMips.add(requested);
underAllocatedMips.add(allocated);
if (getUnderAllocatedMips().containsKey(vm.getUid())) {
underAllocatedMipsArray = getUnderAllocatedMips().get(vm.getUid());
} else {
underAllocatedMipsArray = new ArrayList<List<Double>>();
}
underAllocatedMipsArray.add(underAllocatedMips);
getUnderAllocatedMips().put(vm.getUid(), underAllocatedMipsArray);
}
/**
* Get current utilization of CPU in percentage.
*
......@@ -270,21 +248,24 @@ public class HostDynamicWorkload extends Host {
}
/**
* Gets the under allocated mips.
* Gets the state history.
*
* @return the under allocated mips
* @return the state history
*/
public Map<String, List<List<Double>>> getUnderAllocatedMips() {
return underAllocatedMips;
public List<HostStateHistoryEntry> getStateHistory() {
return stateHistory;
}
/**
* Sets the under allocated mips.
* Adds the state history entry.
*
* @param underAllocatedMips the under allocated mips
* @param time the time
* @param allocatedMips the allocated mips
* @param requestedMips the requested mips
* @param isActive the is active
*/
protected void setUnderAllocatedMips(Map<String, List<List<Double>>> underAllocatedMips) {
this.underAllocatedMips = underAllocatedMips;
public void addStateHistoryEntry(double time, double allocatedMips, double requestedMips, boolean isActive) {
getStateHistory().add(new HostStateHistoryEntry(time, allocatedMips, requestedMips, isActive));
}
}
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2011, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
/**
* The Class HostStateHistoryEntry.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.1.2
*/
public class HostStateHistoryEntry {
/** The time. */
private double time;
/** The allocated mips. */
private double allocatedMips;
/** The requested mips. */
private double requestedMips;
/** The is active. */
private boolean isActive;
/**
* Instantiates a new vm mips allocation history entry.
*
* @param time the time
* @param allocatedMips the allocated mips
* @param requestedMips the requested mips
* @param isActive the is active
*/
public HostStateHistoryEntry(double time, double allocatedMips, double requestedMips, boolean isActive) {
setTime(time);
setAllocatedMips(allocatedMips);
setRequestedMips(requestedMips);
setActive(isActive);
}
/**
* Sets the time.
*
* @param time the new time
*/
protected void setTime(double time) {
this.time = time;
}
/**
* Gets the time.
*
* @return the time
*/
public double getTime() {
return time;
}
/**
* Sets the allocated mips.
*
* @param allocatedMips the new allocated mips
*/
protected void setAllocatedMips(double allocatedMips) {
this.allocatedMips = allocatedMips;
}
/**
* Gets the allocated mips.
*
* @return the allocated mips
*/
public double getAllocatedMips() {
return allocatedMips;
}
/**
* Sets the requested mips.
*
* @param requestedMips the new requested mips
*/
protected void setRequestedMips(double requestedMips) {
this.requestedMips = requestedMips;
}
/**
* Gets the requested mips.
*
* @return the requested mips
*/
public double getRequestedMips() {
return requestedMips;
}
/**
* Sets the active.
*
* @param isActive the new active
*/
public void setActive(boolean isActive) {
this.isActive = isActive;
}
/**
* Checks if is active.
*
* @return true, if is active
*/
public boolean isActive() {
return isActive;
}
}
......@@ -9,6 +9,7 @@
package org.cloudbus.cloudsim;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
......@@ -29,6 +30,7 @@ public class Vm {
/** The user id. */
private int userId;
/** The uid. */
private String uid;
/** The size. */
......@@ -73,20 +75,21 @@ public class Vm {
/** The recently created. */
private boolean recentlyCreated;
/** The mips allocation history. */
private final List<VmStateHistoryEntry> stateHistory = new LinkedList<VmStateHistoryEntry>();
/**
* Creates a new VMCharacteristics object.
*
* @param id unique ID of the VM
* @param userId ID of the VM's owner
* @param size amount of storage
* @param mips the mips
* @param pesNumber amount of CPUs
* @param ram amount of ram
* @param bw amount of bandwidth
* @param pesNumber amount of CPUs
* @param size amount of storage
* @param vmm virtual machine monitor
* @param cloudletScheduler cloudletScheduler policy for cloudlets
* @param priority the priority
* @param mips the mips
*
* @pre id >= 0
* @pre userId >= 0
* @pre size > 0
......@@ -235,6 +238,11 @@ public class Vm {
return getTotalUtilizationOfCpu(time) * getMips();
}
/**
* Sets the uid.
*
* @param uid the new uid
*/
public void setUid(String uid) {
this.uid = uid;
}
......@@ -576,4 +584,25 @@ public class Vm {
this.recentlyCreated = recentlyCreated;
}
/**
* Gets the state history.
*
* @return the state history
*/
public List<VmStateHistoryEntry> getStateHistory() {
return stateHistory;
}
/**
* Adds the state history entry.
*
* @param time the time
* @param allocatedMips the allocated mips
* @param requestedMips the requested mips
* @param isInMigration the is in migration
*/
public void addStateHistoryEntry(double time, double allocatedMips, double requestedMips, boolean isInMigration) {
getStateHistory().add(new VmStateHistoryEntry(time, allocatedMips, requestedMips, isInMigration));
}
}
/*
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation of Clouds
* Licence: GPL - http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2009-2011, The University of Melbourne, Australia
*/
package org.cloudbus.cloudsim;
/**
* The Class VmMipsAllocationHistoryEntry.
*
* @author Anton Beloglazov
* @since CloudSim Toolkit 2.1.2
*/
public class VmStateHistoryEntry {
/** The time. */
private double time;
/** The allocated mips. */
private double allocatedMips;
/** The requested mips. */
private double requestedMips;
/** The is in migration. */
private boolean isInMigration;
/**
* Instantiates a new vm mips allocation history entry.
*
* @param time the time
* @param allocatedMips the allocated mips
* @param requestedMips the requested mips
* @param isInMigration the is in migration
*/
public VmStateHistoryEntry(double time, double allocatedMips, double requestedMips, boolean isInMigration) {
setTime(time);
setAllocatedMips(allocatedMips);
setRequestedMips(requestedMips);
setInMigration(isInMigration);
}
/**
* Sets the time.
*
* @param time the new time
*/
protected void setTime(double time) {
this.time = time;
}
/**
* Gets the time.
*
* @return the time
*/
public double getTime() {
return time;
}
/**
* Sets the allocated mips.
*
* @param allocatedMips the new allocated mips
*/
protected void setAllocatedMips(double allocatedMips) {
this.allocatedMips = allocatedMips;
}
/**
* Gets the allocated mips.
*
* @return the allocated mips
*/
public double getAllocatedMips() {
return allocatedMips;
}
/**
* Sets the requested mips.
*
* @param requestedMips the new requested mips
*/
protected void setRequestedMips(double requestedMips) {
this.requestedMips = requestedMips;
}
/**
* Gets the requested mips.
*
* @return the requested mips
*/
public double getRequestedMips() {
return requestedMips;
}
/**
* Sets the in migration.
*
* @param isInMigration the new in migration
*/
protected void setInMigration(boolean isInMigration) {
this.isInMigration = isInMigration;
}
/**
* Checks if is in migration.
*
* @return true, if is in migration
*/
public boolean isInMigration() {
return isInMigration;
}
}
......@@ -8,11 +8,8 @@
package org.cloudbus.cloudsim.power;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
......@@ -240,25 +237,6 @@ public class PowerDatacenter extends Datacenter {
return result;
}
/**
* Gets the under allocated mips.
*
* @return the under allocated mips
*/
public Map<String, List<List<Double>>> getUnderAllocatedMips() {
Map<String, List<List<Double>>> underAllocatedMips = new HashMap<String, List<List<Double>>>();
for (PowerHost host : this.<PowerHost>getHostList()) {
for (Entry<String, List<List<Double>>> entry : host.getUnderAllocatedMips().entrySet()) {
if (!underAllocatedMips.containsKey(entry.getKey())) {
underAllocatedMips.put(entry.getKey(), new ArrayList<List<Double>>());
}
underAllocatedMips.get(entry.getKey()).addAll(entry.getValue());
}
}
return underAllocatedMips;
}
/**
* Checks if is disable migrations.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment