GaOrtiga commented on code in PR #8875:
URL: https://github.com/apache/cloudstack/pull/8875#discussion_r1549633449


##########
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:
   ```suggestion
   ```



##########
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:
   `DEFAULT_PRIMARY` is already a String, no need to convert it



##########
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");

Review Comment:
   This exception is kind of vague, could you add the reason for the exception 
in the message? (Its current is being the same as the chosen)



##########
plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java:
##########
@@ -543,4 +544,45 @@ public void enableStoragePool(DataStore dataStore) {
     public void disableStoragePool(DataStore dataStore) {
         dataStoreHelper.disable(dataStore);
     }
-}
+
+    public boolean changeStoragePoolScopeToZone(DataStore store, ClusterScope 
clusterScope, HypervisorType hypervisorType) {
+        List<HostVO> hosts = 
_resourceMgr.listAllHostsInOneZoneNotInClusterByHypervisor(hypervisorType, 
clusterScope.getZoneId(), clusterScope.getScopeId());
+        s_logger.debug("In createPool. Attaching the pool to each of the 
hosts.");
+        List<HostVO> poolHosts = new ArrayList<HostVO>();

Review Comment:
   This is never used



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to