cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject [3/4] git commit: updated refs/heads/master to fa74b3a
Date Mon, 28 Jul 2014 21:55:28 GMT
CS-19072: fixed broken pagination and count in listNetworkOfferings


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

Branch: refs/heads/master
Commit: 8b98cc22028ce867671cc360ad81a764b44be88a
Parents: ca8d367
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Mon Jul 28 14:25:46 2014 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Mon Jul 28 14:44:04 2014 -0700

----------------------------------------------------------------------
 .../configuration/ConfigurationService.java     |  3 +-
 .../user/network/ListNetworkOfferingsCmd.java   | 10 +++----
 .../configuration/ConfigurationManagerImpl.java | 30 ++++++++++++++------
 .../cloud/vpc/MockConfigurationManagerImpl.java |  6 ++--
 4 files changed, 31 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b98cc22/api/src/com/cloud/configuration/ConfigurationService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/configuration/ConfigurationService.java b/api/src/com/cloud/configuration/ConfigurationService.java
index 50474de..ecea000 100644
--- a/api/src/com/cloud/configuration/ConfigurationService.java
+++ b/api/src/com/cloud/configuration/ConfigurationService.java
@@ -58,6 +58,7 @@ import com.cloud.offering.DiskOffering;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offering.ServiceOffering;
 import com.cloud.user.Account;
+import com.cloud.utils.Pair;
 
 public interface ConfigurationService {
 
@@ -248,7 +249,7 @@ public interface ConfigurationService {
 
     NetworkOffering updateNetworkOffering(UpdateNetworkOfferingCmd cmd);
 
-    List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd);
+    Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd);
 
     boolean deleteNetworkOffering(DeleteNetworkOfferingCmd cmd);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b98cc22/api/src/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java
b/api/src/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java
index 6ac0f39..27b3e89 100644
--- a/api/src/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/network/ListNetworkOfferingsCmd.java
@@ -19,8 +19,6 @@ package org.apache.cloudstack.api.command.user.network;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.log4j.Logger;
-
 import org.apache.cloudstack.api.APICommand;
 import org.apache.cloudstack.api.ApiConstants;
 import org.apache.cloudstack.api.BaseListCmd;
@@ -29,8 +27,10 @@ import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.NetworkOfferingResponse;
 import org.apache.cloudstack.api.response.NetworkResponse;
 import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.log4j.Logger;
 
 import com.cloud.offering.NetworkOffering;
+import com.cloud.utils.Pair;
 
 @APICommand(name = "listNetworkOfferings", description = "Lists all available network offerings.",
responseObject = NetworkOfferingResponse.class,
         requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -187,15 +187,15 @@ public class ListNetworkOfferingsCmd extends BaseListCmd {
 
     @Override
     public void execute() {
-        List<? extends NetworkOffering> offerings = _configService.searchForNetworkOfferings(this);
+        Pair<List<? extends NetworkOffering>, Integer> offerings = _configService.searchForNetworkOfferings(this);
         ListResponse<NetworkOfferingResponse> response = new ListResponse<NetworkOfferingResponse>();
         List<NetworkOfferingResponse> offeringResponses = new ArrayList<NetworkOfferingResponse>();
-        for (NetworkOffering offering : offerings) {
+        for (NetworkOffering offering : offerings.first()) {
             NetworkOfferingResponse offeringResponse = _responseGenerator.createNetworkOfferingResponse(offering);
             offeringResponses.add(offeringResponse);
         }
 
-        response.setResponses(offeringResponses);
+        response.setResponses(offeringResponses, offerings.second());
         response.setResponseName(getCommandName());
         this.setResponseObject(response);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b98cc22/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 42ac19f..388fc06 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -37,9 +37,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import com.cloud.storage.StorageManager;
-
-import org.apache.log4j.Logger;
 import org.apache.cloudstack.acl.SecurityChecker;
 import org.apache.cloudstack.affinity.AffinityGroup;
 import org.apache.cloudstack.affinity.AffinityGroupService;
@@ -87,6 +84,7 @@ import org.apache.cloudstack.region.dao.RegionDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.apache.log4j.Logger;
 
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -180,6 +178,7 @@ import com.cloud.service.dao.ServiceOfferingDetailsDao;
 import com.cloud.storage.DiskOfferingVO;
 import com.cloud.storage.Storage.ProvisioningType;
 import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.StorageManager;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.test.IPRangeConfig;
 import com.cloud.user.Account;
@@ -4273,10 +4272,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
     }
 
     @Override
-    public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd) {
+    public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd) {
         Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm"));
         isAscending = (isAscending == null ? true : isAscending);
-        Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending,
cmd.getStartIndex(), cmd.getPageSizeVal());
+        Filter searchFilter = new Filter(NetworkOfferingVO.class, "sortKey", isAscending,
null, null);
         Account caller = CallContext.current().getCallingAccount();
         SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
 
@@ -4356,7 +4355,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
             if (zone.getNetworkType() == NetworkType.Basic) {
                 // return empty list as we don't allow to create networks in
                 // basic zone, and shouldn't display networkOfferings
-                return new ArrayList<NetworkOffering>();
+                return new Pair<List<? extends NetworkOffering>, Integer>(new
ArrayList<NetworkOffering>(), 0);
             }
         }
 
@@ -4385,7 +4384,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
             if (!offeringIds.isEmpty()) {
                 sc.addAnd("id", SearchCriteria.Op.IN, offeringIds.toArray());
             } else {
-                return new ArrayList<NetworkOffering>();
+                return new Pair<List<? extends NetworkOffering>, Integer>(new
ArrayList<NetworkOffering>(), 0);
             }
         }
 
@@ -4487,9 +4486,22 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
 
             }
 
-            return supportedOfferings;
+            // Now apply pagination
+            List<?> wPagination = StringUtils.applyPagination(supportedOfferings, cmd.getStartIndex(),
cmd.getPageSizeVal());
+            if (wPagination != null) {
+                @SuppressWarnings("unchecked")
+                Pair<List<? extends NetworkOffering>, Integer> listWPagination
= new Pair<List<? extends NetworkOffering>, Integer>((List<NetworkOffering>)
wPagination, offerings.size());
+                return listWPagination;
+            }
+            return new Pair<List<? extends NetworkOffering>, Integer>(supportedOfferings,
supportedOfferings.size());
         } else {
-            return offerings;
+            List<?> wPagination = StringUtils.applyPagination(offerings, cmd.getStartIndex(),
cmd.getPageSizeVal());
+            if (wPagination != null) {
+                @SuppressWarnings("unchecked")
+                Pair<List<? extends NetworkOffering>, Integer> listWPagination
= new Pair<List<? extends NetworkOffering>, Integer>((List<NetworkOffering>)
wPagination, offerings.size());
+                return listWPagination;
+            }
+            return new Pair<List<? extends NetworkOffering>, Integer>(offerings,
offerings.size());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8b98cc22/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
index 71d8580..fc535bd 100755
--- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java
@@ -24,8 +24,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
 import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
 import org.apache.cloudstack.api.command.admin.network.DeleteNetworkOfferingCmd;
@@ -52,6 +50,7 @@ import org.apache.cloudstack.api.command.user.network.ListNetworkOfferingsCmd;
 import org.apache.cloudstack.config.Configuration;
 import org.apache.cloudstack.region.PortableIp;
 import org.apache.cloudstack.region.PortableIpRange;
+import org.springframework.stereotype.Component;
 
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.configuration.ConfigurationService;
@@ -80,6 +79,7 @@ import com.cloud.offerings.NetworkOfferingVO;
 import com.cloud.offerings.dao.NetworkOfferingDaoImpl;
 import com.cloud.org.Grouping.AllocationState;
 import com.cloud.user.Account;
+import com.cloud.utils.Pair;
 import com.cloud.utils.component.ManagerBase;
 
 @Component
@@ -255,7 +255,7 @@ public class MockConfigurationManagerImpl extends ManagerBase implements
Configu
      * @see com.cloud.configuration.ConfigurationService#searchForNetworkOfferings(org.apache.cloudstack.api.commands.ListNetworkOfferingsCmd)
      */
     @Override
-    public List<? extends NetworkOffering> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd) {
+    public Pair<List<? extends NetworkOffering>, Integer> searchForNetworkOfferings(ListNetworkOfferingsCmd
cmd) {
         // TODO Auto-generated method stub
         return null;
     }


Mime
View raw message