Skip to content

Commit e9176ee

Browse files
committed
Refactor based on review comments
1 parent c3b06da commit e9176ee

File tree

11 files changed

+324
-212
lines changed

11 files changed

+324
-212
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public class ApiConstants {
222222
public static final String EVENT_TYPE = "eventtype";
223223
public static final String EXPIRES = "expires";
224224
public static final String EXTRA_CONFIG = "extraconfig";
225+
public static final String EXTRA_PARAMS = "extraparams";
225226
public static final String EXTRA_DHCP_OPTION = "extradhcpoption";
226227
public static final String EXTRA_DHCP_OPTION_NAME = "extradhcpoptionname";
227228
public static final String EXTRA_DHCP_OPTION_CODE = "extradhcpoptioncode";
@@ -240,6 +241,8 @@ public class ApiConstants {
240241
public static final String FIRSTNAME = "firstname";
241242
public static final String FORCED = "forced";
242243
public static final String FORCED_DESTROY_LOCAL_STORAGE = "forcedestroylocalstorage";
244+
public static final String FORCE_CONVERT_TO_POOL = "forceconverttopool";
245+
243246
public static final String FORCE_DELETE_HOST = "forcedeletehost";
244247
public static final String FORCE_MS_TO_IMPORT_VM_FILES = "forcemstoimportvmfiles";
245248
public static final String FORCE_UPDATE_OS_TYPE = "forceupdateostype";

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ImportVmCmd.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ public class ImportVmCmd extends ImportUnmanagedInstanceCmd {
159159
description = "(only for importing VMs from VMware to KVM) optional - if true, forces MS to export OVF from VMware to temporary storage, else uses KVM Host if ovftool is available, falls back to MS if not.")
160160
private Boolean forceMsToImportVmFiles;
161161

162-
@Parameter(name = "extraparams",
162+
@Parameter(name = ApiConstants.EXTRA_PARAMS,
163163
type = CommandType.STRING,
164164
since = "4.22",
165-
description = "(VMware to KVM only) extra parameters to be passed on the virt-v2v command, if allowed by the administrator")
165+
description = "(only for importing VMs from VMware to KVM) optional - extra parameters to be passed on the virt-v2v command, if allowed by the administrator")
166166
private String extraParams;
167167

168-
@Parameter(name = "forceconverttopool", type = CommandType.BOOLEAN,
168+
@Parameter(name = ApiConstants.FORCE_CONVERT_TO_POOL,
169+
type = CommandType.BOOLEAN,
170+
since = "4.22",
169171
description = "(only for importing VMs from VMware to KVM) optional - if true, forces virt-v2v conversions to write directly on the provided storage pool (avoid using temporary conversion pool).")
170172
private Boolean forceConvertToPool;
171173

api/src/main/java/org/apache/cloudstack/api/command/admin/vm/ListImportVMTasksCmd.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.apache.cloudstack.api.response.ListResponse;
3636
import org.apache.cloudstack.api.response.ZoneResponse;
3737
import org.apache.cloudstack.context.CallContext;
38-
import org.apache.cloudstack.vm.VmImportService;
38+
import org.apache.cloudstack.vm.ImportVmTasksManager;
3939

4040
import javax.inject.Inject;
4141

@@ -45,11 +45,11 @@
4545
responseView = ResponseObject.ResponseView.Full,
4646
requestHasSensitiveInfo = false,
4747
authorized = {RoleType.Admin},
48-
since = "4.22.0")
48+
since = "4.22")
4949
public class ListImportVMTasksCmd extends BaseListCmd {
5050

5151
@Inject
52-
public VmImportService vmImportService;
52+
public ImportVmTasksManager importVmTasksManager;
5353

5454
@Parameter(name = ApiConstants.ZONE_ID,
5555
type = CommandType.UUID,
@@ -107,7 +107,7 @@ public boolean isShowCompleted() {
107107

108108
@Override
109109
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
110-
ListResponse<ImportVMTaskResponse> response = vmImportService.listImportVMTasks(this);
110+
ListResponse<ImportVMTaskResponse> response = importVmTasksManager.listImportVMTasks(this);
111111
response.setResponseName(getCommandName());
112112
setResponseObject(response);
113113
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.cloudstack.vm;
20+
21+
import org.apache.cloudstack.api.Identity;
22+
import org.apache.cloudstack.api.InternalIdentity;
23+
24+
public interface ImportVmTask extends Identity, InternalIdentity {
25+
enum Step {
26+
Prepare, CloningInstance, ConvertingInstance, Importing, Cleaning, Completed
27+
}
28+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.vm;
18+
19+
import com.cloud.dc.DataCenter;
20+
import com.cloud.host.Host;
21+
import com.cloud.user.Account;
22+
import org.apache.cloudstack.api.command.admin.vm.ListImportVMTasksCmd;
23+
import org.apache.cloudstack.api.response.ImportVMTaskResponse;
24+
import org.apache.cloudstack.api.response.ListResponse;
25+
26+
public interface ImportVmTasksManager {
27+
28+
ListResponse<ImportVMTaskResponse> listImportVMTasks(ListImportVMTasksCmd cmd);
29+
30+
ImportVmTask createImportVMTaskRecord(DataCenter zone, Account owner, long userId, String displayName,
31+
String vcenter, String datacenterName, String sourceVMName,
32+
Host convertHost, Host importHost);
33+
34+
void updateImportVMTaskStep(ImportVmTask importVMTaskVO, DataCenter zone, Account owner, Host convertHost,
35+
Host importHost, Long vmId, ImportVmTask.Step step);
36+
37+
boolean removeImportVMTask(long taskId);
38+
}

api/src/main/java/org/apache/cloudstack/vm/VmImportService.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
import org.apache.cloudstack.api.command.admin.vm.ImportUnmanagedInstanceCmd;
2121
import org.apache.cloudstack.api.command.admin.vm.ImportVmCmd;
22-
import org.apache.cloudstack.api.command.admin.vm.ListImportVMTasksCmd;
2322
import org.apache.cloudstack.api.command.admin.vm.ListUnmanagedInstancesCmd;
2423
import org.apache.cloudstack.api.command.admin.vm.ListVmsForImportCmd;
25-
import org.apache.cloudstack.api.response.ImportVMTaskResponse;
2624
import org.apache.cloudstack.api.response.ListResponse;
2725
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
2826
import org.apache.cloudstack.api.response.UserVmResponse;
@@ -44,6 +42,4 @@ public String toString() {
4442
UserVmResponse importVm(ImportVmCmd cmd);
4543

4644
ListResponse<UnmanagedInstanceResponse> listVmsForImport(ListVmsForImportCmd cmd);
47-
48-
ListResponse<ImportVMTaskResponse> listImportVMTasks(ListImportVMTasksCmd cmd);
4945
}

engine/schema/src/main/java/com/cloud/vm/ImportVMTaskVO.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
//
1919
package com.cloud.vm;
2020

21-
import org.apache.cloudstack.api.Identity;
22-
import org.apache.cloudstack.api.InternalIdentity;
21+
import org.apache.cloudstack.vm.ImportVmTask;
2322

2423
import javax.persistence.Column;
2524
import javax.persistence.Entity;
@@ -34,11 +33,7 @@
3433

3534
@Entity
3635
@Table(name = "import_vm_task")
37-
public class ImportVMTaskVO implements Identity, InternalIdentity {
38-
39-
public enum Step {
40-
Prepare, CloningInstance, ConvertingInstance, Importing, Cleaning, Completed
41-
}
36+
public class ImportVMTaskVO implements ImportVmTask {
4237

4338
public ImportVMTaskVO(long zoneId, long accountId, long userId, String displayName,
4439
String vcenter, String datacenter, String sourceVMName, long convertHostId, long importHostId) {

0 commit comments

Comments
 (0)