mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CS-19072: fixed broken pagination and count in listVpcs
This commit is contained in:
parent
d42e20429d
commit
477f91327c
@ -97,7 +97,7 @@ public interface VpcService {
|
||||
* @param vpc
|
||||
* @return
|
||||
*/
|
||||
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr, String cidr, Long vpcOffId, String state,
|
||||
public Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr, String cidr, Long vpcOffId, String state,
|
||||
String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired,
|
||||
Map<String, String> tags, Long projectId, Boolean display);
|
||||
|
||||
|
||||
@ -19,15 +19,15 @@ package org.apache.cloudstack.api.command.admin.vpc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ResponseObject.ResponseView;
|
||||
import org.apache.cloudstack.api.command.user.vpc.ListVPCsCmd;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.VpcResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
|
||||
@APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Full)
|
||||
@ -36,18 +36,18 @@ public class ListVPCsCmdByAdmin extends ListVPCsCmd {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<? extends Vpc> vpcs =
|
||||
Pair<List<? extends Vpc>, Integer> vpcs =
|
||||
_vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
|
||||
getKeyword(), getStartIndex(), getPageSizeVal(), getZoneId(), isRecursive(), listAll(), getRestartRequired(), getTags(),
|
||||
getProjectId(), getDisplay());
|
||||
ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
|
||||
List<VpcResponse> offeringResponses = new ArrayList<VpcResponse>();
|
||||
for (Vpc vpc : vpcs) {
|
||||
List<VpcResponse> vpcResponses = new ArrayList<VpcResponse>();
|
||||
for (Vpc vpc : vpcs.first()) {
|
||||
VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Full, vpc);
|
||||
offeringResponses.add(offeringResponse);
|
||||
vpcResponses.add(offeringResponse);
|
||||
}
|
||||
|
||||
response.setResponses(offeringResponses);
|
||||
response.setResponses(vpcResponses, vpcs.second());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -19,8 +19,6 @@ package org.apache.cloudstack.api.command.user.vpc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.acl.RoleType;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
@ -31,8 +29,10 @@ import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.VpcOfferingResponse;
|
||||
import org.apache.cloudstack.api.response.VpcResponse;
|
||||
import org.apache.cloudstack.api.response.ZoneResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.network.vpc.Vpc;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
|
||||
@APICommand(name = "listVPCs", description = "Lists VPCs", responseObject = VpcResponse.class, responseView = ResponseView.Restricted, entityType = {Vpc.class},
|
||||
@ -129,18 +129,18 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
List<? extends Vpc> vpcs =
|
||||
Pair<List<? extends Vpc>, Integer> vpcs =
|
||||
_vpcService.listVpcs(getId(), getVpcName(), getDisplayText(), getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
|
||||
getKeyword(), getStartIndex(), getPageSizeVal(), getZoneId(), isRecursive(), listAll(), getRestartRequired(), getTags(),
|
||||
getProjectId(), getDisplay());
|
||||
ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
|
||||
List<VpcResponse> offeringResponses = new ArrayList<VpcResponse>();
|
||||
for (Vpc vpc : vpcs) {
|
||||
List<VpcResponse> vpcResponses = new ArrayList<VpcResponse>();
|
||||
for (Vpc vpc : vpcs.first()) {
|
||||
VpcResponse offeringResponse = _responseGenerator.createVpcResponse(ResponseView.Restricted, vpc);
|
||||
offeringResponses.add(offeringResponse);
|
||||
vpcResponses.add(offeringResponse);
|
||||
}
|
||||
|
||||
response.setResponses(offeringResponses);
|
||||
response.setResponses(vpcResponses, vpcs.second());
|
||||
response.setResponseName(getCommandName());
|
||||
setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -1003,7 +1003,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Vpc> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr, String cidr, Long vpcOffId, String state,
|
||||
public Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String displayText, List<String> supportedServicesStr, String cidr, Long vpcOffId, String state,
|
||||
String accountName, Long domainId, String keyword, Long startIndex, Long pageSizeVal, Long zoneId, Boolean isRecursive, Boolean listAll, Boolean restartRequired,
|
||||
Map<String, String> tags, Long projectId, Boolean display) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
@ -1015,7 +1015,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
domainId = domainIdRecursiveListProject.first();
|
||||
isRecursive = domainIdRecursiveListProject.second();
|
||||
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
|
||||
Filter searchFilter = new Filter(VpcVO.class, "created", false, startIndex, pageSizeVal);
|
||||
Filter searchFilter = new Filter(VpcVO.class, "created", false, null, null);
|
||||
|
||||
SearchBuilder<VpcVO> sb = _vpcDao.createSearchBuilder();
|
||||
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
|
||||
@ -1128,9 +1128,21 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
|
||||
}
|
||||
}
|
||||
|
||||
return supportedVpcs;
|
||||
List<?> wPagination = StringUtils.applyPagination(supportedVpcs, startIndex, pageSizeVal);
|
||||
if (wPagination != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>((List<Vpc>) wPagination, supportedVpcs.size());
|
||||
return listWPagination;
|
||||
}
|
||||
return new Pair<List<? extends Vpc>, Integer>(supportedVpcs, supportedVpcs.size());
|
||||
} else {
|
||||
return vpcs;
|
||||
List<?> wPagination = StringUtils.applyPagination(vpcs, startIndex, pageSizeVal);
|
||||
if (wPagination != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<List<? extends Vpc>, Integer> listWPagination = new Pair<List<? extends Vpc>, Integer>((List<Vpc>) wPagination, vpcs.size());
|
||||
return listWPagination;
|
||||
}
|
||||
return new Pair<List<? extends Vpc>, Integer>(vpcs, vpcs.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user