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 @@ -432,4 +432,8 @@ void connectHostsToPool(DataStore primaryStore, List<Long> hostIds, Scope scope,
String[] getStorageAccessGroups(Long zoneId, Long podId, Long clusterId, Long hostId);

CapacityVO getObjectStorageUsedStats(Long zoneId);

static ConfigKey<Boolean> getMountDisabledStoragePool() {
return MountDisabledStoragePool;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {

List<StoragePoolVO> findDisabledPoolsByScope(long dcId, Long podId, Long clusterId, ScopeType scope);

/**
* Finds disabled storage pools within the specified scope that are associated with the given storage access groups.
* This method is used to locate storage pools with 'Disabled' status that match specific storage access group
* filters.
*
* @param dcId the data center ID.
* @param podId the pod ID.
* @param clusterId the cluster ID.
* @param scope ZONE, CLUSTER OR HOST type scope
* @param storageAccessGroups array of storage access group names to match against.
* Only pools associated with these access groups will be returned.
* If null or empty, returns an empty list.
* @return a list of {@link StoragePoolVO} objects.
*/
List<StoragePoolVO> findDisabledPoolsByScopeAndAccessGroups(long dcId, Long podId, Long clusterId, ScopeType scope, String[] storageAccessGroups);

/**
* Find pool by UUID.
*
Expand Down Expand Up @@ -167,7 +183,19 @@ Pair<List<Long>, Integer> searchForIdsAndCount(Long storagePoolId, String storag

List<StoragePoolVO> listByIds(List<Long> ids);

List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId, Long podId, Long clusterId, ScopeType scope, HypervisorType hypervisorType);
/**
* Finds storage pools that have no storage access groups associated with them within the specified criteria.
* This method identifies storage pools without access group restrictions.
*
* @param dcId the data center ID. Can be null to include all data centers.
* @param podId the pod ID. Can be null to include all pods.
* @param clusterId the cluster ID. Can be null to include all clusters.
* @param scope ZONE, CLUSTER or HOST type scope
* @param hypervisorType the hypervisor type filter. Can be null to include all hypervisor types.
* @param status the storage pool status to filter by.
* @return a list of {@link StoragePoolVO} objects that have no storage access groups associated.
*/
List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId, Long podId, Long clusterId, ScopeType scope, HypervisorType hypervisorType, StoragePoolStatus status);

List<StoragePoolVO> findPoolsByStorageTypeAndZone(Storage.StoragePoolType storageType, Long zoneId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.commons.lang3.ArrayUtils;

@DB()
public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long> implements PrimaryDataStoreDao {
Expand Down Expand Up @@ -86,6 +87,37 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
private final String ZoneWideStorageAccessGroupsWithHypervisorTypeSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_and_access_group_map ON storage_pool.id = storage_pool_and_access_group_map.pool_id WHERE storage_pool.removed is null and storage_pool.status = 'Up' and storage_pool.hypervisor = ? and storage_pool.data_center_id = ? and storage_pool.scope = ? and (";
private final String ZoneWideStorageAccessGroupsWithHypervisorTypeSqlSuffix = ") GROUP BY storage_pool_and_access_group_map.pool_id";

/**
* SQL query prefix to find zone-wide disabled storage pools that are associated with specific storage access groups.
*/
private final String ZoneWideDisabledStorageAccessGroupsSqlPrefix =
"SELECT storage_pool.* FROM storage_pool " +
"LEFT JOIN storage_pool_and_access_group_map ON storage_pool.id = storage_pool_and_access_group_map.pool_id " +
"WHERE storage_pool.removed IS NULL " +
" AND storage_pool.status = 'Disabled' " +
" AND storage_pool.data_center_id = ? " +
" AND storage_pool.scope = ? " +
" AND (";

/**
* SQL query prefix to find disabled storage pools with specific storage access groups. The query is used at the HOST scope.
*/
private final String DisabledStorageAccessGroupsForHostConnectionSqlPrefix =
"SELECT storage_pool.* FROM storage_pool " +
"LEFT JOIN storage_pool_and_access_group_map ON storage_pool.id = storage_pool_and_access_group_map.pool_id " +
"WHERE storage_pool.removed IS NULL " +
" AND storage_pool.status = 'Disabled' " +
" AND storage_pool.data_center_id = ? " +
" AND (storage_pool.pod_id = ? OR storage_pool.pod_id IS NULL) " +
" AND storage_pool.scope = ? " +
" AND (";

/**
* SQL query suffix for disabled storage access groups queries. This suffix completes the query by grouping
* results by pool_id.
*/
private final String DisabledStorageAccessGroupsSqlSuffix = ") GROUP BY storage_pool_and_access_group_map.pool_id";

// Storage tags are now separate from storage_pool_details, leaving only details on that table
protected final String TagsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_tags ON storage_pool.id = storage_pool_tags.pool_id WHERE storage_pool.removed is null and storage_pool.status = 'Up' AND storage_pool_tags.is_tag_a_rule = 0 and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and storage_pool.scope = ? and (";
protected final String TagsSqlSuffix = ") GROUP BY storage_pool_tags.pool_id HAVING COUNT(storage_pool_tags.tag) >= ?";
Expand Down Expand Up @@ -568,6 +600,26 @@ public List<StoragePoolVO> findDisabledPoolsByScope(long dcId, Long podId, Long
return storagePools;
}

@Override
public List<StoragePoolVO> findDisabledPoolsByScopeAndAccessGroups(long dcId, Long podId, Long clusterId, ScopeType scope, String[] storageAccessGroups) {
if (ArrayUtils.isEmpty(storageAccessGroups)) {
return List.of();
}

List<StoragePoolVO> storagePools = null;
String sqlValues = getSqlValuesFromStorageAccessGroups(storageAccessGroups);

if (scope == ScopeType.ZONE) {
String sql = getSqlPreparedStatement(ZoneWideDisabledStorageAccessGroupsSqlPrefix, DisabledStorageAccessGroupsSqlSuffix, sqlValues, null);
storagePools = searchStoragePoolsPreparedStatement(sql, dcId, null, null, scope, null);
} else if ((scope == ScopeType.CLUSTER || scope == ScopeType.HOST) && podId != null && clusterId != null) {
String sql = getSqlPreparedStatement(DisabledStorageAccessGroupsForHostConnectionSqlPrefix, DisabledStorageAccessGroupsSqlSuffix, sqlValues, clusterId);
storagePools = searchStoragePoolsPreparedStatement(sql, dcId, podId, clusterId, scope, null);
}

return storagePools;
}

@Override
public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags, boolean validateTagRule) {
return findLocalStoragePoolsByTags(dcId, podId, clusterId, tags, validateTagRule, null);
Expand Down Expand Up @@ -691,7 +743,7 @@ public List<StoragePoolVO> findZoneWideStoragePoolsByAccessGroupsAndHypervisorTy
}

@Override
public List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId, Long podId, Long clusterId, ScopeType scope, HypervisorType hypervisorType) {
public List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId, Long podId, Long clusterId, ScopeType scope, HypervisorType hypervisorType, StoragePoolStatus status) {
SearchBuilder<StoragePoolVO> poolSearch = createSearchBuilder();
SearchBuilder<StoragePoolAndAccessGroupMapVO> storageAccessGroupsPoolSearch = _storagePoolAccessGroupMapDao.createSearchBuilder();
// Set criteria for pools
Expand All @@ -709,7 +761,6 @@ public List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId,

SearchCriteria<StoragePoolVO> sc = poolSearch.create();
sc.setParameters("scope", scope.toString());
sc.setParameters("status", Status.Up.toString());

if (dcId != null) {
sc.setParameters("datacenterid", dcId);
Expand All @@ -727,6 +778,10 @@ public List<StoragePoolVO> findStoragePoolsByEmptyStorageAccessGroups(Long dcId,
sc.setParameters("hypervisortype", hypervisorType);
}

if (status != null) {
sc.setParameters("status", status.toString());
}

return listBy(sc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2744,17 +2744,17 @@ protected List<StoragePoolVO> getStoragePoolsByAccessGroups(Long dcId, Long podI
allPoolsByTags.addAll(_storagePoolDao.findPoolsByAccessGroupsForHostConnection(dcId, podId, clusterId, ScopeType.CLUSTER, storageAccessGroups));
allPoolsByTags.addAll(_storagePoolDao.findZoneWideStoragePoolsByAccessGroupsForHostConnection(dcId, storageAccessGroups));
if (includeEmptyTags) {
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, podId, clusterId, ScopeType.CLUSTER, null));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, null, null, ScopeType.ZONE, null));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, podId, clusterId, ScopeType.CLUSTER, null, StoragePoolStatus.Up));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, null, null, ScopeType.ZONE, null, StoragePoolStatus.Up));
}

return allPoolsByTags;
}

private List<StoragePoolVO> getStoragePoolsByEmptyStorageAccessGroups(Long dcId, Long podId, Long clusterId) {
List<StoragePoolVO> allPoolsByTags = new ArrayList<>();
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, podId, clusterId, ScopeType.CLUSTER, null));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, null, null, ScopeType.ZONE, null));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, podId, clusterId, ScopeType.CLUSTER, null, StoragePoolStatus.Up));
allPoolsByTags.addAll(_storagePoolDao.findStoragePoolsByEmptyStorageAccessGroups(dcId, null, null, ScopeType.ZONE, null, StoragePoolStatus.Up));

return allPoolsByTags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.cloud.dc.dao.HostPodDao;
import com.cloud.exception.StorageConflictException;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePoolStatus;
import com.cloud.storage.dao.StoragePoolHostDao;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.Profiler;
Expand Down Expand Up @@ -123,21 +124,21 @@ public void processConnect(Host host, StartupCommand cmd, boolean forRebalance)
List<StoragePoolVO> pools = new ArrayList<>();
// SAG -> Storage Access Group
if (ArrayUtils.isEmpty(sags)) {
List<StoragePoolVO> clusterStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, null);
List<StoragePoolVO> storagePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, null);
List<StoragePoolVO> zoneStoragePoolsByHypervisor = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, scCmd.getHypervisorType());
List<StoragePoolVO> clusterStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, null, StoragePoolStatus.Up);
List<StoragePoolVO> storagePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, null, StoragePoolStatus.Up);
List<StoragePoolVO> zoneStoragePoolsByHypervisor = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, scCmd.getHypervisorType(), StoragePoolStatus.Up);
storagePoolsByEmptySAGs.retainAll(zoneStoragePoolsByHypervisor);
pools.addAll(storagePoolsByEmptySAGs);
pools.addAll(clusterStoragePoolsByEmptySAGs);
List<StoragePoolVO> zoneStoragePoolsByAnyHypervisor = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, HypervisorType.Any);
List<StoragePoolVO> zoneStoragePoolsByAnyHypervisor = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, HypervisorType.Any, StoragePoolStatus.Up);
pools.addAll(zoneStoragePoolsByAnyHypervisor);
} else {
List<StoragePoolVO> storagePoolsBySAGs = new ArrayList<>();
List<StoragePoolVO> clusterStoragePoolsBySAGs = _poolDao.findPoolsByAccessGroupsForHostConnection(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, sags);
List<StoragePoolVO> clusterStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, null);
List<StoragePoolVO> clusterStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, null, StoragePoolStatus.Up);
List<StoragePoolVO> zoneStoragePoolsBySAGs = _poolDao.findZoneWideStoragePoolsByAccessGroupsAndHypervisorTypeForHostConnection(host.getDataCenterId(), sags, scCmd.getHypervisorType());
List<StoragePoolVO> zoneStoragePoolsByHypervisorTypeAny = _poolDao.findZoneWideStoragePoolsByAccessGroupsAndHypervisorTypeForHostConnection(host.getDataCenterId(), sags, HypervisorType.Any);
List<StoragePoolVO> zoneStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, null);
List<StoragePoolVO> zoneStoragePoolsByEmptySAGs = _poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, null, StoragePoolStatus.Up);

storagePoolsBySAGs.addAll(zoneStoragePoolsBySAGs);
storagePoolsBySAGs.addAll(zoneStoragePoolsByEmptySAGs);
Expand All @@ -148,13 +149,15 @@ public void processConnect(Host host, StartupCommand cmd, boolean forRebalance)
}

// get the zone wide disabled pools list if global setting is true.
if (StorageManager.MountDisabledStoragePool.value()) {
pools.addAll(_poolDao.findDisabledPoolsByScope(host.getDataCenterId(), null, null, ScopeType.ZONE));
if (StorageManager.getMountDisabledStoragePool().value()) {
pools.addAll(_poolDao.findDisabledPoolsByScopeAndAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, sags));
pools.addAll(_poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), null, null, ScopeType.ZONE, null, StoragePoolStatus.Disabled));
}

// get the cluster wide disabled pool list
if (StorageManager.MountDisabledStoragePool.valueIn(host.getClusterId())) {
pools.addAll(_poolDao.findDisabledPoolsByScope(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER));
if (StorageManager.getMountDisabledStoragePool().valueIn(host.getClusterId())) {
pools.addAll(_poolDao.findDisabledPoolsByScopeAndAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, sags));
pools.addAll(_poolDao.findStoragePoolsByEmptyStorageAccessGroups(host.getDataCenterId(), host.getPodId(), host.getClusterId(), ScopeType.CLUSTER, null, StoragePoolStatus.Disabled));
}

List<StoragePoolHostVO> previouslyConnectedPools = new ArrayList<>();
Expand Down
Loading
Loading