diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index e0552aa01bc..f36d0ee02a2 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -223,7 +223,6 @@
-
diff --git a/client/tomcatconf/nonossComponentContext.xml.in b/client/tomcatconf/nonossComponentContext.xml.in
index 2be071eab02..90fd4b0c70b 100644
--- a/client/tomcatconf/nonossComponentContext.xml.in
+++ b/client/tomcatconf/nonossComponentContext.xml.in
@@ -322,7 +322,6 @@
-
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
index 0ba80a922b7..1f5083a8e14 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
@@ -76,7 +76,7 @@ public interface VolumeDao extends GenericDao, StateDao findReadyRootVolumesByInstance(long instanceId);
List listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId);
-
+ List listZoneWidePoolIdsByVolumeCount(long dcId, long accountId);
/**
* Gets the Total Primary Storage space allocated for an account
*
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
index efe41c90973..bf284105685 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -78,7 +78,8 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
+ " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC ";
-
+ private static final String ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
+ + " AND pool.scope = 'ZONE' AND pool.status='Up' " + " GROUP BY pool.id ORDER BY 2 ASC ";
@Override
public List findDetachedByAccount(long accountId) {
SearchCriteria sc = DetachedAccountIdSearch.create();
@@ -480,6 +481,30 @@ public class VolumeDaoImpl extends GenericDaoBase implements Vol
}
}
+ @Override
+ public List listZoneWidePoolIdsByVolumeCount(long dcId, long accountId) {
+
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement pstmt = null;
+ List result = new ArrayList();
+ try {
+ String sql = ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT;
+ pstmt = txn.prepareAutoCloseStatement(sql);
+ pstmt.setLong(1, accountId);
+ pstmt.setLong(2, dcId);
+
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ result.add(rs.getLong(1));
+ }
+ return result;
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("DB Exception on: " + ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
+ } catch (Throwable e) {
+ throw new CloudRuntimeException("Caught: " + ORDER_ZONE_WIDE_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e);
+ }
+ }
+
@Override
@DB(txn = false)
public Pair getNonDestroyedCountAndTotalByPool(long poolId) {
diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java
index 0288b172ca2..38724fa8214 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/ZoneWideStoragePoolAllocator.java
@@ -17,10 +17,13 @@
package org.apache.cloudstack.storage.allocator;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.inject.Inject;
+import com.cloud.user.Account;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
@@ -101,4 +104,35 @@ public class ZoneWideStoragePoolAllocator extends AbstractStoragePoolAllocator {
}
return suitablePools;
}
+ @Override
+ protected List reorderPoolsByNumberOfVolumes(DeploymentPlan plan, List pools,
+ Account account) {
+ if (account == null) {
+ return pools;
+ }
+ long dcId = plan.getDataCenterId();
+
+ List poolIdsByVolCount = _volumeDao.listZoneWidePoolIdsByVolumeCount(dcId,
+ account.getAccountId());
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("List of pools in ascending order of number of volumes for account id: "
+ + account.getAccountId() + " is: " + poolIdsByVolCount);
+ }
+
+ // now filter the given list of Pools by this ordered list
+ Map poolMap = new HashMap();
+ for (StoragePool pool : pools) {
+ poolMap.put(pool.getId(), pool);
+ }
+ List matchingPoolIds = new ArrayList(poolMap.keySet());
+
+ poolIdsByVolCount.retainAll(matchingPoolIds);
+
+ List reorderedPools = new ArrayList();
+ for (Long id : poolIdsByVolCount) {
+ reorderedPools.add(poolMap.get(id));
+ }
+
+ return reorderedPools;
+ }
}