Skip to content

Commit e194ba9

Browse files
committed
Improve the feedback by displaying the running importing tasks
1 parent 3b1ab6f commit e194ba9

File tree

11 files changed

+1056
-143
lines changed

11 files changed

+1056
-143
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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.command.admin.vm;
18+
19+
import com.cloud.exception.ConcurrentOperationException;
20+
import com.cloud.exception.InsufficientCapacityException;
21+
import com.cloud.exception.NetworkRuleConflictException;
22+
import com.cloud.exception.ResourceAllocationException;
23+
import com.cloud.exception.ResourceUnavailableException;
24+
import com.cloud.user.Account;
25+
import org.apache.cloudstack.acl.RoleType;
26+
import org.apache.cloudstack.api.APICommand;
27+
import org.apache.cloudstack.api.ApiConstants;
28+
import org.apache.cloudstack.api.BaseListCmd;
29+
import org.apache.cloudstack.api.Parameter;
30+
import org.apache.cloudstack.api.ResponseObject;
31+
import org.apache.cloudstack.api.ServerApiException;
32+
import org.apache.cloudstack.api.response.AccountResponse;
33+
import org.apache.cloudstack.api.response.HostResponse;
34+
import org.apache.cloudstack.api.response.ImportVMTaskResponse;
35+
import org.apache.cloudstack.api.response.ListResponse;
36+
import org.apache.cloudstack.api.response.ZoneResponse;
37+
import org.apache.cloudstack.context.CallContext;
38+
import org.apache.cloudstack.vm.VmImportService;
39+
40+
import javax.inject.Inject;
41+
42+
@APICommand(name = "listImportVmTasks",
43+
description = "List running import virtual machine tasks from a unmanaged hosts into CloudStack",
44+
responseObject = ImportVMTaskResponse.class,
45+
responseView = ResponseObject.ResponseView.Full,
46+
requestHasSensitiveInfo = false,
47+
authorized = {RoleType.Admin},
48+
since = "4.22.0")
49+
public class ListImportVMTasksCmd extends BaseListCmd {
50+
51+
@Inject
52+
public VmImportService vmImportService;
53+
54+
@Parameter(name = ApiConstants.ZONE_ID,
55+
type = CommandType.UUID,
56+
entityType = ZoneResponse.class,
57+
required = true,
58+
description = "the zone ID")
59+
private Long zoneId;
60+
61+
@Parameter(name = ApiConstants.ACCOUNT_ID,
62+
type = CommandType.UUID,
63+
entityType = AccountResponse.class,
64+
description = "the ID of the Account")
65+
private Long accountId;
66+
67+
@Parameter(name = ApiConstants.VCENTER,
68+
type = CommandType.STRING,
69+
description = "The name/ip of vCenter. Make sure it is IP address or full qualified domain name for host running vCenter server.")
70+
private String vcenter;
71+
72+
@Parameter(name = ApiConstants.CONVERT_INSTANCE_HOST_ID,
73+
type = CommandType.UUID,
74+
entityType = HostResponse.class,
75+
description = "Conversion host of the importing task")
76+
private Long convertHostId;
77+
78+
public Long getZoneId() {
79+
return zoneId;
80+
}
81+
82+
public Long getAccountId() {
83+
return accountId;
84+
}
85+
86+
public String getVcenter() {
87+
return vcenter;
88+
}
89+
90+
public Long getConvertHostId() {
91+
return convertHostId;
92+
}
93+
94+
@Override
95+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
96+
ListResponse<ImportVMTaskResponse> response = vmImportService.listImportVMTasks(this);
97+
response.setResponseName(getCommandName());
98+
setResponseObject(response);
99+
}
100+
101+
@Override
102+
public long getEntityOwnerId() {
103+
Account account = CallContext.current().getCallingAccount();
104+
if (account != null) {
105+
return account.getId();
106+
}
107+
return Account.ACCOUNT_ID_SYSTEM;
108+
}
109+
}
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
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.api.response;
20+
21+
import com.cloud.serializer.Param;
22+
import com.google.gson.annotations.SerializedName;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.BaseResponse;
25+
26+
import java.util.Date;
27+
28+
public class ImportVMTaskResponse extends BaseResponse {
29+
30+
@SerializedName(ApiConstants.ID)
31+
@Param(description = "the ID of importing task")
32+
private String id;
33+
34+
@SerializedName(ApiConstants.ZONE_ID)
35+
@Param(description = "the Zone ID")
36+
private String zoneId;
37+
38+
@SerializedName(ApiConstants.ZONE_NAME)
39+
@Param(description = "the Zone name")
40+
private String zoneName;
41+
42+
@SerializedName(ApiConstants.ACCOUNT)
43+
@Param(description = "the account name")
44+
private String accountName;
45+
46+
@SerializedName(ApiConstants.ACCOUNT_ID)
47+
@Param(description = "the ID of account")
48+
private String accountId;
49+
50+
@SerializedName(ApiConstants.DISPLAY_NAME)
51+
@Param(description = "the display name of the importing VM")
52+
private String displayName;
53+
54+
@SerializedName(ApiConstants.VCENTER)
55+
@Param(description = "the vcenter name of the importing VM task")
56+
private String vcenter;
57+
58+
@SerializedName(ApiConstants.DATACENTER_NAME)
59+
@Param(description = "the datacenter name of the importing VM task")
60+
private String datacenterName;
61+
62+
@SerializedName("sourcevmname")
63+
@Param(description = "the source VM name")
64+
private String sourceVMName;
65+
66+
@SerializedName("step")
67+
@Param(description = "the current step on the importing VM task")
68+
private String step;
69+
70+
@SerializedName(ApiConstants.DURATION)
71+
@Param(description = "the current step duration in seconds")
72+
private Long duration;
73+
74+
@SerializedName(ApiConstants.DESCRIPTION)
75+
@Param(description = "the current step description on the importing VM task")
76+
private String description;
77+
78+
@SerializedName(ApiConstants.CONVERT_INSTANCE_HOST_ID)
79+
@Param(description = "the ID of the host on which the instance is being converted")
80+
private String convertInstanceHostId;
81+
82+
@SerializedName("convertinstancehostname")
83+
@Param(description = "the name of the host on which the instance is being converted")
84+
private String convertInstanceHostName;
85+
86+
@SerializedName(ApiConstants.CREATED)
87+
@Param(description = "the create date of the importing task")
88+
private Date created;
89+
90+
@SerializedName(ApiConstants.LAST_UPDATED)
91+
@Param(description = "the last updated date of the importing task")
92+
private Date lastUpdated;
93+
94+
public String getId() {
95+
return id;
96+
}
97+
98+
public void setId(String id) {
99+
this.id = id;
100+
}
101+
102+
public String getZoneId() {
103+
return zoneId;
104+
}
105+
106+
public void setZoneId(String zoneId) {
107+
this.zoneId = zoneId;
108+
}
109+
110+
public String getZoneName() {
111+
return zoneName;
112+
}
113+
114+
public void setZoneName(String zoneName) {
115+
this.zoneName = zoneName;
116+
}
117+
118+
public String getAccountName() {
119+
return accountName;
120+
}
121+
122+
public void setAccountName(String accountName) {
123+
this.accountName = accountName;
124+
}
125+
126+
public String getAccountId() {
127+
return accountId;
128+
}
129+
130+
public void setAccountId(String accountId) {
131+
this.accountId = accountId;
132+
}
133+
134+
public String getDisplayName() {
135+
return displayName;
136+
}
137+
138+
public void setDisplayName(String displayName) {
139+
this.displayName = displayName;
140+
}
141+
142+
public String getVcenter() {
143+
return vcenter;
144+
}
145+
146+
public void setVcenter(String vcenter) {
147+
this.vcenter = vcenter;
148+
}
149+
150+
public String getDatacenterName() {
151+
return datacenterName;
152+
}
153+
154+
public void setDatacenterName(String datacenterName) {
155+
this.datacenterName = datacenterName;
156+
}
157+
158+
public String getSourceVMName() {
159+
return sourceVMName;
160+
}
161+
162+
public void setSourceVMName(String sourceVMName) {
163+
this.sourceVMName = sourceVMName;
164+
}
165+
166+
public String getStep() {
167+
return step;
168+
}
169+
170+
public void setStep(String step) {
171+
this.step = step;
172+
}
173+
174+
public Long getDuration() {
175+
return duration;
176+
}
177+
178+
public void setDuration(Long duration) {
179+
this.duration = duration;
180+
}
181+
182+
public String getDescription() {
183+
return description;
184+
}
185+
186+
public void setDescription(String description) {
187+
this.description = description;
188+
}
189+
190+
public String getConvertInstanceHostId() {
191+
return convertInstanceHostId;
192+
}
193+
194+
public void setConvertInstanceHostId(String convertInstanceHostId) {
195+
this.convertInstanceHostId = convertInstanceHostId;
196+
}
197+
198+
public String getConvertInstanceHostName() {
199+
return convertInstanceHostName;
200+
}
201+
202+
public void setConvertInstanceHostName(String convertInstanceHostName) {
203+
this.convertInstanceHostName = convertInstanceHostName;
204+
}
205+
206+
public Date getCreated() {
207+
return created;
208+
}
209+
210+
public void setCreated(Date created) {
211+
this.created = created;
212+
}
213+
214+
public Date getLastUpdated() {
215+
return lastUpdated;
216+
}
217+
218+
public void setLastUpdated(Date lastUpdated) {
219+
this.lastUpdated = lastUpdated;
220+
}
221+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
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;
2223
import org.apache.cloudstack.api.command.admin.vm.ListUnmanagedInstancesCmd;
2324
import org.apache.cloudstack.api.command.admin.vm.ListVmsForImportCmd;
25+
import org.apache.cloudstack.api.response.ImportVMTaskResponse;
2426
import org.apache.cloudstack.api.response.ListResponse;
2527
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
2628
import org.apache.cloudstack.api.response.UserVmResponse;
@@ -42,4 +44,6 @@ public String toString() {
4244
UserVmResponse importVm(ImportVmCmd cmd);
4345

4446
ListResponse<UnmanagedInstanceResponse> listVmsForImport(ListVmsForImportCmd cmd);
47+
48+
ListResponse<ImportVMTaskResponse> listImportVMTasks(ListImportVMTasksCmd cmd);
4549
}

0 commit comments

Comments
 (0)