Commit c3a72367 authored by Ahmad Siavashi's avatar Ahmad Siavashi

Add isGpuEquipped method to GpuHost

parent 4f096fa3
...@@ -72,11 +72,11 @@ public class GpuHost extends Host { ...@@ -72,11 +72,11 @@ public class GpuHost extends Host {
} }
return smallerTime; return smallerTime;
} }
@Override @Override
public boolean isSuitableForVm(Vm vm) { public boolean isSuitableForVm(Vm vm) {
boolean result = vmCreate(vm); boolean result = vmCreate(vm);
if(result) { if (result) {
vmDestroy(vm); vmDestroy(vm);
} }
return result; return result;
...@@ -103,7 +103,7 @@ public class GpuHost extends Host { ...@@ -103,7 +103,7 @@ public class GpuHost extends Host {
* @return * @return
*/ */
public boolean hasVideoCard(int videoCardId) { public boolean hasVideoCard(int videoCardId) {
if (getVideoCardAllocationPolicy() == null || getVideoCardAllocationPolicy().getVideoCards().isEmpty()) { if (!isGpuEquipped()) {
return false; return false;
} }
for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) { for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) {
...@@ -121,7 +121,7 @@ public class GpuHost extends Host { ...@@ -121,7 +121,7 @@ public class GpuHost extends Host {
* @return * @return
*/ */
public boolean hasPgpu(int pgpuId) { public boolean hasPgpu(int pgpuId) {
if (getVideoCardAllocationPolicy() == null || getVideoCardAllocationPolicy().getVideoCards().isEmpty()) { if (!isGpuEquipped()) {
return false; return false;
} }
for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) { for (VideoCard videoCard : getVideoCardAllocationPolicy().getVideoCards()) {
...@@ -134,6 +134,10 @@ public class GpuHost extends Host { ...@@ -134,6 +134,10 @@ public class GpuHost extends Host {
return false; return false;
} }
public boolean isGpuEquipped() {
return getVideoCardAllocationPolicy() != null && !getVideoCardAllocationPolicy().getVideoCards().isEmpty();
}
public void vgpuDestroy(Vgpu vgpu) { public void vgpuDestroy(Vgpu vgpu) {
if (vgpu != null) { if (vgpu != null) {
getVideoCardAllocationPolicy().deallocate(vgpu); getVideoCardAllocationPolicy().deallocate(vgpu);
...@@ -163,9 +167,7 @@ public class GpuHost extends Host { ...@@ -163,9 +167,7 @@ public class GpuHost extends Host {
} }
public Set<Vgpu> getVgpuSet() { public Set<Vgpu> getVgpuSet() {
if (getVideoCardAllocationPolicy() == null) { if (!isGpuEquipped()) {
return null;
} else if (getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
return null; return null;
} }
return getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet(); return getVideoCardAllocationPolicy().getVgpuVideoCardMap().keySet();
......
...@@ -149,8 +149,7 @@ public abstract class GpuVmAllocationPolicy extends VmAllocationPolicy { ...@@ -149,8 +149,7 @@ public abstract class GpuVmAllocationPolicy extends VmAllocationPolicy {
protected void setGpuHostList(List<GpuHost> gpuHostList) { protected void setGpuHostList(List<GpuHost> gpuHostList) {
this.gpuHostList = new ArrayList<GpuHost>(); this.gpuHostList = new ArrayList<GpuHost>();
for (GpuHost host : gpuHostList) { for (GpuHost host : gpuHostList) {
if (host.getVideoCardAllocationPolicy() != null if (host.isGpuEquipped()) {
&& !host.getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
getGpuHostList().add(host); getGpuHostList().add(host);
} }
} }
......
...@@ -43,8 +43,7 @@ public class GridGpuVmAllocationPolicyBestFit extends GpuVmAllocationPolicy { ...@@ -43,8 +43,7 @@ public class GridGpuVmAllocationPolicyBestFit extends GpuVmAllocationPolicy {
// Create nonGpuHost list // Create nonGpuHost list
for (Host host : list) { for (Host host : list) {
GpuHost pm = (GpuHost) host; GpuHost pm = (GpuHost) host;
if (pm.getVideoCardAllocationPolicy() == null if (!pm.isGpuEquipped()) {
|| pm.getVideoCardAllocationPolicy().getVideoCards().isEmpty()) {
nonGpuHostList.add(pm); nonGpuHostList.add(pm);
} }
} }
......
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