|
41 | 41 | import javax.inject.Inject; |
42 | 42 | import javax.naming.ConfigurationException; |
43 | 43 |
|
| 44 | +import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand; |
| 45 | +import com.cloud.utils.DateUtil; |
44 | 46 | import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd; |
45 | 47 | import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd; |
46 | 48 | import org.apache.cloudstack.api.command.admin.storage.CreateSecondaryStagingStoreCmd; |
|
49 | 51 | import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd; |
50 | 52 | import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd; |
51 | 53 | import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd; |
52 | | -import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; |
53 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; |
54 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; |
55 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; |
56 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; |
57 | | -import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; |
58 | | -import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; |
59 | | -import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; |
60 | | -import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; |
61 | | -import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; |
62 | | -import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; |
63 | | -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory; |
64 | | -import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; |
65 | | -import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; |
66 | | -import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory; |
67 | | -import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService; |
68 | | -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory; |
69 | | -import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService; |
| 54 | +import org.apache.cloudstack.engine.subsystem.api.storage.*; |
70 | 55 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult; |
71 | | -import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; |
72 | 56 | import org.apache.cloudstack.framework.async.AsyncCallFuture; |
73 | 57 | import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; |
74 | 58 | import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao; |
|
81 | 65 | import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; |
82 | 66 | import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; |
83 | 67 | import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; |
| 68 | +import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; |
84 | 69 | import org.apache.log4j.Logger; |
85 | 70 | import org.springframework.stereotype.Component; |
86 | 71 |
|
@@ -257,6 +242,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C |
257 | 242 | DataStoreManager _dataStoreMgr; |
258 | 243 | @Inject |
259 | 244 | DataStoreProviderManager _dataStoreProviderMgr; |
| 245 | + |
260 | 246 | @Inject |
261 | 247 | private TemplateService _imageSrv; |
262 | 248 | @Inject |
@@ -291,6 +277,8 @@ public void setDiscoverers(List<StoragePoolDiscoverer> _discoverers) { |
291 | 277 | boolean _storageCleanupEnabled; |
292 | 278 | boolean _templateCleanupEnabled = true; |
293 | 279 | int _storageCleanupInterval; |
| 280 | + int _downloadUrlCleanupInterval; |
| 281 | + int _downloadUrlExpirationInterval; |
294 | 282 | private int _createVolumeFromSnapshotWait; |
295 | 283 | private int _copyvolumewait; |
296 | 284 | int _storagePoolAcquisitionWaitSeconds = 1800; // 30 minutes |
@@ -510,6 +498,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu |
510 | 498 | int wrks = NumbersUtil.parseInt(workers, 10); |
511 | 499 | _executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("StorageManager-Scavenger")); |
512 | 500 |
|
| 501 | + String cleanupInterval = configs.get("extract.url.cleanup.interval"); |
| 502 | + _downloadUrlCleanupInterval = NumbersUtil.parseInt(cleanupInterval, 7200); |
| 503 | + |
| 504 | + String urlExpirationInterval = configs.get("extract.url.expiration.interval"); |
| 505 | + _downloadUrlExpirationInterval = NumbersUtil.parseInt(urlExpirationInterval, 14400); |
| 506 | + |
513 | 507 | _agentMgr.registerForHostEvents(ComponentContext.inject(LocalStoragePoolListener.class), true, false, false); |
514 | 508 |
|
515 | 509 | String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size"); |
@@ -571,6 +565,8 @@ public boolean start() { |
571 | 565 | } else { |
572 | 566 | s_logger.debug("Storage cleanup is not enabled, so the storage cleanup thread is not being scheduled."); |
573 | 567 | } |
| 568 | + |
| 569 | + _executor.scheduleWithFixedDelay(new DownloadURLGarbageCollector(), _downloadUrlCleanupInterval, _downloadUrlCleanupInterval, TimeUnit.SECONDS); |
574 | 570 | return true; |
575 | 571 | } |
576 | 572 |
|
@@ -1097,6 +1093,35 @@ List<String> findAllSnapshotForVolume(Long volumeId) { |
1097 | 1093 | } |
1098 | 1094 | } |
1099 | 1095 |
|
| 1096 | + |
| 1097 | + public void cleanupDownloadUrls(){ |
| 1098 | + // find volumesOnImageStoreList with download url |
| 1099 | + List<VolumeDataStoreVO> volumesOnImageStoreList = _volumeStoreDao.listVolumeDownloadUrls(); |
| 1100 | + |
| 1101 | + for(VolumeDataStoreVO volumeOnImageStore : volumesOnImageStoreList){ |
| 1102 | + |
| 1103 | + try { |
| 1104 | + long downloadUrlCurrentAgeInSecs = DateUtil.getTimeDifference(DateUtil.now(), volumeOnImageStore.getUpdated()); |
| 1105 | + if(downloadUrlCurrentAgeInSecs < _downloadUrlExpirationInterval){ // URL hasnt expired yet |
| 1106 | + continue; |
| 1107 | + } |
| 1108 | + |
| 1109 | + s_logger.debug("Removing download url " + volumeOnImageStore.getExtractUrl() + " for volume id " + volumeOnImageStore.getVolumeId()); |
| 1110 | + |
| 1111 | + // Remove it from image store |
| 1112 | + ImageStoreEntity secStore = (ImageStoreEntity) _dataStoreMgr.getDataStore(volumeOnImageStore.getDataStoreId(), DataStoreRole.Image); |
| 1113 | + secStore.deleteExtractUrl(volumeOnImageStore.getInstallPath(), volumeOnImageStore.getExtractUrl(), ImageFormat.VHD); |
| 1114 | + |
| 1115 | + // Now remove it from DB. |
| 1116 | + volumeOnImageStore.setExtractUrl(null); |
| 1117 | + _volumeStoreDao.update(volumeOnImageStore.getId(), volumeOnImageStore); |
| 1118 | + }catch(Throwable th){ |
| 1119 | + s_logger.warn("caught exception while deleting download url " +volumeOnImageStore.getExtractUrl(), th); |
| 1120 | + } |
| 1121 | + } |
| 1122 | + |
| 1123 | + } |
| 1124 | + |
1100 | 1125 | @Override |
1101 | 1126 | @DB |
1102 | 1127 | public void cleanupSecondaryStorage(boolean recurring) { |
@@ -1262,6 +1287,25 @@ public void run() { |
1262 | 1287 | } |
1263 | 1288 | } |
1264 | 1289 |
|
| 1290 | + |
| 1291 | + protected class DownloadURLGarbageCollector implements Runnable { |
| 1292 | + |
| 1293 | + public DownloadURLGarbageCollector() { |
| 1294 | + } |
| 1295 | + |
| 1296 | + @Override |
| 1297 | + public void run() { |
| 1298 | + try { |
| 1299 | + s_logger.trace("Download URL Garbage Collection Thread is running."); |
| 1300 | + |
| 1301 | + cleanupDownloadUrls(); |
| 1302 | + |
| 1303 | + } catch (Exception e) { |
| 1304 | + s_logger.error("Caught the following Exception", e); |
| 1305 | + } |
| 1306 | + } |
| 1307 | + } |
| 1308 | + |
1265 | 1309 | @Override |
1266 | 1310 | public void onManagementNodeJoined(List<ManagementServerHostVO> nodeList, long selfNodeId) { |
1267 | 1311 | // TODO Auto-generated method stub |
|
0 commit comments