GaOrtiga commented on code in PR #8875: URL: https://github.com/apache/cloudstack/pull/8875#discussion_r1549620636
########## 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 scope being the same as the chosen) -- 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