Repository: cloudstack
Updated Branches:
  refs/heads/master 0b5163f8c -> 7c2b1deb3


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.


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

Branch: refs/heads/master
Commit: 7c2b1deb34c0210f812409b6b0f07b04e0142238
Parents: 0b5163f
Author: Devdeep Singh <devd...@gmail.com>
Authored: Tue May 20 11:40:51 2014 +0530
Committer: Devdeep Singh <devd...@gmail.com>
Committed: Fri May 30 14:46:39 2014 +0530

----------------------------------------------------------------------
 .../datastore/db/PrimaryDataStoreDaoImpl.java   | 44 +++++++++-----------
 .../allocator/LocalStoragePoolAllocator.java    |  6 +--
 2 files changed, 21 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7c2b1deb/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
----------------------------------------------------------------------
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 7e558f8..92793f1 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<StoragePoolVO, Long>
     protected final SearchBuilder<StoragePoolVO> DcPodAnyClusterSearch;
     protected final SearchBuilder<StoragePoolVO> DeleteLvmSearch;
     protected final GenericSearchBuilder<StoragePoolVO, Long> 
StatusCountSearch;
-    protected SearchBuilder<StoragePoolVO> HostSearch;
-    protected SearchBuilder<StoragePoolHostVO> HostPoolSearch;
-    protected SearchBuilder<StoragePoolDetailVO> TagPoolSearch;
 
     @Inject
     protected StoragePoolDetailsDao _detailsDao;
@@ -120,26 +116,6 @@ public class PrimaryDataStoreDaoImpl extends 
GenericDaoBase<StoragePoolVO, Long>
 
     }
 
-    @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<StoragePoolVO> findPoolByName(String name) {
         SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
@@ -345,11 +321,29 @@ public class PrimaryDataStoreDaoImpl extends 
GenericDaoBase<StoragePoolVO, Long>
 
     @Override
     public List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, 
String[] tags) {
+        SearchBuilder<StoragePoolVO> hostSearch = createSearchBuilder();
+        SearchBuilder<StoragePoolHostVO> hostPoolSearch = 
_hostDao.createSearchBuilder();
+        SearchBuilder<StoragePoolDetailVO> tagPoolSearch = 
_detailsDao.createSearchBuilder();;
 
-        SearchCriteria<StoragePoolVO> 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<StoragePoolVO> 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<String, String> details = tagsToDetails(tags);
             for (Map.Entry<String, String> detail : details.entrySet()) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7c2b1deb/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java
----------------------------------------------------------------------
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 e988327..446e101 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<StoragePool> suitablePools = new ArrayList<StoragePool>();
 
         // data disk and host identified from deploying vm (attach volume case)
-        if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != 
null) {
-            List<StoragePoolVO> hostTagsPools = null;
-            hostTagsPools 
=_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), 
dskCh.getTags());
+        if (plan.getHostId() != null) {
+            List<StoragePoolVO> hostTagsPools = 
_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), 
dskCh.getTags());
             for (StoragePoolVO pool : hostTagsPools) {
                 if (pool != null && pool.isLocal()) {
                     StoragePool storagePool = 
(StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());

Reply via email to