Skip to content

Commit 7095ea2

Browse files
bvbharatkoushik-das
authored andcommitted
CLOUDSTACK-4738 Dynamic compute offering.
Signed-off-by: Koushik Das <koushik@apache.org>
1 parent 01b29a0 commit 7095ea2

34 files changed

Lines changed: 618 additions & 143 deletions

File tree

api/src/com/cloud/offering/ServiceOffering.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ public enum StorageType {
6161
/**
6262
* @return # of cpu.
6363
*/
64-
int getCpu();
64+
Integer getCpu();
6565

6666
/**
6767
* @return speed in mhz
6868
*/
69-
int getSpeed();
69+
Integer getSpeed();
7070

7171
/**
7272
* @return ram size in megabytes
7373
*/
74-
int getRamSize();
74+
Integer getRamSize();
7575

7676
/**
7777
* @return Does this service plan offer HA?
@@ -117,4 +117,6 @@ public enum StorageType {
117117
String getSystemVmType();
118118

119119
String getDeploymentPlanner();
120+
121+
boolean isDynamic();
120122
}

api/src/com/cloud/vm/UserVmService.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
136136
* Creates a Basic Zone User VM in the database and returns the VM to the
137137
* caller.
138138
*
139+
*
139140
* @param zone
140141
* - availability zone for the virtual machine
141142
* @param serviceOffering
@@ -181,13 +182,15 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
181182
* @param displayVm
182183
* - Boolean flag whether to the display the vm to the end user or not
183184
* @param affinityGroupIdList
184-
*
185185
* @param accountName
186186
* - an optional account for the virtual machine. Must be used
187187
* with domainId
188188
* @param domainId
189189
* - an optional domainId for the virtual machine. If the account
190190
* parameter is used, domainId must also be used
191+
* @param cpuSpeed
192+
* @param memory
193+
* @param cpuNumber
191194
* @return UserVm object if successful.
192195
*
193196
* @throws InsufficientCapacityException
@@ -201,15 +204,16 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
201204
* @throws InsufficientResourcesException
202205
*/
203206
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner, String hostName,
204-
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
205-
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
206-
IpAddresses defaultIp, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList)
207+
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
208+
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
209+
IpAddresses defaultIp, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize)
207210
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
208211

209212
/**
210213
* Creates a User VM in Advanced Zone (Security Group feature is enabled) in
211214
* the database and returns the VM to the caller.
212215
*
216+
*
213217
* @param zone
214218
* - availability zone for the virtual machine
215219
* @param serviceOffering
@@ -257,13 +261,15 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
257261
* @param displayVm
258262
* - Boolean flag whether to the display the vm to the end user or not
259263
* @param affinityGroupIdList
260-
*
261264
* @param accountName
262265
* - an optional account for the virtual machine. Must be used
263266
* with domainId
264267
* @param domainId
265268
* - an optional domainId for the virtual machine. If the account
266269
* parameter is used, domainId must also be used
270+
* @param CpuSpeed
271+
* @param memory
272+
* @param cpuNumber
267273
* @return UserVm object if successful.
268274
*
269275
* @throws InsufficientCapacityException
@@ -277,14 +283,15 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
277283
* @throws InsufficientResourcesException
278284
*/
279285
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, List<Long> securityGroupIdList,
280-
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData, String sshKeyPair,
281-
Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList)
286+
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData, String sshKeyPair,
287+
Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize)
282288
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
283289

284290
/**
285291
* Creates a User VM in Advanced Zone (Security Group feature is disabled)
286292
* in the database and returns the VM to the caller.
287293
*
294+
*
288295
* @param zone
289296
* - availability zone for the virtual machine
290297
* @param serviceOffering
@@ -329,15 +336,17 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
329336
* @param displayVm
330337
* - Boolean flag whether to the display the vm to the end user or not
331338
* @param affinityGroupIdList
332-
*
333339
* @param accountName
334340
* - an optional account for the virtual machine. Must be used
335341
* with domainId
336342
* @param domainId
337343
* - an optional domainId for the virtual machine. If the account
338344
* parameter is used, domainId must also be used
345+
* @param cpuSpeed
346+
* @param memory
347+
* @param cpuNumber
339348
* @return UserVm object if successful.
340-
*
349+
*
341350
* @throws InsufficientCapacityException
342351
* if there is insufficient capacity to deploy the VM.
343352
* @throws ConcurrentOperationException
@@ -349,9 +358,9 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
349358
* @throws InsufficientResourcesException
350359
*/
351360
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
352-
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
353-
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
354-
IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList)
361+
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
362+
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps,
363+
IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdkisksize)
355364

356365
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
357366

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class ApiConstants {
6161
public static final String DEVICE_ID = "deviceid";
6262
public static final String DISK_OFFERING_ID = "diskofferingid";
6363
public static final String DISK_SIZE = "disksize";
64+
public static final String ROOT_DISK_SIZE = "rootdisksize";
6465
public static final String DISPLAY_NAME = "displayname";
6566
public static final String DISPLAY_NETWORK = "displaynetwork";
6667
public static final String DISPLAY_NIC = "displaynic";

api/src/org/apache/cloudstack/api/command/admin/offering/CreateServiceOfferingCmd.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public class CreateServiceOfferingCmd extends BaseCmd {
4141
//////////////// API parameters /////////////////////
4242
/////////////////////////////////////////////////////
4343

44-
@Parameter(name=ApiConstants.CPU_NUMBER, type=CommandType.LONG, required=true, description="the CPU number of the service offering")
45-
private Long cpuNumber;
44+
@Parameter(name=ApiConstants.CPU_NUMBER, type=CommandType.INTEGER, required=false, description="the CPU number of the service offering")
45+
private Integer cpuNumber;
4646

47-
@Parameter(name=ApiConstants.CPU_SPEED, type=CommandType.LONG, required=true, description="the CPU speed of the service offering in MHz.")
48-
private Long cpuSpeed;
47+
@Parameter(name=ApiConstants.CPU_SPEED, type=CommandType.INTEGER, required=false, description="the CPU speed of the service offering in MHz.")
48+
private Integer cpuSpeed;
4949

5050
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the service offering")
5151
private String displayText;
5252

53-
@Parameter(name=ApiConstants.MEMORY, type=CommandType.LONG, required=true, description="the total memory of the service offering in MB")
54-
private Long memory;
53+
@Parameter(name=ApiConstants.MEMORY, type=CommandType.INTEGER, required=false, description="the total memory of the service offering in MB")
54+
private Integer memory;
5555

5656
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the service offering")
5757
private String serviceOfferingName;
@@ -109,19 +109,19 @@ public class CreateServiceOfferingCmd extends BaseCmd {
109109
/////////////////// Accessors ///////////////////////
110110
/////////////////////////////////////////////////////
111111

112-
public Long getCpuNumber() {
112+
public Integer getCpuNumber() {
113113
return cpuNumber;
114114
}
115115

116-
public Long getCpuSpeed() {
116+
public Integer getCpuSpeed() {
117117
return cpuSpeed;
118118
}
119119

120120
public String getDisplayText() {
121121
return displayText;
122122
}
123123

124-
public Long getMemory() {
124+
public Integer getMemory() {
125125
return memory;
126126
}
127127

@@ -173,6 +173,11 @@ public String getDeploymentPlanner() {
173173
return deploymentPlanner;
174174
}
175175

176+
public boolean getCustomized() {
177+
return (cpuNumber == null || memory == null || cpuSpeed == null);
178+
}
179+
180+
176181
public Map<String, String> getDetails() {
177182
if (details == null || details.isEmpty()) {
178183
return null;

api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,18 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
188188
@Parameter(name=ApiConstants.DISPLAY_VM, type=CommandType.BOOLEAN, since="4.2", description="an optional field, whether to the display the vm to the end user or not.")
189189
private Boolean displayVm;
190190

191+
@Parameter(name=ApiConstants.CPU_SPEED, type = CommandType.INTEGER, since="4.3", description = "optional field to specify the cpu speed when using dynamic compute offering.")
192+
private Integer cpuSpeed;
193+
194+
@Parameter(name=ApiConstants.MEMORY, type = CommandType.INTEGER, since="4.3", description = "optional field to specify the memory when using dynamic compute offering")
195+
private Integer memory;
196+
197+
@Parameter(name=ApiConstants.CPU_NUMBER, type=CommandType.INTEGER, since="4.3", description = "optional field to specify the number of cpu cores when using dynamic offering.")
198+
private Integer cpuNumber;
199+
200+
@Parameter(name=ApiConstants.ROOT_DISK_SIZE, type=CommandType.LONG, since="4.3", description = "optional field to specify the number of cpu cores when using dynamic offering.")
201+
private Long rootdisksize;
202+
191203
/////////////////////////////////////////////////////
192204
/////////////////// Accessors ///////////////////////
193205
/////////////////////////////////////////////////////
@@ -227,6 +239,22 @@ public Boolean getDisplayVm() {
227239
return displayVm;
228240
}
229241

242+
public Integer getMemory() {
243+
return memory;
244+
}
245+
246+
public Integer getCpuSpeed() {
247+
return cpuSpeed;
248+
}
249+
250+
public Integer getCpuNumber() {
251+
return cpuNumber;
252+
}
253+
254+
public Long getRootdisksize() {
255+
return rootdisksize;
256+
}
257+
230258
public List<Long> getSecurityGroupIdList() {
231259
if (securityGroupNameList != null && securityGroupIdList != null) {
232260
throw new InvalidParameterValueException("securitygroupids parameter is mutually exclusive with securitygroupnames parameter");
@@ -495,19 +523,19 @@ public void create() throws ResourceAllocationException{
495523
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
496524
} else {
497525
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
498-
displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList());
526+
displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize);
499527
}
500528
} else {
501529
if (zone.isSecurityGroupEnabled()) {
502530
vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(),
503-
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList());
531+
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize );
504532

505533
} else {
506534
if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
507535
throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
508536
}
509537
vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,
510-
diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList());
538+
diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize);
511539

512540
}
513541
}

engine/api/src/org/apache/cloudstack/engine/orchestration/service/VolumeOrchestrationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public interface VolumeOrchestrationService {
8686

8787
boolean canVmRestartOnAnotherServer(long vmId);
8888

89-
DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering offering, VirtualMachineTemplate template, VirtualMachine vm, Account owner);
89+
DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering offering, Long rootDisksize, VirtualMachineTemplate template, VirtualMachine vm, Account owner);
9090

9191
String getVmNameFromVolumeId(long volumeId);
9292

engine/api/src/org/apache/cloudstack/engine/service/api/OrchestrationService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public interface OrchestrationService {
5555
* @param computeTags tags for the compute
5656
* @param rootDiskTags tags for the root disk
5757
* @param networks networks that this VM should join
58+
* @param rootDiskSize size the root disk in case of templates.
5859
* @return VirtualMachineEntity
5960
*/
6061
@POST
@@ -73,7 +74,8 @@ VirtualMachineEntity createVirtualMachine(
7374
@QueryParam("compute-tags") List<String> computeTags,
7475
@QueryParam("root-disk-tags") List<String> rootDiskTags,
7576
@QueryParam("network-nic-map") Map<String, NicProfile> networkNicMap,
76-
@QueryParam("deploymentplan") DeploymentPlan plan
77+
@QueryParam("deploymentplan") DeploymentPlan plan,
78+
@QueryParam("root-disk-size") Long rootDiskSize
7779
) throws InsufficientCapacityException;
7880

7981
@POST

engine/components-api/src/com/cloud/event/UsageEventUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.annotation.PostConstruct;
2626
import javax.inject.Inject;
2727

28+
import com.cloud.event.dao.UsageEventDetailsDao;
2829
import org.apache.log4j.Logger;
2930
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
3031

@@ -38,6 +39,8 @@
3839
import com.cloud.user.Account;
3940
import com.cloud.user.dao.AccountDao;
4041
import com.cloud.utils.component.ComponentContext;
42+
import org.springframework.beans.factory.annotation.Autowire;
43+
import org.springframework.beans.factory.annotation.Autowired;
4144

4245
public class UsageEventUtils {
4346

@@ -103,6 +106,19 @@ public static void publishUsageEvent(String usageType, long accountId,long zoneI
103106
publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
104107
}
105108

109+
public static void publishUsageEvent(String usageType, long accountId, long zoneId, long resourceId,
110+
String resourceName, Long offeringId, Long templateId, String resourceType,
111+
String entityType, String entityUUID, Map<String, String> details) {
112+
saveUsageEvent(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, resourceType, details);
113+
publishUsageEvent(usageType, accountId, zoneId, entityType, entityUUID);
114+
}
115+
116+
private static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType, Map<String,String> details) {
117+
UsageEventVO usageEvent = new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, resourceType);
118+
_usageEventDao.persist(usageEvent);
119+
_usageEventDao.saveDetails(usageEvent.getId(), details);
120+
}
121+
106122
public static void saveUsageEvent(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, Long size) {
107123
_usageEventDao.persist( new UsageEventVO(usageType, accountId, zoneId, resourceId, resourceName, offeringId, templateId, size));
108124
}

0 commit comments

Comments
 (0)