mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
bug 8945: introduced "default.page.limit" config param (default value is 500). Used for pagination in API list* commands.
status 8945: resolved fixed
This commit is contained in:
parent
397b338f09
commit
d3f04b2b38
@ -73,6 +73,7 @@ public abstract class BaseCmd {
|
||||
public static final int MALFORMED_PARAMETER_ERROR = 430;
|
||||
public static final int PARAM_ERROR = 431;
|
||||
public static final int UNSUPPORTED_ACTION_ERROR = 432;
|
||||
public static final int PAGE_LIMIT_EXCEED = 433;
|
||||
|
||||
// Server error codes
|
||||
public static final int INTERNAL_ERROR = 530;
|
||||
|
||||
@ -6,7 +6,7 @@ import com.cloud.exception.InvalidParameterValueException;
|
||||
|
||||
public abstract class BaseListCmd extends BaseCmd {
|
||||
|
||||
private static final Long MAX_PAGESIZE = 500L;
|
||||
private static final Long MAX_PAGESIZE = _configService.getDefaultPageSize();
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////// BaseList API parameters /////////////////
|
||||
@ -52,9 +52,9 @@ public abstract class BaseListCmd extends BaseCmd {
|
||||
if (pageSize == -1) {
|
||||
pageSize = null;
|
||||
} else if (pageSize > MAX_PAGESIZE){//FIX ME - have a validator and do this.
|
||||
throw new InvalidParameterValueException("The parameter " +ApiConstants.PAGE_SIZE+ " exceeded its max value - "+MAX_PAGESIZE);
|
||||
throw new InvalidParameterValueException("The parameter " + ApiConstants.PAGE_SIZE + " exceeded its max value - " + MAX_PAGESIZE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
|
||||
@ -191,5 +191,7 @@ public interface ConfigurationService {
|
||||
DataCenter getZone(long id);
|
||||
|
||||
ServiceOffering getServiceOffering(long serviceOfferingId);
|
||||
|
||||
Long getDefaultPageSize();
|
||||
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
private static List<String> s_allCommands = null;
|
||||
|
||||
private static ExecutorService _executor = new ThreadPoolExecutor(10, 150, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("ApiServer"));
|
||||
|
||||
|
||||
static {
|
||||
s_userCommands = new ArrayList<String>();
|
||||
s_resellerCommands = new ArrayList<String>();
|
||||
@ -436,12 +436,21 @@ public class ApiServer implements HttpRequestHandler {
|
||||
// if the command is of the listXXXCommand, we will need to also return the
|
||||
// the job id and status if possible
|
||||
if (cmdObj instanceof BaseListCmd) {
|
||||
validatePageSize((BaseListCmd)cmdObj);
|
||||
buildAsyncListResponse((BaseListCmd)cmdObj, account);
|
||||
}
|
||||
return ApiResponseSerializer.toSerializedString((ResponseObject)cmdObj.getResponseObject(), cmdObj.getResponseType());
|
||||
}
|
||||
}
|
||||
|
||||
private void validatePageSize(BaseListCmd command) {
|
||||
List<ResponseObject> responses = ((ListResponse)command.getResponseObject()).getResponses();
|
||||
int defaultPageLimit = BaseCmd._configService.getDefaultPageSize().intValue();
|
||||
if (responses != null && responses.size() > defaultPageLimit && command.getPage() == null && command.getPageSize() == null) {
|
||||
throw new ServerApiException(BaseCmd.PAGE_LIMIT_EXCEED, "Number of returned objects per page exceed default page limit " + defaultPageLimit + "; please specify \"page\"/\"pagesize\" parameters");
|
||||
}
|
||||
}
|
||||
|
||||
private void buildAsyncListResponse(BaseListCmd command, Account account) {
|
||||
List<ResponseObject> responses = ((ListResponse)command.getResponseObject()).getResponses();
|
||||
if (responses != null && responses.size() > 0) {
|
||||
|
||||
@ -217,7 +217,9 @@ public enum Config {
|
||||
VmOpLockStateRetry("Advanced", ManagementServer.class, Integer.class, "vm.op.lock.state.retry", "5", "Times to retry locking the state of a VM for operations", "-1 means try forever"),
|
||||
VmOpCleanupInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.interval", "86400", "Interval to run the thread that cleans up the vm operations (in seconds)", "Seconds"),
|
||||
VmOpCleanupWait("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.wait", "3600", "Time (in seconds) to wait before cleanuping up any vm work items", "Seconds"),
|
||||
VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds");
|
||||
VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds"),
|
||||
|
||||
DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null);
|
||||
|
||||
|
||||
private final String _category;
|
||||
|
||||
@ -162,6 +162,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
protected static final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = ComponentLocator.inject(DataCenterLinkLocalIpAddressDaoImpl.class);
|
||||
|
||||
private int _maxVolumeSizeInGb;
|
||||
private long _defaultPageSize;
|
||||
protected Set<String> configValuesForValidation;
|
||||
|
||||
@Override
|
||||
@ -170,6 +171,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
|
||||
String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size");
|
||||
_maxVolumeSizeInGb = NumbersUtil.parseInt(maxVolumeSizeInGbString, 2000);
|
||||
|
||||
String defaultPageSizeString = _configDao.getValue("default.page.size");
|
||||
_defaultPageSize = NumbersUtil.parseLong(defaultPageSizeString, 500L);
|
||||
|
||||
populateConfigValuesForValidationSet();
|
||||
return true;
|
||||
@ -2787,4 +2791,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
||||
public ServiceOffering getServiceOffering(long serviceOfferingId) {
|
||||
return _serviceOfferingDao.findById(serviceOfferingId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDefaultPageSize() {
|
||||
return _defaultPageSize;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user