Skip to content

Commit 83ffb4c

Browse files
committed
code review changes
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent ee3f111 commit 83ffb4c

File tree

20 files changed

+417
-404
lines changed

20 files changed

+417
-404
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class EventTypes {
9797
public static final String EVENT_VM_MOVE = "VM.MOVE";
9898
public static final String EVENT_VM_RESTORE = "VM.RESTORE";
9999
public static final String EVENT_VM_EXPUNGE = "VM.EXPUNGE";
100-
public static final String EVENT_VM_INGEST = "VM.INGEST";
100+
public static final String EVENT_VM_IMPORT = "VM.IMPORT";
101101

102102
// Domain Router
103103
public static final String EVENT_ROUTER_CREATE = "ROUTER.CREATE";
@@ -596,7 +596,7 @@ public class EventTypes {
596596
entityEventDetails.put(EVENT_VM_MOVE, VirtualMachine.class);
597597
entityEventDetails.put(EVENT_VM_RESTORE, VirtualMachine.class);
598598
entityEventDetails.put(EVENT_VM_EXPUNGE, VirtualMachine.class);
599-
entityEventDetails.put(EVENT_VM_INGEST, VirtualMachine.class);
599+
entityEventDetails.put(EVENT_VM_IMPORT, VirtualMachine.class);
600600

601601
entityEventDetails.put(EVENT_ROUTER_CREATE, VirtualRouter.class);
602602
entityEventDetails.put(EVENT_ROUTER_DESTROY, VirtualRouter.class);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
514514

515515
void collectVmNetworkStatistics (UserVm userVm);
516516

517-
UserVm ingestVm(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
517+
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String hostName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
518518
final long accountId, final long userId, final ServiceOffering serviceOffering, final DiskOffering rootDiskOffering, final String sshPublicKey, final LinkedHashMap<String, NicProfile> networkNicMap,
519519
final String instanceName, final HypervisorType hypervisorType, final Map<String, String> customParameters, final VirtualMachine.PowerState powerState) throws InsufficientCapacityException;
520520

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ public class ApiConstants {
4343
public static final String BYTES_WRITE_RATE_MAX = "byteswriteratemax";
4444
public static final String BYTES_WRITE_RATE_MAX_LENGTH = "byteswriteratemaxlength";
4545
public static final String BYPASS_VLAN_OVERLAP_CHECK = "bypassvlanoverlapcheck";
46+
public static final String CAPACITY = "capacity";
4647
public static final String CATEGORY = "category";
4748
public static final String CAN_REVERT = "canrevert";
4849
public static final String CA_CERTIFICATES = "cacertificates";
4950
public static final String CERTIFICATE = "certificate";
5051
public static final String CERTIFICATE_CHAIN = "certchain";
5152
public static final String CERTIFICATE_FINGERPRINT = "fingerprint";
5253
public static final String CERTIFICATE_ID = "certid";
54+
public static final String CONTROLLER = "controller";
55+
public static final String CONTROLLER_UNIT = "controllerunit";
5356
public static final String COPY_IMAGE_TAGS = "copyimagetags";
5457
public static final String CSR = "csr";
5558
public static final String PRIVATE_KEY = "privatekey";
@@ -69,6 +72,7 @@ public class ApiConstants {
6972
public static final String COMMAND = "command";
7073
public static final String CMD_EVENT_TYPE = "cmdeventtype";
7174
public static final String COMPONENT = "component";
75+
public static final String CPU_CORE_PER_SOCKET = "cpucorepersocket";
7276
public static final String CPU_NUMBER = "cpunumber";
7377
public static final String CPU_SPEED = "cpuspeed";
7478
public static final String CREATED = "created";
@@ -90,6 +94,7 @@ public class ApiConstants {
9094
public static final String DETAILS = "details";
9195
public static final String DEVICE_ID = "deviceid";
9296
public static final String DIRECT_DOWNLOAD = "directdownload";
97+
public static final String DISK = "disk";
9398
public static final String DISK_OFFERING_ID = "diskofferingid";
9499
public static final String NEW_DISK_OFFERING_ID = "newdiskofferingid";
95100
public static final String DISK_KBS_READ = "diskkbsread";
@@ -169,6 +174,7 @@ public class ApiConstants {
169174
public static final String PREVIOUS_ACL_RULE_ID = "previousaclruleid";
170175
public static final String NEXT_ACL_RULE_ID = "nextaclruleid";
171176
public static final String MOVE_ACL_CONSISTENCY_HASH = "aclconsistencyhash";
177+
public static final String IMAGE_PATH = "imagepath";
172178
public static final String INTERNAL_DNS1 = "internaldns1";
173179
public static final String INTERNAL_DNS2 = "internaldns2";
174180
public static final String INTERVAL_TYPE = "intervaltype";
@@ -222,6 +228,7 @@ public class ApiConstants {
222228
public static final String NETWORK_DOMAIN = "networkdomain";
223229
public static final String NETMASK = "netmask";
224230
public static final String NEW_NAME = "newname";
231+
public static final String NIC = "nic";
225232
public static final String NUM_RETRIES = "numretries";
226233
public static final String OFFER_HA = "offerha";
227234
public static final String IS_SYSTEM_OFFERING = "issystem";
@@ -253,6 +260,7 @@ public class ApiConstants {
253260
public static final String PORTAL = "portal";
254261
public static final String PORTABLE_IP_ADDRESS = "portableipaddress";
255262
public static final String PORT_FORWARDING_SERVICE_ID = "portforwardingserviceid";
263+
public static final String POSITION = "position";
256264
public static final String POST_URL = "postURL";
257265
public static final String POWER_STATE = "powerstate";
258266
public static final String PRIVATE_INTERFACE = "privateinterface";

api/src/main/java/org/apache/cloudstack/api/command/admin/ingestion/ImportUnmanageInstanceCmd.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import org.apache.cloudstack.api.response.TemplateResponse;
4040
import org.apache.cloudstack.api.response.UserVmResponse;
4141
import org.apache.cloudstack.context.CallContext;
42-
import org.apache.cloudstack.ingestion.VmIngestionService;
42+
import org.apache.cloudstack.ingestion.VmImportService;
4343
import org.apache.log4j.Logger;
4444

4545
import com.cloud.event.EventTypes;
@@ -56,17 +56,21 @@
5656
import com.cloud.user.Account;
5757

5858
@APICommand(name = ImportUnmanageInstanceCmd.API_NAME,
59-
description = "Import unmanaged virtual machine from a given cluster/host.",
59+
description = "Import unmanaged virtual machine from a given cluster.",
6060
responseObject = UserVmResponse.class,
6161
responseView = ResponseObject.ResponseView.Full,
6262
requestHasSensitiveInfo = false,
6363
responseHasSensitiveInfo = true)
6464
public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
65-
public static final Logger s_logger = Logger.getLogger(ImportUnmanageInstanceCmd.class.getName());
65+
public static final Logger s_logger = Logger.getLogger(ImportUnmanageInstanceCmd.class);
6666
public static final String API_NAME = "importUnmanagedInstance";
6767

6868
@Inject
69-
public VmIngestionService vmIngestionService;
69+
public VmImportService vmImportService;
70+
71+
/////////////////////////////////////////////////////
72+
//////////////// API parameters /////////////////////
73+
/////////////////////////////////////////////////////
7074

7175
@Parameter(name = ApiConstants.CLUSTER_ID,
7276
type = CommandType.UUID,
@@ -145,7 +149,11 @@ public class ImportUnmanageInstanceCmd extends BaseAsyncCmd {
145149
@Parameter(name = ApiConstants.DETAILS,
146150
type = CommandType.MAP,
147151
description = "used to specify the custom parameters.")
148-
private Map details;
152+
private Map<String, String> details;
153+
154+
/////////////////////////////////////////////////////
155+
/////////////////// Accessors ///////////////////////
156+
/////////////////////////////////////////////////////
149157

150158
public Long getClusterId() {
151159
return clusterId;
@@ -225,7 +233,7 @@ public Map<String, Long> getDataDiskToDiskOfferingList() {
225233
return dataDiskToDiskOfferingMap;
226234
}
227235

228-
public Map getDetails() {
236+
public Map<String, String> getDetails() {
229237
Map<String, String> customParameterMap = new HashMap<String, String>();
230238
if (details != null && details.size() != 0) {
231239
Collection parameterCollection = details.values();
@@ -242,18 +250,31 @@ public Map getDetails() {
242250

243251
@Override
244252
public String getEventType() {
245-
return EventTypes.EVENT_VM_INGEST;
253+
return EventTypes.EVENT_VM_IMPORT;
246254
}
247255

248256
@Override
249257
public String getEventDescription() {
250258
return "Importing unmanaged VM";
251259
}
252260

261+
/////////////////////////////////////////////////////
262+
/////////////// API Implementation///////////////////
263+
/////////////////////////////////////////////////////
264+
265+
private void validateInput() {
266+
if (_entityMgr.findById(Cluster.class, clusterId) == null) {
267+
throw new InvalidParameterValueException(String.format("Unable to find cluster with ID: %d", clusterId));
268+
}
269+
if (_entityMgr.findById(ServiceOffering.class, serviceOfferingId) == null) {
270+
throw new InvalidParameterValueException(String.format("Unable to find service offering with ID: %d", serviceOfferingId));
271+
}
272+
}
273+
253274
@Override
254275
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
255276
validateInput();
256-
UserVmResponse response = vmIngestionService.importUnmanagedInstance(this);
277+
UserVmResponse response = vmImportService.importUnmanagedInstance(this);
257278
response.setResponseName(getCommandName());
258279
setResponseObject(response);
259280
}
@@ -276,13 +297,4 @@ public long getEntityOwnerId() {
276297
}
277298
return accountId;
278299
}
279-
280-
private void validateInput() {
281-
if (_entityMgr.findById(Cluster.class, clusterId) == null) {
282-
throw new InvalidParameterValueException(String.format("Unable to find cluster with ID: %d", clusterId));
283-
}
284-
if (_entityMgr.findById(ServiceOffering.class, serviceOfferingId) == null) {
285-
throw new InvalidParameterValueException(String.format("Unable to find service offering with ID: %d", serviceOfferingId));
286-
}
287-
}
288300
}

api/src/main/java/org/apache/cloudstack/api/command/admin/ingestion/ListUnmanagedInstancesCmd.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
3232
import org.apache.cloudstack.context.CallContext;
3333
import org.apache.cloudstack.ingestion.UnmanagedInstance;
34-
import org.apache.cloudstack.ingestion.VmIngestionService;
34+
import org.apache.cloudstack.ingestion.VmImportService;
3535
import org.apache.log4j.Logger;
3636

3737
import com.cloud.exception.ConcurrentOperationException;
@@ -42,7 +42,7 @@
4242
import com.cloud.user.Account;
4343

4444
@APICommand(name = ListUnmanagedInstancesCmd.API_NAME,
45-
description = "Lists unmanaged virtual machines for a given cluster/host.",
45+
description = "Lists unmanaged virtual machines for a given cluster.",
4646
responseObject = UnmanagedInstanceResponse.class,
4747
responseView = ResponseObject.ResponseView.Full,
4848
entityType = {UnmanagedInstance.class},
@@ -52,7 +52,11 @@ public class ListUnmanagedInstancesCmd extends BaseListCmd {
5252
public static final String API_NAME = "listUnmanagedInstances";
5353

5454
@Inject
55-
public VmIngestionService vmIngestionService;
55+
public VmImportService vmIngestionService;
56+
57+
/////////////////////////////////////////////////////
58+
//////////////// API parameters /////////////////////
59+
/////////////////////////////////////////////////////
5660

5761
@Parameter(name = ApiConstants.CLUSTER_ID,
5862
type = CommandType.UUID,
@@ -66,6 +70,10 @@ public class ListUnmanagedInstancesCmd extends BaseListCmd {
6670
description = "the hypervisor name of the instance")
6771
private String name;
6872

73+
/////////////////////////////////////////////////////
74+
/////////////////// Accessors ///////////////////////
75+
/////////////////////////////////////////////////////
76+
6977
public Long getClusterId() {
7078
return clusterId;
7179
}
@@ -74,6 +82,10 @@ public String getName() {
7482
return name;
7583
}
7684

85+
86+
/////////////////////////////////////////////////////
87+
/////////////// API Implementation///////////////////
88+
/////////////////////////////////////////////////////
7789
@Override
7890
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
7991
ListResponse<UnmanagedInstanceResponse> response = vmIngestionService.listUnmanagedInstances(this);

api/src/main/java/org/apache/cloudstack/api/response/NicResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class NicResponse extends BaseResponse {
115115
private String nsxLogicalSwitchPort;
116116

117117
@SerializedName(ApiConstants.VLAN_ID)
118-
@Param(description = "VLAN ID (if available), null otherwise", since="4.13.0")
118+
@Param(description = "ID of the VLAN/VNI if available", since="4.14.0")
119119
private Integer vlanId;
120120

121121
public void setVmId(String vmId) {

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceDiskResponse.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,23 @@ public class UnmanagedInstanceDiskResponse extends BaseResponse {
3333
@Param(description = "the label of the disk")
3434
private String label;
3535

36-
37-
@SerializedName("capacity")
36+
@SerializedName(ApiConstants.CAPACITY)
3837
@Param(description = "the capacity in KB of the disk")
3938
private Long capacity;
4039

41-
42-
@SerializedName("imagepath")
40+
@SerializedName(ApiConstants.IMAGE_PATH)
4341
@Param(description = "the file path of the disk image")
4442
private String imagePath;
4543

46-
47-
@SerializedName("controller")
44+
@SerializedName(ApiConstants.CONTROLLER)
4845
@Param(description = "the controller of the disk")
4946
private String controller;
5047

51-
52-
@SerializedName("controllerunit")
48+
@SerializedName(ApiConstants.CONTROLLER_UNIT)
5349
@Param(description = "the controller unit of the disk")
5450
private Integer controllerUnit;
5551

56-
57-
@SerializedName("position")
52+
@SerializedName(ApiConstants.POSITION)
5853
@Param(description = "the position of the disk")
5954
private Integer position;
6055

api/src/main/java/org/apache/cloudstack/api/response/UnmanagedInstanceResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class UnmanagedInstanceResponse extends BaseResponse {
5151
@Param(description = "the CPU cores of the virtual machine")
5252
private Integer cpuCores;
5353

54-
@SerializedName("cpucorespersocket")
54+
@SerializedName(ApiConstants.CPU_CORE_PER_SOCKET)
5555
@Param(description = "the CPU cores per socket for the virtual machine. VMware specific")
5656
private Integer cpuCoresPerSocket;
5757

@@ -67,11 +67,11 @@ public class UnmanagedInstanceResponse extends BaseResponse {
6767
@Param(description = "the operating system of the virtual machine")
6868
private String operatingSystem;
6969

70-
@SerializedName("disk")
70+
@SerializedName(ApiConstants.DISK)
7171
@Param(description = "the list of disks associated with the virtual machine", responseObject = UnmanagedInstanceDiskResponse.class)
7272
private Set<UnmanagedInstanceDiskResponse> disks;
7373

74-
@SerializedName("nic")
74+
@SerializedName(ApiConstants.NIC)
7575
@Param(description = "the list of nics associated with the virtual machine", responseObject = NicResponse.class)
7676
private Set<NicResponse> nics;
7777

api/src/main/java/org/apache/cloudstack/ingestion/VmIngestionService.java renamed to api/src/main/java/org/apache/cloudstack/ingestion/VmImportService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import com.cloud.utils.component.PluggableService;
2727

28-
public interface VmIngestionService extends PluggableService {
28+
public interface VmImportService extends PluggableService {
2929
ListResponse<UnmanagedInstanceResponse> listUnmanagedInstances(ListUnmanagedInstancesCmd cmd);
3030
UserVmResponse importUnmanagedInstance(ImportUnmanageInstanceCmd cmd);
3131
}

engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,5 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon
314314
*/
315315
void cleanupNicDhcpDnsEntry(Network network, VirtualMachineProfile vmProfile, NicProfile nicProfile);
316316

317-
Pair<NicProfile, Integer> ingestNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm);
317+
Pair<NicProfile, Integer> importNic(final String macAddress, int deviceId, final Network network, final Boolean isDefaultNic, final VirtualMachine vm);
318318
}

0 commit comments

Comments
 (0)