abh1sar commented on code in PR #8875:
URL: https://github.com/apache/cloudstack/pull/8875#discussion_r1554533111
##########
server/src/main/java/com/cloud/storage/StorageManagerImpl.java:
##########
@@ -1148,6 +1150,91 @@ public PrimaryDataStoreInfo
updateStoragePool(UpdateStoragePoolCmd cmd) throws I
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(),
DataStoreRole.Primary);
}
+ @Override
+ public boolean changeStoragePoolScope(ChangeStoragePoolScopeCmd cmd)
throws IllegalArgumentException, InvalidParameterValueException,
PermissionDeniedException {
+ Long id = cmd.getId();
+
+ Long accountId = cmd.getEntityOwnerId();
+ if (!_accountMgr.isRootAdmin(accountId)) {
+ throw new PermissionDeniedException("Only root admin can perform
this operation");
+ }
+
+ ScopeType scopeType =
ScopeType.validateAndGetScopeType(cmd.getScope());
+ if (scopeType != ScopeType.ZONE && scopeType != ScopeType.CLUSTER) {
+ throw new InvalidParameterValueException("Invalid scope " +
scopeType.toString() + "for Primary storage");
+ }
+
+ StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
+ if (primaryStorage == null) {
+ throw new IllegalArgumentException("Unable to find storage pool
with ID: " + id);
+ }
+
+ if
(!primaryStorage.getStorageProviderName().equals(DataStoreProvider.DEFAULT_PRIMARY))
{
+ throw new InvalidParameterValueException("Primary storage scope
change is only supported with "
+ + DataStoreProvider.DEFAULT_PRIMARY.toString() + " data
store provider");
Review Comment:
Done
##########
server/src/main/java/com/cloud/storage/StorageManagerImpl.java:
##########
@@ -1148,6 +1150,91 @@ public PrimaryDataStoreInfo
updateStoragePool(UpdateStoragePoolCmd cmd) throws I
return (PrimaryDataStoreInfo)_dataStoreMgr.getDataStore(pool.getId(),
DataStoreRole.Primary);
}
+ @Override
+ public boolean changeStoragePoolScope(ChangeStoragePoolScopeCmd cmd)
throws IllegalArgumentException, InvalidParameterValueException,
PermissionDeniedException {
+ Long id = cmd.getId();
+
+ Long accountId = cmd.getEntityOwnerId();
+ if (!_accountMgr.isRootAdmin(accountId)) {
+ throw new PermissionDeniedException("Only root admin can perform
this operation");
+ }
+
+ ScopeType scopeType =
ScopeType.validateAndGetScopeType(cmd.getScope());
+ if (scopeType != ScopeType.ZONE && scopeType != ScopeType.CLUSTER) {
+ throw new InvalidParameterValueException("Invalid scope " +
scopeType.toString() + "for Primary storage");
+ }
+
+ StoragePoolVO primaryStorage = _storagePoolDao.findById(id);
+ if (primaryStorage == null) {
+ throw new IllegalArgumentException("Unable to find storage pool
with ID: " + id);
+ }
+
+ if
(!primaryStorage.getStorageProviderName().equals(DataStoreProvider.DEFAULT_PRIMARY))
{
+ throw new InvalidParameterValueException("Primary storage scope
change is only supported with "
+ + DataStoreProvider.DEFAULT_PRIMARY.toString() + " data
store provider");
+ }
+
+ if
(!primaryStorage.getPoolType().equals(Storage.StoragePoolType.NetworkFilesystem)
&&
+ !primaryStorage.getPoolType().equals(Storage.StoragePoolType.RBD))
{
+ throw new InvalidParameterValueException("Primary storage scope
change is not supported for protocol "
+ + primaryStorage.getPoolType().toString());
+ }
+
+ HypervisorType hypervisorType = primaryStorage.getHypervisor();
+ Set<HypervisorType> supportedHypervisorTypes =
Sets.newHashSet(HypervisorType.KVM, HypervisorType.VMware,
HypervisorType.Simulator);
+ if (!supportedHypervisorTypes.contains(hypervisorType)) {
+ throw new InvalidParameterValueException("Primary storage scope
change is not supported for hypervisor type " + hypervisorType);
+ }
+
+ if (StoragePoolStatus.Disabled != primaryStorage.getStatus()) {
+ throw new InvalidParameterValueException("Primary storage should
be disabled for this operation");
+ }
+
+ if (scopeType == primaryStorage.getScope()) {
+ throw new InvalidParameterValueException("Invalid scope change");
+ }
+
+ if (!primaryStorage.getStatus().equals(StoragePoolStatus.Disabled)) {
+ throw new InvalidParameterValueException("Scope of the Primary
storage with id "
+ + primaryStorage.getUuid() +
+ " cannot be changed, as it is not in the Disabled state");
+ }
+
+ String providerName = primaryStorage.getStorageProviderName();
+ DataStoreProvider storeProvider =
_dataStoreProviderMgr.getDataStoreProvider(providerName);
+ PrimaryDataStoreLifeCycle lifeCycle = (PrimaryDataStoreLifeCycle)
storeProvider.getDataStoreLifeCycle();
+ DataStore primaryStore = _dataStoreMgr.getPrimaryDataStore(id);
+
+ Long zoneId = primaryStorage.getDataCenterId();
+ DataCenterVO zone = _dcDao.findById(zoneId);
+ if (zone == null) {
+ throw new InvalidParameterValueException("unable to find zone by
id " + zoneId);
+ }
+ if (Grouping.AllocationState.Disabled == zone.getAllocationState()) {
+ throw new PermissionDeniedException("Cannot perform this
operation, Zone is currently disabled: " + zoneId);
+ }
+
+ if (scopeType == ScopeType.ZONE) {
+ ClusterScope clusterScope = new
ClusterScope(primaryStorage.getClusterId(), null, zoneId);
+ lifeCycle.changeStoragePoolScopeToZone(primaryStore, clusterScope,
hypervisorType);
+
+ } else {
+
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]