From c12ccbd06fc3acaa259c38bf653161e75c502a29 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Wed, 27 Apr 2011 13:42:24 +0530 Subject: [PATCH] Bug 9534 : implement CPU cap Introducing new boolean flag in service offering to restrict the user VM's CPU utilization to what service offering it is entitled for. --- .../cloud/agent/api/to/VirtualMachineTO.java | 8 ++++- api/src/com/cloud/api/ApiConstants.java | 1 + .../commands/CreateServiceOfferingCmd.java | 7 +++++ .../com/cloud/offering/ServiceOffering.java | 5 +++ api/src/com/cloud/vm/VirtualMachine.java | 6 +++- core/src/com/cloud/vm/UserVmVO.java | 3 +- core/src/com/cloud/vm/VMInstanceVO.java | 31 +++++++++++++++++-- .../configuration/ConfigurationManager.java | 2 +- .../ConfigurationManagerImpl.java | 11 +++++-- .../cloud/hypervisor/HypervisorGuruBase.java | 2 +- .../cloud/migration/ServiceOffering21VO.java | 7 ++++- .../com/cloud/service/ServiceOfferingVO.java | 22 ++++++++++--- .../src/com/cloud/vm/UserVmManagerImpl.java | 2 +- setup/db/create-schema.sql | 2 ++ 14 files changed, 92 insertions(+), 17 deletions(-) diff --git a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java index 7694f7bb014..20d824c8ede 100644 --- a/api/src/com/cloud/agent/api/to/VirtualMachineTO.java +++ b/api/src/com/cloud/agent/api/to/VirtualMachineTO.java @@ -39,13 +39,14 @@ public class VirtualMachineTO { String[] bootupScripts; boolean rebootOnCrash; boolean enableHA; + boolean limitCpuUse; String vncPassword; Map params; VolumeTO[] disks; NicTO[] nics; - public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, String vncPassword) { + public VirtualMachineTO(long id, String instanceName, VirtualMachine.Type type, int cpus, Integer speed, long minRam, long maxRam, BootloaderType bootloader, String os, boolean enableHA, boolean limitCpuUse, String vncPassword) { this.id = id; this.name = instanceName; this.type = type; @@ -56,6 +57,7 @@ public class VirtualMachineTO { this.bootloader = bootloader; this.os = os; this.enableHA = enableHA; + this.limitCpuUse = limitCpuUse; this.vncPassword = vncPassword; } @@ -102,6 +104,10 @@ public class VirtualMachineTO { return speed; } + public boolean getLimitCpuUse() { + return limitCpuUse; + } + public long getMinRam() { return minRam; } diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 464b62e0959..126f4e0bf10 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -98,6 +98,7 @@ public class ApiConstants { public static final String JOB_STATUS = "jobstatus"; public static final String LASTNAME = "lastname"; public static final String LEVEL = "level"; + public static final String LIMIT_CPU_USE = "limitcpuuse"; public static final String LOCK = "lock"; public static final String LUN = "lun"; public static final String MAX = "max"; diff --git a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java index abcb41aa366..00cacff8f2b 100644 --- a/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java +++ b/api/src/com/cloud/api/commands/CreateServiceOfferingCmd.java @@ -56,6 +56,9 @@ public class CreateServiceOfferingCmd extends BaseCmd { @Parameter(name=ApiConstants.OFFER_HA, type=CommandType.BOOLEAN, description="the HA for the service offering") private Boolean offerHa; + @Parameter(name=ApiConstants.LIMIT_CPU_USE, type=CommandType.BOOLEAN, description="restrict the CPU usage to committed service offering") + private Boolean limitCpuUse; + @Parameter(name=ApiConstants.STORAGE_TYPE, type=CommandType.STRING, description="the storage type of the service offering. Values are local and shared.") private String storageType; @@ -97,6 +100,10 @@ public class CreateServiceOfferingCmd extends BaseCmd { return offerHa; } + public Boolean GetLimitCpuUse() { + return limitCpuUse; + } + public String getStorageType() { return storageType; } diff --git a/api/src/com/cloud/offering/ServiceOffering.java b/api/src/com/cloud/offering/ServiceOffering.java index 8d80248075a..d15c1151b5b 100755 --- a/api/src/com/cloud/offering/ServiceOffering.java +++ b/api/src/com/cloud/offering/ServiceOffering.java @@ -56,6 +56,11 @@ public interface ServiceOffering { * @return Does this service plan offer HA? */ boolean getOfferHA(); + + /** + * @return Does this service plan offer VM to use CPU resources beyond the service offering limits? + */ + boolean getLimitCpuUse(); /** * @return the rate in megabits per sec to which a VM's network interface is throttled to diff --git a/api/src/com/cloud/vm/VirtualMachine.java b/api/src/com/cloud/vm/VirtualMachine.java index 5a2a06603e4..d0c70d3ad8b 100755 --- a/api/src/com/cloud/vm/VirtualMachine.java +++ b/api/src/com/cloud/vm/VirtualMachine.java @@ -236,7 +236,11 @@ public interface VirtualMachine extends RunningOn, ControlledEntity, StateObject * @return should HA be enabled for this machine? */ public boolean isHaEnabled(); - + + /** + * @return should limit CPU usage to the service offering? + */ + public boolean limitCpuUse(); /** * @return date when machine was created */ diff --git a/core/src/com/cloud/vm/UserVmVO.java b/core/src/com/cloud/vm/UserVmVO.java index 2fa2be2947c..43365b7da10 100755 --- a/core/src/com/cloud/vm/UserVmVO.java +++ b/core/src/com/cloud/vm/UserVmVO.java @@ -80,12 +80,13 @@ public class UserVmVO extends VMInstanceVO implements UserVm { HypervisorType hypervisorType, long guestOsId, boolean haEnabled, + boolean limitCpuUse, long domainId, long accountId, long serviceOfferingId, String userData, String name) { - super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled); + super(id, serviceOfferingId, name, instanceName, Type.User, templateId, hypervisorType, guestOsId, domainId, accountId, haEnabled, limitCpuUse); this.userData = userData; this.displayName = displayName != null ? displayName : null; this.details = new HashMap(); diff --git a/core/src/com/cloud/vm/VMInstanceVO.java b/core/src/com/cloud/vm/VMInstanceVO.java index 5f6ae97ed50..156eaf38c6b 100644 --- a/core/src/com/cloud/vm/VMInstanceVO.java +++ b/core/src/com/cloud/vm/VMInstanceVO.java @@ -107,7 +107,10 @@ public class VMInstanceVO implements VirtualMachine, FiniteStateObject