Skip to content

Commit 80aff27

Browse files
Gupta, SuryaGupta, Surya
authored andcommitted
[CSTACKEX-204] Added Validation check for ASUP
1 parent daa7c1a commit 80aff27

6 files changed

Lines changed: 313 additions & 174 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S
182182

183183
boolean existsWithKmsKey(long kmsKeyId);
184184

185+
/**
186+
* Returns true if any VM with a non-destroyed ROOT volume on {@code poolId} also has a
187+
* non-destroyed DATADISK on a different pool. Existence check only ({@code LIMIT 1});
188+
* does not load volumes into memory.
189+
*/
190+
boolean hasMultiPoolVm(long poolId);
191+
185192
/**
186193
* Retrieves volume by its externalId
187194
*

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
9696
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 = ?";
9797
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 = ?";
9898
protected static final String SELECT_POOLSCOPE = "SELECT s.scope from storage_pool s, volumes v where s.id = v.pool_id and v.id = ?";
99+
private static final String HAS_MULTI_POOL_VM =
100+
"SELECT 1 FROM volumes root INNER JOIN volumes data ON data.instance_id = root.instance_id "
101+
+ "WHERE root.pool_id = ? AND root.volume_type = 'ROOT' AND root.instance_id IS NOT NULL "
102+
+ "AND root.removed IS NULL AND root.state NOT IN ('Destroy', 'Expunged') "
103+
+ "AND data.volume_type = 'DATADISK' AND data.pool_id IS NOT NULL AND data.pool_id <> ? "
104+
+ "AND data.removed IS NULL AND data.state NOT IN ('Destroy', 'Expunged') LIMIT 1";
99105

100106
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART1 = "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 = ? ";
101107
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART2 = " GROUP BY pool.id ORDER BY 2 ASC ";
@@ -998,6 +1004,21 @@ public boolean existsWithKmsKey(long kmsKeyId) {
9981004
return findOneBy(sc) != null;
9991005
}
10001006

1007+
@Override
1008+
@DB
1009+
public boolean hasMultiPoolVm(long poolId) {
1010+
TransactionLegacy txn = TransactionLegacy.currentTxn();
1011+
try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(HAS_MULTI_POOL_VM)) {
1012+
pstmt.setLong(1, poolId);
1013+
pstmt.setLong(2, poolId);
1014+
try (ResultSet rs = pstmt.executeQuery()) {
1015+
return rs.next();
1016+
}
1017+
} catch (SQLException e) {
1018+
throw new CloudRuntimeException("DB Exception on: " + HAS_MULTI_POOL_VM, e);
1019+
}
1020+
}
1021+
10011022
public VolumeVO findByExternalUuid(String externalUuid) {
10021023
SearchCriteria<VolumeVO> sc = ExternalUuidSearch.create();
10031024
sc.setParameters("externalUuid", externalUuid);

‎plugins/storage/volume/ontap/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
<artifactId>cloud-engine-storage-volume</artifactId>
8787
<version>${project.version}</version>
8888
</dependency>
89+
<dependency>
90+
<groupId>org.apache.cloudstack</groupId>
91+
<artifactId>cloud-framework-cluster</artifactId>
92+
<version>${project.version}</version>
93+
</dependency>
8994
<dependency>
9095
<groupId>io.swagger</groupId>
9196
<artifactId>swagger-annotations</artifactId>

0 commit comments

Comments
 (0)