Skip to content

Commit d8bdc41

Browse files
[CSTACKEX-204] ASUP Implementation
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent cc30155 commit d8bdc41

16 files changed

Lines changed: 2207 additions & 12 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 Ready ROOT volume on poolId also has an attached
187+
* Ready DATADISK on a different primary storage pool. Existence check only
188+
* ({@code LIMIT 1}); does not load volumes into memory.
189+
*/
190+
boolean hasMultiPrimaryStoragePoolVm(long poolId);
191+
185192
/**
186193
* Retrieves volume by its externalId
187194
*

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ 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+
// Looks for a VM whose Ready root disk is on this pool and whose attached Ready data disk is on another pool.
100+
// LIMIT 1 stops after the first match so we do not load all volumes.
101+
private static final String HAS_MULTI_PRIMARY_STORAGE_POOL_VM =
102+
"SELECT 1 FROM volumes root INNER JOIN volumes data ON data.instance_id = root.instance_id "
103+
+ "WHERE root.pool_id = ? AND root.volume_type = 'ROOT' AND root.instance_id IS NOT NULL "
104+
+ "AND root.removed IS NULL AND root.state = 'Ready' "
105+
+ "AND data.volume_type = 'DATADISK' AND data.pool_id IS NOT NULL AND data.pool_id <> ? "
106+
+ "AND data.removed IS NULL AND data.state = 'Ready' LIMIT 1";
99107

100108
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 = ? ";
101109
private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT_PART2 = " GROUP BY pool.id ORDER BY 2 ASC ";
@@ -998,6 +1006,21 @@ public boolean existsWithKmsKey(long kmsKeyId) {
9981006
return findOneBy(sc) != null;
9991007
}
10001008

1009+
@Override
1010+
@DB
1011+
public boolean hasMultiPrimaryStoragePoolVm(long poolId) {
1012+
TransactionLegacy txn = TransactionLegacy.currentTxn();
1013+
try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(HAS_MULTI_PRIMARY_STORAGE_POOL_VM)) {
1014+
pstmt.setLong(1, poolId);
1015+
pstmt.setLong(2, poolId);
1016+
try (ResultSet rs = pstmt.executeQuery()) {
1017+
return rs.next();
1018+
}
1019+
} catch (SQLException e) {
1020+
throw new CloudRuntimeException("DB Exception on: " + HAS_MULTI_PRIMARY_STORAGE_POOL_VM, e);
1021+
}
1022+
}
1023+
10011024
public VolumeVO findByExternalUuid(String externalUuid) {
10021025
SearchCriteria<VolumeVO> sc = ExternalUuidSearch.create();
10031026
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)