diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java index 7e558f81ea7..92793f1fb1a 100644 --- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java +++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.annotation.PostConstruct; import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; @@ -55,9 +54,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase protected final SearchBuilder DcPodAnyClusterSearch; protected final SearchBuilder DeleteLvmSearch; protected final GenericSearchBuilder StatusCountSearch; - protected SearchBuilder HostSearch; - protected SearchBuilder HostPoolSearch; - protected SearchBuilder TagPoolSearch; @Inject protected StoragePoolDetailsDao _detailsDao; @@ -120,26 +116,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase } - @PostConstruct - void init() { - HostSearch = createSearchBuilder(); - TagPoolSearch = _detailsDao.createSearchBuilder(); - HostPoolSearch = _hostDao.createSearchBuilder(); - // Search for pools on the host - HostPoolSearch.and("hostId", HostPoolSearch.entity().getHostId(), Op.EQ); - // Set criteria for pools - HostSearch.and("scope", HostSearch.entity().getScope(), Op.EQ); - HostSearch.and("removed", HostSearch.entity().getRemoved(), Op.NULL); - HostSearch.and("status", HostSearch.entity().getStatus(), Op.EQ); - HostSearch.join("hostJoin", HostPoolSearch, HostSearch.entity().getId(), HostPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER); - // Set criteria for tags - TagPoolSearch.and("name", TagPoolSearch.entity().getName(), Op.EQ); - TagPoolSearch.and("value", TagPoolSearch.entity().getValue(), Op.EQ); - - HostSearch.join("tagJoin", TagPoolSearch, HostSearch.entity().getId(), TagPoolSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); - HostSearch.done(); - } - @Override public List findPoolByName(String name) { SearchCriteria sc = AllFieldSearch.create(); @@ -345,11 +321,29 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase @Override public List findLocalStoragePoolsByHostAndTags(long hostId, String[] tags) { + SearchBuilder hostSearch = createSearchBuilder(); + SearchBuilder hostPoolSearch = _hostDao.createSearchBuilder(); + SearchBuilder tagPoolSearch = _detailsDao.createSearchBuilder();; - SearchCriteria sc = HostSearch.create(); + // Search for pools on the host + hostPoolSearch.and("hostId", hostPoolSearch.entity().getHostId(), Op.EQ); + // Set criteria for pools + hostSearch.and("scope", hostSearch.entity().getScope(), Op.EQ); + hostSearch.and("removed", hostSearch.entity().getRemoved(), Op.NULL); + hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ); + hostSearch.join("hostJoin", hostPoolSearch, hostSearch.entity().getId(), hostPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER); + + if (!(tags == null || tags.length == 0 )) { + tagPoolSearch.and("name", tagPoolSearch.entity().getName(), Op.EQ); + tagPoolSearch.and("value", tagPoolSearch.entity().getValue(), Op.EQ); + hostSearch.join("tagJoin", tagPoolSearch, hostSearch.entity().getId(), tagPoolSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); + } + + SearchCriteria sc = hostSearch.create(); sc.setJoinParameters("hostJoin", "hostId", hostId ); sc.setParameters("scope", ScopeType.HOST.toString()); sc.setParameters("status", Status.Up.toString()); + if (!(tags == null || tags.length == 0 )) { Map details = tagsToDetails(tags); for (Map.Entry detail : details.entrySet()) { diff --git a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java index e988327ce0f..446e101141b 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java +++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java @@ -36,7 +36,6 @@ import com.cloud.deploy.DeploymentPlan; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.StoragePool; -import com.cloud.storage.Volume; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.NumbersUtil; import com.cloud.vm.DiskProfile; @@ -73,9 +72,8 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator { List suitablePools = new ArrayList(); // data disk and host identified from deploying vm (attach volume case) - if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) { - List hostTagsPools = null; - hostTagsPools =_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags()); + if (plan.getHostId() != null) { + List hostTagsPools = _storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags()); for (StoragePoolVO pool : hostTagsPools) { if (pool != null && pool.isLocal()) { StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());