You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/05/30 03:06:27 UTC

[07/17] clean up storage related coded

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java
index 187d1f5..ef5c4ca 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTest.java
@@ -40,7 +40,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.storage.RemoteHostEndPoint;
 import org.apache.cloudstack.storage.command.CopyCmdAnswer;
@@ -50,6 +49,7 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.testng.AssertJUnit;
@@ -88,7 +88,7 @@ import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.utils.component.ComponentContext;
 
-@ContextConfiguration(locations={"classpath:/storageContext.xml"})
+@ContextConfiguration(locations = { "classpath:/storageContext.xml" })
 public class VolumeTest extends CloudStackTestNGBase {
     @Inject
     ImageStoreDao imageStoreDao;
@@ -140,6 +140,7 @@ public class VolumeTest extends CloudStackTestNGBase {
     long primaryStoreId;
     VMTemplateVO image;
     String imageStoreName = "testImageStore";
+
     @Test(priority = -1)
     public void setUp() {
         ComponentContext.initComponentsLifeCycle();
@@ -151,24 +152,25 @@ public class VolumeTest extends CloudStackTestNGBase {
             podId = host.getPodId();
             imageStore = this.imageStoreDao.findByName(imageStoreName);
         } else {
-            //create data center
-            DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,  "10.0.0.1/24",
-                    null, null, NetworkType.Basic, null, null, true,  true, null, null);
+            // create data center
+            DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,
+                    "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
             dc = dcDao.persist(dc);
             dcId = dc.getId();
-            //create pod
+            // create pod
 
-            HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
+            HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(),
+                    this.getHostCidr(), 8, "test");
             pod = podDao.persist(pod);
             podId = pod.getId();
-            //create xen cluster
+            // create xen cluster
             ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
             cluster.setHypervisorType(this.getHypervisor().toString());
             cluster.setClusterType(ClusterType.CloudManaged);
             cluster.setManagedState(ManagedState.Managed);
             cluster = clusterDao.persist(cluster);
             clusterId = cluster.getId();
-            //create xen host
+            // create xen host
 
             host = new HostVO(this.getHostGuid());
             host.setName("devcloud xen host");
@@ -217,16 +219,17 @@ public class VolumeTest extends CloudStackTestNGBase {
 
         image = imageDataDao.persist(image);
 
-        /*TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
-
-        templateStore.setDataStoreId(imageStore.getId());
-        templateStore.setDownloadPercent(100);
-        templateStore.setDownloadState(Status.DOWNLOADED);
-        templateStore.setDownloadUrl(imageStore.getUrl());
-        templateStore.setInstallPath(this.getImageInstallPath());
-        templateStore.setTemplateId(image.getId());
-        templateStoreDao.persist(templateStore);*/
-
+        /*
+         * TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
+         * 
+         * templateStore.setDataStoreId(imageStore.getId());
+         * templateStore.setDownloadPercent(100);
+         * templateStore.setDownloadState(Status.DOWNLOADED);
+         * templateStore.setDownloadUrl(imageStore.getUrl());
+         * templateStore.setInstallPath(this.getImageInstallPath());
+         * templateStore.setTemplateId(image.getId());
+         * templateStoreDao.persist(templateStore);
+         */
 
         DataStore store = this.dataStoreMgr.getDataStore(imageStore.getId(), DataStoreRole.Image);
         TemplateInfo template = templateFactory.getTemplate(image.getId(), DataStoreRole.Image);
@@ -238,20 +241,23 @@ public class VolumeTest extends CloudStackTestNGBase {
         templateOnStore.processEvent(Event.CreateOnlyRequested);
         templateOnStore.processEvent(Event.OperationSuccessed, answer);
 
-
     }
 
     @Override
     protected void injectMockito() {
         List<HostVO> hosts = new ArrayList<HostVO>();
         hosts.add(this.host);
-        Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
-
-        RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
-        Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(ep);
-        Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep);
-        Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);
-        Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(Mockito.anyLong(), Mockito.any(Command.class))).thenReturn(this.host.getId());
+        Mockito.when(
+                resourceMgr.listAllUpAndEnabledHosts((Type) Matchers.any(), Matchers.anyLong(), Matchers.anyLong(),
+                        Matchers.anyLong())).thenReturn(hosts);
+
+        RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(),
+                this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
+        Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
+        Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
+        Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
+        Mockito.when(hyGuruMgr.getGuruProcessedCommandTargetHost(Matchers.anyLong(), Matchers.any(Command.class)))
+                .thenReturn(this.host.getId());
     }
 
     public DataStore createPrimaryDataStore() {
@@ -262,26 +268,27 @@ public class VolumeTest extends CloudStackTestNGBase {
                 return this.dataStoreMgr.getPrimaryDataStore(pools.get(0).getId());
             }
 
-            /*DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("cloudstack primary data store provider");
-            Map<String, Object> params = new HashMap<String, Object>();
-            URI uri = new URI(this.getPrimaryStorageUrl());
-            params.put("url", this.getPrimaryStorageUrl());
-            params.put("server", uri.getHost());
-            params.put("path", uri.getPath());
-            params.put("protocol", Storage.StoragePoolType.NetworkFilesystem);
-            params.put("zoneId", dcId);
-            params.put("clusterId", clusterId);
-            params.put("name", this.primaryName);
-            params.put("port", 1);
-            params.put("podId", this.podId);
-            params.put("roles", DataStoreRole.Primary.toString());
-            params.put("uuid", uuid);
-            params.put("providerName", String.valueOf(provider.getName()));
-
-            DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
-            DataStore store = lifeCycle.initialize(params);
-            ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
-            lifeCycle.attachCluster(store, scope);*/
+            /*
+             * DataStoreProvider provider =
+             * dataStoreProviderMgr.getDataStoreProvider
+             * ("cloudstack primary data store provider"); Map<String, Object>
+             * params = new HashMap<String, Object>(); URI uri = new
+             * URI(this.getPrimaryStorageUrl()); params.put("url",
+             * this.getPrimaryStorageUrl()); params.put("server",
+             * uri.getHost()); params.put("path", uri.getPath());
+             * params.put("protocol",
+             * Storage.StoragePoolType.NetworkFilesystem); params.put("zoneId",
+             * dcId); params.put("clusterId", clusterId); params.put("name",
+             * this.primaryName); params.put("port", 1); params.put("podId",
+             * this.podId); params.put("roles",
+             * DataStoreRole.Primary.toString()); params.put("uuid", uuid);
+             * params.put("providerName", String.valueOf(provider.getName()));
+             * 
+             * DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
+             * DataStore store = lifeCycle.initialize(params); ClusterScope
+             * scope = new ClusterScope(clusterId, podId, dcId);
+             * lifeCycle.attachCluster(store, scope);
+             */
 
             StoragePoolVO pool = new StoragePoolVO();
             pool.setClusterId(clusterId);
@@ -306,7 +313,8 @@ public class VolumeTest extends CloudStackTestNGBase {
     }
 
     private VolumeVO createVolume(Long templateId, long dataStoreId) {
-        VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);;
+        VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);
+        ;
         volume.setPoolId(dataStoreId);
         volume = volumeDao.persist(volume);
         return volume;
@@ -319,7 +327,8 @@ public class VolumeTest extends CloudStackTestNGBase {
         primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
         VolumeVO volume = createVolume(image.getId(), primaryStore.getId());
         VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
-        AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeFromTemplateAsync(volInfo, this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image));
+        AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeFromTemplateAsync(volInfo,
+                this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image));
         try {
             VolumeApiResult result = future.get();
 
@@ -427,6 +436,5 @@ public class VolumeTest extends CloudStackTestNGBase {
             e.printStackTrace();
         }
 
-
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java
index 9d5555a..4acc8dc 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/VolumeTestVmware.java
@@ -39,7 +39,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.storage.RemoteHostEndPoint;
 import org.apache.cloudstack.storage.command.CopyCmdAnswer;
@@ -49,6 +48,7 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
 import org.apache.cloudstack.storage.to.TemplateObjectTO;
+import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.testng.AssertJUnit;
@@ -87,7 +87,7 @@ import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.utils.component.ComponentContext;
 
-@ContextConfiguration(locations={"classpath:/storageContext.xml"})
+@ContextConfiguration(locations = { "classpath:/storageContext.xml" })
 public class VolumeTestVmware extends CloudStackTestNGBase {
     @Inject
     ImageStoreDao imageStoreDao;
@@ -139,6 +139,7 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
     long primaryStoreId;
     VMTemplateVO image;
     String imageStoreName = "testImageStore";
+
     @Test(priority = -1)
     public void setUp() {
         ComponentContext.initComponentsLifeCycle();
@@ -150,17 +151,18 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
             podId = host.getPodId();
             imageStore = this.imageStoreDao.findByName(imageStoreName);
         } else {
-            //create data center
-            DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,  "10.0.0.1/24",
-                    null, null, NetworkType.Basic, null, null, true,  true, null, null);
+            // create data center
+            DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,
+                    "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
             dc = dcDao.persist(dc);
             dcId = dc.getId();
-            //create pod
+            // create pod
 
-            HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
+            HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(),
+                    this.getHostCidr(), 8, "test");
             pod = podDao.persist(pod);
             podId = pod.getId();
-            //create xen cluster
+            // create xen cluster
             ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
             cluster.setHypervisorType(HypervisorType.VMware.toString());
             cluster.setClusterType(ClusterType.ExternalManaged);
@@ -168,14 +170,14 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
             cluster = clusterDao.persist(cluster);
             clusterId = cluster.getId();
 
-            //setup vcenter
+            // setup vcenter
             ClusterDetailsVO clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "url", null);
             this.clusterDetailsDao.persist(clusterDetailVO);
             clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "username", null);
             this.clusterDetailsDao.persist(clusterDetailVO);
             clusterDetailVO = new ClusterDetailsVO(cluster.getId(), "password", null);
             this.clusterDetailsDao.persist(clusterDetailVO);
-            //create xen host
+            // create xen host
 
             host = new HostVO(this.getHostGuid());
             host.setName("devcloud vmware host");
@@ -224,16 +226,17 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
 
         image = imageDataDao.persist(image);
 
-        /*TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
-
-        templateStore.setDataStoreId(imageStore.getId());
-        templateStore.setDownloadPercent(100);
-        templateStore.setDownloadState(Status.DOWNLOADED);
-        templateStore.setDownloadUrl(imageStore.getUrl());
-        templateStore.setInstallPath(this.getImageInstallPath());
-        templateStore.setTemplateId(image.getId());
-        templateStoreDao.persist(templateStore);*/
-
+        /*
+         * TemplateDataStoreVO templateStore = new TemplateDataStoreVO();
+         * 
+         * templateStore.setDataStoreId(imageStore.getId());
+         * templateStore.setDownloadPercent(100);
+         * templateStore.setDownloadState(Status.DOWNLOADED);
+         * templateStore.setDownloadUrl(imageStore.getUrl());
+         * templateStore.setInstallPath(this.getImageInstallPath());
+         * templateStore.setTemplateId(image.getId());
+         * templateStoreDao.persist(templateStore);
+         */
 
         DataStore store = this.dataStoreMgr.getDataStore(imageStore.getId(), DataStoreRole.Image);
         TemplateInfo template = templateFactory.getTemplate(image.getId(), DataStoreRole.Image);
@@ -244,19 +247,21 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
         templateOnStore.processEvent(Event.CreateOnlyRequested);
         templateOnStore.processEvent(Event.OperationSuccessed, answer);
 
-
     }
 
     @Override
     protected void injectMockito() {
         List<HostVO> hosts = new ArrayList<HostVO>();
         hosts.add(this.host);
-        Mockito.when(resourceMgr.listAllUpAndEnabledHosts((Type) Mockito.any(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(hosts);
-
-        RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(), this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
-        Mockito.when(epSelector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(ep);
-        Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep);
-        Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);
+        Mockito.when(
+                resourceMgr.listAllUpAndEnabledHosts((Type) Matchers.any(), Matchers.anyLong(), Matchers.anyLong(),
+                        Matchers.anyLong())).thenReturn(hosts);
+
+        RemoteHostEndPoint ep = RemoteHostEndPoint.getHypervisorHostEndPoint(this.host.getId(),
+                this.host.getPrivateIpAddress(), this.host.getPublicIpAddress());
+        Mockito.when(epSelector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(ep);
+        Mockito.when(epSelector.select(Matchers.any(DataObject.class))).thenReturn(ep);
+        Mockito.when(epSelector.select(Matchers.any(DataStore.class))).thenReturn(ep);
     }
 
     public DataStore createPrimaryDataStore() {
@@ -267,26 +272,27 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
                 return this.dataStoreMgr.getPrimaryDataStore(pools.get(0).getId());
             }
 
-            /*DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("cloudstack primary data store provider");
-            Map<String, Object> params = new HashMap<String, Object>();
-            URI uri = new URI(this.getPrimaryStorageUrl());
-            params.put("url", this.getPrimaryStorageUrl());
-            params.put("server", uri.getHost());
-            params.put("path", uri.getPath());
-            params.put("protocol", Storage.StoragePoolType.NetworkFilesystem);
-            params.put("zoneId", dcId);
-            params.put("clusterId", clusterId);
-            params.put("name", this.primaryName);
-            params.put("port", 1);
-            params.put("podId", this.podId);
-            params.put("roles", DataStoreRole.Primary.toString());
-            params.put("uuid", uuid);
-            params.put("providerName", String.valueOf(provider.getName()));
-
-            DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
-            DataStore store = lifeCycle.initialize(params);
-            ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
-            lifeCycle.attachCluster(store, scope);*/
+            /*
+             * DataStoreProvider provider =
+             * dataStoreProviderMgr.getDataStoreProvider
+             * ("cloudstack primary data store provider"); Map<String, Object>
+             * params = new HashMap<String, Object>(); URI uri = new
+             * URI(this.getPrimaryStorageUrl()); params.put("url",
+             * this.getPrimaryStorageUrl()); params.put("server",
+             * uri.getHost()); params.put("path", uri.getPath());
+             * params.put("protocol",
+             * Storage.StoragePoolType.NetworkFilesystem); params.put("zoneId",
+             * dcId); params.put("clusterId", clusterId); params.put("name",
+             * this.primaryName); params.put("port", 1); params.put("podId",
+             * this.podId); params.put("roles",
+             * DataStoreRole.Primary.toString()); params.put("uuid", uuid);
+             * params.put("providerName", String.valueOf(provider.getName()));
+             * 
+             * DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
+             * DataStore store = lifeCycle.initialize(params); ClusterScope
+             * scope = new ClusterScope(clusterId, podId, dcId);
+             * lifeCycle.attachCluster(store, scope);
+             */
 
             StoragePoolVO pool = new StoragePoolVO();
             pool.setClusterId(clusterId);
@@ -311,20 +317,22 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
     }
 
     private VolumeVO createVolume(Long templateId, long dataStoreId) {
-        VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);;
+        VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);
+        ;
         volume.setPoolId(dataStoreId);
         volume = volumeDao.persist(volume);
         return volume;
     }
 
-    //@Test
+    // @Test
     public void testCopyBaseImage() {
         DataStore primaryStore = createPrimaryDataStore();
         primaryStoreId = primaryStore.getId();
         primaryStore = this.dataStoreMgr.getPrimaryDataStore(primaryStoreId);
         VolumeVO volume = createVolume(image.getId(), primaryStore.getId());
         VolumeInfo volInfo = this.volFactory.getVolume(volume.getId());
-        AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeFromTemplateAsync(volInfo, this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image));
+        AsyncCallFuture<VolumeApiResult> future = this.volumeService.createVolumeFromTemplateAsync(volInfo,
+                this.primaryStoreId, this.templateFactory.getTemplate(this.image.getId(), DataStoreRole.Image));
         try {
             VolumeApiResult result = future.get();
 
@@ -432,6 +440,5 @@ public class VolumeTestVmware extends CloudStackTestNGBase {
             e.printStackTrace();
         }
 
-
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
index 4e22101..42b0463 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/volumeServiceTest.java
@@ -50,6 +50,7 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
+import org.mockito.Matchers;
 import org.mockito.Mockito;
 import org.springframework.test.context.ContextConfiguration;
 import org.testng.Assert;
@@ -82,50 +83,50 @@ import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.utils.component.ComponentContext;
 
-@ContextConfiguration(locations={"classpath:/storageContext.xml"})
+@ContextConfiguration(locations = { "classpath:/storageContext.xml" })
 public class volumeServiceTest extends CloudStackTestNGBase {
-	//@Inject
-	//ImageDataStoreProviderManager imageProviderMgr;
-	@Inject
-	TemplateService imageService;
-	@Inject
-	VolumeService volumeService;
-	@Inject
-	VMTemplateDao imageDataDao;
-	@Inject
-	VolumeDao volumeDao;
-	@Inject
-	HostDao hostDao;
-	@Inject
-	HostPodDao podDao;
-	@Inject
-	ClusterDao clusterDao;
-	@Inject
-	DataCenterDao dcDao;
-	@Inject
-	PrimaryDataStoreDao primaryStoreDao;
-	@Inject
-	DataStoreProviderManager dataStoreProviderMgr;
-	@Inject
-	AgentManager agentMgr;
-	@Inject
-	EndPointSelector selector;
-	@Inject
-	TemplateDataFactory imageDataFactory;
-	@Inject
-	VolumeDataFactory volumeFactory;
-	@Inject
-	ImageStoreDao imageStoreDao;
-	ImageStoreVO imageStore;
-	Long dcId;
-	Long clusterId;
-	Long podId;
-	HostVO host;
-	String primaryName = "my primary data store";
-	DataStore primaryStore;
+    // @Inject
+    // ImageDataStoreProviderManager imageProviderMgr;
+    @Inject
+    TemplateService imageService;
+    @Inject
+    VolumeService volumeService;
+    @Inject
+    VMTemplateDao imageDataDao;
+    @Inject
+    VolumeDao volumeDao;
+    @Inject
+    HostDao hostDao;
+    @Inject
+    HostPodDao podDao;
+    @Inject
+    ClusterDao clusterDao;
+    @Inject
+    DataCenterDao dcDao;
+    @Inject
+    PrimaryDataStoreDao primaryStoreDao;
+    @Inject
+    DataStoreProviderManager dataStoreProviderMgr;
+    @Inject
+    AgentManager agentMgr;
+    @Inject
+    EndPointSelector selector;
+    @Inject
+    TemplateDataFactory imageDataFactory;
+    @Inject
+    VolumeDataFactory volumeFactory;
+    @Inject
+    ImageStoreDao imageStoreDao;
+    ImageStoreVO imageStore;
+    Long dcId;
+    Long clusterId;
+    Long podId;
+    HostVO host;
+    String primaryName = "my primary data store";
+    DataStore primaryStore;
 
     @Test(priority = -1)
-	public void setUp() {
+    public void setUp() {
         ComponentContext.initComponentsLifeCycle();
 
         host = hostDao.findByGuid(this.getHostGuid());
@@ -135,51 +136,52 @@ public class volumeServiceTest extends CloudStackTestNGBase {
             podId = host.getPodId();
             return;
         }
-		//create data center
-		DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,  "10.0.0.1/24",
-				null, null, NetworkType.Basic, null, null, true,  true, null, null);
-		dc = dcDao.persist(dc);
-		dcId = dc.getId();
-		//create pod
-
-		HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
-		pod = podDao.persist(pod);
-		podId = pod.getId();
-		//create xen cluster
-		ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
-		cluster.setHypervisorType(HypervisorType.XenServer.toString());
-		cluster.setClusterType(ClusterType.CloudManaged);
-		cluster.setManagedState(ManagedState.Managed);
-		cluster = clusterDao.persist(cluster);
-		clusterId = cluster.getId();
-		//create xen host
-
-		host = new HostVO(this.getHostGuid());
-		host.setName("devcloud xen host");
-		host.setType(Host.Type.Routing);
-		host.setPrivateIpAddress(this.getHostIp());
-		host.setDataCenterId(dc.getId());
-		host.setVersion("6.0.1");
-		host.setAvailable(true);
-		host.setSetup(true);
-		host.setPodId(podId);
-		host.setLastPinged(0);
-		host.setResourceState(ResourceState.Enabled);
-		host.setHypervisorType(HypervisorType.XenServer);
-		host.setClusterId(cluster.getId());
-
-		host = hostDao.persist(host);
-
-		imageStore = new ImageStoreVO();
-		imageStore.setName("test");
-		imageStore.setDataCenterId(dcId);
-		imageStore.setProviderName("CloudStack ImageStore Provider");
-		imageStore.setRole(DataStoreRole.Image);
-		imageStore.setUrl(this.getSecondaryStorage());
-		imageStore.setUuid(UUID.randomUUID().toString());
-		imageStore = imageStoreDao.persist(imageStore);
-
-	}
+        // create data center
+        DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null,
+                "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
+        dc = dcDao.persist(dc);
+        dcId = dc.getId();
+        // create pod
+
+        HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(),
+                this.getHostCidr(), 8, "test");
+        pod = podDao.persist(pod);
+        podId = pod.getId();
+        // create xen cluster
+        ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
+        cluster.setHypervisorType(HypervisorType.XenServer.toString());
+        cluster.setClusterType(ClusterType.CloudManaged);
+        cluster.setManagedState(ManagedState.Managed);
+        cluster = clusterDao.persist(cluster);
+        clusterId = cluster.getId();
+        // create xen host
+
+        host = new HostVO(this.getHostGuid());
+        host.setName("devcloud xen host");
+        host.setType(Host.Type.Routing);
+        host.setPrivateIpAddress(this.getHostIp());
+        host.setDataCenterId(dc.getId());
+        host.setVersion("6.0.1");
+        host.setAvailable(true);
+        host.setSetup(true);
+        host.setPodId(podId);
+        host.setLastPinged(0);
+        host.setResourceState(ResourceState.Enabled);
+        host.setHypervisorType(HypervisorType.XenServer);
+        host.setClusterId(cluster.getId());
+
+        host = hostDao.persist(host);
+
+        imageStore = new ImageStoreVO();
+        imageStore.setName("test");
+        imageStore.setDataCenterId(dcId);
+        imageStore.setProviderName("CloudStack ImageStore Provider");
+        imageStore.setRole(DataStoreRole.Image);
+        imageStore.setUrl(this.getSecondaryStorage());
+        imageStore.setUuid(UUID.randomUUID().toString());
+        imageStore = imageStoreDao.persist(imageStore);
+
+    }
 
     @Override
     protected void injectMockito() {
@@ -189,74 +191,79 @@ public class volumeServiceTest extends CloudStackTestNGBase {
         List<HostVO> results = new ArrayList<HostVO>();
         results.add(host);
         Mockito.when(hostDao.listAll()).thenReturn(results);
-        Mockito.when(hostDao.findById(Mockito.anyLong())).thenReturn(host);
-        Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
+        Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(host);
+        Mockito.when(hostDao.findHypervisorHostInCluster(Matchers.anyLong())).thenReturn(results);
         List<EndPoint> eps = new ArrayList<EndPoint>();
-        eps.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(),
-                host.getPrivateIpAddress(), host.getPublicIpAddress()));
-        Mockito.when(selector.selectAll(Mockito.any(DataStore.class))).thenReturn(eps);
-        Mockito.when(selector.select(Mockito.any(DataObject.class))).thenReturn(eps.get(0));
-        Mockito.when(selector.select(Mockito.any(DataObject.class), Mockito.any(DataObject.class))).thenReturn(eps.get(0));
+        eps.add(RemoteHostEndPoint.getHypervisorHostEndPoint(host.getId(), host.getPrivateIpAddress(),
+                host.getPublicIpAddress()));
+        Mockito.when(selector.selectAll(Matchers.any(DataStore.class))).thenReturn(eps);
+        Mockito.when(selector.select(Matchers.any(DataObject.class))).thenReturn(eps.get(0));
+        Mockito.when(selector.select(Matchers.any(DataObject.class), Matchers.any(DataObject.class))).thenReturn(
+                eps.get(0));
+    }
+
+    private VMTemplateVO createImageData() {
+        VMTemplateVO image = new VMTemplateVO();
+        image.setTemplateType(TemplateType.USER);
+        image.setUrl(this.getTemplateUrl());
+        image.setUniqueName(UUID.randomUUID().toString());
+        image.setName(UUID.randomUUID().toString());
+        image.setPublicTemplate(true);
+        image.setFeatured(true);
+        image.setRequiresHvm(true);
+        image.setBits(64);
+        image.setFormat(Storage.ImageFormat.VHD);
+        image.setEnablePassword(true);
+        image.setEnableSshKey(true);
+        image.setGuestOSId(1);
+        image.setBootable(true);
+        image.setPrepopulate(true);
+        image.setCrossZones(true);
+        image.setExtractable(true);
+
+        // image.setImageDataStoreId(storeId);
+        image = imageDataDao.persist(image);
+
+        return image;
     }
 
-	private VMTemplateVO createImageData() {
-		VMTemplateVO image = new VMTemplateVO();
-		image.setTemplateType(TemplateType.USER);
-		image.setUrl(this.getTemplateUrl());
-		image.setUniqueName(UUID.randomUUID().toString());
-		image.setName(UUID.randomUUID().toString());
-		image.setPublicTemplate(true);
-		image.setFeatured(true);
-		image.setRequiresHvm(true);
-		image.setBits(64);
-		image.setFormat(Storage.ImageFormat.VHD);
-		image.setEnablePassword(true);
-		image.setEnableSshKey(true);
-		image.setGuestOSId(1);
-		image.setBootable(true);
-		image.setPrepopulate(true);
-		image.setCrossZones(true);
-		image.setExtractable(true);
-
-
-		//image.setImageDataStoreId(storeId);
-		image = imageDataDao.persist(image);
-
-
-		return image;
-	}
-
-	private TemplateInfo createTemplate() {
-		try {
-		    DataStore store = createImageStore();
-		    VMTemplateVO image = createImageData();
-		    TemplateInfo template = imageDataFactory.getTemplate(image.getId(), store);
-		    //AsyncCallFuture<TemplateApiResult> future = imageService.createTemplateAsync(template, store);
-		    //future.get();
-		    template = imageDataFactory.getTemplate(image.getId(), store);
-			/*imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
-			VMTemplateVO image = createImageData();
-			ImageDataStoreProvider defaultProvider = imageProviderMgr.getProvider("DefaultProvider");
-			ImageDataStoreLifeCycle lifeCycle = defaultProvider.getLifeCycle();
-			ImageDataStore store = lifeCycle.registerDataStore("defaultHttpStore", new HashMap<String, String>());
-			imageService.registerTemplate(image.getId(), store.getImageDataStoreId());
-			TemplateEntity te = imageService.getTemplateEntity(image.getId());
-			return te;*/
-		    return template;
-		} catch (Exception e) {
-		    Assert.fail("failed", e);
-		    return null;
-		}
-	}
-
-	//@Test
-	public void createTemplateTest() {
-		createTemplate();
-	}
-
-	@Test
-	public void testCreatePrimaryStorage() {
-	    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
+    private TemplateInfo createTemplate() {
+        try {
+            DataStore store = createImageStore();
+            VMTemplateVO image = createImageData();
+            TemplateInfo template = imageDataFactory.getTemplate(image.getId(), store);
+            // AsyncCallFuture<TemplateApiResult> future =
+            // imageService.createTemplateAsync(template, store);
+            // future.get();
+            template = imageDataFactory.getTemplate(image.getId(), store);
+            /*
+             * imageProviderMgr.configure("image Provider", new HashMap<String,
+             * Object>()); VMTemplateVO image = createImageData();
+             * ImageDataStoreProvider defaultProvider =
+             * imageProviderMgr.getProvider("DefaultProvider");
+             * ImageDataStoreLifeCycle lifeCycle =
+             * defaultProvider.getLifeCycle(); ImageDataStore store =
+             * lifeCycle.registerDataStore("defaultHttpStore", new
+             * HashMap<String, String>());
+             * imageService.registerTemplate(image.getId(),
+             * store.getImageDataStoreId()); TemplateEntity te =
+             * imageService.getTemplateEntity(image.getId()); return te;
+             */
+            return template;
+        } catch (Exception e) {
+            Assert.fail("failed", e);
+            return null;
+        }
+    }
+
+    // @Test
+    public void createTemplateTest() {
+        createTemplate();
+    }
+
+    @Test
+    public void testCreatePrimaryStorage() {
+        DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
         Map<String, Object> params = new HashMap<String, Object>();
         URI uri = null;
         try {
@@ -278,13 +285,13 @@ public class volumeServiceTest extends CloudStackTestNGBase {
         params.put("providerName", String.valueOf(provider.getName()));
 
         DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
-        this.primaryStore  = lifeCycle.initialize(params);
+        this.primaryStore = lifeCycle.initialize(params);
         ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
         lifeCycle.attachCluster(this.primaryStore, scope);
-	}
+    }
 
-	private DataStore createImageStore() {
-	    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample image data store provider");
+    private DataStore createImageStore() {
+        DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample image data store provider");
         Map<String, Object> params = new HashMap<String, Object>();
         String name = UUID.randomUUID().toString();
         params.put("name", name);
@@ -295,19 +302,20 @@ public class volumeServiceTest extends CloudStackTestNGBase {
         DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
         DataStore store = lifeCycle.initialize(params);
         return store;
-	}
-	//@Test
-	public void testcreateImageStore() {
-	    createImageStore();
-	}
-
-
-	public DataStore createPrimaryDataStore() {
-		try {
-		    DataStoreProvider provider = dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
-		    Map<String, Object> params = new HashMap<String, Object>();
-		    URI uri = new URI(this.getPrimaryStorageUrl());
-		    params.put("url", this.getPrimaryStorageUrl());
+    }
+
+    // @Test
+    public void testcreateImageStore() {
+        createImageStore();
+    }
+
+    public DataStore createPrimaryDataStore() {
+        try {
+            DataStoreProvider provider = dataStoreProviderMgr
+                    .getDataStoreProvider("sample primary data store provider");
+            Map<String, Object> params = new HashMap<String, Object>();
+            URI uri = new URI(this.getPrimaryStorageUrl());
+            params.put("url", this.getPrimaryStorageUrl());
             params.put("server", uri.getHost());
             params.put("path", uri.getPath());
             params.put("protocol", Storage.StoragePoolType.NetworkFilesystem);
@@ -319,57 +327,75 @@ public class volumeServiceTest extends CloudStackTestNGBase {
             params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
             params.put("providerName", String.valueOf(provider.getName()));
 
-		    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
-		    DataStore store = lifeCycle.initialize(params);
-		    ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
-		    lifeCycle.attachCluster(store, scope);
-
-		    /*
-		    PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
-		    primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
-
-		    List<PrimaryDataStoreVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
-		    if (ds.size() >= 1) {
-		        PrimaryDataStoreVO store = ds.get(0);
-		        if (store.getRemoved() == null) {
-		            return provider.getDataStore(store.getId());
-		        }
-		    }
-
-
-			Map<String, String> params = new HashMap<String, String>();
-			params.put("url", this.getPrimaryStorageUrl());
-			params.put("dcId", dcId.toString());
-			params.put("clusterId", clusterId.toString());
-			params.put("name", this.primaryName);
-			PrimaryDataStoreInfo primaryDataStoreInfo = provider.registerDataStore(params);
-			PrimaryDataStoreLifeCycle lc = primaryDataStoreInfo.getLifeCycle();
-			ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
-			lc.attachCluster(scope);
-			return primaryDataStoreInfo;
-			*/
-		    return store;
-		} catch (Exception e) {
-			return null;
-		}
-	}
-
-	private VolumeVO createVolume(Long templateId, long dataStoreId) {
-		VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);
-		volume.setPoolId(dataStoreId);
-		volume = volumeDao.persist(volume);
-		return volume;
-	}
-
-	@Test(priority=2)
-	public void createVolumeFromTemplate() {
-	    DataStore primaryStore = this.primaryStore;
-		TemplateInfo te = createTemplate();
-		VolumeVO volume = createVolume(te.getId(), primaryStore.getId());
-		VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
-		//ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
-		AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeFromTemplateAsync(vol, primaryStore.getId(), te);
-		try {
+            DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
+            DataStore store = lifeCycle.initialize(params);
+            ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
+            lifeCycle.attachCluster(store, scope);
+
+            /*
+             * PrimaryDataStoreProvider provider =
+             * primaryDataStoreProviderMgr.getDataStoreProvider
+             * ("sample primary data store provider");
+             * primaryDataStoreProviderMgr.configure("primary data store mgr",
+             * new HashMap<String, Object>());
+             * 
+             * List<PrimaryDataStoreVO> ds =
+             * primaryStoreDao.findPoolByName(this.primaryName); if (ds.size()
+             * >= 1) { PrimaryDataStoreVO store = ds.get(0); if
+             * (store.getRemoved() == null) { return
+             * provider.getDataStore(store.getId()); } }
+             * 
+             * 
+             * Map<String, String> params = new HashMap<String, String>();
+             * params.put("url", this.getPrimaryStorageUrl());
+             * params.put("dcId", dcId.toString()); params.put("clusterId",
+             * clusterId.toString()); params.put("name", this.primaryName);
+             * PrimaryDataStoreInfo primaryDataStoreInfo =
+             * provider.registerDataStore(params); PrimaryDataStoreLifeCycle lc
+             * = primaryDataStoreInfo.getLifeCycle(); ClusterScope scope = new
+             * ClusterScope(clusterId, podId, dcId); lc.attachCluster(scope);
+             * return primaryDataStoreInfo;
+             */
+            return store;
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    private VolumeVO createVolume(Long templateId, long dataStoreId) {
+        VolumeVO volume = new VolumeVO(Volume.Type.DATADISK, UUID.randomUUID().toString(), this.dcId, 1L, 1L, 1L, 1000);
+        volume.setPoolId(dataStoreId);
+        volume = volumeDao.persist(volume);
+        return volume;
+    }
+
+    @Test(priority = 2)
+    public void createVolumeFromTemplate() {
+        DataStore primaryStore = this.primaryStore;
+        TemplateInfo te = createTemplate();
+        VolumeVO volume = createVolume(te.getId(), primaryStore.getId());
+        VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
+        // ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
+        AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeFromTemplateAsync(vol,
+                primaryStore.getId(), te);
+        try {
+            future.get();
+        } catch (InterruptedException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (ExecutionException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    // @Test(priority=3)
+    public void createDataDisk() {
+        DataStore primaryStore = this.primaryStore;
+        VolumeVO volume = createVolume(null, primaryStore.getId());
+        VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
+        AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeAsync(vol, primaryStore);
+        try {
             future.get();
         } catch (InterruptedException e) {
             // TODO Auto-generated catch block
@@ -378,15 +404,15 @@ public class volumeServiceTest extends CloudStackTestNGBase {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-	}
-
-	//@Test(priority=3)
-	public void createDataDisk() {
-	    DataStore primaryStore = this.primaryStore;
-	    VolumeVO volume = createVolume(null, primaryStore.getId());
-	    VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
-	    AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeAsync(vol, primaryStore);
-	    try {
+    }
+
+    // @Test(priority=3)
+    public void createAndDeleteDataDisk() {
+        DataStore primaryStore = this.primaryStore;
+        VolumeVO volume = createVolume(null, primaryStore.getId());
+        VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
+        AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeAsync(vol, primaryStore);
+        try {
             future.get();
         } catch (InterruptedException e) {
             // TODO Auto-generated catch block
@@ -395,28 +421,11 @@ public class volumeServiceTest extends CloudStackTestNGBase {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-	}
-
-	//@Test(priority=3)
-	public void createAndDeleteDataDisk() {
-	    DataStore primaryStore = this.primaryStore;
-	    VolumeVO volume = createVolume(null, primaryStore.getId());
-	    VolumeInfo vol = volumeFactory.getVolume(volume.getId(), primaryStore);
-	    AsyncCallFuture<VolumeApiResult> future = volumeService.createVolumeAsync(vol, primaryStore);
-	    try {
-	        future.get();
-	    } catch (InterruptedException e) {
-	        // TODO Auto-generated catch block
-	        e.printStackTrace();
-	    } catch (ExecutionException e) {
-	        // TODO Auto-generated catch block
-	        e.printStackTrace();
-	    }
-
-	    //delete the volume
-	    vol = volumeFactory.getVolume(volume.getId(), primaryStore);
-	    future = volumeService.expungeVolumeAsync(vol);
-	    try {
+
+        // delete the volume
+        vol = volumeFactory.getVolume(volume.getId(), primaryStore);
+        future = volumeService.expungeVolumeAsync(vol);
+        try {
             future.get();
         } catch (InterruptedException e) {
             // TODO Auto-generated catch block
@@ -425,41 +434,40 @@ public class volumeServiceTest extends CloudStackTestNGBase {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
-	}
-
-	//@Test(priority=3)
-	public void tearDown() {
-	    List<StoragePoolVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
-	    for (int i = 0; i < ds.size(); i++) {
-	        StoragePoolVO store = ds.get(i);
-	        store.setUuid(null);
-	        primaryStoreDao.remove(ds.get(i).getId());
-	        primaryStoreDao.expunge(ds.get(i).getId());
-	    }
-	}
-
-	//@Test
-	//@Test
+    }
+
+    // @Test(priority=3)
+    public void tearDown() {
+        List<StoragePoolVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
+        for (int i = 0; i < ds.size(); i++) {
+            StoragePoolVO store = ds.get(i);
+            store.setUuid(null);
+            primaryStoreDao.remove(ds.get(i).getId());
+            primaryStoreDao.expunge(ds.get(i).getId());
+        }
+    }
+
+    // @Test
+    // @Test
     public void test1() {
-		/*System.out.println(VolumeTypeHelper.getType("Root"));
-		System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk"));
-		System.out.println(ImageFormatHelper.getFormat("ova"));
-		AssertJUnit.assertFalse(new VMDK().equals(new VHD()));
-		VMDK vmdk = new VMDK();
-		AssertJUnit.assertTrue(vmdk.equals(vmdk));
-		VMDK newvmdk = new VMDK();
-		AssertJUnit.assertTrue(vmdk.equals(newvmdk));
-
-		ImageFormat ova = new OVA();
-		ImageFormat iso = new ISO();
-		AssertJUnit.assertTrue(ova.equals(new OVA()));
-		AssertJUnit.assertFalse(ova.equals(iso));
-		AssertJUnit.assertTrue(ImageFormatHelper.getFormat("test").equals(new Unknown()));
-
-		VolumeDiskType qcow2 = new QCOW2();
-		ImageFormat qcow2format = new org.apache.cloudstack.storage.image.format.QCOW2();
-		AssertJUnit.assertFalse(qcow2.equals(qcow2format));
-*/
-	}
+        /*
+         * System.out.println(VolumeTypeHelper.getType("Root"));
+         * System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk"));
+         * System.out.println(ImageFormatHelper.getFormat("ova"));
+         * AssertJUnit.assertFalse(new VMDK().equals(new VHD())); VMDK vmdk =
+         * new VMDK(); AssertJUnit.assertTrue(vmdk.equals(vmdk)); VMDK newvmdk =
+         * new VMDK(); AssertJUnit.assertTrue(vmdk.equals(newvmdk));
+         * 
+         * ImageFormat ova = new OVA(); ImageFormat iso = new ISO();
+         * AssertJUnit.assertTrue(ova.equals(new OVA()));
+         * AssertJUnit.assertFalse(ova.equals(iso));
+         * AssertJUnit.assertTrue(ImageFormatHelper.getFormat("test").equals(new
+         * Unknown()));
+         * 
+         * VolumeDiskType qcow2 = new QCOW2(); ImageFormat qcow2format = new
+         * org.apache.cloudstack.storage.image.format.QCOW2();
+         * AssertJUnit.assertFalse(qcow2.equals(qcow2format));
+         */
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
index c530e4a..aafdad0 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotDataFactoryImpl.java
@@ -26,18 +26,13 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
-import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.springframework.stereotype.Component;
 
 import com.cloud.storage.DataStoreRole;
-import com.cloud.storage.Snapshot;
 import com.cloud.storage.SnapshotVO;
 import com.cloud.storage.dao.SnapshotDao;
-import com.cloud.utils.db.SearchCriteria2;
-import com.cloud.utils.db.SearchCriteriaService;
-import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.exception.CloudRuntimeException;
 
 @Component
@@ -50,10 +45,11 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
     DataStoreManager storeMgr;
     @Inject
     VolumeDataFactory volumeFactory;
+
     @Override
     public SnapshotInfo getSnapshot(long snapshotId, DataStore store) {
         SnapshotVO snapshot = snapshotDao.findById(snapshotId);
-        SnapshotObject so =  SnapshotObject.getSnapshotObject(snapshot, store);
+        SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
         return so;
     }
 
@@ -63,7 +59,7 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
         if (snapshot == null) {
             throw new CloudRuntimeException("Can't find snapshot: " + obj.getId());
         }
-        SnapshotObject so =  SnapshotObject.getSnapshotObject(snapshot, store);
+        SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
         return so;
     }
 
@@ -75,7 +71,7 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
             return null;
         }
         DataStore store = this.storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
-        SnapshotObject so =  SnapshotObject.getSnapshotObject(snapshot, store);
+        SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
         return so;
     }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
index 8b3c1f6..6aee3ea 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotObject.java
@@ -91,7 +91,8 @@ public class SnapshotObject implements SnapshotInfo {
 
     @Override
     public SnapshotInfo getParent() {
-        SnapshotDataStoreVO snapStoreVO = this.snapshotStoreDao.findByStoreSnapshot(this.store.getRole(), this.store.getId(), this.snapshot.getId());
+        SnapshotDataStoreVO snapStoreVO = this.snapshotStoreDao.findByStoreSnapshot(this.store.getRole(),
+                this.store.getId(), this.snapshot.getId());
         if (snapStoreVO == null) {
             return null;
         }
@@ -106,7 +107,8 @@ public class SnapshotObject implements SnapshotInfo {
 
     @Override
     public SnapshotInfo getChild() {
-        SearchCriteriaService<SnapshotDataStoreVO, SnapshotDataStoreVO> sc = SearchCriteria2.create(SnapshotDataStoreVO.class);
+        SearchCriteriaService<SnapshotDataStoreVO, SnapshotDataStoreVO> sc = SearchCriteria2
+                .create(SnapshotDataStoreVO.class);
         sc.addAnd(sc.getEntity().getDataStoreId(), Op.EQ, this.store.getId());
         sc.addAnd(sc.getEntity().getRole(), Op.EQ, this.store.getRole());
         sc.addAnd(sc.getEntity().getParentSnapshotId(), Op.EQ, this.getId());
@@ -246,8 +248,8 @@ public class SnapshotObject implements SnapshotInfo {
     @Override
     public void processEvent(ObjectInDataStoreStateMachine.Event event, Answer answer) {
         try {
-            SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(this.getDataStore().getRole(), this.getDataStore().getId(),
-                    this.getId());
+            SnapshotDataStoreVO snapshotStore = this.snapshotStoreDao.findByStoreSnapshot(
+                    this.getDataStore().getRole(), this.getDataStore().getId(), this.getId());
             if (answer instanceof CreateObjectAnswer) {
                 SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
                 snapshotStore.setInstallPath(snapshotTO.getPath());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0a522892/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
index 5717c17..545a6a0 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java
@@ -17,7 +17,6 @@
 
 package org.apache.cloudstack.storage.snapshot;
 
-import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 import javax.inject.Inject;
@@ -25,19 +24,16 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
 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.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
-import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.State;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
-import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult;
 import org.apache.cloudstack.framework.async.AsyncCallFuture;
 import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
@@ -51,10 +47,7 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
-import com.cloud.agent.api.BackupSnapshotAnswer;
-import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.dao.ClusterDao;
-import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.Snapshot;
 import com.cloud.storage.SnapshotVO;
@@ -70,391 +63,372 @@ import com.cloud.vm.snapshot.dao.VMSnapshotDao;
 
 @Component
 public class SnapshotServiceImpl implements SnapshotService {
-	private static final Logger s_logger = Logger.getLogger(SnapshotServiceImpl.class);
-	@Inject
-	protected VolumeDao _volsDao;
-	@Inject
-	protected UserVmDao _vmDao;
-	@Inject
-	protected PrimaryDataStoreDao _storagePoolDao;
-	@Inject
-	protected ClusterDao _clusterDao;
-	@Inject
-	protected SnapshotDao _snapshotDao;
-	@Inject
-	protected SnapshotDataStoreDao _snapshotStoreDao;
-
-	@Inject
-	protected SnapshotManager snapshotMgr;
-	@Inject
-	protected VolumeManager volumeMgr;
-	@Inject
-	private ConfigurationDao _configDao;
-	@Inject
-	protected SnapshotStateMachineManager stateMachineManager;
-	@Inject
-	private VolumeDao volumeDao;
-	@Inject
-	SnapshotDataFactory snapshotfactory;
-	@Inject
-	DataStoreManager dataStoreMgr;
-	@Inject
-	DataMotionService motionSrv;
-	@Inject
-	ObjectInDataStoreManager objInStoreMgr;
-	@Inject
-	VMSnapshotDao _vmSnapshotDao;
-
-
-
-
-	static private class CreateSnapshotContext<T> extends AsyncRpcConext<T> {
-		final VolumeInfo volume;
-		final SnapshotInfo snapshot;
-		final AsyncCallFuture<SnapshotResult> future;
-		public CreateSnapshotContext(AsyncCompletionCallback<T> callback, VolumeInfo volume,
-				SnapshotInfo snapshot,
-				AsyncCallFuture<SnapshotResult> future) {
-			super(callback);
-			this.volume = volume;
-			this.snapshot = snapshot;
-			this.future = future;
-		}
-	}
-
-	static private class DeleteSnapshotContext<T> extends AsyncRpcConext<T> {
-		final SnapshotInfo snapshot;
-		final AsyncCallFuture<SnapshotResult> future;
-		public DeleteSnapshotContext(AsyncCompletionCallback<T> callback, SnapshotInfo snapshot,
-				AsyncCallFuture<SnapshotResult> future) {
-			super(callback);
-			this.snapshot = snapshot;
-			this.future = future;
-		}
-
-	}
-
-	static private class CopySnapshotContext<T> extends AsyncRpcConext<T> {
-		final SnapshotInfo srcSnapshot;
-		final SnapshotInfo destSnapshot;
-		final AsyncCallFuture<SnapshotResult> future;
-		public CopySnapshotContext(AsyncCompletionCallback<T> callback,
-				SnapshotInfo srcSnapshot,
-				SnapshotInfo destSnapshot,
-				AsyncCallFuture<SnapshotResult> future) {
-			super(callback);
-			this.srcSnapshot = srcSnapshot;
-			this.destSnapshot = destSnapshot;
-			this.future = future;
-		}
-
-	}
-
-	protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> callback,
-			CreateSnapshotContext<CreateCmdResult> context) {
-		CreateCmdResult result = callback.getResult();
-		SnapshotObject snapshot = (SnapshotObject)context.snapshot;
-		AsyncCallFuture<SnapshotResult> future = context.future;
-		SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer());
-		if (result.isFailed()) {
-			s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult());
-			try {
-				snapshot.processEvent(Snapshot.Event.OperationFailed);
-				snapshot.processEvent(Event.OperationFailed);
-			} catch (Exception e) {
-				s_logger.debug("Failed to update snapshot state due to " + e.getMessage());
-			}
-
-			snapResult.setResult(result.getResult());
-			future.complete(snapResult);
-			return null;
-		}
-
-		try {
-			snapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
-			snapshot.processEvent(Snapshot.Event.OperationSucceeded);
-		} catch (Exception e) {
-			s_logger.debug("Failed to create snapshot: ", e);
-			snapResult.setResult(e.toString());
-			try {
+    private static final Logger s_logger = Logger.getLogger(SnapshotServiceImpl.class);
+    @Inject
+    protected VolumeDao _volsDao;
+    @Inject
+    protected UserVmDao _vmDao;
+    @Inject
+    protected PrimaryDataStoreDao _storagePoolDao;
+    @Inject
+    protected ClusterDao _clusterDao;
+    @Inject
+    protected SnapshotDao _snapshotDao;
+    @Inject
+    protected SnapshotDataStoreDao _snapshotStoreDao;
+
+    @Inject
+    protected SnapshotManager snapshotMgr;
+    @Inject
+    protected VolumeManager volumeMgr;
+    @Inject
+    protected SnapshotStateMachineManager stateMachineManager;
+    @Inject
+    SnapshotDataFactory snapshotfactory;
+    @Inject
+    DataStoreManager dataStoreMgr;
+    @Inject
+    DataMotionService motionSrv;
+    @Inject
+    ObjectInDataStoreManager objInStoreMgr;
+    @Inject
+    VMSnapshotDao _vmSnapshotDao;
+
+    static private class CreateSnapshotContext<T> extends AsyncRpcConext<T> {
+        final SnapshotInfo snapshot;
+        final AsyncCallFuture<SnapshotResult> future;
+
+        public CreateSnapshotContext(AsyncCompletionCallback<T> callback, VolumeInfo volume, SnapshotInfo snapshot,
+                AsyncCallFuture<SnapshotResult> future) {
+            super(callback);
+            this.snapshot = snapshot;
+            this.future = future;
+        }
+    }
+
+    static private class DeleteSnapshotContext<T> extends AsyncRpcConext<T> {
+        final SnapshotInfo snapshot;
+        final AsyncCallFuture<SnapshotResult> future;
+
+        public DeleteSnapshotContext(AsyncCompletionCallback<T> callback, SnapshotInfo snapshot,
+                AsyncCallFuture<SnapshotResult> future) {
+            super(callback);
+            this.snapshot = snapshot;
+            this.future = future;
+        }
+
+    }
+
+    static private class CopySnapshotContext<T> extends AsyncRpcConext<T> {
+        final SnapshotInfo srcSnapshot;
+        final SnapshotInfo destSnapshot;
+        final AsyncCallFuture<SnapshotResult> future;
+
+        public CopySnapshotContext(AsyncCompletionCallback<T> callback, SnapshotInfo srcSnapshot,
+                SnapshotInfo destSnapshot, AsyncCallFuture<SnapshotResult> future) {
+            super(callback);
+            this.srcSnapshot = srcSnapshot;
+            this.destSnapshot = destSnapshot;
+            this.future = future;
+        }
+
+    }
+
+    protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> callback,
+            CreateSnapshotContext<CreateCmdResult> context) {
+        CreateCmdResult result = callback.getResult();
+        SnapshotObject snapshot = (SnapshotObject) context.snapshot;
+        AsyncCallFuture<SnapshotResult> future = context.future;
+        SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer());
+        if (result.isFailed()) {
+            s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult());
+            try {
+                snapshot.processEvent(Snapshot.Event.OperationFailed);
+                snapshot.processEvent(Event.OperationFailed);
+            } catch (Exception e) {
+                s_logger.debug("Failed to update snapshot state due to " + e.getMessage());
+            }
+
+            snapResult.setResult(result.getResult());
+            future.complete(snapResult);
+            return null;
+        }
+
+        try {
+            snapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
+            snapshot.processEvent(Snapshot.Event.OperationSucceeded);
+        } catch (Exception e) {
+            s_logger.debug("Failed to create snapshot: ", e);
+            snapResult.setResult(e.toString());
+            try {
                 snapshot.processEvent(Snapshot.Event.OperationFailed);
             } catch (NoTransitionException e1) {
                 s_logger.debug("Failed to change snapshot state: " + e1.toString());
             }
-		}
-
-		future.complete(snapResult);
-		return null;
-	}
-
-
-
-	@Override
-	public SnapshotResult takeSnapshot(SnapshotInfo snap) {
-		SnapshotObject snapshot = (SnapshotObject)snap;
-
-		SnapshotObject snapshotOnPrimary = null;
-		try {
-		    snapshotOnPrimary = (SnapshotObject)snap.getDataStore().create(snapshot);
-		} catch(Exception e) {
-		    s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage());
-		    throw new CloudRuntimeException(e);
-		}
-
-		try {
-		    snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested);
-		} catch (NoTransitionException e) {
-		    s_logger.debug("Failed to change snapshot state: " + e.toString());
-		    throw new CloudRuntimeException(e);
-		}
-
-		try {
-		    snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
-		} catch (Exception e) {
-		    s_logger.debug("Failed to change snapshot state: " + e.toString());
-		    try {
-		        snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
-		    } catch (NoTransitionException e1) {
-		        s_logger.debug("Failed to change snapshot state: " + e1.toString());
-		    }
-		    throw new CloudRuntimeException(e);
-		}
-
-		AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
-		try {
-		    CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<CommandResult>(
-		            null, snap.getBaseVolume(), snapshotOnPrimary, future);
-		    AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher
-		            .create(this);
-		    caller.setCallback(
-		            caller.getTarget().createSnapshotAsyncCallback(null, null))
-		            .setContext(context);
-		    PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver)snapshotOnPrimary.getDataStore().getDriver();
-		    primaryStore.takeSnapshot(snapshot, caller);
-		} catch (Exception e) {
-		    s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
-		    try {
+        }
+
+        future.complete(snapResult);
+        return null;
+    }
+
+    @Override
+    public SnapshotResult takeSnapshot(SnapshotInfo snap) {
+        SnapshotObject snapshot = (SnapshotObject) snap;
+
+        SnapshotObject snapshotOnPrimary = null;
+        try {
+            snapshotOnPrimary = (SnapshotObject) snap.getDataStore().create(snapshot);
+        } catch (Exception e) {
+            s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage());
+            throw new CloudRuntimeException(e);
+        }
+
+        try {
+            snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested);
+        } catch (NoTransitionException e) {
+            s_logger.debug("Failed to change snapshot state: " + e.toString());
+            throw new CloudRuntimeException(e);
+        }
+
+        try {
+            snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
+        } catch (Exception e) {
+            s_logger.debug("Failed to change snapshot state: " + e.toString());
+            try {
+                snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
+            } catch (NoTransitionException e1) {
+                s_logger.debug("Failed to change snapshot state: " + e1.toString());
+            }
+            throw new CloudRuntimeException(e);
+        }
+
+        AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
+        try {
+            CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<CommandResult>(null,
+                    snap.getBaseVolume(), snapshotOnPrimary, future);
+            AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
+            caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
+            PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver) snapshotOnPrimary.getDataStore().getDriver();
+            primaryStore.takeSnapshot(snapshot, caller);
+        } catch (Exception e) {
+            s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
+            try {
                 snapshot.processEvent(Snapshot.Event.OperationFailed);
             } catch (NoTransitionException e1) {
-                s_logger.debug("Failed to change state for event: OperationFailed" , e);
+                s_logger.debug("Failed to change state for event: OperationFailed", e);
+            }
+            throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
+        }
+
+        SnapshotResult result;
+
+        try {
+            result = future.get();
+            if (result.isFailed()) {
+                s_logger.debug("Failed to create snapshot:" + result.getResult());
+                throw new CloudRuntimeException(result.getResult());
+            }
+            return result;
+        } catch (InterruptedException e) {
+            s_logger.debug("Failed to create snapshot", e);
+            throw new CloudRuntimeException("Failed to create snapshot", e);
+        } catch (ExecutionException e) {
+            s_logger.debug("Failed to create snapshot", e);
+            throw new CloudRuntimeException("Failed to create snapshot", e);
+        }
+
+    }
+
+    // if a snapshot has parent snapshot, the new snapshot should be stored in
+    // the same store as its parent since
+    // we are taking delta snapshot
+    private DataStore findSnapshotImageStore(SnapshotInfo snapshot) {
+        if (snapshot.getParent() == null) {
+            return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
+        } else {
+            SnapshotInfo parentSnapshot = snapshot.getParent();
+            // Note that DataStore information in parentSnapshot is for primary
+            // data store here, we need to
+            // find the image store where the parent snapshot backup is located
+            SnapshotDataStoreVO parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(),
+                    DataStoreRole.Image);
+            return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(),
+                    parentSnapshotOnBackupStore.getRole());
+        }
+    }
+
+    @Override
+    public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
+        SnapshotObject snapObj = (SnapshotObject) snapshot;
+        AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
+        SnapshotResult result = new SnapshotResult(snapshot, null);
+        try {
+
+            snapObj.processEvent(Snapshot.Event.BackupToSecondary);
+
+            DataStore imageStore = this.findSnapshotImageStore(snapshot);
+            if (imageStore == null) {
+                throw new CloudRuntimeException("can not find an image stores");
             }
-		    throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
-		}
-
-		SnapshotResult result;
-
-		try {
-			result = future.get();
-			if (result.isFailed()) {
-				s_logger.debug("Failed to create snapshot:" + result.getResult());
-				throw new CloudRuntimeException(result.getResult());
-			}
-			return result;
-		} catch (InterruptedException e) {
-			s_logger.debug("Failed to create snapshot", e);
-			throw new CloudRuntimeException("Failed to create snapshot", e);
-		} catch (ExecutionException e) {
-			s_logger.debug("Failed to create snapshot", e);
-			throw new CloudRuntimeException("Failed to create snapshot", e);
-		}
-
-	}
-
-	// if a snapshot has parent snapshot, the new snapshot should be stored in the same store as its parent since
-	// we are taking delta snapshot
-	private DataStore findSnapshotImageStore(SnapshotInfo snapshot){
-	    if ( snapshot.getParent() == null ){
-	        return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
-	    } else{
-	        SnapshotInfo parentSnapshot = snapshot.getParent();
-	        // Note that DataStore information in parentSnapshot is for primary data store here, we need to
-	        // find the image store where the parent snapshot backup is located
-	        SnapshotDataStoreVO parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
-	        return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(),
-	                        parentSnapshotOnBackupStore.getRole());
-	    }
-	}
-
-
-	@Override
-	public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
-		SnapshotObject snapObj = (SnapshotObject)snapshot;
-		AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
-		SnapshotResult result = new SnapshotResult(snapshot, null);
-		try {
-
-			snapObj.processEvent(Snapshot.Event.BackupToSecondary);
-
-			DataStore imageStore = this.findSnapshotImageStore(snapshot);
-			if (imageStore == null) {
-				throw new CloudRuntimeException("can not find an image stores");
-			}
-
-			SnapshotInfo snapshotOnImageStore = (SnapshotInfo)imageStore.create(snapshot);
-
-			snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
-			CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot,
-					snapshotOnImageStore, future);
-			AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher
-					.create(this);
-			caller.setCallback(
-					caller.getTarget().copySnapshotAsyncCallback(null, null))
-					.setContext(context);
-			this.motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
-		} catch (Exception e) {
-			s_logger.debug("Failed to copy snapshot", e);
-			result.setResult("Failed to copy snapshot:" +e.toString());
-			try {
+
+            SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
+
+            snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
+            CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot,
+                    snapshotOnImageStore, future);
+            AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher
+                    .create(this);
+            caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
+            this.motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
+        } catch (Exception e) {
+            s_logger.debug("Failed to copy snapshot", e);
+            result.setResult("Failed to copy snapshot:" + e.toString());
+            try {
                 snapObj.processEvent(Snapshot.Event.OperationFailed);
             } catch (NoTransitionException e1) {
                 s_logger.debug("Failed to change state: " + e1.toString());
             }
-			future.complete(result);
-		}
-
-		try {
-			SnapshotResult res = future.get();
-			if (res.isFailed()) {
-				throw new CloudRuntimeException(res.getResult());
-			}
-			SnapshotInfo destSnapshot = res.getSnashot();
-			return destSnapshot;
-		} catch (InterruptedException e) {
-			s_logger.debug("failed copy snapshot", e);
-			throw new CloudRuntimeException("Failed to copy snapshot" , e);
-		} catch (ExecutionException e) {
-			s_logger.debug("Failed to copy snapshot", e);
-			throw new CloudRuntimeException("Failed to copy snapshot" , e);
-		}
-
-	}
-
-	protected Void copySnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback,
-			CopySnapshotContext<CommandResult> context) {
-		CopyCommandResult result = callback.getResult();
-		SnapshotInfo destSnapshot = context.destSnapshot;
-		SnapshotObject srcSnapshot = (SnapshotObject)context.srcSnapshot;
-		AsyncCallFuture<SnapshotResult> future = context.future;
-		SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
-		if (result.isFailed()) {
-			try {
-				destSnapshot.processEvent(Event.OperationFailed);
-				srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
-			} catch (NoTransitionException e) {
-				s_logger.debug("Failed to update state: " + e.toString());
-			}
-			snapResult.setResult(result.getResult());
-			future.complete(snapResult);
-			return null;
-		}
-
-		try {
-		    CopyCmdAnswer answer = (CopyCmdAnswer)result.getAnswer();
-		    destSnapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
-			srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
-			snapResult = new SnapshotResult(this.snapshotfactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), answer);
-			future.complete(snapResult);
-		} catch (Exception e) {
-			s_logger.debug("Failed to update snapshot state", e);
-			snapResult.setResult(e.toString());
-			future.complete(snapResult);
-		}
-		return null;
-	}
-
-	@DB
-	protected boolean destroySnapshotBackUp(SnapshotVO snapshot) {
-	    SnapshotDataStoreVO snapshotStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image);
-	    if ( snapshotStore == null ){
+            future.complete(result);
+        }
+
+        try {
+            SnapshotResult res = future.get();
+            if (res.isFailed()) {
+                throw new CloudRuntimeException(res.getResult());
+            }
+            SnapshotInfo destSnapshot = res.getSnashot();
+            return destSnapshot;
+        } catch (InterruptedException e) {
+            s_logger.debug("failed copy snapshot", e);
+            throw new CloudRuntimeException("Failed to copy snapshot", e);
+        } catch (ExecutionException e) {
+            s_logger.debug("Failed to copy snapshot", e);
+            throw new CloudRuntimeException("Failed to copy snapshot", e);
+        }
+
+    }
+
+    protected Void copySnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback,
+            CopySnapshotContext<CommandResult> context) {
+        CopyCommandResult result = callback.getResult();
+        SnapshotInfo destSnapshot = context.destSnapshot;
+        SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
+        AsyncCallFuture<SnapshotResult> future = context.future;
+        SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
+        if (result.isFailed()) {
+            try {
+                destSnapshot.processEvent(Event.OperationFailed);
+                srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
+            } catch (NoTransitionException e) {
+                s_logger.debug("Failed to update state: " + e.toString());
+            }
+            snapResult.setResult(result.getResult());
+            future.complete(snapResult);
+            return null;
+        }
+
+        try {
+            CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
+            destSnapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
+            srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
+            snapResult = new SnapshotResult(this.snapshotfactory.getSnapshot(destSnapshot.getId(),
+                    destSnapshot.getDataStore()), answer);
+            future.complete(snapResult);
+        } catch (Exception e) {
+            s_logger.debug("Failed to update snapshot state", e);
+            snapResult.setResult(e.toString());
+            future.complete(snapResult);
+        }
+        return null;
+    }
+
+    @DB
+    protected boolean destroySnapshotBackUp(SnapshotVO snapshot) {
+        SnapshotDataStoreVO snapshotStore = this._snapshotStoreDao
+                .findBySnapshot(snapshot.getId(), DataStoreRole.Image);
+        if (snapshotStore == null) {
             s_logger.debug("Can't find snapshot" + snapshot.getId() + " backed up into image store");
             return false;
-	    }
-		DataStore store = this.dataStoreMgr.getDataStore(snapshotStore.getDataStoreId(), DataStoreRole.Image);
-		if (store == null) {
-			s_logger.debug("Can't find mage store " + snapshotStore.getDataStoreId());
-			return false;
-		}
-
-		try {
-			SnapshotInfo snapshotInfo = this.snapshotfactory.getSnapshot(snapshot.getId(), store);
-			snapshotInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
-
-			AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
-			DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null,
-					snapshotInfo, future);
-			AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher
-					.create(this);
-			caller.setCallback(
-					caller.getTarget().deleteSnapshotCallback(null, null))
-					.setContext(context);
-
-			store.getDriver().deleteAsync(snapshotInfo, caller);
-
-			SnapshotResult result = future.get();
-			if (result.isFailed()) {
-				s_logger.debug("Failed to delete snapsoht: " + result.getResult());
-			}
-			return result.isSuccess();
-		} catch (Exception e) {
-			s_logger.debug("Failed to delete snapshot", e);
-			return false;
-		}
-	}
-
-	protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback,
-			DeleteSnapshotContext<CommandResult> context) {
-		CommandResult result = callback.getResult();
-		AsyncCallFuture<SnapshotResult> future = context.future;
-		SnapshotInfo snapshot = context.snapshot;
-		if (result.isFailed()) {
-			s_logger.debug("delete snapshot failed" + result.getResult());
-			snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
-			SnapshotResult res = new SnapshotResult(context.snapshot, null);
-			future.complete(res);
-			return null;
-		}
-		snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
-		SnapshotResult res = new SnapshotResult(context.snapshot, null);
-		future.complete(res);
-		return null;
-	}
-
-	@Override
-	public boolean deleteSnapshot(SnapshotInfo snapInfo) {
-		snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
-
-		AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
-		DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null,
-				snapInfo, future);
-		AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher
-				.create(this);
-		caller.setCallback(
-				caller.getTarget().deleteSnapshotCallback(null, null))
-				.setContext(context);
-		DataStore store = snapInfo.getDataStore();
-		store.getDriver().deleteAsync(snapInfo, caller);
-
-		SnapshotResult result = null;
-		try {
-			result = future.get();
-			if (result.isFailed()) {
-				throw new CloudRuntimeException(result.getResult());
-			}
-			return true;
-		} catch (InterruptedException e) {
-			s_logger.debug("delete snapshot is failed: " + e.toString());
-		} catch (ExecutionException e) {
-			s_logger.debug("delete snapshot is failed: " + e.toString());
-		}
-
-		return false;
-
-	}
-
-	@Override
-	public boolean revertSnapshot(SnapshotInfo snapshot) {
-		// TODO Auto-generated method stub
-		return false;
-	}
+        }
+        DataStore store = this.dataStoreMgr.getDataStore(snapshotStore.getDataStoreId(), DataStoreRole.Image);
+        if (store == null) {
+            s_logger.debug("Can't find mage store " + snapshotStore.getDataStoreId());
+            return false;
+        }
+
+        try {
+            SnapshotInfo snapshotInfo = this.snapshotfactory.getSnapshot(snapshot.getId(), store);
+            snapshotInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
+
+            AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
+            DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null, snapshotInfo,
+                    future);
+            AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
+            caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
+
+            store.getDriver().deleteAsync(snapshotInfo, caller);
+
+            SnapshotResult result = future.get();
+            if (result.isFailed()) {
+                s_logger.debug("Failed to delete snapsoht: " + result.getResult());
+            }
+            return result.isSuccess();
+        } catch (Exception e) {
+            s_logger.debug("Failed to delete snapshot", e);
+            return false;
+        }
+    }
+
+    protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback,
+            DeleteSnapshotContext<CommandResult> context) {
+        CommandResult result = callback.getResult();
+        AsyncCallFuture<SnapshotResult> future = context.future;
+        SnapshotInfo snapshot = context.snapshot;
+        if (result.isFailed()) {
+            s_logger.debug("delete snapshot failed" + result.getResult());
+            snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
+            SnapshotResult res = new SnapshotResult(context.snapshot, null);
+            future.complete(res);
+            return null;
+        }
+        snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
+        SnapshotResult res = new SnapshotResult(context.snapshot, null);
+        future.complete(res);
+        return null;
+    }
+
+    @Override
+    public boolean deleteSnapshot(SnapshotInfo snapInfo) {
+        snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
+
+        AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
+        DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<CommandResult>(null, snapInfo, future);
+        AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
+        caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
+        DataStore store = snapInfo.getDataStore();
+        store.getDriver().deleteAsync(snapInfo, caller);
+
+        SnapshotResult result = null;
+        try {
+            result = future.get();
+            if (result.isFailed()) {
+                throw new CloudRuntimeException(result.getResult());
+            }
+            return true;
+        } catch (InterruptedException e) {
+            s_logger.debug("delete snapshot is failed: " + e.toString());
+        } catch (ExecutionException e) {
+            s_logger.debug("delete snapshot is failed: " + e.toString());
+        }
+
+        return false;
+
+    }
+
+    @Override
+    public boolean revertSnapshot(SnapshotInfo snapshot) {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
 }