cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/4.3 to c305e4e
Date Sat, 07 Dec 2013 00:47:53 GMT
Updated Branches:
  refs/heads/4.3 90d29ac86 -> c305e4ec5


CLOUDSTACK-5390: obey page/pageSize parameters in listNetworks call

Conflicts:
	server/src/com/cloud/network/NetworkServiceImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c305e4ec
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c305e4ec
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c305e4ec

Branch: refs/heads/4.3
Commit: c305e4ec5a0cf3e0403b96b1613316ac19155255
Parents: 90d29ac
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Dec 6 16:16:39 2013 -0800
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Dec 6 16:47:41 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/network/NetworkServiceImpl.java   | 36 +++++++++++++++++---
 1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c305e4ec/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index c6c78f5..0a98503 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -1481,7 +1481,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             isRecursive = true;
         }
 
-        Filter searchFilter = new Filter(NetworkVO.class, "id", false, cmd.getStartIndex(),
cmd.getPageSizeVal());
+        Filter searchFilter = new Filter(NetworkVO.class, "id", false, null, null);
         SearchBuilder<NetworkVO> sb = _networksDao.createSearchBuilder();
 
         if (forVpc != null) {
@@ -1608,14 +1608,40 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
             networksToReturn=networksForDeploy;
         }
 
-            return networksToReturn;
+        //Now apply pagination
+        //Most likely pageSize will never exceed int value, and we need integer to partition
the listToReturn
+        boolean notNull = cmd.getStartIndex() != null && cmd.getPageSizeVal() !=
null;
+        if (notNull && cmd.getStartIndex() <= Integer.MAX_VALUE && cmd.getStartIndex()
>= Integer.MIN_VALUE &&
+                cmd.getPageSizeVal() <= Integer.MAX_VALUE && cmd.getPageSizeVal()
>= Integer.MIN_VALUE) {
+            int startIndex = cmd.getStartIndex().intValue() == 0 ? 0 : cmd.getStartIndex().intValue()
- 1;
+            List<NetworkVO> wPagination = new ArrayList<NetworkVO>();
+            List<List<NetworkVO>> partitions = partitionNetworks(networksToReturn,
cmd.getPageSizeVal().intValue());
+            if (startIndex< partitions.size()) {
+                wPagination = partitions.get(startIndex);
+            }
+            return wPagination;
         }
 
+        return networksToReturn;
+    }
 
+    private static List<List<NetworkVO>> partitionNetworks(List<NetworkVO>
originalList,
+            int chunkSize) {
+        List<List<NetworkVO>> listOfChunks = new ArrayList<List<NetworkVO>>();
+        for (int i = 0; i < originalList.size() / chunkSize; i++) {
+            listOfChunks.add(originalList.subList(i * chunkSize, i * chunkSize
+                    + chunkSize));
+        }
+        if (originalList.size() % chunkSize != 0) {
+            listOfChunks.add(originalList.subList(originalList.size()
+                    - originalList.size() % chunkSize, originalList.size()));
+        }
+        return listOfChunks;
+    }
 
-    private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO>
sb, String keyword, Long id,
-            Boolean isSystem, Long zoneId, String guestIpType, String trafficType, Long physicalNetworkId,
-            String aclType, boolean skipProjectNetworks, Boolean restartRequired, Boolean
specifyIpRanges, Long vpcId, Map<String, String> tags) {
+    private SearchCriteria<NetworkVO> buildNetworkSearchCriteria(SearchBuilder<NetworkVO>
sb, String keyword, Long id, Boolean isSystem, Long zoneId, String guestIpType,
+        String trafficType, Long physicalNetworkId, String aclType, boolean skipProjectNetworks,
Boolean restartRequired, Boolean specifyIpRanges, Long vpcId,
+        Map<String, String> tags) {
 
         SearchCriteria<NetworkVO> sc = sb.create();
 


Mime
View raw message