cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [03/50] [abbrv] git commit: updated refs/heads/master to 97f8c52
Date Thu, 20 Jun 2013 07:19:36 GMT
Have different callback for create template and create volume since they
will update different tables.

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

Branch: refs/heads/master
Commit: 2473ceb111804a2c9d5394919dac73e73669eb0c
Parents: eb93efd
Author: Min Chen <min.chen@citrix.com>
Authored: Thu May 30 17:39:44 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Thu May 30 17:39:44 2013 -0700

----------------------------------------------------------------------
 .../driver/CloudStackImageStoreDriverImpl.java  | 50 ++++++++++++++++++--
 .../driver/S3ImageStoreDriverImpl.java          | 47 ++++++++++++++++--
 .../driver/SwiftImageStoreDriverImpl.java       | 49 +++++++++++++++++--
 3 files changed, 134 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2473ceb1/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index 52595a1..862af19 100644
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@ -154,17 +154,16 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
         AsyncCallbackDispatcher<CloudStackImageStoreDriverImpl, DownloadAnswer> caller
= AsyncCallbackDispatcher
                 .create(this);
         caller.setContext(context);
-        caller.setCallback(caller.getTarget().createAsyncCallback(null, null));
-
         if (data.getType() == DataObjectType.TEMPLATE) {
+            caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
             _downloadMonitor.downloadTemplateToStorage(data, caller);
         } else if (data.getType() == DataObjectType.VOLUME) {
+            caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
             _downloadMonitor.downloadVolumeToStorage(data, caller);
         }
     }
 
-    protected Void createAsyncCallback(
-            AsyncCallbackDispatcher<CloudStackImageStoreDriverImpl, DownloadAnswer>
callback,
+    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<CloudStackImageStoreDriverImpl,
DownloadAnswer> callback,
             CreateContext<CreateCmdResult> context) {
         DownloadAnswer answer = callback.getResult();
         DataObject obj = context.data;
@@ -205,7 +204,48 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
                 templateDao.update(obj.getId(), templateDaoBuilder);
             }
 
-            CreateCmdResult result = new CreateCmdResult(null, answer);
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            caller.complete(result);
+        }
+        return null;
+    }
+
+    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<CloudStackImageStoreDriverImpl,
DownloadAnswer> callback,
+            CreateContext<CreateCmdResult> context) {
+        DownloadAnswer answer = callback.getResult();
+        DataObject obj = context.data;
+        DataStore store = obj.getDataStore();
+
+        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
+        if (volStoreVO != null) {
+            VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
+            updateBuilder.setDownloadPercent(answer.getDownloadPct());
+            updateBuilder.setDownloadState(answer.getDownloadStatus());
+            updateBuilder.setLastUpdated(new Date());
+            updateBuilder.setErrorString(answer.getErrorString());
+            updateBuilder.setJobId(answer.getJobId());
+            updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
+            updateBuilder.setInstallPath(answer.getInstallPath());
+            updateBuilder.setSize(answer.getTemplateSize());
+            updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
+            _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
+            // update size in volume table
+            VolumeVO volUpdater = volumeDao.createForUpdate();
+            volUpdater.setSize(answer.getTemplateSize());
+            volumeDao.update(obj.getId(), volUpdater);
+        }
+
+        AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
+
+        if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            result.setSuccess(false);
+            result.setResult(answer.getErrorString());
+            caller.complete(result);
+        } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
             caller.complete(result);
         }
         return null;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2473ceb1/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
index 0a2a840..6f50067 100644
--- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
+++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
@@ -173,11 +173,11 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
         CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback,
data);
         AsyncCallbackDispatcher<S3ImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher.create(this);
         caller.setContext(context);
-        caller.setCallback(caller.getTarget().createAsyncCallback(null, null));
-
         if (data.getType() == DataObjectType.TEMPLATE) {
+            caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
             _downloadMonitor.downloadTemplateToStorage(data, caller);
         } else if (data.getType() == DataObjectType.VOLUME) {
+            caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
             _downloadMonitor.downloadVolumeToStorage(data, caller);
         }
     }
@@ -214,7 +214,7 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
         }
     }
 
-    protected Void createAsyncCallback(AsyncCallbackDispatcher<S3ImageStoreDriverImpl,
DownloadAnswer> callback,
+    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<S3ImageStoreDriverImpl,
DownloadAnswer> callback,
             CreateContext<CreateCmdResult> context) {
         DownloadAnswer answer = callback.getResult();
         DataObject obj = context.data;
@@ -261,6 +261,47 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
         return null;
     }
 
+    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<S3ImageStoreDriverImpl,
DownloadAnswer> callback,
+            CreateContext<CreateCmdResult> context) {
+        DownloadAnswer answer = callback.getResult();
+        DataObject obj = context.data;
+        DataStore store = obj.getDataStore();
+
+        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
+        if (volStoreVO != null) {
+            VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
+            updateBuilder.setDownloadPercent(answer.getDownloadPct());
+            updateBuilder.setDownloadState(answer.getDownloadStatus());
+            updateBuilder.setLastUpdated(new Date());
+            updateBuilder.setErrorString(answer.getErrorString());
+            updateBuilder.setJobId(answer.getJobId());
+            updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
+            updateBuilder.setInstallPath(answer.getInstallPath());
+            updateBuilder.setSize(answer.getTemplateSize());
+            updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
+            _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
+            // update size in volume table
+            VolumeVO volUpdater = volumeDao.createForUpdate();
+            volUpdater.setSize(answer.getTemplateSize());
+            volumeDao.update(obj.getId(), volUpdater);
+        }
+
+        AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
+
+        if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            result.setSuccess(false);
+            result.setResult(answer.getErrorString());
+            caller.complete(result);
+        } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            caller.complete(result);
+        }
+        return null;
+    }
+
     private void deleteTemplate(DataObject data, AsyncCompletionCallback<CommandResult>
callback) {
         TemplateObject templateObj = (TemplateObject) data;
         VMTemplateVO template = templateObj.getImage();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2473ceb1/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
index 71b18d5..e5d40d1 100644
--- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
+++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
@@ -172,16 +172,16 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
         AsyncCallbackDispatcher<SwiftImageStoreDriverImpl, DownloadAnswer> caller =
AsyncCallbackDispatcher
                 .create(this);
         caller.setContext(context);
-        caller.setCallback(caller.getTarget().createAsyncCallback(null, null));
-
         if (data.getType() == DataObjectType.TEMPLATE) {
+            caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
             _downloadMonitor.downloadTemplateToStorage(data, caller);
         } else if (data.getType() == DataObjectType.VOLUME) {
+            caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
             _downloadMonitor.downloadVolumeToStorage(data, caller);
         }
     }
 
-    protected Void createAsyncCallback(AsyncCallbackDispatcher<SwiftImageStoreDriverImpl,
DownloadAnswer> callback,
+    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<SwiftImageStoreDriverImpl,
DownloadAnswer> callback,
             CreateContext<CreateCmdResult> context) {
         DownloadAnswer answer = callback.getResult();
         DataObject obj = context.data;
@@ -212,7 +212,7 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
                 || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
                 || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN)
{
             CreateCmdResult result = new CreateCmdResult(null, null);
-            // result.setSucess(false);
+            result.setSuccess(false);
             result.setResult(answer.getErrorString());
             caller.complete(result);
         } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED)
{
@@ -228,6 +228,47 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
         return null;
     }
 
+    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<SwiftImageStoreDriverImpl,
DownloadAnswer> callback,
+            CreateContext<CreateCmdResult> context) {
+        DownloadAnswer answer = callback.getResult();
+        DataObject obj = context.data;
+        DataStore store = obj.getDataStore();
+
+        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
+        if (volStoreVO != null) {
+            VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
+            updateBuilder.setDownloadPercent(answer.getDownloadPct());
+            updateBuilder.setDownloadState(answer.getDownloadStatus());
+            updateBuilder.setLastUpdated(new Date());
+            updateBuilder.setErrorString(answer.getErrorString());
+            updateBuilder.setJobId(answer.getJobId());
+            updateBuilder.setLocalDownloadPath(answer.getDownloadPath());
+            updateBuilder.setInstallPath(answer.getInstallPath());
+            updateBuilder.setSize(answer.getTemplateSize());
+            updateBuilder.setPhysicalSize(answer.getTemplatePhySicalSize());
+            _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
+            // update size in volume table
+            VolumeVO volUpdater = volumeDao.createForUpdate();
+            volUpdater.setSize(answer.getTemplateSize());
+            volumeDao.update(obj.getId(), volUpdater);
+        }
+
+        AsyncCompletionCallback<CreateCmdResult> caller = context.getParentCallback();
+
+        if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.ABANDONED
+                || answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.UNKNOWN)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            result.setSuccess(false);
+            result.setResult(answer.getErrorString());
+            caller.complete(result);
+        } else if (answer.getDownloadStatus() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED)
{
+            CreateCmdResult result = new CreateCmdResult(null, null);
+            caller.complete(result);
+        }
+        return null;
+    }
+
     private void deleteVolume(DataObject data, AsyncCompletionCallback<CommandResult>
callback) {
         // TODO Auto-generated method stub
         VolumeVO vol = volumeDao.findById(data.getId());


Mime
View raw message