Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 01A5517A99 for ; Fri, 21 Nov 2014 23:19:34 +0000 (UTC) Received: (qmail 49670 invoked by uid 500); 21 Nov 2014 23:19:33 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 49631 invoked by uid 500); 21 Nov 2014 23:19:33 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 49622 invoked by uid 99); 21 Nov 2014 23:19:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Nov 2014 23:19:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 628E39AEE51; Fri, 21 Nov 2014 23:19:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mchen@apache.org To: commits@cloudstack.apache.org Message-Id: <5733c5bf2c3f45318298a92ebdf742a3@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/4.5 to b85183e Date: Fri, 21 Nov 2014 23:19:33 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/4.5 93b2b3a4a -> b85183ede CLOUDSTACK-7678:volumes are getting uploaded successfully with wrong url. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b85183ed Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b85183ed Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b85183ed Branch: refs/heads/4.5 Commit: b85183ede7c1a94b8d8fcdec744ac0c1b9b56df9 Parents: 93b2b3a Author: Min Chen Authored: Fri Nov 21 15:18:47 2014 -0800 Committer: Min Chen Committed: Fri Nov 21 15:18:47 2014 -0800 ---------------------------------------------------------------------- .../storage/volume/VolumeServiceImpl.java | 23 ++++++++++++++------ .../com/cloud/storage/VolumeApiServiceImpl.java | 2 ++ utils/src/com/cloud/utils/UriUtils.java | 21 +++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b85183ed/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java ---------------------------------------------------------------------- diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java index 7e3239f..e91477e 100644 --- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java +++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java @@ -125,8 +125,6 @@ public class VolumeServiceImpl implements VolumeService { @Inject VMTemplatePoolDao _tmpltPoolDao; @Inject - VolumeDao _volumeDao; - @Inject EndPointSelector _epSelector; @Inject HostDao _hostDao; @@ -1021,7 +1019,7 @@ public class VolumeServiceImpl implements VolumeService { } srcVolume.processEvent(Event.OperationSuccessed); destVolume.processEvent(Event.OperationSuccessed, result.getAnswer()); - _volumeDao.updateUuid(srcVolume.getId(), destVolume.getId()); + volDao.updateUuid(srcVolume.getId(), destVolume.getId()); try { destroyVolume(srcVolume.getId()); srcVolume = volFactory.getVolume(srcVolume.getId()); @@ -1226,10 +1224,16 @@ public class VolumeServiceImpl implements VolumeService { protected Void registerVolumeCallback(AsyncCallbackDispatcher callback, CreateVolumeContext context) { CreateCmdResult result = callback.getResult(); + VolumeObject vo = (VolumeObject)context.volume; try { - VolumeObject vo = (VolumeObject)context.volume; if (result.isFailed()) { vo.processEvent(Event.OperationFailed); + // delete the volume entry from volumes table in case of failure + VolumeVO vol = volDao.findById(vo.getId()); + if (vol != null) { + volDao.remove(vo.getId()); + } + } else { vo.processEvent(Event.OperationSuccessed, result.getAnswer()); @@ -1268,6 +1272,11 @@ public class VolumeServiceImpl implements VolumeService { } catch (Exception e) { s_logger.error("register volume failed: ", e); + // delete the volume entry from volumes table in case of failure + VolumeVO vol = volDao.findById(vo.getId()); + if (vol != null) { + volDao.remove(vo.getId()); + } VolumeApiResult res = new VolumeApiResult(null); context.future.complete(res); return null; @@ -1303,7 +1312,7 @@ public class VolumeServiceImpl implements VolumeService { EndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(destHost); if (ep != null) { - VolumeVO volume = _volumeDao.findById(volumeId); + VolumeVO volume = volDao.findById(volumeId); PrimaryDataStore primaryDataStore = this.dataStoreMgr.getPrimaryDataStore(volume.getPoolId()); ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(volume.getPath(), new StorageFilerTO(primaryDataStore), volume.getSize(), newSize, true, instanceName); @@ -1375,7 +1384,7 @@ public class VolumeServiceImpl implements VolumeService { List dbVolumes = _volumeStoreDao.listByStoreId(storeId); List toBeDownloaded = new ArrayList(dbVolumes); for (VolumeDataStoreVO volumeStore : dbVolumes) { - VolumeVO volume = _volumeDao.findById(volumeStore.getVolumeId()); + VolumeVO volume = volDao.findById(volumeStore.getVolumeId()); if (volume == null) { s_logger.warn("Volume_store_ref shows that volume " + volumeStore.getVolumeId() + " is on image store " + storeId + ", but the volume is not found in volumes table, potentially some bugs in deleteVolume, so we just treat this volume to be deleted and mark it as destroyed"); @@ -1420,7 +1429,7 @@ public class VolumeServiceImpl implements VolumeService { if (volume.getSize() == 0) { // Set volume size in volumes table volume.setSize(volInfo.getSize()); - _volumeDao.update(volumeStore.getVolumeId(), volume); + volDao.update(volumeStore.getVolumeId(), volume); } if (volInfo.getSize() > 0) { http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b85183ed/server/src/com/cloud/storage/VolumeApiServiceImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/VolumeApiServiceImpl.java b/server/src/com/cloud/storage/VolumeApiServiceImpl.java index 26678e6..92d84d5 100644 --- a/server/src/com/cloud/storage/VolumeApiServiceImpl.java +++ b/server/src/com/cloud/storage/VolumeApiServiceImpl.java @@ -298,6 +298,8 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic UriUtils.validateUrl(format, url); + // check URL existence + UriUtils.checkUrlExistence(url); // Check that the resource limit for secondary storage won't be exceeded _resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.secondary_storage, UriUtils.getRemoteSize(url)); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b85183ed/utils/src/com/cloud/utils/UriUtils.java ---------------------------------------------------------------------- diff --git a/utils/src/com/cloud/utils/UriUtils.java b/utils/src/com/cloud/utils/UriUtils.java index 9f6f037..631c629 100644 --- a/utils/src/com/cloud/utils/UriUtils.java +++ b/utils/src/com/cloud/utils/UriUtils.java @@ -38,15 +38,18 @@ import javax.net.ssl.HttpsURLConnection; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.HeadMethod; import org.apache.commons.httpclient.util.URIUtil; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URLEncodedUtils; + import org.apache.http.message.BasicNameValuePair; import org.apache.log4j.Logger; @@ -273,12 +276,28 @@ public class UriUtils { checkFormat(format, uripath); } return new Pair(host, port); - } catch (URISyntaxException use) { throw new IllegalArgumentException("Invalid URL: " + url); } } + // use http HEAD method to validate url + public static void checkUrlExistence(String url) { + if (url.toLowerCase().startsWith("http") || url.toLowerCase().startsWith("https")) { + HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); + HeadMethod httphead = new HeadMethod(url); + try { + if (httpClient.executeMethod(httphead) != HttpStatus.SC_OK) { + throw new IllegalArgumentException("Invalid URL: " + url); + } + } catch (HttpException hte) { + throw new IllegalArgumentException("Cannot reach URL: " + url); + } catch (IOException ioe) { + throw new IllegalArgumentException("Cannot reach URL: " + url); + } + } + } + // verify if a URI path is compliance with the file format given private static void checkFormat(String format, String uripath) { if ((!uripath.toLowerCase().endsWith("vhd")) && (!uripath.toLowerCase().endsWith("vhd.zip")) && (!uripath.toLowerCase().endsWith("vhd.bz2")) &&