cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [39/50] git commit: updated refs/heads/master to 0b83559
Date Wed, 29 Apr 2015 05:44:23 GMT
Returning template/volume download percent in UploadStatusAnswer

Also updating the store ref entries on receiving the answer.


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

Branch: refs/heads/master
Commit: ce823a3a2639f4272b96facd1ee08b26ad461681
Parents: 7c2c9b4
Author: Rajani Karuturi <rajanikaruturi@gmail.com>
Authored: Thu Apr 9 15:24:39 2015 +0530
Committer: Rajani Karuturi <rajanikaruturi@gmail.com>
Committed: Thu Apr 9 15:38:58 2015 +0530

----------------------------------------------------------------------
 .../cloudstack/storage/command/UploadStatusAnswer.java      | 9 +++++++++
 .../src/com/cloud/storage/ImageStoreUploadMonitorImpl.java  | 6 ++++++
 .../storage/resource/NfsSecondaryStorageResource.java       | 8 +++++++-
 .../apache/cloudstack/storage/template/UploadEntity.java    | 9 +++++++++
 4 files changed, 31 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce823a3a/core/src/org/apache/cloudstack/storage/command/UploadStatusAnswer.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/UploadStatusAnswer.java b/core/src/org/apache/cloudstack/storage/command/UploadStatusAnswer.java
index a5ef53b..1825b5a 100644
--- a/core/src/org/apache/cloudstack/storage/command/UploadStatusAnswer.java
+++ b/core/src/org/apache/cloudstack/storage/command/UploadStatusAnswer.java
@@ -30,6 +30,7 @@ public class UploadStatusAnswer extends Answer {
     private long virtualSize = 0;
     private long physicalSize = 0;
     private String installPath = null;
+    private int downloadPercent = 0;
 
     protected UploadStatusAnswer() {
     }
@@ -76,4 +77,12 @@ public class UploadStatusAnswer extends Answer {
     public void setInstallPath(String installPath) {
         this.installPath = installPath;
     }
+
+    public int getDownloadPercent() {
+        return downloadPercent;
+    }
+
+    public void setDownloadPercent(int downloadPercent) {
+        this.downloadPercent = downloadPercent;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce823a3a/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java b/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
index 7841ad9..01bda4f 100755
--- a/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
+++ b/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
@@ -293,6 +293,7 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements
ImageSto
                         case IN_PROGRESS:
                             if (tmpVolume.getState() == Volume.State.NotUploaded) {
                                 tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS);
+                                tmpVolumeDataStore.setDownloadPercent(answer.getDownloadPercent());
                                 stateMachine.transitTo(tmpVolume, Event.UploadRequested,
null, _volumeDao);
                             } else if (tmpVolume.getState() == Volume.State.UploadInProgress)
{ // check for timeout
                                 if (System.currentTimeMillis() - tmpVolumeDataStore.getCreated().getTime()
> _uploadOperationTimeout) {
@@ -301,6 +302,8 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements
ImageSto
                                     if (s_logger.isDebugEnabled()) {
                                         s_logger.debug("Volume " + tmpVolume.getUuid() +
" failed to upload due to operation timed out");
                                     }
+                                } else {
+                                    tmpVolumeDataStore.setDownloadPercent(answer.getDownloadPercent());
                                 }
                             }
                             break;
@@ -364,6 +367,7 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements
ImageSto
                             if (tmpTemplate.getState() == VirtualMachineTemplate.State.NotUploaded)
{
                                 tmpTemplateDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS);
                                 stateMachine.transitTo(tmpTemplate, VirtualMachineTemplate.Event.UploadRequested,
null, _templateDao);
+                                tmpTemplateDataStore.setDownloadPercent(answer.getDownloadPercent());
                             } else if (tmpTemplate.getState() == VirtualMachineTemplate.State.UploadInProgress)
{ // check for timeout
                                 if (System.currentTimeMillis() - tmpTemplateDataStore.getCreated().getTime()
> _uploadOperationTimeout) {
                                     tmpTemplateDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
@@ -371,6 +375,8 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements
ImageSto
                                     if (s_logger.isDebugEnabled()) {
                                         s_logger.debug("Template " + tmpTemplate.getUuid()
+ " failed to upload due to operation timed out");
                                     }
+                                } else {
+                                    tmpTemplateDataStore.setDownloadPercent(answer.getDownloadPercent());
                                 }
                             }
                             break;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce823a3a/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 1571f50..4644785 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
@@ -1689,10 +1689,15 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 answer.setVirtualSize(uploadEntity.getVirtualSize());
                 answer.setInstallPath(uploadEntity.getTmpltPath());
                 answer.setPhysicalSize(uploadEntity.getPhysicalSize());
+                answer.setDownloadPercent(100);
                 uploadEntityStateMap.remove(entityUuid);
                 return answer;
             } else if (uploadEntity.getUploadState() == UploadEntity.Status.IN_PROGRESS)
{
-                return new UploadStatusAnswer(cmd, UploadStatus.IN_PROGRESS);
+                UploadStatusAnswer answer =  new UploadStatusAnswer(cmd, UploadStatus.IN_PROGRESS);
+                long downloadedSize = FileUtils.sizeOfDirectory(new File(uploadEntity.getInstallPathPrefix()));
+                int downloadPercent = (int) (100 * downloadedSize / uploadEntity.getContentLength());
+                answer.setDownloadPercent(Math.min(downloadPercent, 100));
+                return answer;
             }
         }
         return new UploadStatusAnswer(cmd, UploadStatus.UNKNOWN);
@@ -2637,6 +2642,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase
implements S
                 uploadEntity.setChksum(cmd.getChecksum());
                 uploadEntity.setMaxSizeInGB(maxSizeInGB);
                 uploadEntity.setDescription(cmd.getDescription());
+                uploadEntity.setContentLength(contentLength);
                 // create a install dir
                 if (!_storage.exists(installPathPrefix)) {
                     _storage.mkdir(installPathPrefix);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ce823a3a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java
----------------------------------------------------------------------
diff --git a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java
b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java
index e9444c2..d851143 100644
--- a/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java
+++ b/services/secondary-storage/server/src/org/apache/cloudstack/storage/template/UploadEntity.java
@@ -33,6 +33,7 @@ public class UploadEntity {
     private long physicalSize;
     private int maxSizeInGB;
     private String description;
+    private long contentLength;
 
     public static enum ResourceType {
         VOLUME, TEMPLATE
@@ -189,4 +190,12 @@ public class UploadEntity {
     public void setDescription(String description) {
         this.description = description;
     }
+
+    public long getContentLength() {
+        return contentLength;
+    }
+
+    public void setContentLength(long contentLength) {
+        this.contentLength = contentLength;
+    }
 }


Mime
View raw message