cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahu...@apache.org
Subject [22/50] [abbrv] git commit: updated refs/heads/vmsync to f737019
Date Mon, 01 Jul 2013 21:25:06 GMT
the plugin better not touch database


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

Branch: refs/heads/vmsync
Commit: 49ded7e4a36789d13f4ab260bc45e8cd58967342
Parents: 57641d8
Author: Edison Su <sudison@gmail.com>
Authored: Thu Jun 27 17:23:16 2013 -0700
Committer: Prasanna Santhanam <tsp@apache.org>
Committed: Sat Jun 29 15:09:43 2013 +0530

----------------------------------------------------------------------
 .../storage/image/BaseImageStoreDriverImpl.java |   6 +-
 .../driver/SimulatorImageStoreDriverImpl.java   | 100 ++++++-------------
 .../SamplePrimaryDataStoreDriverImpl.java       |   4 -
 .../com/cloud/storage/StorageManagerImpl.java   |  43 ++++----
 4 files changed, 52 insertions(+), 101 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49ded7e4/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
index 9db205b..8646247 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java
@@ -68,7 +68,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
         return null;
     }
 
-    class CreateContext<T> extends AsyncRpcContext<T> {
+    protected class CreateContext<T> extends AsyncRpcContext<T> {
         final DataObject data;
 
         public CreateContext(AsyncCompletionCallback<T> callback, DataObject data)
{
@@ -92,7 +92,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
         }
     }
 
-    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<BaseImageStoreDriverImpl,
DownloadAnswer> callback,
+    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl,
DownloadAnswer> callback,
             CreateContext<CreateCmdResult> context) {
         DownloadAnswer answer = callback.getResult();
         DataObject obj = context.data;
@@ -139,7 +139,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver
{
         return null;
     }
 
-    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<BaseImageStoreDriverImpl,
DownloadAnswer> callback,
+    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl,
DownloadAnswer> callback,
             CreateContext<CreateCmdResult> context) {
         DownloadAnswer answer = callback.getResult();
         DataObject obj = context.data;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49ded7e4/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java
b/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java
index 8816fc2..d5fe8a1 100644
--- a/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java
+++ b/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java
@@ -26,28 +26,20 @@ import com.cloud.agent.api.to.DataStoreTO;
 import com.cloud.agent.api.to.NfsTO;
 import com.cloud.storage.Storage;
 import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.apache.cloudstack.framework.async.AsyncRpcContext;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
 import org.apache.cloudstack.storage.image.BaseImageStoreDriverImpl;
 import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
-import org.apache.cloudstack.storage.to.TemplateObjectTO;
-import org.apache.cloudstack.storage.to.VolumeObjectTO;
 
 import javax.inject.Inject;
-import java.util.Date;
+import java.util.UUID;
 
 public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl {
 
@@ -69,82 +61,46 @@ public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl
{
         return nfsTO;
     }
 
-    class CreateContext<T> extends AsyncRpcContext<T> {
-        final DataObject data;
 
-        public CreateContext(AsyncCompletionCallback<T> callback, DataObject data)
{
-            super(callback);
-            this.data = data;
-        }
-    }
 
     public String createEntityExtractUrl(DataStore store, String installPath, Storage.ImageFormat
format) {
         return null;
     }
 
     @Override
-    public void createAsync(DataObject data, AsyncCompletionCallback<CreateCmdResult>
callback) {
-        CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback,
data);
-        AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller
= AsyncCallbackDispatcher
-                .create(this);
-        caller.setContext(context);
+    public void createAsync(DataStore store, DataObject data, AsyncCompletionCallback<CreateCmdResult>
callback) {
         if (data.getType() == DataObjectType.TEMPLATE) {
-            this.createTemplateAsyncCallback(caller, context);
+            this.createTemplate(data, callback);
         } else if (data.getType() == DataObjectType.VOLUME) {
-            this.createVolumeAsyncCallback(caller, context);
+            this.createVolume(data, callback);
         }
     }
 
-    protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl,
DownloadAnswer> callback,
-                                               CreateContext<CreateCmdResult> context)
{
-        DataObject obj = context.data;
-        DataStore store = obj.getDataStore();
-        TemplateObjectTO templateTO = (TemplateObjectTO)context.data.getTO();
-
-        TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(),
obj.getId());
-        if (tmpltStoreVO != null) {
-            TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
-            updateBuilder.setDownloadPercent(100);
-            updateBuilder.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
-            updateBuilder.setLastUpdated(new Date());
-            updateBuilder.setSize(new Long(5 * 1024L * 1024L));
-            updateBuilder.setPhysicalSize(new Long(5 * 1024L * 1024L));
-            updateBuilder.setDownloadUrl(templateTO.getOrigUrl());
-            updateBuilder.setInstallPath(templateTO.getPath());
-            updateBuilder.setTemplateId(templateTO.getId());
-            updateBuilder.setState(ObjectInDataStoreStateMachine.State.Ready);
-            _templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
-            // update size in vm_template table
-            VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
-            tmlptUpdater.setSize(new Long(5 * 1024l * 1024l));
-            _templateDao.update(obj.getId(), tmlptUpdater);
-        }
-        return null;
+    protected void createTemplate(DataObject data, AsyncCompletionCallback<CreateCmdResult>
callback) {
+        CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback,
data);
+        AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller
= AsyncCallbackDispatcher
+                .create(this);
+        caller.setContext(context);
+        caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
+        String path =  UUID.randomUUID().toString();
+        Long size = new Long(5 * 1024L * 1024L);
+        DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
+                path, path, size, size, null);
+        caller.complete(answer);
+        return;
     }
 
-    protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl,
DownloadAnswer> callback,
-                                             CreateContext<CreateCmdResult> context)
{
-        DataObject obj = context.data;
-        DataStore store = obj.getDataStore();
-        VolumeObjectTO volumeTO = (VolumeObjectTO) context.data.getTO();
-
-        VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
-        if (volStoreVO != null) {
-            VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
-            updateBuilder.setDownloadPercent(100);
-            updateBuilder.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
-            updateBuilder.setLastUpdated(new Date());
-            updateBuilder.setInstallPath(volumeTO.getPath());
-            updateBuilder.setVolumeId(volumeTO.getVolumeId());
-            updateBuilder.setSize(volumeTO.getSize());
-            updateBuilder.setPhysicalSize(volumeTO.getSize());
-            updateBuilder.setState(ObjectInDataStoreStateMachine.State.Ready);
-            _volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
-            // update size in volume table
-            VolumeVO volUpdater = _volumeDao.createForUpdate();
-            volUpdater.setSize(volumeTO.getSize());
-            _volumeDao.update(obj.getId(), volUpdater);
-        }
-        return null;
+    protected void createVolume(DataObject data, AsyncCompletionCallback<CreateCmdResult>
callback) {
+        CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback,
data);
+        AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller
= AsyncCallbackDispatcher
+                .create(this);
+        caller.setContext(context);
+        caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
+        String path =  UUID.randomUUID().toString();
+        Long size = new Long(5 * 1024L * 1024L);
+        DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
+                path, path, size, size, null);
+        caller.complete(answer);
+        return;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49ded7e4/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
index 1d00c97..ece7b26 100644
--- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
+++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java
@@ -54,16 +54,12 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
         return null;
     }
 
-<<<<<<< HEAD
     @Override
     public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
         return null;
     }
 
-    private class CreateVolumeContext<T> extends AsyncRpcConext<T> {
-=======
     private class CreateVolumeContext<T> extends AsyncRpcContext<T> {
->>>>>>> Fix typo in class name
         private final DataObject volume;
         public CreateVolumeContext(AsyncCompletionCallback<T> callback, DataObject
volume) {
             super(callback);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/49ded7e4/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index ff323cb..138c6d7 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -570,7 +570,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         } else {
             s_logger.debug("Storage cleanup is not enabled, so the storage cleanup thread
is not being scheduled.");
         }
-
         return true;
     }
 
@@ -579,7 +578,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         if (_storageCleanupEnabled) {
             _executor.shutdown();
         }
-
         return true;
     }
 
@@ -591,7 +589,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         if (dc == null || !dc.isLocalStorageEnabled()) {
             return null;
         }
-        DataStore store = null;
+        DataStore store;
         try {
             StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(),
host.getPodId(), pInfo.getHost(), pInfo.getHostPath(),
                     pInfo.getUuid());
@@ -693,21 +691,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
             }
         }
 
-        Map ds = cmd.getDetails();
-        Map<String, String> details = new HashMap<String, String>();
-        if (ds != null) {
-            Collection detailsCollection = ds.values();
-            Iterator it = detailsCollection.iterator();
-            while (it.hasNext()) {
-                HashMap d = (HashMap) it.next();
-                Iterator it2 = d.entrySet().iterator();
-                while (it2.hasNext()) {
-                    Map.Entry entry = (Map.Entry) it2.next();
-                    details.put((String) entry.getKey(), (String) entry.getValue());
-                }
-            }
-        }
-
+        Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
         DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
         if (zone == null) {
             throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
@@ -732,10 +716,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         params.put("capacityIops", cmd.getCapacityIops());
 
         DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
-        DataStore store = null;
+        DataStore store;
         try {
             store = lifeCycle.initialize(params);
-
             if (scopeType == ScopeType.CLUSTER) {
                 ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
                 lifeCycle.attachCluster(store, clusterScope);
@@ -751,6 +734,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
     }
 
+    private Map<String, String> extractApiParamAsMap(Map ds) {
+        Map<String, String> details = new HashMap<String, String>();
+        if (ds != null) {
+            Collection detailsCollection = ds.values();
+            Iterator it = detailsCollection.iterator();
+            while (it.hasNext()) {
+                HashMap d = (HashMap) it.next();
+                Iterator it2 = d.entrySet().iterator();
+                while (it2.hasNext()) {
+                    Map.Entry entry = (Map.Entry) it2.next();
+                    details.put((String) entry.getKey(), (String) entry.getValue());
+                }
+            }
+        }
+        return details;
+    }
+
     @Override
     public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException
{
         // Input validation
@@ -1637,7 +1637,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         }
 
         Long dcId = cmd.getZoneId();
-        String url = cmd.getUrl();
         Map details = cmd.getDetails();
         ScopeType scopeType = ScopeType.ZONE;
         if (dcId == null) {
@@ -1686,7 +1685,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
         params.put("role", DataStoreRole.Image);
 
         DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
-        DataStore store = null;
+        DataStore store;
         try {
             store = lifeCycle.initialize(params);
         } catch (Exception e) {


Mime
View raw message