2727
2828import javax .inject .Inject ;
2929
30+ import org .apache .log4j .Logger ;
31+
3032import org .apache .cloudstack .engine .subsystem .api .storage .ClusterScope ;
3133import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
3234import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
3840import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
3941import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
4042import org .apache .cloudstack .storage .volume .datastore .PrimaryDataStoreHelper ;
41- import org .apache .log4j .Logger ;
4243
4344import com .cloud .agent .AgentManager ;
4445import com .cloud .agent .api .Answer ;
5051import com .cloud .exception .InvalidParameterValueException ;
5152import com .cloud .host .Host ;
5253import com .cloud .host .HostVO ;
54+ import com .cloud .host .dao .HostDao ;
5355import com .cloud .hypervisor .Hypervisor .HypervisorType ;
5456import com .cloud .resource .ResourceManager ;
5557import com .cloud .server .ManagementServer ;
@@ -120,6 +122,8 @@ public class CloudStackPrimaryDataStoreLifeCycleImpl implements PrimaryDataStore
120122 PrimaryDataStoreHelper dataStoreHelper ;
121123 @ Inject
122124 StoragePoolAutomation storagePoolAutmation ;
125+ @ Inject
126+ protected HostDao _hostDao ;
123127
124128 @ SuppressWarnings ("unchecked" )
125129 @ Override
@@ -386,7 +390,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) {
386390 List <HostVO > poolHosts = new ArrayList <HostVO >();
387391 for (HostVO h : allHosts ) {
388392 try {
389- this . storageMgr .connectHostToSharedPool (h .getId (), primarystore .getId ());
393+ storageMgr .connectHostToSharedPool (h .getId (), primarystore .getId ());
390394 poolHosts .add (h );
391395 } catch (Exception e ) {
392396 s_logger .warn ("Unable to establish a connection between " + h + " and " + primarystore , e );
@@ -400,7 +404,7 @@ public boolean attachCluster(DataStore store, ClusterScope scope) {
400404 throw new CloudRuntimeException ("Failed to access storage pool" );
401405 }
402406
403- this . dataStoreHelper .attachCluster (store );
407+ dataStoreHelper .attachCluster (store );
404408 return true ;
405409 }
406410
@@ -443,9 +447,14 @@ public boolean cancelMaintain(DataStore store) {
443447 @ DB
444448 @ Override
445449 public boolean deleteDataStore (DataStore store ) {
446- List <StoragePoolHostVO > hostPoolRecords = this . _storagePoolHostDao .listByPoolId (store .getId ());
450+ List <StoragePoolHostVO > hostPoolRecords = _storagePoolHostDao .listByPoolId (store .getId ());
447451 StoragePool pool = (StoragePool ) store ;
448452 boolean deleteFlag = false ;
453+ // find the hypervisor where the storage is attached to.
454+ HypervisorType hType = null ;
455+ if (hostPoolRecords .size () > 0 ){
456+ hType = getHypervisorType (hostPoolRecords .get (0 ).getHostId ());
457+ }
449458
450459 // Remove the SR associated with the Xenserver
451460 for (StoragePoolHostVO host : hostPoolRecords ) {
@@ -454,7 +463,10 @@ public boolean deleteDataStore(DataStore store) {
454463
455464 if (answer != null && answer .getResult ()) {
456465 deleteFlag = true ;
457- break ;
466+ // if host is KVM hypervisor then send deleteStoragepoolcmd to all the kvm hosts.
467+ if (HypervisorType .KVM != hType ) {
468+ break ;
469+ }
458470 } else {
459471 if (answer != null ) {
460472 s_logger .debug ("Failed to delete storage pool: " + answer .getResult ());
@@ -466,12 +478,19 @@ public boolean deleteDataStore(DataStore store) {
466478 throw new CloudRuntimeException ("Failed to delete storage pool on host" );
467479 }
468480
469- return this .dataStoreHelper .deletePrimaryDataStore (store );
481+ return dataStoreHelper .deletePrimaryDataStore (store );
482+ }
483+
484+ private HypervisorType getHypervisorType (long hostId ) {
485+ HostVO host = _hostDao .findById (hostId );
486+ if (host != null )
487+ return host .getHypervisorType ();
488+ return HypervisorType .None ;
470489 }
471490
472491 @ Override
473492 public boolean attachHost (DataStore store , HostScope scope , StoragePoolInfo existingInfo ) {
474- this . dataStoreHelper .attachHost (store , scope , existingInfo );
493+ dataStoreHelper .attachHost (store , scope , existingInfo );
475494 return true ;
476495 }
477496}
0 commit comments