Skip to content

Commit 6bea532

Browse files
committed
CLOUDSTACK-5206: Ability to control the external id of first
class objects. Putting in the generic methods and trying it for objects like vm, volume. This is the first cut
1 parent 8b237eb commit 6bea532

18 files changed

Lines changed: 300 additions & 64 deletions

File tree

api/src/com/cloud/storage/VolumeApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public interface VolumeApiService {
8787

8888
Snapshot allocSnapshot(Long volumeId, Long policyId) throws ResourceAllocationException;
8989

90-
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume);
90+
Volume updateVolume(long volumeId, String path, String state, Long storageId, Boolean displayVolume, String customId);
9191

9292
/**
9393
* Extracts the volume to a particular location.

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
137137
* caller.
138138
*
139139
*
140+
*
140141
* @param zone
141142
* - availability zone for the virtual machine
142143
* @param serviceOffering
@@ -182,15 +183,10 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
182183
* @param displayVm
183184
* - Boolean flag whether to the display the vm to the end user or not
184185
* @param affinityGroupIdList
185-
* @param accountName
186-
* - an optional account for the virtual machine. Must be used
187-
* with domainId
188-
* @param domainId
189-
* - an optional domainId for the virtual machine. If the account
190-
* parameter is used, domainId must also be used
191186
* @param cpuSpeed
192187
* @param memory
193188
* @param cpuNumber
189+
* @param customId
194190
* @return UserVm object if successful.
195191
*
196192
* @throws InsufficientCapacityException
@@ -204,16 +200,17 @@ UserVm startVirtualMachine(StartVMCmd cmd) throws StorageUnavailableException, E
204200
* @throws InsufficientResourcesException
205201
*/
206202
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList,
207-
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
208-
String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
209-
List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize) throws InsufficientCapacityException,
203+
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod,
204+
String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIp, Boolean displayVm, String keyboard,
205+
List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize, String customId) throws InsufficientCapacityException,
210206
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
211207

212208
/**
213209
* Creates a User VM in Advanced Zone (Security Group feature is enabled) in
214210
* the database and returns the VM to the caller.
215211
*
216212
*
213+
*
217214
* @param zone
218215
* - availability zone for the virtual machine
219216
* @param serviceOffering
@@ -261,15 +258,9 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
261258
* @param displayVm
262259
* - Boolean flag whether to the display the vm to the end user or not
263260
* @param affinityGroupIdList
264-
* @param accountName
265-
* - an optional account for the virtual machine. Must be used
266-
* with domainId
267-
* @param domainId
268-
* - an optional domainId for the virtual machine. If the account
269-
* parameter is used, domainId must also be used
270-
* @param CpuSpeed
271261
* @param memory
272262
* @param cpuNumber
263+
* @param customId
273264
* @return UserVm object if successful.
274265
*
275266
* @throws InsufficientCapacityException
@@ -283,16 +274,17 @@ UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering s
283274
* @throws InsufficientResourcesException
284275
*/
285276
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
286-
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
287-
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard,
288-
List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize) throws InsufficientCapacityException,
277+
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor,
278+
HTTPMethod httpmethod, String userData, String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard,
279+
List<Long> affinityGroupIdList, Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdisksize, String customId) throws InsufficientCapacityException,
289280
ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
290281

291282
/**
292283
* Creates a User VM in Advanced Zone (Security Group feature is disabled)
293284
* in the database and returns the VM to the caller.
294285
*
295286
*
287+
*
296288
* @param zone
297289
* - availability zone for the virtual machine
298290
* @param serviceOffering
@@ -337,15 +329,10 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
337329
* @param displayVm
338330
* - Boolean flag whether to the display the vm to the end user or not
339331
* @param affinityGroupIdList
340-
* @param accountName
341-
* - an optional account for the virtual machine. Must be used
342-
* with domainId
343-
* @param domainId
344-
* - an optional domainId for the virtual machine. If the account
345-
* parameter is used, domainId must also be used
346332
* @param cpuSpeed
347333
* @param memory
348334
* @param cpuNumber
335+
* @param customId
349336
* @return UserVm object if successful.
350337
*
351338
* @throws InsufficientCapacityException
@@ -359,9 +346,9 @@ UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOfferin
359346
* @throws InsufficientResourcesException
360347
*/
361348
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner,
362-
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
363-
String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
364-
Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdkisksize)
349+
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, HTTPMethod httpmethod, String userData,
350+
String sshKeyPair, Map<Long, IpAddresses> requestedIps, IpAddresses defaultIps, Boolean displayVm, String keyboard, List<Long> affinityGroupIdList,
351+
Integer cpuSpeed, Integer memory, Integer cpuNumber, Long rootdkisksize, String customId)
365352

366353
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
367354

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class ApiConstants {
5454
public static final String CREATED = "created";
5555
public static final String CUSTOMIZED = "customized";
5656
public static final String CUSTOMIZED_IOPS = "customizediops";
57+
public static final String CUSTOM_ID = "customid";
5758
public static final String MIN_IOPS = "miniops";
5859
public static final String MAX_IOPS = "maxiops";
5960
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api;
18+
19+
20+
public abstract class BaseAsyncCreateCustomIdCmd extends BaseAsyncCreateCmd{
21+
@Parameter(name=ApiConstants.CUSTOM_ID, type=CommandType.STRING, description="an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only")
22+
private String customId;
23+
24+
public String getCustomId() {
25+
return customId;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api;
18+
19+
20+
public abstract class BaseAsyncCustomIdCmd extends BaseAsyncCmd {
21+
@Parameter(name=ApiConstants.CUSTOM_ID, type=CommandType.STRING, description="an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only")
22+
private String customId;
23+
24+
public String getCustomId() {
25+
return customId;
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api;
18+
19+
public abstract class BaseCustomIdCmd extends BaseCmd {
20+
21+
@Parameter(name=ApiConstants.CUSTOM_ID, type=CommandType.STRING, description="an optional field, in case you want to set a custom id to the resource. Allowed to Root Admins only")
22+
private String customId;
23+
24+
public String getCustomId() {
25+
return customId;
26+
}
27+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import org.apache.cloudstack.api.BaseAsyncCreateCustomIdCmd;
2728
import org.apache.log4j.Logger;
2829

2930
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
@@ -69,7 +70,7 @@
6970
@APICommand(name = "deployVirtualMachine",
7071
description = "Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.",
7172
responseObject = UserVmResponse.class)
72-
public class DeployVMCmd extends BaseAsyncCreateCmd {
73+
public class DeployVMCmd extends BaseAsyncCreateCustomIdCmd {
7374
public static final Logger s_logger = Logger.getLogger(DeployVMCmd.class.getName());
7475

7576
private static final String s_name = "deployvirtualmachineresponse";
@@ -576,14 +577,14 @@ public void create() throws ResourceAllocationException {
576577
vm =
577578
_userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name, displayName,
578579
diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard,
579-
getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize);
580+
getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize, getCustomId());
580581
}
581582
} else {
582583
if (zone.isSecurityGroupEnabled()) {
583584
vm =
584585
_userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(), owner, name,
585586
displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm,
586-
keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize);
587+
keyboard, getAffinityGroupIdList(), cpuSpeed, memory, cpuNumber, rootdisksize, getCustomId());
587588

588589
} else {
589590
if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
@@ -592,7 +593,7 @@ displayName, diskOfferingId, size, group, getHypervisor(), getHttpMethod(), user
592593
vm =
593594
_userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName, diskOfferingId, size,
594595
group, getHypervisor(), getHttpMethod(), userData, sshKeyPairName, getIpToNetworkMap(), addrs, displayVm, keyboard, getAffinityGroupIdList(),
595-
cpuSpeed, memory, cpuNumber, rootdisksize);
596+
cpuSpeed, memory, cpuNumber, rootdisksize, getCustomId());
596597

597598
}
598599
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19+
import org.apache.cloudstack.api.BaseCustomIdCmd;
1920
import org.apache.log4j.Logger;
2021

2122
import org.apache.cloudstack.api.APICommand;
@@ -36,7 +37,7 @@
3637
@APICommand(name = "updateVirtualMachine", description = "Updates properties of a virtual machine. The VM has to be stopped and restarted for the "
3738
+ "new properties to take effect. UpdateVirtualMachine does not first check whether the VM is stopped. "
3839
+ "Therefore, stop the VM manually before issuing this call.", responseObject = UserVmResponse.class)
39-
public class UpdateVMCmd extends BaseCmd {
40+
public class UpdateVMCmd extends BaseCustomIdCmd {
4041
public static final Logger s_logger = Logger.getLogger(UpdateVMCmd.class.getName());
4142
private static final String s_name = "updatevirtualmachineresponse";
4243

api/src/org/apache/cloudstack/api/command/user/volume/CreateVolumeCmd.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.volume;
1818

19+
import org.apache.cloudstack.api.BaseAsyncCreateCustomIdCmd;
20+
import org.apache.cloudstack.api.BaseCmd;
1921
import org.apache.log4j.Logger;
2022

2123
import org.apache.cloudstack.api.APICommand;
@@ -41,7 +43,7 @@
4143
@APICommand(name = "createVolume",
4244
responseObject = VolumeResponse.class,
4345
description = "Creates a disk volume from a disk offering. This disk volume must still be attached to a virtual machine to make use of it.")
44-
public class CreateVolumeCmd extends BaseAsyncCreateCmd {
46+
public class CreateVolumeCmd extends BaseAsyncCreateCustomIdCmd {
4547
public static final Logger s_logger = Logger.getLogger(CreateVolumeCmd.class.getName());
4648
private static final String s_name = "createvolumeresponse";
4749

@@ -50,7 +52,7 @@ public class CreateVolumeCmd extends BaseAsyncCreateCmd {
5052
/////////////////////////////////////////////////////
5153

5254
@Parameter(name = ApiConstants.ACCOUNT,
53-
type = CommandType.STRING,
55+
type = BaseCmd.CommandType.STRING,
5456
description = "the account associated with the disk volume. Must be used with the domainId parameter.")
5557
private String accountName;
5658

api/src/org/apache/cloudstack/api/command/user/volume/UpdateVolumeCmd.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.volume;
1818

19+
import org.apache.cloudstack.api.BaseAsyncCustomIdCmd;
1920
import org.apache.log4j.Logger;
2021

2122
import org.apache.cloudstack.api.APICommand;
@@ -34,7 +35,7 @@
3435
import com.cloud.storage.Volume;
3536

3637
@APICommand(name = "updateVolume", description = "Updates the volume.", responseObject = VolumeResponse.class)
37-
public class UpdateVolumeCmd extends BaseAsyncCmd {
38+
public class UpdateVolumeCmd extends BaseAsyncCustomIdCmd {
3839
public static final Logger s_logger = Logger.getLogger(UpdateVolumeCmd.class.getName());
3940
private static final String s_name = "updatevolumeresponse";
4041

@@ -140,7 +141,7 @@ public String getEventDescription() {
140141
@Override
141142
public void execute() {
142143
CallContext.current().setEventDetails("Volume Id: " + getId());
143-
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume());
144+
Volume result = _volumeService.updateVolume(getId(), getPath(), getState(), getStorageId(), getDisplayVolume(), getCustomId());
144145
if (result != null) {
145146
VolumeResponse response = _responseGenerator.createVolumeResponse(result);
146147
response.setResponseName(getCommandName());

0 commit comments

Comments
 (0)