|
27 | 27 | import com.cloud.agent.AgentManager; |
28 | 28 | import com.cloud.agent.api.Answer; |
29 | 29 | import com.cloud.agent.api.CreateStoragePoolCommand; |
| 30 | +import com.cloud.agent.api.DeleteStoragePoolCommand; |
30 | 31 | import com.cloud.agent.api.StoragePoolInfo; |
31 | 32 | import com.cloud.capacity.CapacityManager; |
32 | 33 | import com.cloud.dc.ClusterVO; |
|
39 | 40 | import com.cloud.storage.StorageManager; |
40 | 41 | import com.cloud.storage.StoragePool; |
41 | 42 | import com.cloud.storage.StoragePoolAutomation; |
| 43 | +import com.cloud.storage.StoragePoolHostVO; |
| 44 | +import com.cloud.storage.VMTemplateStoragePoolVO; |
| 45 | +import com.cloud.storage.VMTemplateStorageResourceAssoc; |
| 46 | +import com.cloud.template.TemplateManager; |
42 | 47 | import com.cloud.utils.exception.CloudRuntimeException; |
43 | 48 | import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; |
44 | 49 | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
@@ -71,6 +76,8 @@ public class LinstorPrimaryDataStoreLifeCycleImpl extends BasePrimaryDataStoreLi |
71 | 76 | @Inject |
72 | 77 | private CapacityManager _capacityMgr; |
73 | 78 | @Inject |
| 79 | + private TemplateManager templateMgr; |
| 80 | + @Inject |
74 | 81 | AgentManager _agentMgr; |
75 | 82 |
|
76 | 83 | public LinstorPrimaryDataStoreLifeCycleImpl() |
@@ -289,6 +296,34 @@ public boolean cancelMaintain(DataStore store) { |
289 | 296 |
|
290 | 297 | @Override |
291 | 298 | public boolean deleteDataStore(DataStore store) { |
| 299 | + StoragePool storagePool = (StoragePool)store; |
| 300 | + StoragePoolVO storagePoolVO = _primaryDataStoreDao.findById(storagePool.getId()); |
| 301 | + if (storagePoolVO == null) { |
| 302 | + return false; |
| 303 | + } |
| 304 | + |
| 305 | + List<VMTemplateStoragePoolVO> unusedTemplatesInPool = templateMgr.getUnusedTemplatesInPool(storagePoolVO); |
| 306 | + for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool) { |
| 307 | + if (templatePoolVO.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { |
| 308 | + templateMgr.evictTemplateFromStoragePool(templatePoolVO); |
| 309 | + } |
| 310 | + } |
| 311 | + |
| 312 | + List<StoragePoolHostVO> poolHostVOs = storagePoolHostDao.listByPoolId(store.getId()); |
| 313 | + for (StoragePoolHostVO poolHostVO : poolHostVOs) { |
| 314 | + DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand(storagePool); |
| 315 | + final Answer answer = agentMgr.easySend(poolHostVO.getHostId(), deleteStoragePoolCommand); |
| 316 | + if (answer != null && answer.getResult()) { |
| 317 | + s_logger.info("Successfully deleted storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); |
| 318 | + } else { |
| 319 | + if (answer != null) { |
| 320 | + s_logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId() + " , result: " + answer.getResult()); |
| 321 | + } else { |
| 322 | + s_logger.error("Failed to delete storage pool: " + storagePool.getId() + " from host: " + poolHostVO.getHostId()); |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | + |
292 | 327 | return dataStoreHelper.deletePrimaryDataStore(store); |
293 | 328 | } |
294 | 329 |
|
|
0 commit comments