Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ public interface VolumeDao extends GenericDao<VolumeVO, Long>, StateDao<Volume.S

boolean existsWithKmsKey(long kmsKeyId);

/**
* Returns true if any VM with a non-destroyed ROOT volume on {@code poolId} also has a
* non-destroyed DATADISK on a different primary storage pool. Existence check only
* ({@code LIMIT 1}); does not load volumes into memory.
*/
boolean hasMultiPrimaryStoragePoolVm(long poolId);

/**
* Retrieves volume by its externalId
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public class VolumeDaoImpl extends GenericDaoBase<VolumeVO, Long> implements Vol
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 = ?";
// Looks for a VM whose root disk is on this pool and whose data disk is on another pool.
// LIMIT 1 stops after the first match so we do not load all volumes.
private static final String HAS_MULTI_PRIMARY_STORAGE_POOL_VM =
"SELECT 1 FROM volumes root INNER JOIN volumes data ON data.instance_id = root.instance_id "
+ "WHERE root.pool_id = ? AND root.volume_type = 'ROOT' AND root.instance_id IS NOT NULL "
+ "AND root.removed IS NULL AND root.state NOT IN ('Destroy', 'Expunged') "
+ "AND data.volume_type = 'DATADISK' AND data.pool_id IS NOT NULL AND data.pool_id <> ? "
+ "AND data.removed IS NULL AND data.state NOT IN ('Destroy', 'Expunged') LIMIT 1";

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

@Override
@DB
public boolean hasMultiPrimaryStoragePoolVm(long poolId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
try (PreparedStatement pstmt = txn.prepareAutoCloseStatement(HAS_MULTI_PRIMARY_STORAGE_POOL_VM)) {
pstmt.setLong(1, poolId);
pstmt.setLong(2, poolId);
try (ResultSet rs = pstmt.executeQuery()) {
return rs.next();
}
} catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + HAS_MULTI_PRIMARY_STORAGE_POOL_VM, e);
}
}

public VolumeVO findByExternalUuid(String externalUuid) {
SearchCriteria<VolumeVO> sc = ExternalUuidSearch.create();
sc.setParameters("externalUuid", externalUuid);
Expand Down
5 changes: 5 additions & 0 deletions plugins/storage/volume/ontap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@
<artifactId>cloud-engine-storage-volume</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cloudstack</groupId>
<artifactId>cloud-framework-cluster</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
Expand Down
Loading
Loading