You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ko...@apache.org on 2015/01/16 11:02:04 UTC

git commit: updated refs/heads/volume-upload to 1f1c96d

Repository: cloudstack
Updated Branches:
  refs/heads/volume-upload 0eee9e813 -> 1f1c96d2e


volume upload: management server polling and upload status from agent
- Added config parameters for upload monitoring interval and operation timeout
- Some updates to the volume state machine


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

Branch: refs/heads/volume-upload
Commit: 1f1c96d2eea88340c25bfacbab09d613c835a12c
Parents: 0eee9e8
Author: Koushik Das <ko...@apache.org>
Authored: Fri Jan 16 15:28:17 2015 +0530
Committer: Koushik Das <ko...@apache.org>
Committed: Fri Jan 16 15:28:17 2015 +0530

----------------------------------------------------------------------
 api/src/com/cloud/storage/Volume.java           |  2 +
 .../storage/command/UploadStatusCommand.java    | 13 +++++-
 .../storage/ImageStoreUploadMonitorImpl.java    | 47 +++++++++++++-------
 3 files changed, 43 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f1c96d2/api/src/com/cloud/storage/Volume.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/storage/Volume.java b/api/src/com/cloud/storage/Volume.java
index 50ff210..dbe370c 100755
--- a/api/src/com/cloud/storage/Volume.java
+++ b/api/src/com/cloud/storage/Volume.java
@@ -106,6 +106,8 @@ public interface Volume extends ControlledEntity, Identity, InternalIdentity, Ba
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Expunged, Event.OperationFailed, Expunged, null));
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationTimeout, UploadAbandoned, null));
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.UploadRequested, UploadInProgress, null));
+            s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationSucceeded, Uploaded, null));
+            s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationFailed, UploadError, null));
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationSucceeded, Uploaded, null));
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationFailed, UploadError, null));
             s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationTimeout, UploadError, null));

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f1c96d2/core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java
----------------------------------------------------------------------
diff --git a/core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java b/core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java
index 957854e..bad821e 100644
--- a/core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java
+++ b/core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java
@@ -22,20 +22,29 @@ package org.apache.cloudstack.storage.command;
 import com.cloud.agent.api.Command;
 
 public class UploadStatusCommand extends Command {
-
+    public enum EntityType {
+        Volume,
+        Template
+    }
     private long entityId;
+    private EntityType entityType;
 
     protected UploadStatusCommand() {
     }
 
-    public UploadStatusCommand(long entityId) {
+    public UploadStatusCommand(long entityId, EntityType entityType) {
         this.entityId = entityId;
+        this.entityType = entityType;
     }
 
     public long getEntityId() {
         return entityId;
     }
 
+    public EntityType getEntityType() {
+        return entityType;
+    }
+
     @Override
     public boolean executeInSequence() {
         return false;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1f1c96d2/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 422b58c..6defb89 100755
--- a/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
+++ b/server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java
@@ -32,10 +32,12 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.managed.context.ManagedContextRunnable;
 import org.apache.cloudstack.storage.command.UploadStatusAnswer;
 import org.apache.cloudstack.storage.command.UploadStatusCommand;
+import org.apache.cloudstack.storage.command.UploadStatusCommand.EntityType;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.utils.identity.ManagementServerNode;
@@ -65,13 +67,11 @@ import com.cloud.utils.fsm.StateMachine2;
  */
 @Component
 @Local(value = {ImageStoreUploadMonitor.class})
-public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageStoreUploadMonitor, Listener {
+public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageStoreUploadMonitor, Listener, Configurable {
 
     static final Logger s_logger = Logger.getLogger(ImageStoreUploadMonitorImpl.class);
 
     @Inject
-    private ConfigurationDao _configDao;
-    @Inject
     private VolumeDao _volumeDao;
     @Inject
     private VolumeDataStoreDao _volumeDataStoreDao;
@@ -87,12 +87,16 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
     private int _monitoringInterval;
     private long _uploadOperationTimeout;
 
+    static final ConfigKey<Integer> UploadMonitoringInterval = new ConfigKey<Integer>("Advanced", Integer.class, "upload.monitoring.interval", "60",
+            "Interval (in seconds) to check the status of volumes that are uploaded using HTTP POST request", true);
+    static final ConfigKey<Integer> UploadOperationTimeout = new ConfigKey<Integer>("Advanced", Integer.class, "upload.operation.timeout", "10",
+            "Time (in minutes) to wait before abandoning volume upload using HTTP POST request", true);
+
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
         _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Upload-Monitor"));
-        //TODO: use config variable
-        _monitoringInterval = 60;
-        _uploadOperationTimeout = 10 * 60 * 1000; // 10 minutes
+        _monitoringInterval = UploadMonitoringInterval.value();
+        _uploadOperationTimeout = UploadOperationTimeout.value() * 60 * 1000;
         _nodeId = ManagementServerNode.getManagementServerId();
         return true;
     }
@@ -176,18 +180,18 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
                 }
                 Host host = _hostDao.findById(ep.getId());
                 if (host != null && host.getManagementServerId() != null && _nodeId == host.getManagementServerId().longValue()) {
-                    UploadStatusCommand cmd = new UploadStatusCommand(volume.getId());
+                    UploadStatusCommand cmd = new UploadStatusCommand(volume.getId(), EntityType.Volume);
                     Answer answer = ep.sendMessage(cmd);
                     if (answer == null || !(answer instanceof UploadStatusAnswer)) {
                         s_logger.warn("No or invalid answer corresponding to UploadStatusCommand for volume " + volumeDataStore.getVolumeId());
                         continue;
                     }
-                    handleStatusResponse((UploadStatusAnswer)answer, volume, volumeDataStore);
+                    handleVolumeStatusResponse((UploadStatusAnswer)answer, volume, volumeDataStore);
                 }
             }
         }
 
-        private void handleStatusResponse(final UploadStatusAnswer answer, final VolumeVO volume, final VolumeDataStoreVO volumeDataStore) {
+        private void handleVolumeStatusResponse(final UploadStatusAnswer answer, final VolumeVO volume, final VolumeDataStoreVO volumeDataStore) {
             final StateMachine2<Volume.State, Event, Volume> stateMachine = Volume.State.getStateMachine();
             Transaction.execute(new TransactionCallbackNoReturn() {
                 @Override
@@ -204,13 +208,13 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
                             }
                             break;
                         case IN_PROGRESS:
-                            tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS);
-                            // check for timeout
-                            if (tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.NOT_UPLOADED ||
-                                tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS) {
+                            if (tmpVolume.getState() == Volume.State.NotUploaded) {
+                                tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS);
+                                stateMachine.transitTo(tmpVolume, Event.UploadRequested, null, _volumeDao);
+                            } else if (tmpVolume.getState() == Volume.State.UploadInProgress) { // check for timeout
                                 if (System.currentTimeMillis() - tmpVolumeDataStore.getCreated().getTime() > _uploadOperationTimeout) {
-                                    tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
-                                    stateMachine.transitTo(tmpVolume, Event.OperationTimeout, null, _volumeDao);
+                                    tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_ERROR);
+                                    stateMachine.transitTo(tmpVolume, Event.OperationFailed, null, _volumeDao);
                                     if (s_logger.isDebugEnabled()) {
                                         s_logger.debug("Volume " + tmpVolume.getUuid() + " failed to upload due to operation timed out");
                                     }
@@ -226,7 +230,7 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
                             break;
                         case UNKNOWN:
                             // check for timeout
-                            if (tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.NOT_UPLOADED) {
+                            if (tmpVolume.getState() == Volume.State.NotUploaded) {
                                 if (System.currentTimeMillis() - tmpVolumeDataStore.getCreated().getTime() > _uploadOperationTimeout) {
                                     tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.ABANDONED);
                                     stateMachine.transitTo(tmpVolume, Event.OperationTimeout, null, _volumeDao);
@@ -246,5 +250,14 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
         }
     }
 
+    @Override
+    public String getConfigComponentName() {
+        return ImageStoreUploadMonitor.class.getSimpleName();
+    }
+
+    @Override
+    public ConfigKey<?>[] getConfigKeys() {
+        return new ConfigKey<?>[] {UploadMonitoringInterval, UploadOperationTimeout};
+    }
 
 }