cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject git commit: updated refs/heads/4.3-forward to a8b34c0
Date Wed, 05 Mar 2014 09:11:13 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/4.3-forward cd0d16f05 -> a8b34c0c4


CLOUDSTACK-6151: Local data disk with tag goes to the wrong local storage pool

Signed-off-by: Koushik Das <koushik@apache.org>


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

Branch: refs/heads/4.3-forward
Commit: a8b34c0c4f99067243524813f136b31cb78c5f78
Parents: cd0d16f
Author: Saksham Srivastava <saksham.srivastava@citrix.com>
Authored: Thu Feb 20 11:25:25 2014 +0530
Committer: Koushik Das <koushik@apache.org>
Committed: Wed Mar 5 14:26:01 2014 +0530

----------------------------------------------------------------------
 .../spring-engine-schema-core-daos-context.xml  |  2 +-
 .../datastore/db/PrimaryDataStoreDao.java       |  2 +
 .../datastore/db/PrimaryDataStoreDaoImpl.java   | 48 ++++++++++++++++++--
 .../allocator/LocalStoragePoolAllocator.java    |  8 ++--
 server/test/resources/createNetworkOffering.xml |  2 +
 5 files changed, 53 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8b34c0c/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
----------------------------------------------------------------------
diff --git a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
index 47e020f..445e2e7 100644
--- a/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
+++ b/engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml
@@ -222,6 +222,7 @@
   <bean id="PortableIpRangeDaoImpl" class="org.apache.cloudstack.region.PortableIpRangeDaoImpl"
/>
   <bean id="portForwardingRulesDaoImpl" class="com.cloud.network.rules.dao.PortForwardingRulesDaoImpl"
/>
   <bean id="portProfileDaoImpl" class="com.cloud.network.dao.PortProfileDaoImpl" />
+  <bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl"
/>
   <bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl"
/>
   <bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.volume.db.PrimaryDataStoreDetailsDaoImpl"
/>
   <bean id="privateIpDaoImpl" class="com.cloud.network.vpc.dao.PrivateIpDaoImpl" />
@@ -259,7 +260,6 @@
   <bean id="storageNetworkIpAddressDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpAddressDaoImpl"
/>
   <bean id="storageNetworkIpRangeDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpRangeDaoImpl"
/>
   <bean id="storagePoolDetailsDaoImpl" class="com.cloud.storage.dao.StoragePoolDetailsDaoImpl"
/>
-  <bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl"
/>
   <bean id="storagePoolJoinDaoImpl" class="com.cloud.api.query.dao.StoragePoolJoinDaoImpl"
/>
   <bean id="storagePoolWorkDaoImpl" class="com.cloud.storage.dao.StoragePoolWorkDaoImpl"
/>
   <bean id="templatePrimaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.volume.db.TemplatePrimaryDataStoreDaoImpl"
/>

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8b34c0c/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
index 59c338e..a3cb76f 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
@@ -114,4 +114,6 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO,
Long> {
     List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags);
 
     List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType
hypervisorType);
+
+    List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8b34c0c/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 d35aa44..eea0762 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,19 +24,21 @@ 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;
 
-import org.springframework.stereotype.Component;
-
 import com.cloud.host.Status;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.ScopeType;
+import com.cloud.storage.StoragePoolHostVO;
 import com.cloud.storage.StoragePoolStatus;
+import com.cloud.storage.dao.StoragePoolHostDao;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
@@ -45,7 +47,6 @@ import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
 
-
 @Local(value = { PrimaryDataStoreDao.class })
 @DB()
 public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long> implements
PrimaryDataStoreDao {
@@ -54,8 +55,12 @@ 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;
+    @Inject protected StoragePoolHostDao _hostDao;
 
     private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT
JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed
is null and storage_pool.status = 'Up' and storage_pool.data_center_id = ? and (storage_pool.pod_id
= ? or storage_pool.pod_id is null) and storage_pool.scope = ? and (";
     private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING
COUNT(storage_pool_details.name) >= ?";
@@ -112,6 +117,26 @@ 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();
@@ -354,6 +379,23 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO,
Long>
     }
 
     @Override
+    public List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[]
tags) {
+
+        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()) {
+                sc.setJoinParameters("tagJoin","name", detail.getKey());
+                sc.setJoinParameters("tagJoin", "value", detail.getValue());
+            }
+        }
+        return listBy(sc);
+    }
+
+    @Override
     @DB
     public List<String> searchForStoragePoolDetails(long poolId, String value) {
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8b34c0c/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 1f61e8b..51ab0fe 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java
@@ -28,7 +28,6 @@ import javax.naming.ConfigurationException;
 import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -73,14 +72,13 @@ public class LocalStoragePoolAllocator extends AbstractStoragePoolAllocator
{
         if (!dskCh.useLocalStorage()) {
             return null;
         }
-
         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<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId());
-            for (StoragePoolHostVO hostPool : hostPools) {
-                StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId());
+            List<StoragePoolVO> hostTagsPools = null;
+            hostTagsPools =_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(),
dskCh.getTags());
+            for (StoragePoolVO pool : hostTagsPools) {
                 if (pool != null && pool.isLocal()) {
                     StoragePool storagePool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(pool.getId());
                     if (filter(avoid, storagePool, dskCh, plan)) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8b34c0c/server/test/resources/createNetworkOffering.xml
----------------------------------------------------------------------
diff --git a/server/test/resources/createNetworkOffering.xml b/server/test/resources/createNetworkOffering.xml
index c6228da..6ae7393 100644
--- a/server/test/resources/createNetworkOffering.xml
+++ b/server/test/resources/createNetworkOffering.xml
@@ -46,4 +46,6 @@
     <bean id="UservmDetailsDaoImpl" class="com.cloud.vm.dao.UserVmDetailsDaoImpl" />
     <bean id="usageEventDaoImpl" class="com.cloud.event.dao.UsageEventDaoImpl" />
     <bean id="usageEventDetailsDaoImpl" class="com.cloud.event.dao.UsageEventDetailsDaoImpl"
/>
+    <bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl"
/>
+    <bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl"
/>
 </beans>


Mime
View raw message