cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject git commit: updated refs/heads/4.2 to d284fd9
Date Tue, 06 Aug 2013 19:57:26 GMT
Updated Branches:
  refs/heads/4.2 ef839427c -> d284fd989


CLOUDSTACK-3781 Unable to resize disk with Zone wide storage


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

Branch: refs/heads/4.2
Commit: d284fd9894061fc77ed45631f3a62dde1df64eb6
Parents: ef83942
Author: Rajesh Battala <rajesh.battala@citrix.com>
Authored: Fri Aug 2 15:18:54 2013 +0530
Committer: Edison Su <sudison@gmail.com>
Committed: Tue Aug 6 12:57:10 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/VolumeDao.java    |  8 +++
 .../com/cloud/storage/dao/VolumeDaoImpl.java    | 67 +++++++++++++++-----
 2 files changed, 60 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d284fd98/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
index 7b58e7d..0ba80a9 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDao.java
@@ -19,6 +19,7 @@ package com.cloud.storage.dao;
 import java.util.List;
 
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.ScopeType;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
@@ -93,4 +94,11 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
      * @return total Secondary Storage space (in bytes) used
      */
     long secondaryStorageUsedForAccount(long accountId);
+
+    /***
+     *
+     * @param volumeId
+     * @return the scope of the storage pool where the volume is present (ZONE/CLUSTER)
+     */
+    ScopeType getVolumeStoragePoolScope(long volumeId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d284fd98/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
index e6595b2..273f7f9 100755
--- a/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java
@@ -29,8 +29,10 @@ import javax.inject.Inject;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.server.ResourceTag.TaggedResourceType;
+import com.cloud.storage.ScopeType;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Volume;
 import com.cloud.storage.Volume.Event;
@@ -70,7 +72,9 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
     // need to account for zone-wide primary storage where storage_pool has
     // null-value pod and cluster, where hypervisor information is stored in
     // storage_pool
-    protected static final String SELECT_HYPERTYPE_FROM_VOLUME = "SELECT s.hypervisor, c.hypervisor_type
from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and
v.id = ?";
+    protected static final String SELECT_HYPERTYPE_FROM_CLUSTER_VOLUME = "SELECT c.hypervisor_type
from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and
v.id = ?";
+    protected static final String SELECT_HYPERTYPE_FROM_ZONE_VOLUME = "SELECT s.hypervisor
from volumes v, storage_pool s where v.pool_id = s.id and v.id = ?";
+    protected static final String SELECT_POOLSCOPE = "SELECT s.scope from storage_pool s,
volumes v where s.id = v.pool_id and v.id = ?";
 
     private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id,
SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT
JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? "
             + " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER
BY 2 ASC ";
@@ -234,25 +238,29 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
         /* lookup from cluster of pool */
         Transaction txn = Transaction.currentTxn();
         PreparedStatement pstmt = null;
-
+        String sql = null;
         try {
-            String sql = SELECT_HYPERTYPE_FROM_VOLUME;
-            pstmt = txn.prepareAutoCloseStatement(sql);
-            pstmt.setLong(1, volumeId);
-            ResultSet rs = pstmt.executeQuery();
-            if (rs.next()) {
-                String hypervisor;
-                if (rs.getString(1) != null)
-                    hypervisor = rs.getString(1);
-                else
-                    hypervisor = rs.getString(2);
-                return HypervisorType.getType(hypervisor);
+            ScopeType scope = getVolumeStoragePoolScope(volumeId);
+            if (scope != null ) {
+                if (scope == ScopeType.CLUSTER)
+                    sql = SELECT_HYPERTYPE_FROM_CLUSTER_VOLUME;
+                else if (scope == ScopeType.ZONE)
+                    sql = SELECT_HYPERTYPE_FROM_ZONE_VOLUME;
+
+                pstmt = txn.prepareAutoCloseStatement(sql);
+                pstmt.setLong(1, volumeId);
+                ResultSet rs = pstmt.executeQuery();
+                if (rs.next()) {
+                    if (rs.getString(1) != null) {
+                        return HypervisorType.getType(rs.getString(1));
+                    }
+                }
             }
             return HypervisorType.None;
         } catch (SQLException e) {
-            throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME,
e);
+            throw new CloudRuntimeException("DB Exception on: " + sql, e);
         } catch (Throwable e) {
-            throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
+            throw new CloudRuntimeException("Caught: " + sql, e);
         }
     }
 
@@ -494,4 +502,33 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long>
implements Vol
         txn.commit();
         return result;
     }
+
+    @Override
+    public ScopeType getVolumeStoragePoolScope(long volumeId) {
+        // finding the storage scope where the volume is present
+        Transaction txn = Transaction.currentTxn();
+        PreparedStatement pstmt = null;
+
+        try {
+            String sql = SELECT_POOLSCOPE;
+            pstmt = txn.prepareAutoCloseStatement(sql);
+            pstmt.setLong(1, volumeId);
+            ResultSet rs = pstmt.executeQuery();
+            if (rs.next()) {
+                String scope = rs.getString(1);
+                if (scope != null) {
+                    try {
+                        return Enum.valueOf(ScopeType.class, scope.toUpperCase());
+                    } catch (Exception e) {
+                        throw new InvalidParameterValueException("invalid scope for pool
" + scope);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            throw new CloudRuntimeException("DB Exception on: " + SELECT_POOLSCOPE, e);
+        } catch (Throwable e) {
+            throw new CloudRuntimeException("Caught: " + SELECT_POOLSCOPE, e);
+        }
+        return null;
+    }
 }


Mime
View raw message