Skip to content

Commit 15bda19

Browse files
committed
propagate token to user/UI
1 parent f7171f2 commit 15bda19

File tree

4 files changed

+49
-33
lines changed

4 files changed

+49
-33
lines changed

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/VmwareDatacenterService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.cloud.exception.DiscoveryException;
2424
import com.cloud.exception.ResourceInUseException;
2525
import com.cloud.storage.StoragePool;
26+
import com.cloud.utils.Pair;
2627
import com.cloud.utils.component.PluggableService;
2728
import com.cloud.utils.exception.CloudRuntimeException;
2829
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
@@ -53,5 +54,5 @@ public interface VmwareDatacenterService extends PluggableService {
5354

5455
List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsphereStoragePolicyCompatiblePoolsCmd cmd);
5556

56-
List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd);
57+
Pair<String, List<UnmanagedInstanceTO>> listVMsInDatacenter(ListVmwareDcVmsCmd cmd);
5758
}

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,21 +1558,13 @@ public List<StoragePool> listVsphereStoragePolicyCompatibleStoragePools(ListVsph
15581558
}
15591559

15601560
@Override
1561-
public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
1561+
public Pair<String, List<UnmanagedInstanceTO>> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
15621562
String vcenter = cmd.getVcenter();
15631563
String datacenterName = cmd.getDatacenterName();
15641564
String username = cmd.getUsername();
15651565
String password = cmd.getPassword();
15661566
Integer maxObjects = cmd.getPageSize();
1567-
boolean forced = cmd.isForced();
1568-
// TODO refactor to check if the page is available
1569-
boolean nextPage = cmd.getPageNumber() == null || cmd.getPageNumber() <= 1;
1570-
if (forced) {
1571-
// remove existing data from local map
1572-
}
1573-
if (nextPage) {
1574-
// check if there is a next page possible
1575-
}
1567+
String token = cmd.getToken();
15761568

15771569
Long existingVcenterId = cmd.getExistingVcenterId();
15781570
String keyword = cmd.getKeyword();
@@ -1613,10 +1605,7 @@ public List<UnmanagedInstanceTO> listVMsInDatacenter(ListVmwareDcVmsCmd cmd) {
16131605
s_logger.error(msg);
16141606
throw new InvalidParameterValueException(msg);
16151607
}
1616-
List<UnmanagedInstanceTO> instances = Collections.synchronizedList(new ArrayList<>());
1617-
instances.addAll(dcMo.getVmsOnDatacenter(maxObjects, null).second());
1618-
return StringUtils.isBlank(keyword) ? instances :
1619-
instances.stream().filter(x -> x.getName().toLowerCase().contains(keyword.toLowerCase())).collect(Collectors.toList());
1608+
return dcMo.getVmsOnDatacenter(maxObjects, token);
16201609
} catch (InvalidParameterValueException | VmwareClientException | InvalidLocaleFaultMsg | InvalidLoginFaultMsg |
16211610
RuntimeFaultFaultMsg | URISyntaxException | InvalidPropertyFaultMsg | InvocationTargetException |
16221611
NoSuchMethodException | IllegalAccessException e) {

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/api/command/admin/zone/ListVmwareDcVmsCmd.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.cloud.exception.ResourceUnavailableException;
2424
import com.cloud.hypervisor.vmware.VmwareDatacenterService;
2525
import com.cloud.user.Account;
26+
import com.cloud.utils.Pair;
2627
import com.cloud.utils.exception.CloudRuntimeException;
2728
import org.apache.cloudstack.api.APICommand;
2829
import org.apache.cloudstack.api.ApiConstants;
@@ -31,7 +32,6 @@
3132
import org.apache.cloudstack.api.BaseResponse;
3233
import org.apache.cloudstack.api.Parameter;
3334
import org.apache.cloudstack.api.ServerApiException;
34-
import org.apache.cloudstack.api.response.ListResponse;
3535
import org.apache.cloudstack.api.response.UnmanagedInstanceResponse;
3636
import org.apache.cloudstack.api.response.VmwareDatacenterResponse;
3737
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
@@ -73,11 +73,10 @@ public class ListVmwareDcVmsCmd extends BaseListCmd {
7373
@Parameter(name = ApiConstants.PAGE_SIZE, type = CommandType.INTEGER, description = "The maximum number of results to return.")
7474
private Integer pageSize;
7575

76-
@Parameter(name = ApiConstants.PAGE, type = CommandType.INTEGER,
77-
description = "For listVmwareDcVms, the maximum number of results to return is either 0, 1 or more." +
78-
" When more than 1, the next page as returned by the vcenter will be propagated to the caller." +
79-
" If no previous call has been done, this is the same as the first page")
80-
private Integer pageNumber;
76+
@Parameter(name = ApiConstants.TOKEN, type = CommandType.STRING,
77+
description = "For listVmwareDcVms, if the maximum number of results (the `pagesize`) is exceeded, " +
78+
" a token is returned. This token can be used in subsequent calls to retrieve more results")
79+
private String token;
8180

8281
@Parameter(name = ApiConstants.FORCED, type = CommandType.BOOLEAN, description = "force retrieving new results, ignoring any cached data.")
8382
private Boolean forced;
@@ -94,16 +93,8 @@ public String getPassword() {
9493
return password;
9594
}
9695

97-
public Integer getPageSize() {
98-
return pageSize;
99-
}
100-
101-
public Integer getPageNumber() {
102-
return pageNumber;
103-
}
104-
105-
public boolean isForced() {
106-
return forced == null ? true : forced;
96+
public String getToken() {
97+
return token;
10798
}
10899

109100
public String getDatacenterName() {
@@ -118,7 +109,8 @@ public Long getExistingVcenterId() {
118109
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
119110
checkParameters();
120111
try {
121-
List<UnmanagedInstanceTO> vms = _vmwareDatacenterService.listVMsInDatacenter(this);
112+
Pair<String, List<UnmanagedInstanceTO>> results = _vmwareDatacenterService.listVMsInDatacenter(this);
113+
List<UnmanagedInstanceTO> vms = results.second();
122114
List<BaseResponse> baseResponseList = new ArrayList<>();
123115
if (CollectionUtils.isNotEmpty(vms)) {
124116
for (UnmanagedInstanceTO vmwareVm : vms) {
@@ -130,9 +122,10 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
130122
if (CollectionUtils.isEmpty(pagingList)) {
131123
pagingList = baseResponseList;
132124
}
133-
ListResponse<BaseResponse> response = new ListResponse<>();
125+
VmwarRequestReponse<BaseResponse> response = new VmwarRequestReponse<>();
134126
response.setResponses(pagingList, baseResponseList.size());
135127
response.setResponseName(getCommandName());
128+
response.setToken(results.first());
136129
setResponseObject(response);
137130
} catch (CloudRuntimeException e) {
138131
String errorMsg = String.format("Error retrieving VMs from VMware VC: %s", e.getMessage());
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
18+
package org.apache.cloudstack.api.command.admin.zone;
19+
20+
import org.apache.cloudstack.api.ResponseObject;
21+
import org.apache.cloudstack.api.response.ListResponse;
22+
23+
public class VmwarRequestReponse <T extends ResponseObject> extends ListResponse<T> {
24+
private transient String token;
25+
26+
public String getToken() {
27+
return token;
28+
}
29+
30+
public void setToken(String token) {
31+
this.token = token;
32+
}
33+
}

0 commit comments

Comments
 (0)