You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2014/11/21 23:49:57 UTC

git commit: updated refs/heads/master to 9ac93d3

Repository: cloudstack
Updated Branches:
  refs/heads/master 50bf7496e -> 9ac93d3e4


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/9ac93d3e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/9ac93d3e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/9ac93d3e

Branch: refs/heads/master
Commit: 9ac93d3e435bf7150b68c92cc1b6b630b197bc56
Parents: 50bf749
Author: Min Chen <mi...@citrix.com>
Authored: Fri Nov 21 13:31:18 2014 -0800
Committer: Min Chen <mi...@citrix.com>
Committed: Fri Nov 21 14:36:36 2014 -0800

----------------------------------------------------------------------
 .../storage/volume/VolumeServiceImpl.java       | 21 +++++++++++++++-----
 .../com/cloud/storage/VolumeApiServiceImpl.java |  2 ++
 utils/src/com/cloud/utils/UriUtils.java         | 21 +++++++++++++++++++-
 3 files changed, 38 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9ac93d3e/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 edb50b2..4f8255a 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
@@ -1020,7 +1020,7 @@ public class VolumeServiceImpl implements VolumeService {
             }
             srcVolume.processEvent(Event.OperationSuccessed);
             destVolume.processEvent(Event.MigrationCopySucceeded, result.getAnswer());
-            _volumeDao.updateUuid(srcVolume.getId(), destVolume.getId());
+            volDao.updateUuid(srcVolume.getId(), destVolume.getId());
             try {
                 destroyVolume(srcVolume.getId());
                 srcVolume = volFactory.getVolume(srcVolume.getId());
@@ -1225,10 +1225,16 @@ public class VolumeServiceImpl implements VolumeService {
 
     protected Void registerVolumeCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, CreateVolumeContext<VolumeApiResult> 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());
 
@@ -1267,6 +1273,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;
@@ -1302,7 +1313,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);
 
@@ -1374,7 +1385,7 @@ public class VolumeServiceImpl implements VolumeService {
                     List<VolumeDataStoreVO> dbVolumes = _volumeStoreDao.listUploadedVolumesByStoreId(storeId);
                     List<VolumeDataStoreVO> toBeDownloaded = new ArrayList<VolumeDataStoreVO>(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");
@@ -1419,7 +1430,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/9ac93d3e/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 928c63b..785a95e 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/9ac93d3e/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<String, Integer>(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")) &&