diff --git a/server/src/com/cloud/storage/dao/StoragePoolDao.java b/server/src/com/cloud/storage/dao/StoragePoolDao.java index ce2f25e7d68..201f9153eab 100644 --- a/server/src/com/cloud/storage/dao/StoragePoolDao.java +++ b/server/src/com/cloud/storage/dao/StoragePoolDao.java @@ -14,9 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - */ -package com.cloud.storage.dao; - + */ +package com.cloud.storage.dao; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -25,47 +25,47 @@ import com.cloud.host.Status; import com.cloud.storage.StoragePoolStatus; import com.cloud.storage.StoragePoolVO; import com.cloud.utils.db.GenericDao; -/** - * Data Access Object for storage_pool table - */ -public interface StoragePoolDao extends GenericDao { - - /** - * @param datacenterId -- the id of the datacenter (availability zone) - * @return the list of storage pools in the datacenter - */ - List listByDataCenterId(long datacenterId); - - /** - * @param datacenterId -- the id of the datacenter (availability zone) - * @param podId the id of the pod - * @return the list of storage pools in the datacenter - */ - List listBy(long datacenterId, long podId, Long clusterId); - - /** - * Set capacity of storage pool in bytes - * @param id pool id. - * @param capacity capacity in bytes - */ - void updateCapacity(long id, long capacity); - - /** - * Set available bytes of storage pool in bytes - * @param id pool id. - * @param available available capacity in bytes - */ - void updateAvailable(long id, long available); +/** + * Data Access Object for storage_pool table + */ +public interface StoragePoolDao extends GenericDao { + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + * @return the list of storage pools in the datacenter + */ + List listByDataCenterId(long datacenterId); + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + * @param podId the id of the pod + * @return the list of storage pools in the datacenter + */ + List listBy(long datacenterId, long podId, Long clusterId); + + /** + * Set capacity of storage pool in bytes + * @param id pool id. + * @param capacity capacity in bytes + */ + void updateCapacity(long id, long capacity); + + /** + * Set available bytes of storage pool in bytes + * @param id pool id. + * @param available available capacity in bytes + */ + void updateAvailable(long id, long available); - + StoragePoolVO persist(StoragePoolVO pool, Map details); - /** - * Find pool by name. - * - * @param name name of pool. - * @return the single StoragePoolVO - */ + /** + * Find pool by name. + * + * @param name name of pool. + * @return the single StoragePoolVO + */ List findPoolByName(String name); /** @@ -79,18 +79,18 @@ public interface StoragePoolDao extends GenericDao { List findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared); - /** - * Find pool by UUID. - * - * @param uuid uuid of pool. - * @return the single StoragePoolVO - */ - StoragePoolVO findPoolByUUID(String uuid); - - List listByStorageHost(String hostFqdnOrIp); - - StoragePoolVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid); - + /** + * Find pool by UUID. + * + * @param uuid uuid of pool. + * @return the single StoragePoolVO + */ + StoragePoolVO findPoolByUUID(String uuid); + + List listByStorageHost(String hostFqdnOrIp); + + StoragePoolVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid); + List listPoolByHostPath(String host, String path); void deleteStoragePoolRecords(ArrayList ids); @@ -101,9 +101,10 @@ public interface StoragePoolDao extends GenericDao { List searchForStoragePoolDetails(long poolId, String value); - long countBy(long podId, Status... statuses); - List findIfDuplicatePoolsExistByUUID(String uuid); List listByStatus(StoragePoolStatus status); -} + + long countPoolsByStatus(StoragePoolStatus... statuses); + +} diff --git a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java index 468284b237f..146d8e9d134 100644 --- a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java +++ b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java @@ -50,7 +50,8 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp protected final SearchBuilder DcPodSearch; protected final SearchBuilder DcPodAnyClusterSearch; protected final SearchBuilder DeleteLvmSearch; - protected final GenericSearchBuilder MaintenanceCountSearch; + protected final GenericSearchBuilder StatusCountSearch; + protected final StoragePoolDetailsDao _detailsDao; @@ -94,11 +95,12 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp DeleteLvmSearch.cp(); DeleteLvmSearch.done(); - MaintenanceCountSearch = createSearchBuilder(Long.class); - MaintenanceCountSearch.and("pool", MaintenanceCountSearch.entity().getId(), SearchCriteria.Op.EQ); - MaintenanceCountSearch.select(null, Func.COUNT, null); - MaintenanceCountSearch.and("status", MaintenanceCountSearch.entity().getStatus(), SearchCriteria.Op.IN); - MaintenanceCountSearch.done(); + + + StatusCountSearch = createSearchBuilder(Long.class); + StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN); + StatusCountSearch.select(null, Func.COUNT, null); + StatusCountSearch.done(); _detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class); } @@ -349,12 +351,13 @@ public class StoragePoolDaoImpl extends GenericDaoBase imp return true; } + + @Override - public long countBy(long primaryStorageId, Status... statuses) { - SearchCriteria sc = MaintenanceCountSearch.create(); + public long countPoolsByStatus( StoragePoolStatus... statuses) { + SearchCriteria sc = StatusCountSearch.create(); sc.setParameters("status", (Object[])statuses); - sc.setParameters("pool", primaryStorageId); List rs = customSearchIncludingRemoved(sc, null); if (rs.size() == 0) { diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 43c7c90591a..e3d3d236f5f 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2383,9 +2383,8 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager } // check if we have available pools for vm deployment - List availablePools = _storagePoolDao.listByStatus(StoragePoolStatus.Up); - - if (availablePools == null || availablePools.size() < 1) { + long availablePools = _storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up); + if (availablePools < 1) { throw new StorageUnavailableException("There are no available pools in the UP state for vm deployment", -1); }