Skip to content

Commit 50ee981

Browse files
nitinmehke4qqq
authored andcommitted
CLOUDSTACK-6826: Improving the download url expiration where the expiration work would be handled by the ssvm that has the corresponding symlink created on it. In case it doesnt exist, then would be any one of the ssvm in the zone.
Also when the ssvm is destroyed all the download urls are expired to be cleaned up in the next run by the new ssvm. (cherry picked from commit ce90837)
1 parent 003269e commit 50ee981

10 files changed

Lines changed: 102 additions & 3 deletions

File tree

‎engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ public interface EndPointSelector {
3636
EndPoint select(Scope scope, Long storeId);
3737

3838
EndPoint selectHypervisorHost(Scope scope);
39+
40+
EndPoint select(DataStore store, String downloadUrl);
3941
}

‎engine/schema/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,6 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
8888
List<HostVO> listByDataCenterId(long id);
8989

9090
List<Long> listAllHosts(long zoneId);
91+
92+
HostVO findByPublicIp(String publicIp);
9193
}

‎engine/schema/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
8484
protected SearchBuilder<HostVO> MsStatusSearch;
8585
protected SearchBuilder<HostVO> DcPrivateIpAddressSearch;
8686
protected SearchBuilder<HostVO> DcStorageIpAddressSearch;
87+
protected SearchBuilder<HostVO> PublicIpAddressSearch;
8788

8889
protected SearchBuilder<HostVO> GuidSearch;
8990
protected SearchBuilder<HostVO> DcSearch;
@@ -207,6 +208,10 @@ public void init() {
207208
DcStorageIpAddressSearch.and("dc", DcStorageIpAddressSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
208209
DcStorageIpAddressSearch.done();
209210

211+
PublicIpAddressSearch = createSearchBuilder();
212+
PublicIpAddressSearch.and("publicIpAddress", PublicIpAddressSearch.entity().getPublicIpAddress(), SearchCriteria.Op.EQ);
213+
PublicIpAddressSearch.done();
214+
210215
GuidSearch = createSearchBuilder();
211216
GuidSearch.and("guid", GuidSearch.entity().getGuid(), SearchCriteria.Op.EQ);
212217
GuidSearch.done();
@@ -1068,6 +1073,14 @@ public List<HostVO> findByClusterId(Long clusterId) {
10681073
return listBy(sc);
10691074
}
10701075

1076+
@Override
1077+
public HostVO findByPublicIp(String publicIp) {
1078+
SearchCriteria<HostVO> sc = PublicIpAddressSearch.create();
1079+
sc.setParameters("publicIpAddress", publicIp);
1080+
return findOneBy(sc);
1081+
}
1082+
1083+
10711084
@Override
10721085
public List<HostVO> findHypervisorHostInCluster(long clusterId) {
10731086
SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();

‎engine/schema/src/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
7878
List<TemplateDataStoreVO> listTemplateDownloadUrls();
7979

8080
void removeByTemplateStore(long templateId, long imageStoreId);
81+
82+
void expireDnldUrlsForZone(Long dcId);
8183
}

‎engine/schema/src/org/apache/cloudstack/storage/datastore/db/VolumeDataStoreDao.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>,
4444
void duplicateCacheRecordsOnRegionStore(long storeId);
4545

4646
List<VolumeDataStoreVO> listVolumeDownloadUrls();
47+
48+
void expireDnldUrlsForZone(Long dcId);
4749
}

‎engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.cloudstack.storage.endpoint;
2020

21+
import java.net.URI;
22+
import java.net.URISyntaxException;
2123
import java.sql.PreparedStatement;
2224
import java.sql.ResultSet;
2325
import java.sql.SQLException;
@@ -261,6 +263,33 @@ public EndPoint select(DataObject object) {
261263
return null;
262264
}
263265

266+
@Override
267+
public EndPoint select(DataStore store, String downloadUrl){
268+
269+
HostVO host = null;
270+
try {
271+
URI uri = new URI(downloadUrl);
272+
String scheme = uri.getScheme();
273+
String publicIp = uri.getHost();
274+
// If its https then public ip will be of the form xxx-xxx-xxx-xxx.mydomain.com
275+
if(scheme.equalsIgnoreCase("https")){
276+
publicIp = publicIp.split("\\.")[0]; // We want xxx-xxx-xxx-xxx
277+
publicIp = publicIp.replace("-","."); // We not want the IP - xxx.xxx.xxx.xxx
278+
}
279+
host = hostDao.findByPublicIp(publicIp);
280+
if(host != null){
281+
return RemoteHostEndPoint.getHypervisorHostEndPoint(host);
282+
}
283+
284+
} catch (URISyntaxException e) {
285+
s_logger.debug("Received URISyntaxException for url" +downloadUrl);
286+
}
287+
288+
// If ssvm doesnt exist then find any ssvm in the zone.
289+
s_logger.debug("Coudn't find ssvm for url" +downloadUrl);
290+
return findEndpointForImageStorage(store);
291+
}
292+
264293
@Override
265294
public EndPoint select(DataStore store) {
266295
if (store.getRole() == DataStoreRole.Primary) {

‎engine/storage/src/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.image.db;
1818

19+
import java.sql.PreparedStatement;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.Date;
@@ -64,6 +65,7 @@ public class TemplateDataStoreDaoImpl extends GenericDaoBase<TemplateDataStoreVO
6465
private SearchBuilder<TemplateDataStoreVO> storeTemplateStateSearch;
6566
private SearchBuilder<TemplateDataStoreVO> storeTemplateDownloadStatusSearch;
6667
private SearchBuilder<TemplateDataStoreVO> downloadTemplateSearch;
68+
private static final String EXPIRE_DOWNLOAD_URLS_FOR_ZONE = "update template_store_ref set download_url_created=? where store_id in (select id from image_store where data_center_id=?)";
6769

6870
@Inject
6971
private DataStoreManager _storeMgr;
@@ -511,4 +513,22 @@ public List<TemplateDataStoreVO> listTemplateDownloadUrls() {
511513
return listBy(sc);
512514
}
513515

516+
@Override
517+
public void expireDnldUrlsForZone(Long dcId){
518+
TransactionLegacy txn = TransactionLegacy.currentTxn();
519+
PreparedStatement pstmt = null;
520+
try {
521+
txn.start();
522+
pstmt = txn.prepareAutoCloseStatement(EXPIRE_DOWNLOAD_URLS_FOR_ZONE);
523+
pstmt.setDate(1, new java.sql.Date(-1l));// Set the time before the epoch time.
524+
pstmt.setLong(2, dcId);
525+
pstmt.executeUpdate();
526+
txn.commit();
527+
} catch (Exception e) {
528+
txn.rollback();
529+
s_logger.warn("Failed expiring download urls for dcId: " + dcId, e);
530+
}
531+
532+
}
533+
514534
}

‎engine/storage/src/org/apache/cloudstack/storage/image/db/VolumeDataStoreDaoImpl.java‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.image.db;
1818

19+
import java.sql.PreparedStatement;
1920
import java.util.ArrayList;
2021
import java.util.Date;
2122
import java.util.List;
@@ -51,6 +52,8 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
5152
private SearchBuilder<VolumeDataStoreVO> cacheSearch;
5253
private SearchBuilder<VolumeDataStoreVO> storeVolumeSearch;
5354
private SearchBuilder<VolumeDataStoreVO> downloadVolumeSearch;
55+
private static final String EXPIRE_DOWNLOAD_URLS_FOR_ZONE = "update volume_store_ref set download_url_created=? where store_id in (select id from image_store where data_center_id=?)";
56+
5457

5558
@Inject
5659
DataStoreManager storeMgr;
@@ -267,4 +270,22 @@ public List<VolumeDataStoreVO> listVolumeDownloadUrls() {
267270
sc.setParameters("destroyed", false);
268271
return listBy(sc);
269272
}
273+
274+
@Override
275+
public void expireDnldUrlsForZone(Long dcId){
276+
TransactionLegacy txn = TransactionLegacy.currentTxn();
277+
PreparedStatement pstmt = null;
278+
try {
279+
txn.start();
280+
pstmt = txn.prepareAutoCloseStatement(EXPIRE_DOWNLOAD_URLS_FOR_ZONE);
281+
pstmt.setDate(1, new java.sql.Date(-1l));// Set the time before the epoch time.
282+
pstmt.setLong(2, dcId);
283+
pstmt.executeUpdate();
284+
txn.commit();
285+
} catch (Exception e) {
286+
txn.rollback();
287+
s_logger.warn("Failed expiring download urls for dcId: " + dcId, e);
288+
}
289+
290+
}
270291
}

‎plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import javax.inject.Inject;
2424

2525
import com.cloud.agent.api.storage.DeleteEntityDownloadURLCommand;
26+
import com.cloud.host.dao.HostDao;
2627
import com.cloud.storage.Upload;
2728
import org.apache.log4j.Logger;
2829

@@ -49,6 +50,8 @@ public class CloudStackImageStoreDriverImpl extends BaseImageStoreDriverImpl {
4950
@Inject
5051
ConfigurationDao _configDao;
5152
@Inject
53+
HostDao _hostDao;
54+
@Inject
5255
EndPointSelector _epSelector;
5356

5457
@Override
@@ -113,8 +116,8 @@ private String generateCopyUrl(String ipAddress, String uuid) {
113116

114117
@Override
115118
public void deleteEntityExtractUrl(DataStore store, String installPath, String downloadUrl, Upload.Type entityType) {
116-
// find an endpoint to send command
117-
EndPoint ep = _epSelector.select(store);
119+
// find an endpoint to send command based on the ssvm on which the url was created.
120+
EndPoint ep = _epSelector.select(store, downloadUrl);
118121

119122
// Delete Symlink at ssvm. In case of volume also delete the volume.
120123
DeleteEntityDownloadURLCommand cmd = new DeleteEntityDownloadURLCommand(installPath, entityType, downloadUrl, ((ImageStoreEntity) store).getMountPoint());

‎services/secondary-storage/controller/src/org/apache/cloudstack/secondarystorage/SecondaryStorageManagerImpl.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
4444
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
4545
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
46+
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
4647
import org.apache.cloudstack.utils.identity.ManagementServerNode;
4748
import org.apache.log4j.Logger;
4849

@@ -236,6 +237,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
236237
ImageStoreDao _imageStoreDao;
237238
@Inject
238239
TemplateDataStoreDao _tmplStoreDao;
240+
@Inject
241+
VolumeDataStoreDao _volumeStoreDao;
239242
private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL;
240243
private int _secStorageVmMtuSize;
241244

@@ -987,7 +990,9 @@ public boolean destroySecStorageVm(long vmId) {
987990
s_logger.debug("Removing host entry for ssvm id=" + vmId);
988991
_hostDao.remove(host.getId());
989992
}
990-
993+
//Expire the download urls in the entire zone for templates and volumes.
994+
_tmplStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
995+
_volumeStoreDao.expireDnldUrlsForZone(host.getDataCenterId());
991996
return true;
992997
} catch (ResourceUnavailableException e) {
993998
s_logger.warn("Unable to expunge " + ssvm, e);

0 commit comments

Comments
 (0)