mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	linstor: implement missing deleteDatastore (#10561)
Somehow deleteDatastore was never implemented, that meant: templates haven't been cleaned up on datastore delete and also agents have never been informed about storage pool removal.
This commit is contained in:
		
							parent
							
								
									7978141464
								
							
						
					
					
						commit
						f4a7c8ab89
					
				| @ -22,8 +22,13 @@ import java.util.List; | |||||||
| 
 | 
 | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.storage.VMTemplateStoragePoolVO; | ||||||
|  | import com.cloud.storage.VMTemplateStorageResourceAssoc; | ||||||
|  | import com.cloud.template.TemplateManager; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
|  | import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||||||
|  | import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||||||
| import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; | import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| @ -54,6 +59,10 @@ public class BasePrimaryDataStoreLifeCycleImpl { | |||||||
|     protected HostDao hostDao; |     protected HostDao hostDao; | ||||||
|     @Inject |     @Inject | ||||||
|     protected StoragePoolHostDao storagePoolHostDao; |     protected StoragePoolHostDao storagePoolHostDao; | ||||||
|  |     @Inject | ||||||
|  |     private PrimaryDataStoreDao primaryDataStoreDao; | ||||||
|  |     @Inject | ||||||
|  |     private TemplateManager templateMgr; | ||||||
| 
 | 
 | ||||||
|     private List<HostVO> getPoolHostsList(ClusterScope clusterScope, HypervisorType hypervisorType) { |     private List<HostVO> getPoolHostsList(ClusterScope clusterScope, HypervisorType hypervisorType) { | ||||||
|         List<HostVO> hosts; |         List<HostVO> hosts; | ||||||
| @ -103,4 +112,42 @@ public class BasePrimaryDataStoreLifeCycleImpl { | |||||||
|         } |         } | ||||||
|         dataStoreHelper.switchToCluster(store, clusterScope); |         dataStoreHelper.switchToCluster(store, clusterScope); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     private void evictTemplates(StoragePoolVO storagePoolVO) { | ||||||
|  |         List<VMTemplateStoragePoolVO> unusedTemplatesInPool = templateMgr.getUnusedTemplatesInPool(storagePoolVO); | ||||||
|  |         for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) { | ||||||
|  |             if (templatePoolVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { | ||||||
|  |                 templateMgr.evictTemplateFromStoragePool(templatePoolVO); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void deleteAgentStoragePools(StoragePool storagePool) { | ||||||
|  |         List<StoragePoolHostVO> poolHostVOs = storagePoolHostDao.listByPoolId(storagePool.getId()); | ||||||
|  |         for (StoragePoolHostVO poolHostVO : poolHostVOs) { | ||||||
|  |             DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand(storagePool); | ||||||
|  |             final Answer answer = agentMgr.easySend(poolHostVO.getHostId(), deleteStoragePoolCommand); | ||||||
|  |             if (answer != null && answer.getResult()) { | ||||||
|  |                 s_logger.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); | ||||||
|  |             } else { | ||||||
|  |                 if (answer != null) { | ||||||
|  |                     s_logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult()); | ||||||
|  |                 } else { | ||||||
|  |                     s_logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected boolean cleanupDatastore(DataStore store) { | ||||||
|  |         StoragePool storagePool = (StoragePool)store; | ||||||
|  |         StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(storagePool.getId()); | ||||||
|  |         if (storagePoolVO == null) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         evictTemplates(storagePoolVO); | ||||||
|  |         deleteAgentStoragePools(storagePool); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -5,6 +5,12 @@ All notable changes to Linstor CloudStack plugin will be documented in this file | |||||||
| The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||||||
| and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||||||
| 
 | 
 | ||||||
|  | ## [2025-03-13] | ||||||
|  | 
 | ||||||
|  | ### Fixed | ||||||
|  | 
 | ||||||
|  | - Implemented missing delete datastore, to correctly cleanup on datastore removal | ||||||
|  | 
 | ||||||
| ## [2025-02-21] | ## [2025-02-21] | ||||||
| 
 | 
 | ||||||
| ### Fixed | ### Fixed | ||||||
|  | |||||||
| @ -289,7 +289,10 @@ public class LinstorPrimaryDataStoreLifeCycleImpl extends BasePrimaryDataStoreLi | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deleteDataStore(DataStore store) { |     public boolean deleteDataStore(DataStore store) { | ||||||
|         return dataStoreHelper.deletePrimaryDataStore(store); |         if (cleanupDatastore(store)) { | ||||||
|  |             return dataStoreHelper.deletePrimaryDataStore(store); | ||||||
|  |         } | ||||||
|  |         return false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* (non-Javadoc) |     /* (non-Javadoc) | ||||||
|  | |||||||
| @ -50,8 +50,6 @@ import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; | |||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.agent.AgentManager; | import com.cloud.agent.AgentManager; | ||||||
| import com.cloud.agent.api.Answer; |  | ||||||
| import com.cloud.agent.api.DeleteStoragePoolCommand; |  | ||||||
| import com.cloud.agent.api.StoragePoolInfo; | import com.cloud.agent.api.StoragePoolInfo; | ||||||
| import com.cloud.capacity.CapacityManager; | import com.cloud.capacity.CapacityManager; | ||||||
| import com.cloud.dc.ClusterVO; | import com.cloud.dc.ClusterVO; | ||||||
| @ -65,9 +63,6 @@ import com.cloud.storage.Storage; | |||||||
| import com.cloud.storage.StorageManager; | import com.cloud.storage.StorageManager; | ||||||
| import com.cloud.storage.StoragePool; | import com.cloud.storage.StoragePool; | ||||||
| import com.cloud.storage.StoragePoolAutomation; | import com.cloud.storage.StoragePoolAutomation; | ||||||
| import com.cloud.storage.StoragePoolHostVO; |  | ||||||
| import com.cloud.storage.VMTemplateStoragePoolVO; |  | ||||||
| import com.cloud.storage.VMTemplateStorageResourceAssoc; |  | ||||||
| import com.cloud.storage.dao.StoragePoolHostDao; | import com.cloud.storage.dao.StoragePoolHostDao; | ||||||
| import com.cloud.template.TemplateManager; | import com.cloud.template.TemplateManager; | ||||||
| import com.cloud.utils.UriUtils; | import com.cloud.utils.UriUtils; | ||||||
| @ -345,37 +340,11 @@ public class ScaleIOPrimaryDataStoreLifeCycle extends BasePrimaryDataStoreLifeCy | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean deleteDataStore(DataStore dataStore) { |     public boolean deleteDataStore(DataStore dataStore) { | ||||||
|         StoragePool storagePool = (StoragePool)dataStore; |         if (cleanupDatastore(dataStore)) { | ||||||
|         StoragePoolVO storagePoolVO = primaryDataStoreDao.findById(storagePool.getId()); |             ScaleIOGatewayClientConnectionPool.getInstance().removeClient(dataStore.getId()); | ||||||
|         if (storagePoolVO == null) { |             return dataStoreHelper.deletePrimaryDataStore(dataStore); | ||||||
|             return false; |  | ||||||
|         } |         } | ||||||
| 
 |         return false; | ||||||
|         List<VMTemplateStoragePoolVO> unusedTemplatesInPool = templateMgr.getUnusedTemplatesInPool(storagePoolVO); |  | ||||||
|         for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) { |  | ||||||
|             if (templatePoolVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { |  | ||||||
|                 templateMgr.evictTemplateFromStoragePool(templatePoolVO); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         List<StoragePoolHostVO> poolHostVOs = storagePoolHostDao.listByPoolId(dataStore.getId()); |  | ||||||
|         for (StoragePoolHostVO poolHostVO : poolHostVOs) { |  | ||||||
|             DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand(storagePool); |  | ||||||
|             final Answer answer = agentMgr.easySend(poolHostVO.getHostId(), deleteStoragePoolCommand); |  | ||||||
|             if (answer != null && answer.getResult()) { |  | ||||||
|                 LOGGER.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); |  | ||||||
|             } else { |  | ||||||
|                 if (answer != null) { |  | ||||||
|                     LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult()); |  | ||||||
|                 } else { |  | ||||||
|                     LOGGER.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         ScaleIOGatewayClientConnectionPool.getInstance().removeClient(dataStore.getId()); |  | ||||||
| 
 |  | ||||||
|         return dataStoreHelper.deletePrimaryDataStore(dataStore); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user