abh1sar commented on code in PR #8875:
URL: https://github.com/apache/cloudstack/pull/8875#discussion_r1554532232
##########
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>();
+ for (HostVO host : hosts) {
+ try {
+ storageMgr.connectHostToSharedPool(host.getId(),
store.getId());
+ } catch (Exception e) {
+ s_logger.warn("Unable to establish a connection between " +
host + " and " + store, e);
Review Comment:
The Host might be in switched off state. In that case when it comes up, the
agent will get the storage pool information from the db and mount the storage
pool according to the new zone scope. So, we don't need to fail the operation.
This behaviour is similar to when we are creating a new storage pool and
connecting it to each host (`CloudStackPrimaryDataStoreLifeCycleImpl ->
attachZone)`
##########
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>();
+ for (HostVO host : hosts) {
+ try {
+ storageMgr.connectHostToSharedPool(host.getId(),
store.getId());
+ } catch (Exception e) {
+ s_logger.warn("Unable to establish a connection between " +
host + " and " + store, e);
+ }
+ }
+ dataStoreHelper.switchToZone(store);
+ return true;
+ }
+
+ public boolean changeStoragePoolScopeToCluster(DataStore store,
ClusterScope clusterScope, HypervisorType hypervisorType) {
+ Pair<List<StoragePoolHostVO>, Integer> hostPoolRecords =
_storagePoolHostDao.listByPoolIdNotInCluster(clusterScope.getScopeId(),
store.getId());
+ HypervisorType hType = null;
+ if (hostPoolRecords.second() > 0) {
+ hType =
getHypervisorType(hostPoolRecords.first().get(0).getHostId());
+ }
+
+ StoragePool pool = (StoragePool) store;
+ for (StoragePoolHostVO host : hostPoolRecords.first()) {
+ DeleteStoragePoolCommand deleteCmd = new
DeleteStoragePoolCommand(pool);
+ final Answer answer = agentMgr.easySend(host.getHostId(),
deleteCmd);
+
+ if (answer != null && answer.getResult()) {
+ if (HypervisorType.KVM != hType) {
+ break;
+ }
+ } else {
+ if (answer != null) {
+ s_logger.debug("Failed to delete storage pool: " +
answer.getResult());
Review Comment:
Similar to the above comment. We shouldn't fail the operation similar to
`CloudStackPrimaryDataStoreLifeCycleImpl -> deleteDataStore`
--
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]