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 2012/11/14 01:35:10 UTC

[1/2] git commit: refactor apis

Updated Branches:
  refs/heads/javelin 2251d5bb4 -> a06eb4557


refactor apis


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

Branch: refs/heads/javelin
Commit: a06eb4557e3af792641eae1eb2f101d6c34e3fad
Parents: 2251d5b
Author: Edison Su <su...@gmail.com>
Authored: Tue Nov 13 16:34:44 2012 -0800
Committer: Edison Su <su...@gmail.com>
Committed: Tue Nov 13 16:34:44 2012 -0800

----------------------------------------------------------------------
 .../engine/cloud/entity/api/VolumeEntity.java      |    8 +-
 .../engine/subsystem/api/storage/ImageService.java |   33 ++
 .../subsystem/api/storage/PrimaryDataStore.java    |   34 --
 .../api/storage/PrimaryDataStoreProvider.java      |    9 +
 .../subsystem/api/storage/StorageOrchestrator.java |   68 ++++
 .../engine/subsystem/api/storage/VolumeInfo.java   |   42 +++
 .../subsystem/api/storage/VolumeService.java       |   69 ----
 engine/components-api/PrimaryDataStore.java        |   34 ++
 .../cloudstack/storage/StorageOrchestrator.java    |   59 ---
 .../storage/StorageOrchestratorImpl.java           |   40 ++
 .../storage/command/CreateVolumeCommand.java       |    2 +-
 .../datastore/DefaultPrimaryDataStoreImpl.java     |   90 +++--
 .../storage/datastore/PrimaryDataStore.java        |   40 ++
 .../driver/DefaultPrimaryDataStoreDriverImpl.java  |   15 +-
 .../datastore/driver/PrimaryDataStoreDriver.java   |    9 +-
 .../DefaultPrimaryDataStoreManagerImpl.java        |    4 +-
 .../datastore/manager/PrimaryDataStoreManager.java |    2 +-
 .../DefaultPrimaryDatastoreProviderImpl.java       |    3 +-
 .../provider/PrimaryDataStoreProvider.java         |    9 -
 .../provider/PrimaryDataStoreProviderManager.java  |    2 +
 .../PrimaryDataStoreProviderManagerImpl.java       |    1 +
 .../cloudstack/storage/image/ImageService.java     |   30 --
 .../cloudstack/storage/image/ImageServiceImpl.java |   11 +-
 .../apache/cloudstack/storage/image/Template.java  |   44 ---
 .../storage/image/TemplateEntityImpl.java          |  278 +++++++++++++++
 .../cloudstack/storage/image/TemplateInfo.java     |   25 ++
 .../cloudstack/storage/image/TemplateObject.java   |   23 ++
 .../storage/image/downloader/ImageDownloader.java  |    4 +-
 .../provider/ImageDataStoreProviderManager.java    |    2 +
 .../storage/image/store/ImageDataStore.java        |    6 +-
 .../storage/image/store/ImageDataStoreInfo.java    |   23 ++
 .../storage/manager/PrimaryDataStoreManager.java   |    2 +-
 .../manager/PrimaryDataStoreManagerImpl.java       |    2 +-
 .../storage/volume/VolumeEntityImpl.java           |  189 +++++------
 .../cloudstack/storage/volume/VolumeInfo.java      |   77 ----
 .../cloudstack/storage/volume/VolumeObject.java    |  135 +++++++
 .../cloudstack/storage/volume/VolumeService.java   |   71 ++++
 .../storage/volume/VolumeServiceImpl.java          |   50 +++-
 .../cloudstack/storage/test/volumeServiceTest.java |    4 +-
 39 files changed, 1052 insertions(+), 497 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VolumeEntity.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VolumeEntity.java b/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VolumeEntity.java
index e8c0e75..e30fdc8 100755
--- a/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VolumeEntity.java
+++ b/engine/api/src/org/apache/cloudstack/engine/cloud/entity/api/VolumeEntity.java
@@ -18,12 +18,12 @@
  */
 package org.apache.cloudstack.engine.cloud.entity.api;
 
+import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
 import org.apache.cloudstack.engine.entity.api.CloudStackEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
 import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 
-import com.cloud.storage.Volume;
 
 public interface VolumeEntity extends CloudStackEntity {
 
@@ -81,6 +81,6 @@ public interface VolumeEntity extends CloudStackEntity {
     String getTemplateUuid();
     VolumeDiskType getDiskType();
     VolumeType getType();
-    PrimaryDataStore getDataStore();
-    void setUuid(String uuid);
+    StorageEntity getDataStore();
+    void setPath(String path);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
new file mode 100644
index 0000000..a3dba26
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+
+public interface ImageService {
+	boolean registerTemplate(long templateId, long imageStoreId);
+	boolean deleteTemplate(long templateId);
+	long registerIso(String isoUrl, long accountId);
+	boolean deleteIso(long isoId);
+	String grantTemplateAccess(long templateId, long endpointId);
+	boolean revokeTemplateAccess(long templateId, long endpointId);
+	String grantIsoAccess(long isoId, long endpointId);
+	boolean revokeIsoAccess(long isoId, long endpointId);
+	TemplateEntity getTemplateEntity(long templateId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStore.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStore.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStore.java
deleted file mode 100644
index 3f8bae0..0000000
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStore.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.engine.subsystem.api.storage;
-
-import java.util.List;
-
-import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
-
-
-public interface PrimaryDataStore {
-	VolumeEntity getVolume(long id);
-	List<VolumeEntity> getVolumes();
-	boolean deleteVolume(long id);
-	VolumeEntity createVolume(long id, VolumeDiskType diskType);
-	List<EndPoint> getEndPoints();
-	PrimaryDataStoreInfo getDataStoreInfo();
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreProvider.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreProvider.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreProvider.java
new file mode 100644
index 0000000..e8fd059
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreProvider.java
@@ -0,0 +1,9 @@
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
+
+
+public interface PrimaryDataStoreProvider {
+	public PrimaryDataStore getDataStore(long dataStoreId);
+	public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java
new file mode 100755
index 0000000..c1c1e90
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/StorageOrchestrator.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+
+import com.cloud.deploy.DeploymentPlan;
+
+public interface StorageOrchestrator {
+
+    /**
+     * Prepares all storage ready for a VM to start
+     * @param vm
+     * @param reservationId
+     */
+    void prepare(long vmId, DeploymentPlan plan, String reservationId);
+
+    /**
+     * Releases all storage that were used for a VM shutdown
+     * @param vm
+     * @param disks
+     * @param reservationId
+     */
+    void release(long vmId, String reservationId);
+
+    /**
+     * Destroy all disks
+     * @param disks
+     * @param reservationId
+     */
+    void destroy(List<Long> disks, String reservationId);
+
+    /**
+     * Cancel a reservation
+     * @param reservationId reservation to 
+     */
+    void cancel(String reservationId);
+    
+    /**
+     * If attaching a volume in allocated state to a running vm, need to create this volume
+     */
+    void prepareAttachDiskToVM(long diskId, long vmId, String reservationId);
+    
+    boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType);
+    boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, VolumeDiskType dis, TemplateEntity template);
+    VolumeEntity allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
new file mode 100644
index 0000000..8785bc5
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+
+import java.util.Date;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+
+import com.cloud.storage.Volume;
+
+public interface VolumeInfo {
+	public long getSize();
+	public String getUuid();
+	public String getPath();
+	public PrimaryDataStoreInfo getDataStore() ;
+	public String getTemplateUuid();
+	public String getTemplatePath() ;
+	public VolumeType getType();
+	public VolumeDiskType getDiskType();
+	public long getId();
+	public Volume.State getCurrentState();
+	public Volume.State getDesiredState();
+	public Date getCreatedData();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
deleted file mode 100644
index 290a74c..0000000
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.engine.subsystem.api.storage;
-
-import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
-import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
-
-
-public interface VolumeService {
-
-	/**
-	 * 
-	 */
-	VolumeEntity allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId);
-	
-    /**
-     * Creates the volume based on the given criteria
-     * 
-     * @param cmd
-     *            
-     * @return the volume object
-     */
-	VolumeEntity createVolume(long volumeId, long dataStoreId, VolumeDiskType diskType);
-
-    /**
-     * Delete volume
-     * @param volumeId
-     * @return
-     * @throws ConcurrentOperationException
-     */
-    boolean deleteVolume(long volumeId);
-    
-    /**
-     * 
-     */
-    boolean cloneVolume(long volumeId, long baseVolId);
-    
-    /**
-     * 
-     */
-    boolean createVolumeFromSnapshot(long volumeId, long snapshotId);
-    
-    /**
-     * 
-     */
-    String grantAccess(long volumeId, long endpointId);
-    
-    /**
-     * 
-     */
-    boolean rokeAccess(long volumeId, long endpointId);
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/components-api/PrimaryDataStore.java
----------------------------------------------------------------------
diff --git a/engine/components-api/PrimaryDataStore.java b/engine/components-api/PrimaryDataStore.java
new file mode 100644
index 0000000..87aee25
--- /dev/null
+++ b/engine/components-api/PrimaryDataStore.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+
+
+public interface PrimaryDataStore {
+	VolumeEntity getVolume(String id);
+	List<VolumeEntity> getVolumes();
+	boolean deleteVolume(VolumeEntity id);
+	VolumeEntity createVolume(String id, VolumeDiskType diskType);
+	List<EndPoint> getEndPoints();
+	PrimaryDataStoreInfo getDataStoreInfo();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java
deleted file mode 100755
index 691c413..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage;
-
-import java.util.List;
-
-import com.cloud.deploy.DeploymentPlan;
-
-public interface StorageOrchestrator {
-
-    /**
-     * Prepares all storage ready for a VM to start
-     * @param vm
-     * @param reservationId
-     */
-    void prepare(long vmId, DeploymentPlan plan, String reservationId);
-
-    /**
-     * Releases all storage that were used for a VM shutdown
-     * @param vm
-     * @param disks
-     * @param reservationId
-     */
-    void release(long vmId, String reservationId);
-
-    /**
-     * Destroy all disks
-     * @param disks
-     * @param reservationId
-     */
-    void destroy(List<Long> disks, String reservationId);
-
-    /**
-     * Cancel a reservation
-     * @param reservationId reservation to 
-     */
-    void cancel(String reservationId);
-    
-    /**
-     * If attaching a volume in allocated state to a running vm, need to create this volume
-     */
-    void prepareAttachDiskToVM(long diskId, long vmId, String reservationId);
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
index 2118afb..eb3b1e0 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
@@ -21,16 +21,27 @@ package org.apache.cloudstack.storage;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectBackupStorageOperationState;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.StorageOrchestrator;
 import org.apache.cloudstack.engine.subsystem.api.storage.StorageProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateProfile;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeProfile;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeStrategy;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
+import org.apache.cloudstack.storage.datastore.manager.PrimaryDataStoreManager;
 import org.apache.cloudstack.storage.image.ImageManager;
 import org.apache.cloudstack.storage.manager.BackupStorageManager;
 import org.apache.cloudstack.storage.manager.SecondaryStorageManager;
+import org.apache.cloudstack.storage.volume.VolumeEntityImpl;
 import org.apache.cloudstack.storage.volume.VolumeManager;
+import org.apache.cloudstack.storage.volume.VolumeObject;
+import org.apache.cloudstack.storage.volume.VolumeService;
 import org.apache.log4j.Logger;
 
 import com.cloud.deploy.DeploymentPlan;
@@ -78,6 +89,10 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
 	ImageManager _templateMgr;
 	@Inject
 	VMTemplateDao _templateDao;
+	@Inject
+	VolumeService volumeService;
+	@Inject
+	PrimaryDataStoreManager primaryStorageMgr;
 	
 	@DB
 	protected Volume copyVolumeFromBackupStorage(VolumeVO volume, DataStore destStore, String reservationId) throws NoTransitionException {
@@ -312,4 +327,29 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
 		volume.setInstanceId(vmId);
 		_volumeDao.update(volume.getId(), volume);
 	}
+
+
+
+	@Override
+	public boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType) {
+		VolumeEntityImpl vei = ((VolumeEntityImpl)volume);
+		VolumeInfo vi = volumeService.createVolume(vei.getVolumeInfo(), dataStoreId, diskType);
+		vei.setVolumeInfo(vi);
+		return true;
+	}
+
+	@Override
+	public VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) {
+		return volumeService.allocateVolumeInDb(size, type, volName, templateId);
+	}
+	
+	@Override
+	public boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType, TemplateEntity template) {
+		PrimaryDataStore pd = primaryStorageMgr.getPrimaryDataStore(dataStoreId);
+		boolean existsOnPrimaryStorage = pd.templateExists(template.getId());
+		if (!existsOnPrimaryStorage) {
+			
+		}
+		return false;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java
index 243e016..e7ae083 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cloudstack.storage.command;
 
-import org.apache.cloudstack.storage.volume.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 
 import com.cloud.agent.api.Command;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java
index 1dc86f7..bafd280 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java
@@ -8,8 +8,8 @@ import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
 import org.apache.cloudstack.storage.HypervisorHostEndPoint;
 import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
@@ -17,6 +17,7 @@ import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
 
 import org.apache.cloudstack.storage.volume.VolumeEntityImpl;
 import org.apache.cloudstack.storage.volume.VolumeEvent;
+import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.cloudstack.storage.volume.db.VolumeDao;
 import org.apache.cloudstack.storage.volume.db.VolumeVO;
 
@@ -24,6 +25,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.utils.component.ComponentInject;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -45,14 +47,14 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
 	}
 	
 	@Override
-	public VolumeEntity getVolume(long id) {
+	public VolumeInfo getVolume(long id) {
 		VolumeVO volumeVO = volumeDao.findById(id);
-		VolumeEntity vol = new VolumeEntityImpl(this, volumeVO);
+		VolumeObject vol = new VolumeObject(this, volumeVO);
 		return vol;
 	}
 
 	@Override
-	public List<VolumeEntity> getVolumes() {
+	public List<VolumeInfo> getVolumes() {
 		// TODO Auto-generated method stub
 		return null;
 	}
@@ -64,39 +66,10 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
 	}
 
 	@Override
-	public VolumeEntity createVolume(long id, VolumeDiskType diskType) {
-		/*
-		VolumeEntity vol = this.getVolume(id);
-		if (vol == null) {
-			return null;
-		}
-		
-		if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) {
-			return null;
-		}
+	public VolumeInfo createVolume(VolumeInfo vol, VolumeDiskType diskType) {
 		
-		boolean result = vol.stateTransit(VolumeEvent.CreateRequested);
-		if (!result) {
-			return null;
-		}
 		
-		try {
-			vol.setVolumeDiskType(diskType);
-			result = this.driver.createVolume(vol);
-			vol.update();
-			return vol;
-		} catch (Exception e) {
-			result = false;
-			s_logger.debug("Failed to create volume: " + e.toString());
-			throw new CloudRuntimeException(e.toString());
-		} finally {
-			if (result == true) {
-				vol.stateTransit(VolumeEvent.OperationSucceeded);
-			} else {
-				vol.stateTransit(VolumeEvent.OperationFailed);
-			}
-		}*/
-		return null;
+	
 	}
 
 	@Override
@@ -121,4 +94,51 @@ public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore {
 		// TODO Auto-generated method stub
 		return null;
 	}
+
+	@Override
+	public boolean isHypervisorSupported(HypervisorType hypervisor) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean isLocalStorageSupported() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public long getCapacity() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public long getAvailableCapacity() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public VolumeObject createVolume(VolumeObject vo, VolumeDiskType diskType) {
+		if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) {
+			return null;
+		}
+
+		vo.setVolumeDiskType(diskType);
+		this.driver.createVolume(vo);
+		return vo;
+	}
+
+	@Override
+	public boolean exists(VolumeInfo vi) {
+		// TODO Auto-generated method stub
+		return false;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java
new file mode 100644
index 0000000..dd9be51
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore;
+
+import java.util.List;
+
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.storage.volume.VolumeObject;
+
+
+public interface PrimaryDataStore extends PrimaryDataStoreInfo {
+	VolumeInfo getVolume(long id);
+	List<VolumeInfo> getVolumes();
+	boolean deleteVolume(long id);
+	VolumeObject createVolume(VolumeObject vo, VolumeDiskType diskType);
+	List<EndPoint> getEndPoints();
+	PrimaryDataStoreInfo getDataStoreInfo();
+	boolean exists(VolumeInfo vi);
+	boolean templateExists(long templateId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
index 16c54ae..1bb6ee7 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java
@@ -4,9 +4,10 @@ import java.util.List;
 
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
 import org.apache.cloudstack.storage.command.CreateVolumeCommand;
-import org.apache.cloudstack.storage.volume.VolumeInfo;
+import org.apache.cloudstack.storage.volume.VolumeObject;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -17,11 +18,11 @@ public class DefaultPrimaryDataStoreDriverImpl implements
 		PrimaryDataStoreDriver {
 	private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class);
 	@Override
-	public boolean createVolume(VolumeEntity vol) {
+	public boolean createVolume(VolumeObject vol) {
 		//The default driver will send createvolume command to one of hosts which can access its datastore
 		List<EndPoint> endPoints = vol.getDataStore().getEndPoints();
 		int retries = 3;
-		VolumeInfo volInfo = new VolumeInfo(vol);
+		VolumeInfo volInfo = vol;
 		CreateVolumeCommand createCmd = new CreateVolumeCommand(volInfo);
 		Answer answer = null;
 		int i = 0;
@@ -36,7 +37,7 @@ public class DefaultPrimaryDataStoreDriverImpl implements
 				i++;
 			} else {
 				CreateVolumeAnswer volAnswer = (CreateVolumeAnswer)answer;
-				vol.setUuid(volAnswer.getVolumeUuid());
+				vol.setPath(volAnswer.getVolumeUuid());
 				result = true;
 			}
 		}
@@ -45,19 +46,19 @@ public class DefaultPrimaryDataStoreDriverImpl implements
 	}
 
 	@Override
-	public boolean deleteVolume(VolumeEntity vo) {
+	public boolean deleteVolume(VolumeObject vo) {
 		// TODO Auto-generated method stub
 		return false;
 	}
 
 	@Override
-	public String grantAccess(VolumeEntity vol, EndPoint ep) {
+	public String grantAccess(VolumeObject vol, EndPoint ep) {
 		// TODO Auto-generated method stub
 		return null;
 	}
 
 	@Override
-	public boolean revokeAccess(VolumeEntity vol, EndPoint ep) {
+	public boolean revokeAccess(VolumeObject vol, EndPoint ep) {
 		// TODO Auto-generated method stub
 		return false;
 	}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java
index 006c0d5..d000b49 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java
@@ -2,11 +2,12 @@ package org.apache.cloudstack.storage.datastore.driver;
 
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.storage.volume.VolumeObject;
 
 
 public interface PrimaryDataStoreDriver {
-	boolean createVolume(VolumeEntity vol);
-	boolean deleteVolume(VolumeEntity vo);
-	String grantAccess(VolumeEntity vol,  EndPoint ep);
-	boolean revokeAccess(VolumeEntity vol, EndPoint ep);
+	boolean createVolume(VolumeObject vol);
+	boolean deleteVolume(VolumeObject vo);
+	String grantAccess(VolumeObject vol,  EndPoint ep);
+	boolean revokeAccess(VolumeObject vol, EndPoint ep);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java
index 4095acb..22011e4 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java
@@ -20,12 +20,12 @@ package org.apache.cloudstack.storage.datastore.manager;
 
 import javax.inject.Inject;
 
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
 import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
-import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider;
 import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
 import org.springframework.stereotype.Component;
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java
index 33fac99..b6ac34d 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java
@@ -18,7 +18,7 @@
  */
 package org.apache.cloudstack.storage.datastore.manager;
 
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle;
 
 public interface PrimaryDataStoreManager {

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
index bd65752..af10693 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java
@@ -2,9 +2,10 @@ package org.apache.cloudstack.storage.datastore.provider;
 
 import javax.inject.Inject;
 
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
 import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java
deleted file mode 100644
index 9c9a830..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.apache.cloudstack.storage.datastore.provider;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
-
-public interface PrimaryDataStoreProvider {
-	public PrimaryDataStore getDataStore(long dataStoreId);
-	public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId);
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java
index 4ef9a5c..03b67b1 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java
@@ -1,5 +1,7 @@
 package org.apache.cloudstack.storage.datastore.provider;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
+
 public interface PrimaryDataStoreProviderManager {
 	public PrimaryDataStoreProvider getDataStoreProvider(Long providerId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java
index 0875553..63723a4 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cloudstack.storage.datastore.provider;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
 import org.springframework.stereotype.Component;
 
 @Component

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java
deleted file mode 100644
index ebdc594..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.image;
-
-public interface ImageService {
-	boolean registerTemplate(long templateId, long imageStoreId);
-	boolean deleteTemplate(long templateId);
-	long registerIso(String isoUrl, long accountId);
-	boolean deleteIso(long isoId);
-	String grantTemplateAccess(long templateId, long endpointId);
-	boolean revokeTemplateAccess(long templateId, long endpointId);
-	String grantIsoAccess(long isoId, long endpointId);
-	boolean revokeIsoAccess(long isoId, long endpointId);
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
index 7fabffa..1f765fc 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
@@ -20,6 +20,8 @@ package org.apache.cloudstack.storage.image;
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
 import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
 import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
 import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
@@ -29,10 +31,12 @@ public class ImageServiceImpl implements ImageService {
 
 	@Inject
 	ImageDataStoreProviderManager imageStoreProviderMgr;
+	@Inject
+	
 	@Override
 	public boolean registerTemplate(long templateId, long imageStoreId) {
 		ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
-		Template template = ids.registerTemplate(templateId);
+		TemplateInfo template = ids.registerTemplate(templateId);
 		if (ids.needDownloadToCacheStorage()) {
 			ImageDownloader imageDl = ids.getImageDownloader();
 			imageDl.downloadImage(template);
@@ -82,4 +86,9 @@ public class ImageServiceImpl implements ImageService {
 		return false;
 	}
 
+	@Override
+	public TemplateEntity getTemplateEntity(long templateId) {
+		TemplateObject to = imageStoreProviderMgr.getTemplate(templateId);
+		return new TemplateEntityImpl(to);
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/Template.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/Template.java b/engine/storage/src/org/apache/cloudstack/storage/image/Template.java
deleted file mode 100644
index ae12e0c..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/image/Template.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.image;
-
-import org.apache.cloudstack.storage.image.db.ImageDataVO;
-import org.apache.cloudstack.storage.image.store.ImageDataStore;
-
-public class Template {
-    protected ImageDataVO imageVO;
-    protected ImageDataStore dataStore;
-    public Template(ImageDataStore dataStore, ImageDataVO imageVO) {
-        this.dataStore = dataStore;
-        this.imageVO = imageVO;
-    }
-
-    public ImageDataStore getImageDataStore() {
-        return this.dataStore;
-    }
-    
-    public void setImageDataStoreId(long dataStoreId) {
-    	imageVO.setImageDataStoreId(dataStoreId);
-    }
-    
-    public long getImageDataStoreId() {
-    	return imageVO.getImageDataStoreId();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
new file mode 100644
index 0000000..f514fab
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateEntityImpl.java
@@ -0,0 +1,278 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.image;
+
+import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
+import org.apache.cloudstack.storage.image.db.ImageDataVO;
+import org.apache.cloudstack.storage.image.store.ImageDataStore;
+import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.Storage.TemplateType;
+
+public class TemplateEntityImpl implements TemplateEntity {
+	protected TemplateInfo templateInfo;
+    public TemplateEntityImpl(TemplateInfo templateInfo) {
+       this.templateInfo = templateInfo;
+    }
+
+    public ImageDataStoreInfo getImageDataStore() {
+        return templateInfo.getImageDataStore();
+    }
+
+    
+    public long getImageDataStoreId() {
+    	return getImageDataStore().getImageDataStoreId();
+    }
+
+	@Override
+	public String getUuid() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public long getId() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public String getExternalId() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getCurrentState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getDesiredState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Date getCreatedTime() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Date getLastUpdatedTime() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getOwner() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Map<String, String> getDetails(String source) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public List<String> getDetailSources() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void addDetail(String source, String name, String value) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void delDetail(String source, String name, String value) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public void updateDetail(String source, String name, String value) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	@Override
+	public List<Method> getApplicableActions() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean isFeatured() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean isPublicTemplate() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean isExtractable() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public String getName() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public ImageFormat getFormat() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean isRequiresHvm() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public String getDisplayText() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public boolean getEnablePassword() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean getEnableSshKey() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public boolean isCrossZones() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public Date getCreated() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public long getGuestOSId() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public boolean isBootable() {
+		// TODO Auto-generated method stub
+		return false;
+	}
+
+	@Override
+	public TemplateType getTemplateType() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public HypervisorType getHypervisorType() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public int getBits() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public String getUniqueName() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getUrl() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getChecksum() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Long getSourceTemplateId() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getTemplateTag() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Map getDetails() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public long getAccountId() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public long getDomainId() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
new file mode 100644
index 0000000..312aa7b
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateInfo.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.image;
+
+import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
+
+public interface TemplateInfo {
+	ImageDataStoreInfo getImageDataStore();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
new file mode 100644
index 0000000..f1181db
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/TemplateObject.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.image;
+
+public class TemplateObject implements TemplateInfo {
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
index 123df61..ef9bc3f 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
@@ -18,8 +18,8 @@
  */
 package org.apache.cloudstack.storage.image.downloader;
 
-import org.apache.cloudstack.storage.image.Template;
+import org.apache.cloudstack.storage.image.TemplateInfo;
 
 public interface ImageDownloader {
-	public void downloadImage(Template template);
+	public void downloadImage(TemplateInfo template);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
index dd98a7a..407a644 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
@@ -18,10 +18,12 @@
  */
 package org.apache.cloudstack.storage.image.provider;
 
+import org.apache.cloudstack.storage.image.TemplateObject;
 import org.apache.cloudstack.storage.image.store.ImageDataStore;
 
 public interface ImageDataStoreProviderManager {
 	public ImageDataStoreProvider getProvider(long providerId);
 	public ImageDataStore getDataStore(long dataStoreId);
 	public ImageDataStore getDataStoreFromTemplateId(long templateId);
+	public TemplateObject getTemplate(long templateId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
index d712acc..5422bad 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
@@ -18,11 +18,11 @@
  */
 package org.apache.cloudstack.storage.image.store;
 
-import org.apache.cloudstack.storage.image.Template;
+import org.apache.cloudstack.storage.image.TemplateInfo;
 import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
 
-public interface ImageDataStore {
-	Template registerTemplate(long templateId);
+public interface ImageDataStore extends ImageDataStoreInfo {
+	TemplateInfo registerTemplate(long templateId);
 	String grantAccess(long templateId, long endPointId);
 	boolean revokeAccess(long templateId, long endPointId);
 	boolean deleteTemplate(long templateId);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreInfo.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreInfo.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreInfo.java
new file mode 100644
index 0000000..7be4da0
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreInfo.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.image.store;
+
+public interface ImageDataStoreInfo {
+	public long getImageDataStoreId();
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
index 4b7142f..6292ab8 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
@@ -21,7 +21,7 @@ package org.apache.cloudstack.storage.manager;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.StoragePool;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
index 24ae5ea..2af2ef0 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
@@ -24,9 +24,9 @@ import java.util.Map;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.StorageProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.DataCenterVO;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java
index 13308e8..e79614c 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEntityImpl.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.cloudstack.storage.volume;
 
 import java.lang.reflect.Method;
@@ -5,113 +23,36 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-import javax.inject.Inject;
-
 import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
-import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper;
 import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
-import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
-import org.apache.cloudstack.storage.volume.db.VolumeDao;
-import org.apache.cloudstack.storage.volume.db.VolumeVO;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.storage.Volume;
-import com.cloud.utils.fsm.NoTransitionException;
-import com.cloud.utils.fsm.StateMachine2;
 
 public class VolumeEntityImpl implements VolumeEntity {
-	private static final Logger s_logger = Logger.getLogger(VolumeEntityImpl.class);
-	protected VolumeVO volumeVO;
-	private StateMachine2<Volume.State, VolumeEvent, VolumeVO> _volStateMachine;
-	protected PrimaryDataStore dataStore;
-	@Inject
-	VolumeDiskTypeHelper diskTypeHelper;
-	@Inject
-	VolumeTypeHelper volumeTypeHelper;
-	@Inject
-	VolumeDao volumeDao;
-	
-	public VolumeEntityImpl(PrimaryDataStore dataStore, VolumeVO volumeVO) {
-		this.volumeVO = volumeVO;
-		this.dataStore = dataStore;
-	}
-	
-	public String getUuid() {
-		return volumeVO.getUuid();
-	}
-	
-	public void setUuid(String uuid) {
-		volumeVO.setUuid(uuid);
-	}
-	
-	public String getPath() {
-		return volumeVO.getPath();
-	}
+	private VolumeInfo volumeInfo;
 	
-	public String getTemplateUuid() {
-		return null;
-	}
-	
-	public String getTemplatePath() {
-		return null;
+	public VolumeEntityImpl(VolumeInfo volumeObject) {
+		this.volumeInfo = volumeObject;
 	}
 	
-	public PrimaryDataStoreInfo getDataStoreInfo() {
-		return dataStore.getDataStoreInfo();
+	public VolumeInfo getVolumeInfo() {
+		return volumeInfo;
 	}
 	
-	public Volume.State getState() {
-		return volumeVO.getState();
-	}
-
-	public PrimaryDataStore getDataStore() {
-		return dataStore;
-	}
-	
-	public long getSize() {
-		return volumeVO.getSize();
+	public void setVolumeInfo(VolumeInfo vi) {
+		this.volumeInfo = vi;
 	}
 	
-	public VolumeDiskType getDiskType() {
-		return diskTypeHelper.getDiskType(volumeVO.getDiskType());
-	}
-	
-	public VolumeType getType() {
-		return volumeTypeHelper.getType(volumeVO.getVolumeType());
-	}
-	
-	public long getVolumeId() {
-		return volumeVO.getId();
-	}
-	
-	public void setVolumeDiskType(VolumeDiskType type) {
-		volumeVO.setDiskType(type.toString());
-	}
-	
-	public boolean stateTransit(VolumeEvent event) {
-		boolean result = false;
-		try {
-			result = _volStateMachine.transitTo(volumeVO, event, null, volumeDao);
-		} catch (NoTransitionException e) {
-			s_logger.debug("Failed to transit volume: " + this.getVolumeId() + ", due to: " + e.toString());
-		}
-		return result;
-	}
-	
-	public void update() {
-		volumeDao.update(volumeVO.getId(), volumeVO);
-		volumeVO = volumeDao.findById(volumeVO.getId());
+	@Override 
+	public String getUuid() {
+		return volumeInfo.getUuid();
 	}
 
 	@Override
 	public long getId() {
-		// TODO Auto-generated method stub
-		return 0;
+		return volumeInfo.getId();
 	}
 
 	@Override
@@ -122,20 +63,17 @@ public class VolumeEntityImpl implements VolumeEntity {
 
 	@Override
 	public String getCurrentState() {
-		// TODO Auto-generated method stub
-		return null;
+		return volumeInfo.getCurrentState().toString();
 	}
 
 	@Override
 	public String getDesiredState() {
-		// TODO Auto-generated method stub
-		return null;
+		return volumeInfo.getDesiredState().toString();
 	}
 
 	@Override
 	public Date getCreatedTime() {
-		// TODO Auto-generated method stub
-		return null;
+		return volumeInfo.getCreatedData();
 	}
 
 	@Override
@@ -165,19 +103,19 @@ public class VolumeEntityImpl implements VolumeEntity {
 	@Override
 	public void addDetail(String source, String name, String value) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void delDetail(String source, String name, String value) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void updateDetail(String source, String name, String value) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
@@ -201,7 +139,7 @@ public class VolumeEntityImpl implements VolumeEntity {
 	@Override
 	public void migrate(String reservationToken) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
@@ -213,24 +151,67 @@ public class VolumeEntityImpl implements VolumeEntity {
 	@Override
 	public void copy(VolumeEntity dest) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void attachTo(String vm, long deviceId) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void detachFrom() {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void destroy() {
 		// TODO Auto-generated method stub
-		
+
+	}
+
+	@Override
+	public long getSize() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public String getTemplatePath() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public String getTemplateUuid() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public VolumeDiskType getDiskType() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public VolumeType getType() {
+		// TODO Auto-generated method stub
+		return null;
 	}
+
+	@Override
+	public StorageEntity getDataStore() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void setPath(String path) {
+		// TODO Auto-generated method stub
+
+	}
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java
deleted file mode 100644
index bc8fbe5..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.cloudstack.storage.volume;
-
-import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
-import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
-
-public class VolumeInfo {
-	private long size;
-	private String uuid;
-	private String path;
-	private PrimaryDataStoreInfo dataStoreInfo;
-	private String baseTemplateUuid;
-	private String baseTemplatePath;
-	private VolumeType type;
-	private VolumeDiskType diskType;
-	
-	public VolumeInfo(VolumeEntity volume) {
-		this.size = volume.getSize();
-		this.uuid = volume.getUuid();
-		this.baseTemplatePath = volume.getTemplatePath();
-		this.baseTemplateUuid = volume.getTemplateUuid();
-		//this.dataStoreInfo = volume.getDataStoreInfo();
-		this.diskType = volume.getDiskType();
-		this.type = volume.getType();
-	}
-	
-	public long getSize() {
-		return this.size;
-	}
-	
-	public String getUuid() {
-		return this.uuid;
-	}
-	
-	public String getPath() {
-		return this.path;
-	}
-	
-	public PrimaryDataStoreInfo getDataStore() {
-		return this.dataStoreInfo;
-	}
-	
-	public String getTemplateUuid() {
-		return this.baseTemplateUuid;
-	}
-	
-	public String getTemplatePath() {
-		return this.baseTemplatePath;
-	}
-	
-	public VolumeType getType() {
-		return this.type;
-	}
-	
-	public VolumeDiskType getDiskType() {
-		return this.diskType;
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeObject.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeObject.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeObject.java
new file mode 100644
index 0000000..d495c35
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeObject.java
@@ -0,0 +1,135 @@
+package org.apache.cloudstack.storage.volume;
+
+
+import java.util.Date;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
+import org.apache.cloudstack.storage.volume.db.VolumeDao;
+import org.apache.cloudstack.storage.volume.db.VolumeVO;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.storage.Volume;
+import com.cloud.storage.Volume.State;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.fsm.NoTransitionException;
+import com.cloud.utils.fsm.StateMachine2;
+
+public class VolumeObject implements VolumeInfo {
+	private static final Logger s_logger = Logger.getLogger(VolumeObject.class);
+	protected VolumeVO volumeVO;
+	private StateMachine2<Volume.State, VolumeEvent, VolumeVO> _volStateMachine;
+	protected PrimaryDataStore dataStore;
+	@Inject
+	VolumeDiskTypeHelper diskTypeHelper;
+	@Inject
+	VolumeTypeHelper volumeTypeHelper;
+	@Inject
+	VolumeDao volumeDao;
+	
+	public VolumeObject(PrimaryDataStore dataStore, VolumeVO volumeVO) {
+		this.volumeVO = volumeVO;
+		this.dataStore = dataStore;
+	}
+	
+	public String getUuid() {
+		return volumeVO.getUuid();
+	}
+	
+	public void setPath(String uuid) {
+		volumeVO.setUuid(uuid);
+	}
+	
+	public String getPath() {
+		return volumeVO.getPath();
+	}
+	
+	public String getTemplateUuid() {
+		return null;
+	}
+	
+	public String getTemplatePath() {
+		return null;
+	}
+	
+	public PrimaryDataStoreInfo getDataStoreInfo() {
+		return dataStore.getDataStoreInfo();
+	}
+	
+	public Volume.State getState() {
+		return volumeVO.getState();
+	}
+
+	public PrimaryDataStore getDataStore() {
+		return dataStore;
+	}
+	
+	public long getSize() {
+		return volumeVO.getSize();
+	}
+	
+	public VolumeDiskType getDiskType() {
+		return diskTypeHelper.getDiskType(volumeVO.getDiskType());
+	}
+	
+	public VolumeType getType() {
+		return volumeTypeHelper.getType(volumeVO.getVolumeType());
+	}
+	
+	public long getVolumeId() {
+		return volumeVO.getId();
+	}
+	
+	public void setVolumeDiskType(VolumeDiskType type) {
+		volumeVO.setDiskType(type.toString());
+	}
+	
+	public boolean stateTransit(VolumeEvent event) {
+		boolean result = false;
+		try {
+			result = _volStateMachine.transitTo(volumeVO, event, null, volumeDao);
+		} catch (NoTransitionException e) {
+			String errorMessage = "Failed to transit volume: " + this.getVolumeId() + ", due to: " + e.toString();
+			s_logger.debug(errorMessage);
+			throw new CloudRuntimeException(errorMessage);
+		}
+		return result;
+	}
+	
+	public void update() {
+		volumeDao.update(volumeVO.getId(), volumeVO);
+		volumeVO = volumeDao.findById(volumeVO.getId());
+	}
+
+	@Override
+	public long getId() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	@Override
+	public State getCurrentState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public State getDesiredState() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public Date getCreatedData() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java
new file mode 100644
index 0000000..fe4aba0
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.volume;
+
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
+import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+
+
+public interface VolumeService {
+	/**
+	 * 
+	 */
+	VolumeEntity allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId);
+	
+    /**
+     * Creates the volume based on the given criteria
+     * 
+     * @param cmd
+     *            
+     * @return the volume object
+     */
+	VolumeInfo createVolume(VolumeInfo volume, long dataStoreId, VolumeDiskType diskType);
+
+    /**
+     * Delete volume
+     * @param volumeId
+     * @return
+     * @throws ConcurrentOperationException
+     */
+    boolean deleteVolume(long volumeId);
+    
+    /**
+     * 
+     */
+    boolean cloneVolume(long volumeId, long baseVolId);
+    
+    /**
+     * 
+     */
+    boolean createVolumeFromSnapshot(long volumeId, long snapshotId);
+    
+    /**
+     * 
+     */
+    String grantAccess(long volumeId, long endpointId);
+    
+    /**
+     * 
+     */
+    boolean rokeAccess(long volumeId, long endpointId);
+    
+    VolumeEntity getVolumeEntity(long volumeId);
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a06eb455/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 83b9831..40c270f 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -21,16 +21,22 @@ package org.apache.cloudstack.storage.volume;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
-import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
 import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.manager.PrimaryDataStoreManager;
 import org.apache.cloudstack.storage.volume.db.VolumeDao;
+import org.apache.cloudstack.storage.volume.db.VolumeVO;
 
 import org.springframework.stereotype.Service;
 
+import com.cloud.storage.Volume;
 import com.cloud.utils.db.DB;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+//1. change volume state
+//2. orchestrator of volume, control most of the information of volume, storage pool id, voluem state, scope etc.
 
 @Service
 public class VolumeServiceImpl implements VolumeService {
@@ -39,9 +45,27 @@ public class VolumeServiceImpl implements VolumeService {
 	@Inject
 	PrimaryDataStoreManager dataStoreMgr;
 	@Override
-	public VolumeEntity createVolume(long volumeId, long dataStoreId, VolumeDiskType diskType) {
+	public VolumeInfo createVolume(VolumeInfo volume, long dataStoreId, VolumeDiskType diskType) {
 		PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(dataStoreId);
-		return dataStore.createVolume(volumeId, diskType);
+		if (dataStore == null) {
+			throw new CloudRuntimeException("Can't find dataStoreId: " + dataStoreId);
+		}
+		
+		if (dataStore.exists(volume)) {
+			return volume;
+		}
+		
+		VolumeObject vo = (VolumeObject)volume;
+		vo.stateTransit(VolumeEvent.CreateRequested);
+		
+		try {
+			VolumeInfo vi = dataStore.createVolume(vo, diskType);
+			vo.stateTransit(VolumeEvent.OperationSucceeded);
+			return vi;
+		} catch (Exception e) {
+			vo.stateTransit(VolumeEvent.OperationFailed);
+			throw new CloudRuntimeException(e.toString());
+		}
 	}
 
 	@DB
@@ -76,8 +100,22 @@ public class VolumeServiceImpl implements VolumeService {
 
 	@Override
 	public VolumeEntity allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) {
-		volDao.allocVolume(size, type, volName, templateId);
-		return null;
+		VolumeVO vo = volDao.allocVolume(size, type, volName, templateId);
+		return new VolumeEntityImpl(new VolumeObject(null, vo));
 	}
 
+	@Override
+	public VolumeEntity getVolumeEntity(long volumeId) {
+		VolumeVO vo = volDao.findById(volumeId);
+		if (vo == null) {
+			return null;
+		}
+		
+		if (vo.getPoolId() == null) {
+			return new VolumeEntityImpl(new VolumeObject(null, vo));
+		} else {
+			PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(vo.getPoolId());
+			return new VolumeEntityImpl(dataStore.getVolume(volumeId));
+		}
+	}
 }