From f5ce280da32c4e0837fa39651dc801ba3f906e41 Mon Sep 17 00:00:00 2001 From: Devdeep Singh Date: Tue, 20 May 2014 11:40:51 +0530 Subject: [PATCH] CLOUDSTACK-6810: Fix storage migration of a vm with volume on local was failing. When a plan with hostid included was passed to the local storage pool allocator, it returned all the local storage pools in the cluster, instead of just the local pool on the given host in the plan. This was happening the search at a host level was happening only for data disk. Fixed this. Additionally, the query to list the storage pools on a host was failing if the pool did have tags. Fixed the query too. CLOUDSTACK-6802: Fix for not being able to attach data disk on local. This issue gets fixed with the above issue too. The query to list pools on a host was failing if there were no tags on the storage pool. --- .../datastore/db/PrimaryDataStoreDaoImpl.java | 44 ++++++++----------- .../allocator/LocalStoragePoolAllocator.java | 6 +-- 2 files changed, 21 insertions(+), 29 deletions(-) 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());