Skip to content

Commit 667aa17

Browse files
bvbharatAbhinandan Prateek
authored andcommitted
CLOUDSTACK 711: CPU and RAM overcommit update cluster part
1 parent 54f7933 commit 667aa17

4 files changed

Lines changed: 44 additions & 9 deletions

File tree

api/src/com/cloud/resource/ResourceService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface ResourceService {
7171

7272
boolean deleteCluster(DeleteClusterCmd cmd);
7373

74-
Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio);
74+
Cluster updateCluster(Cluster cluster, String clusterType, String hypervisor, String allocationState, String managedstate,Float memoryOvercommitRatio, Float cpuOvercommitRatio);
7575

7676
List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
7777

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,15 +2921,11 @@ protected LibvirtVMDef createVMFromSpec(VirtualMachineTO vmTO) {
29212921
vm.addComp(guest);
29222922

29232923
GuestResourceDef grd = new GuestResourceDef();
2924-
//check if overcommit should be considered.
2925-
if(vmTO.getMinSpeed() == vmTO.getMaxSpeed()){
29262924

2927-
2928-
}
29292925
if (vmTO.getMinRam() != vmTO.getMaxRam()){
2930-
grd.setMemBalloning(true);
2931-
grd.setCurrentMem((int)vmTO.getMinRam()/1024);
2932-
grd.setMemorySize((int)vmTO.getMaxRam()/1024);
2926+
grd.setMemBalloning(true);
2927+
grd.setCurrentMem((int)vmTO.getMinRam()/1024);
2928+
grd.setMemorySize((int)vmTO.getMaxRam()/1024);
29332929
}
29342930
else{
29352931
grd.setMemorySize(vmTO.getMaxRam() / 1024);

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,17 @@ public List<? extends Cluster> discoverCluster(AddClusterCmd cmd)
496496

497497
_clusterDetailsDao.persist(cluster_detail_cpu);
498498
_clusterDetailsDao.persist(cluster_detail_ram);
499+
//create a new entry only if the overcommit ratios are greater than 1.
500+
if(cmd.getCpuOvercommitRatio().compareTo(1f) > 0) {
501+
cluster_detail_cpu = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", Float.toString(cmd.getCpuOvercommitRatio()));
502+
_clusterDetailsDao.persist(cluster_detail_cpu);
503+
}
504+
505+
506+
if(cmd.getMemoryOvercommitRaito().compareTo(1f) > 0) {
507+
cluster_detail_ram = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", Float.toString(cmd.getMemoryOvercommitRaito()));
508+
_clusterDetailsDao.persist(cluster_detail_ram);
509+
}
499510

500511

501512
boolean success = false;
@@ -1065,7 +1076,7 @@ public boolean deleteCluster(DeleteClusterCmd cmd) {
10651076
@Override
10661077
@DB
10671078
public Cluster updateCluster(Cluster clusterToUpdate, String clusterType,
1068-
String hypervisor, String allocationState, String managedstate, Float memoryOvercommitRaito, Float cpuOvercommitRatio) {
1079+
String hypervisor, String allocationState, String managedstate,Float memoryovercommitratio, Float cpuovercommitratio) {
10691080

10701081
ClusterVO cluster = (ClusterVO) clusterToUpdate;
10711082
// Verify cluster information and update the cluster if needed
@@ -1148,6 +1159,31 @@ public Cluster updateCluster(Cluster clusterToUpdate, String clusterType,
11481159
}
11491160
}
11501161

1162+
ClusterDetailsVO memory_detail = _clusterDetailsDao.findDetail(cluster.getId(),"memoryOvercommitRatio");
1163+
if( memory_detail == null){
1164+
if (memoryovercommitratio.compareTo(1f) > 0){
1165+
memory_detail = new ClusterDetailsVO(cluster.getId(),"memoryOvercommitRatio",Float.toString(memoryovercommitratio));
1166+
_clusterDetailsDao.persist(memory_detail);
1167+
}
1168+
}
1169+
else {
1170+
memory_detail.setValue(Float.toString(memoryovercommitratio));
1171+
_clusterDetailsDao.update(memory_detail.getId(),memory_detail);
1172+
}
1173+
1174+
ClusterDetailsVO cpu_detail = _clusterDetailsDao.findDetail(cluster.getId(),"cpuOvercommitRatio");
1175+
if( cpu_detail == null){
1176+
if (cpuovercommitratio.compareTo(1f) > 0){
1177+
cpu_detail = new ClusterDetailsVO(cluster.getId(),"cpuOvercommitRatio",Float.toString(cpuovercommitratio));
1178+
_clusterDetailsDao.persist(cpu_detail);
1179+
}
1180+
}
1181+
else {
1182+
cpu_detail.setValue(Float.toString(cpuovercommitratio));
1183+
_clusterDetailsDao.update(cpu_detail.getId(),cpu_detail);
1184+
}
1185+
1186+
11511187
if (doUpdate) {
11521188
Transaction txn = Transaction.currentTxn();
11531189
try {

server/test/com/cloud/resource/MockResourceManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
import com.cloud.template.VirtualMachineTemplate;
5555
import com.cloud.utils.Pair;
5656
import com.cloud.utils.component.ManagerBase;
57+
import com.cloud.utils.component.Manager;
58+
59+
5760
import com.cloud.utils.fsm.NoTransitionException;
5861

5962
@Local(value = {ResourceManager.class})

0 commit comments

Comments
 (0)