Skip to content

Commit d284fd9

Browse files
rajesh-battalasudison
authored andcommitted
CLOUDSTACK-3781 Unable to resize disk with Zone wide storage
1 parent ef83942 commit d284fd9

2 files changed

Lines changed: 60 additions & 15 deletions

File tree

‎engine/schema/src/com/cloud/storage/dao/VolumeDao.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.List;
2020

2121
import com.cloud.hypervisor.Hypervisor.HypervisorType;
22+
import com.cloud.storage.ScopeType;
2223
import com.cloud.storage.Storage.ImageFormat;
2324
import com.cloud.storage.Volume;
2425
import com.cloud.storage.VolumeVO;
@@ -93,4 +94,11 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
9394
* @return total Secondary Storage space (in bytes) used
9495
*/
9596
long secondaryStorageUsedForAccount(long accountId);
97+
98+
/***
99+
*
100+
* @param volumeId
101+
* @return the scope of the storage pool where the volume is present (ZONE/CLUSTER)
102+
*/
103+
ScopeType getVolumeStoragePoolScope(long volumeId);
96104
}

‎engine/schema/src/com/cloud/storage/dao/VolumeDaoImpl.java‎

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
import org.apache.log4j.Logger;
3030
import org.springframework.stereotype.Component;
3131

32+
import com.cloud.exception.InvalidParameterValueException;
3233
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3334
import com.cloud.server.ResourceTag.TaggedResourceType;
35+
import com.cloud.storage.ScopeType;
3436
import com.cloud.storage.Storage.ImageFormat;
3537
import com.cloud.storage.Volume;
3638
import com.cloud.storage.Volume.Event;
@@ -70,7 +72,9 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
7072
// need to account for zone-wide primary storage where storage_pool has
7173
// null-value pod and cluster, where hypervisor information is stored in
7274
// storage_pool
73-
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 = ?";
75+
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 = ?";
76+
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 = ?";
77+
protected static final String SELECT_POOLSCOPE = "SELECT s.scope from storage_pool s, volumes v where s.id = v.pool_id and v.id = ?";
7478

7579
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 = ? "
7680
+ " AND pool.pod_id = ? AND pool.cluster_id = ? " + " GROUP BY pool.id ORDER BY 2 ASC ";
@@ -234,25 +238,29 @@ public HypervisorType getHypervisorType(long volumeId) {
234238
/* lookup from cluster of pool */
235239
Transaction txn = Transaction.currentTxn();
236240
PreparedStatement pstmt = null;
237-
241+
String sql = null;
238242
try {
239-
String sql = SELECT_HYPERTYPE_FROM_VOLUME;
240-
pstmt = txn.prepareAutoCloseStatement(sql);
241-
pstmt.setLong(1, volumeId);
242-
ResultSet rs = pstmt.executeQuery();
243-
if (rs.next()) {
244-
String hypervisor;
245-
if (rs.getString(1) != null)
246-
hypervisor = rs.getString(1);
247-
else
248-
hypervisor = rs.getString(2);
249-
return HypervisorType.getType(hypervisor);
243+
ScopeType scope = getVolumeStoragePoolScope(volumeId);
244+
if (scope != null ) {
245+
if (scope == ScopeType.CLUSTER)
246+
sql = SELECT_HYPERTYPE_FROM_CLUSTER_VOLUME;
247+
else if (scope == ScopeType.ZONE)
248+
sql = SELECT_HYPERTYPE_FROM_ZONE_VOLUME;
249+
250+
pstmt = txn.prepareAutoCloseStatement(sql);
251+
pstmt.setLong(1, volumeId);
252+
ResultSet rs = pstmt.executeQuery();
253+
if (rs.next()) {
254+
if (rs.getString(1) != null) {
255+
return HypervisorType.getType(rs.getString(1));
256+
}
257+
}
250258
}
251259
return HypervisorType.None;
252260
} catch (SQLException e) {
253-
throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
261+
throw new CloudRuntimeException("DB Exception on: " + sql, e);
254262
} catch (Throwable e) {
255-
throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e);
263+
throw new CloudRuntimeException("Caught: " + sql, e);
256264
}
257265
}
258266

@@ -494,4 +502,33 @@ public boolean remove(Long id) {
494502
txn.commit();
495503
return result;
496504
}
505+
506+
@Override
507+
public ScopeType getVolumeStoragePoolScope(long volumeId) {
508+
// finding the storage scope where the volume is present
509+
Transaction txn = Transaction.currentTxn();
510+
PreparedStatement pstmt = null;
511+
512+
try {
513+
String sql = SELECT_POOLSCOPE;
514+
pstmt = txn.prepareAutoCloseStatement(sql);
515+
pstmt.setLong(1, volumeId);
516+
ResultSet rs = pstmt.executeQuery();
517+
if (rs.next()) {
518+
String scope = rs.getString(1);
519+
if (scope != null) {
520+
try {
521+
return Enum.valueOf(ScopeType.class, scope.toUpperCase());
522+
} catch (Exception e) {
523+
throw new InvalidParameterValueException("invalid scope for pool " + scope);
524+
}
525+
}
526+
}
527+
} catch (SQLException e) {
528+
throw new CloudRuntimeException("DB Exception on: " + SELECT_POOLSCOPE, e);
529+
} catch (Throwable e) {
530+
throw new CloudRuntimeException("Caught: " + SELECT_POOLSCOPE, e);
531+
}
532+
return null;
533+
}
497534
}

0 commit comments

Comments
 (0)