diff --git a/api/src/com/cloud/api/BaseListCmd.java b/api/src/com/cloud/api/BaseListCmd.java
index de98b0a36d5..9b43435c1b9 100755
--- a/api/src/com/cloud/api/BaseListCmd.java
+++ b/api/src/com/cloud/api/BaseListCmd.java
@@ -3,28 +3,27 @@ package com.cloud.api;
import com.cloud.async.AsyncJob;
import com.cloud.exception.InvalidParameterValueException;
-
public abstract class BaseListCmd extends BaseCmd {
private static Long MAX_PAGESIZE = 500L;
- /////////////////////////////////////////////////////
- /////////// BaseList API parameters /////////////////
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
+ // ///////// BaseList API parameters /////////////////
+ // ///////////////////////////////////////////////////
- @Parameter(name="keyword", type=CommandType.STRING, description="List by keyword")
+ @Parameter(name = "keyword", type = CommandType.STRING, description = "List by keyword")
private String keyword;
- // FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
- @Parameter(name=ApiConstants.PAGE, type=CommandType.INTEGER)
+ // FIXME: Need to be able to specify next/prev/first/last, so Integer might not be right
+ @Parameter(name = ApiConstants.PAGE, type = CommandType.INTEGER)
private Integer page;
- @Parameter(name=ApiConstants.PAGE_SIZE, type=CommandType.INTEGER)
+ @Parameter(name = ApiConstants.PAGE_SIZE, type = CommandType.INTEGER)
private Integer pageSize;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
public String getKeyword() {
return keyword;
@@ -35,51 +34,46 @@ public abstract class BaseListCmd extends BaseCmd {
}
public Integer getPageSize() {
+ if (pageSize != null && pageSize.longValue() > MAX_PAGESIZE.longValue()) {
+ throw new InvalidParameterValueException("Page size can't exceed max allowed page size value: " + MAX_PAGESIZE.longValue());
+ }
+
return pageSize;
}
-
-
+
static void configure() {
MAX_PAGESIZE = _configService.getDefaultPageSize();
}
-
+
@Override
public long getEntityOwnerId() {
- //no owner is needed for list command
+ // no owner is needed for list command
return 0;
}
public Long getPageSizeVal() {
- Long pageSize = null;
+ Long pageSize = MAX_PAGESIZE;
Integer pageSizeInt = getPageSize();
- if (pageSizeInt != null) {
- pageSize = pageSizeInt.longValue();
- 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);
- }
- }
+ if (pageSizeInt != null && pageSizeInt.intValue() != -1) {
+ pageSize = pageSizeInt.longValue();
+ }
return pageSize;
}
public Long getStartIndex() {
Long startIndex = Long.valueOf(0);
Long pageSizeVal = getPageSizeVal();
- if (pageSizeVal == null) {
- return null; // there's no limit, so start index is irrelevant
- }
if (page != null) {
int pageNum = page.intValue();
if (pageNum > 0) {
- startIndex = Long.valueOf(pageSizeVal * (pageNum-1));
+ startIndex = Long.valueOf(pageSizeVal * (pageNum - 1));
}
}
return startIndex;
}
-
+
public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.None;
+ return AsyncJob.Type.None;
}
}
diff --git a/api/src/com/cloud/api/commands/ListAlertsCmd.java b/api/src/com/cloud/api/commands/ListAlertsCmd.java
index b4bbc24b6dd..dbb603d06ef 100644
--- a/api/src/com/cloud/api/commands/ListAlertsCmd.java
+++ b/api/src/com/cloud/api/commands/ListAlertsCmd.java
@@ -15,8 +15,8 @@
* along with this program. If not, see .
*
*/
-package com.cloud.api.commands;
-
+package com.cloud.api.commands;
+
import java.util.ArrayList;
import java.util.List;
@@ -27,50 +27,49 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
-import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.AlertResponse;
import com.cloud.api.response.ListResponse;
-@Implementation(description="Lists all alerts.", responseObject=AlertResponse.class)
+@Implementation(description = "Lists all alerts.", responseObject = AlertResponse.class)
public class ListAlertsCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListAlertsCmd.class.getName());
private static final String s_name = "listalertsresponse";
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
- @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the ID of the alert")
+ @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the ID of the alert")
private Long id;
-
- @Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, description="list by alert type")
+
+ @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "list by alert type")
private String type;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
public Long getId() {
return id;
}
-
+
public String getType() {
return type;
}
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
-
+
@Override
- public void execute(){
+ public void execute() {
List extends Alert> result = _mgr.searchForAlerts(this);
ListResponse response = new ListResponse();
List alertResponseList = new ArrayList();
diff --git a/api/src/com/cloud/api/commands/ListCapacityCmd.java b/api/src/com/cloud/api/commands/ListCapacityCmd.java
index f54c98dc1ba..5b36b9616e2 100755
--- a/api/src/com/cloud/api/commands/ListCapacityCmd.java
+++ b/api/src/com/cloud/api/commands/ListCapacityCmd.java
@@ -93,9 +93,7 @@ public class ListCapacityCmd extends BaseListCmd {
pageSizeVal = pageSize.longValue();
}
return pageSizeVal;
- }
-
-
+ }
@Override
public void execute(){
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index f8ce0a295f1..5f3bb98bbe1 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -431,20 +431,12 @@ 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 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 responses = ((ListResponse)command.getResponseObject()).getResponses();