cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [44/50] git commit: updated refs/heads/master to 0b83559
Date Wed, 29 Apr 2015 05:44:28 GMT
Added file exists check for onetime post url

also, fixed an issue where in the upload was going to error state in
case of parallel call to the same post url


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a7e511c1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a7e511c1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a7e511c1

Branch: refs/heads/master
Commit: a7e511c1a30c974038ebd5683f112631e5abb6da
Parents: 4f35d36
Author: Rajani Karuturi <rajanikaruturi@gmail.com>
Authored: Fri Apr 17 18:03:13 2015 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Fri Apr 17 18:08:23 2015 +0530

----------------------------------------------------------------------
 .../storage/resource/HttpUploadServerHandler.java     | 13 +++++++++----
 .../storage/resource/NfsSecondaryStorageResource.java | 14 ++++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7e511c1/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java
index 4a3fa86..05e5fe4 100644
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/HttpUploadServerHandler.java
@@ -77,7 +77,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
 
     private String uuid;
 
-    private boolean fileReceived = false;
+    private boolean requestProcessed = false;
 
     private static final String HEADER_SIGNATURE = "X-signature";
 
@@ -96,12 +96,12 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
         if (decoder != null) {
             decoder.cleanFiles();
         }
-        fileReceived = false;
+        requestProcessed = false;
     }
 
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        if (!fileReceived) {
+        if (!requestProcessed) {
             String message = "file receive failed or connection closed prematurely.";
             logger.error(message);
             storageResource.updateStateMapWithError(uuid, message);
@@ -163,12 +163,14 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
                     logger.error("post request validation failed", ex);
                     responseContent.append(ex.getMessage());
                     writeResponse(ctx.channel(), HttpResponseStatus.BAD_REQUEST);
+                    requestProcessed = true;
                     return;
                 }
                 if (uploadEntity == null) {
                     logger.error("Unable to create upload entity. An exception occurred.");
                     responseContent.append("Internal Server Error");
                     writeResponse(ctx.channel(), HttpResponseStatus.INTERNAL_SERVER_ERROR);
+                    requestProcessed = true;
                     return;
                 }
                 //set the base directory to download the file
@@ -181,12 +183,14 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
                     logger.error("exception while initialising the decoder", e);
                     responseContent.append(e.getMessage());
                     writeResponse(ctx.channel(), HttpResponseStatus.INTERNAL_SERVER_ERROR);
+                    requestProcessed = true;
                     return;
                 }
             } else {
                 logger.warn("received a get request");
                 responseContent.append("only post requests are allowed");
                 writeResponse(ctx.channel(), HttpResponseStatus.BAD_REQUEST);
+                requestProcessed = true;
                 return;
             }
 
@@ -202,6 +206,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
                     logger.error("data decoding exception", e);
                     responseContent.append(e.getMessage());
                     writeResponse(ctx.channel(), HttpResponseStatus.INTERNAL_SERVER_ERROR);
+                    requestProcessed = true;
                     return;
                 }
                 if (chunk instanceof LastHttpContent) {
@@ -229,7 +234,7 @@ public class HttpUploadServerHandler extends SimpleChannelInboundHandler<HttpObj
                     if (data.getHttpDataType() == HttpDataType.FileUpload) {
                         FileUpload fileUpload = (FileUpload) data;
                         if (fileUpload.isCompleted()) {
-                            fileReceived = true;
+                            requestProcessed = true;
                             String format = ImageStoreUtil.checkTemplateFormat(fileUpload.getFile().getAbsolutePath(),
fileUpload.getFilename());
                             if(StringUtils.isNotBlank(format)) {
                                 String errorString = "File type mismatch between the sent
file and the actual content. Received: " + format;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a7e511c1/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
index 4644785..7cfaa9c 100755
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java
@@ -2617,9 +2617,13 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
             throw new InvalidParameterValueException("unable to decode and deserialize metadata");
         } else {
             uuid = cmd.getEntityUUID();
-            if (uploadEntityStateMap.containsKey(uuid)) {
+            if (isOneTimePostUrlUsed(cmd)) {
                 uploadEntity = uploadEntityStateMap.get(uuid);
-                throw new InvalidParameterValueException("The one time post url is already
used and the upload is in " + uploadEntity.getUploadState() + " state.");
+                StringBuilder errorMessage = new StringBuilder("The one time post url is
already used");
+                if (uploadEntity != null) {
+                    errorMessage.append(" and the upload is in ").append(uploadEntity.getUploadState()).append("
state.");
+                }
+                throw new InvalidParameterValueException(errorMessage.toString());
             }
             int maxSizeInGB = Integer.valueOf(cmd.getMaxUploadSize());
             int contentLengthInGB = getSizeInGB(contentLength);
@@ -2657,6 +2661,12 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
         return uploadEntity;
     }
 
+    private boolean isOneTimePostUrlUsed(TemplateOrVolumePostUploadCommand cmd) {
+        String uuid = cmd.getEntityUUID();
+        String uploadPath = this.getRootDir(cmd.getDataTo()) + File.separator + cmd.getAbsolutePath();
+        return uploadEntityStateMap.containsKey(uuid) || new File(uploadPath).exists();
+    }
+
     private int getSizeInGB(long sizeInBytes) {
         return (int)Math.ceil(sizeInBytes * 1.0d / (1024 * 1024 * 1024));
     }


Mime
View raw message