Commit 53e893b0 authored by rodrigo.calheiros's avatar rodrigo.calheiros

Issue #1 solved: Host now considers its available storage before accepting a VM.

parent 755f3817
...@@ -159,6 +159,11 @@ public class Host { ...@@ -159,6 +159,11 @@ public class Host {
* @post $none * @post $none
*/ */
public boolean vmCreate(Vm vm) { public boolean vmCreate(Vm vm) {
if (storage<vm.getSize()){
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by storage");
return false;
}
if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) { if (!getRamProvisioner().allocateRamForVm(vm, vm.getCurrentRequestedRam())) {
Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by RAM"); Log.printLine("Allocation of VM #" + vm.getId() + " to Host #" + getId() + " failed by RAM");
return false; return false;
...@@ -177,6 +182,7 @@ public class Host { ...@@ -177,6 +182,7 @@ public class Host {
return false; return false;
} }
storage-=vm.getSize();
getVmList().add(vm); getVmList().add(vm);
vm.setHost(this); vm.setHost(this);
return true; return true;
...@@ -195,6 +201,7 @@ public class Host { ...@@ -195,6 +201,7 @@ public class Host {
vmDeallocate(vm); vmDeallocate(vm);
getVmList().remove(vm); getVmList().remove(vm);
vm.setHost(null); vm.setHost(null);
storage+=vm.getSize();
} }
} }
...@@ -208,6 +215,7 @@ public class Host { ...@@ -208,6 +215,7 @@ public class Host {
vmDeallocateAll(); vmDeallocateAll();
for (Vm vm : getVmList()) { for (Vm vm : getVmList()) {
vm.setHost(null); vm.setHost(null);
storage+=vm.getSize();
} }
getVmList().clear(); getVmList().clear();
} }
...@@ -383,7 +391,7 @@ public class Host { ...@@ -383,7 +391,7 @@ public class Host {
* @return the machine storage * @return the machine storage
* *
* @pre $none * @pre $none
* @post $result > 0 * @post $result >= 0
*/ */
public long getStorage() { public long getStorage() {
return storage; return storage;
......
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