cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [1/3] add cache storage
Date Thu, 11 Apr 2013 18:01:49 GMT
Updated Branches:
  refs/heads/object_store dcbeea057 -> 1c448cd6e


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/DefaultImageMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/DefaultImageMotionStrategy.java b/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/DefaultImageMotionStrategy.java
deleted file mode 100644
index c49a521..0000000
--- a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/DefaultImageMotionStrategy.java
+++ /dev/null
@@ -1,140 +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.motion;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
-import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.apache.cloudstack.framework.async.AsyncRpcConext;
-import org.apache.cloudstack.storage.command.CopyCmd;
-import org.apache.cloudstack.storage.command.CopyCmdAnswer;
-import org.apache.cloudstack.storage.endpoint.EndPointSelector;
-import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
-
-import com.cloud.agent.api.Answer;
-
-//At least one of datastore is coming from image store or image cache store
-
-public class DefaultImageMotionStrategy implements ImageMotionStrategy {
-    @Inject
-    EndPointSelector selector;
-    private class CreateTemplateContext<T> extends AsyncRpcConext<T> {
-        private final TemplateOnPrimaryDataStoreInfo template;
-        public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateOnPrimaryDataStoreInfo template) {
-            super(callback);
-            this.template = template;
-        }
-        
-        public TemplateOnPrimaryDataStoreInfo getTemplate() {
-            return this.template;
-        }
-        
-    }
-/*
-    @Override
-    public void copyTemplateAsync(String destUri, String srcUri, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) {
-
-        CopyCmd copyCommand = new CopyCmd(destUri, srcUri);
-        CreateTemplateContext<CommandResult> context = new CreateTemplateContext<CommandResult>(callback, null);
-        AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> caller = AsyncCallbackDispatcher.create(this);
-        caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null))
-            .setContext(context);
-             
-        ep.sendMessageAsync(copyCommand, caller);
-    }
-    
-    public Object copyTemplateCallBack(AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> callback, CreateTemplateContext<CommandResult> context) {
-        AsyncCompletionCallback<CommandResult> parentCall = context.getParentCallback();
-        CopyTemplateToPrimaryStorageAnswer answer = (CopyTemplateToPrimaryStorageAnswer)callback.getResult();
-        CommandResult result = new CommandResult();
-       
-        if (!answer.getResult()) {
-            result.setSucess(answer.getResult());
-            result.setResult(answer.getDetails());
-        } else {
-            TemplateOnPrimaryDataStoreInfo templateStore = context.getTemplate();
-            templateStore.setPath(answer.getPath());
-            result.setSucess(true);
-        }
-
-        parentCall.complete(result);
-        return null;
-    }*/
-
-    @Override
-    public boolean canHandle(DataObject srcData, DataObject destData) {
-        /*
-        DataStore destStore = destData.getDataStore();
-        DataStore srcStore = srcData.getDataStore();
-        if (destStore.getRole() == DataStoreRole.Image || destStore.getRole() == DataStoreRole.ImageCache 
-                || srcStore.getRole() == DataStoreRole.Image 
-                || srcStore.getRole() == DataStoreRole.ImageCache) {
-            return true;
-        }*/
-        return false;
-    }
-
-    @Override
-    public Void copyAsync(DataObject srcData, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback) {
-        DataStore destStore = destData.getDataStore();
-        DataStore srcStore = srcData.getDataStore();
-        EndPoint ep = selector.select(srcData, destData);
-        CopyCommandResult result = new CopyCommandResult("", null);
-        if (ep == null) {
-            result.setResult("can't find end point");
-            callback.complete(result);
-            return null;
-        }
-        
-        String srcUri = srcStore.getDriver().grantAccess(srcData, ep);
-        String destUri = destStore.getDriver().grantAccess(destData, ep);
-        CopyCmd cmd = new CopyCmd(srcUri, destUri);
-        
-        CreateTemplateContext<CopyCommandResult> context = new CreateTemplateContext<CopyCommandResult>(callback, null);
-        AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> caller = AsyncCallbackDispatcher.create(this);
-        caller.setCallback(caller.getTarget().copyAsyncCallback(null, null))
-            .setContext(context);
-             
-        ep.sendMessageAsync(cmd, caller);
-        return null;
-    }
-    
-    protected Void copyAsyncCallback(AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> callback, CreateTemplateContext<CopyCommandResult> context) {
-        AsyncCompletionCallback<CopyCommandResult> parentCall = context.getParentCallback();
-        Answer answer = (Answer)callback.getResult();
-        if (!answer.getResult()) {
-            CopyCommandResult result = new CopyCommandResult("", null);
-            result.setResult(answer.getDetails());
-            parentCall.complete(result);
-        } else {
-            CopyCmdAnswer ans = (CopyCmdAnswer)answer;
-            CopyCommandResult result = new CopyCommandResult(ans.getPath(), null);
-            parentCall.complete(result);
-        }
-        return null;
-        
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionServiceImpl.java b/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionServiceImpl.java
deleted file mode 100644
index 93ba4a5..0000000
--- a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionServiceImpl.java
+++ /dev/null
@@ -1,70 +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.motion;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
-import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-
-
-public class ImageMotionServiceImpl implements ImageMotionService {
-    @Inject
-    List<ImageMotionStrategy> motionStrategies;
-    @Inject
-    VolumeService volumeService;
-    @Inject
-    ImageService imageService;
-
-    @Override
-    public boolean copyIso(String isoUri, String destIsoUri) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-  
-
-    @Override
-    public void copyTemplateAsync(TemplateInfo destTemplate, TemplateInfo srcTemplate, AsyncCompletionCallback<CommandResult> callback) {
-     /*   ImageMotionStrategy ims = null;
-        for (ImageMotionStrategy strategy : motionStrategies) {
-            if (strategy.canHandle(srcTemplate)) {
-                ims = strategy;
-                break;
-            }
-        }
-
-        if (ims == null) {
-            throw new CloudRuntimeException("Can't find proper image motion strategy");
-        }
-
-        EndPoint ep = ims.getEndPoint(destTemplate, srcTemplate);
-        String srcUri = srcTemplate.getDataStore().grantAccess(srcTemplate, ep);
-        String destUri = destTemplate.getDataStore().grantAccess(destTemplate, ep);
-        
-        ims.copyTemplateAsync(destUri, srcUri, ep, callback);*/
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionStrategy.java b/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionStrategy.java
deleted file mode 100644
index 7a47636..0000000
--- a/engine/storage/imagemotion/src/org/apache/cloudstack/storage/image/motion/ImageMotionStrategy.java
+++ /dev/null
@@ -1,24 +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.motion;
-
-import org.apache.cloudstack.storage.motion.DataMotionStrategy;
-
-public interface ImageMotionStrategy extends DataMotionStrategy {
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockStorageMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockStorageMotionStrategy.java b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockStorageMotionStrategy.java
index b619ee9..5305131 100644
--- a/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockStorageMotionStrategy.java
+++ b/engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockStorageMotionStrategy.java
@@ -19,9 +19,9 @@
 package org.apache.cloudstack.storage.test;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.apache.cloudstack.storage.motion.DataMotionStrategy;
 
 public class MockStorageMotionStrategy implements DataMotionStrategy {
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/strategy/AncientSnapshotStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/strategy/AncientSnapshotStrategy.java b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/strategy/AncientSnapshotStrategy.java
index 3863481..7eddb34 100644
--- a/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/strategy/AncientSnapshotStrategy.java
+++ b/engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/strategy/AncientSnapshotStrategy.java
@@ -25,7 +25,7 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
 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.DataObject;
+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.DataObjectType;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@@ -45,23 +45,15 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcConext;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
-import org.apache.cloudstack.storage.motion.DataMotionService;
 import org.apache.cloudstack.storage.snapshot.SnapshotObject;
 import org.apache.cloudstack.storage.snapshot.SnapshotStateMachineManager;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
-import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.BackupSnapshotAnswer;
-import com.cloud.agent.api.DeleteSnapshotBackupCommand;
-import com.cloud.agent.api.to.S3TO;
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.dao.ClusterDao;
-import com.cloud.event.EventTypes;
-import com.cloud.event.UsageEventUtils;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.host.HostVO;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -73,12 +65,9 @@ import com.cloud.storage.VolumeManager;
 import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.s3.S3Manager;
 import com.cloud.storage.snapshot.SnapshotManager;
-import com.cloud.storage.swift.SwiftManager;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.NoTransitionException;
 import com.cloud.vm.UserVmVO;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java
index 218f901..566da62 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataObjectManagerImpl.java
@@ -23,6 +23,7 @@ import javax.inject.Inject;
 import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
 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.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
@@ -31,7 +32,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreState
 import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcConext;
-import org.apache.cloudstack.storage.motion.DataMotionService;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
index eb233aa..adc7250 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreManagerImpl.java
@@ -46,6 +46,8 @@ public class DataStoreManagerImpl implements DataStoreManager {
             return primaryStorMgr.getPrimaryDataStore(storeId);
         } else if (role == DataStoreRole.Image) {
             return imageDataStoreMgr.getImageStore(storeId);
+        } else if (role == DataStoreRole.ImageCache) {
+            return imageDataStoreMgr.getImageStore(storeId);
         }
         throw new CloudRuntimeException("un recognized type" + role);
     }
@@ -81,5 +83,8 @@ public class DataStoreManagerImpl implements DataStoreManager {
     public DataStore getPrimaryDataStore(long storeId) {
         return primaryStorMgr.getPrimaryDataStore(storeId);
     }
-
+    @Override
+    public List<DataStore> getImageCacheStores(Scope scope) {
+    	return imageDataStoreMgr.listImageCacheStores(scope);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
index 80badc5..9f98d5d 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java
@@ -161,11 +161,7 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
             this.stateMachines.transitTo(obj, event, null,
                     templatePoolDao);
             } catch (NoTransitionException e) {
-                if (event == Event.CreateOnlyRequested || event == Event.OperationSuccessed) {
-                    s_logger.debug("allow muliple create requests");
-                } else {
                     throw e;
-                }
             }
         } else {
             throw new CloudRuntimeException("Invalid data or store type: " + data.getType() + " " + data.getDataStore().getRole());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java
index b7ed53d..e34a35e 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DataStoreProviderManagerImpl.java
@@ -34,8 +34,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManag
 import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
-import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
+import org.apache.cloudstack.storage.image.ImageStoreDriver;
 import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
@@ -68,7 +68,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
     public List<StorageProviderResponse> getPrimaryDataStoreProviders() {
         List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>();
         for (DataStoreProvider provider : providerMap.values()) {
-            if (provider instanceof PrimaryDataStoreProvider) {
+            if (provider.getTypes().contains(DataStoreProviderType.PRIMARY)) {
                 StorageProviderResponse response = new StorageProviderResponse();
                 response.setName(provider.getName());
                 response.setType(DataStoreProvider.DataStoreProviderType.PRIMARY.toString());
@@ -81,7 +81,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
     public List<StorageProviderResponse> getImageDataStoreProviders() {
         List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>();
         for (DataStoreProvider provider : providerMap.values()) {
-            if (provider instanceof ImageStoreProvider) {
+            if (provider.getTypes().contains(DataStoreProviderType.IMAGE)) {
                 StorageProviderResponse response = new StorageProviderResponse();
                 response.setName(provider.getName());
                 response.setType(DataStoreProvider.DataStoreProviderType.IMAGE.toString());
@@ -90,6 +90,19 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
         }
         return providers;
     }
+    
+    public List<StorageProviderResponse> getCacheDataStoreProviders() {
+        List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>();
+        for (DataStoreProvider provider : providerMap.values()) {
+            if (provider.getTypes().contains(DataStoreProviderType.ImageCache)) {
+                StorageProviderResponse response = new StorageProviderResponse();
+                response.setName(provider.getName());
+                response.setType(DataStoreProviderType.ImageCache.toString());
+                providers.add(response);
+            }
+        }
+        return providers;
+    }
 
     @Override
     public boolean configure(String name, Map<String, Object> params)
@@ -125,6 +138,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
             } catch(Exception e) {
                 s_logger.debug("configure provider failed", e);
                 providerMap.remove(providerName);
+                return false;
             }
         }
 
@@ -141,6 +155,11 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
     public DataStoreProvider getDefaultImageDataStoreProvider() {
         return this.getDataStoreProvider("CloudStack ImageStore Provider");
     }
+    
+    @Override
+    public DataStoreProvider getDefaultCacheDataStoreProvider() {
+        return this.getDataStoreProvider("cloudstack image store provider");
+    }
 
     @Override
     public List<StorageProviderResponse> getDataStoreProviders(String type) {
@@ -151,6 +170,8 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto
             return this.getPrimaryDataStoreProviders();
         } else if (type.equalsIgnoreCase(DataStoreProvider.DataStoreProviderType.IMAGE.toString())) {
             return this.getImageDataStoreProviders();
+        } else if (type.equalsIgnoreCase(DataStoreProvider.DataStoreProviderType.ImageCache.toString())) {
+           return this.getCacheDataStoreProviders();
         } else {
             throw new InvalidParameterValueException("Invalid parameter: " + type);
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
index 33fda48..a4d3db9 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailVO;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
@@ -52,6 +53,7 @@ public class ImageStoreHelper {
         store.setScope((ScopeType)params.get("scope"));
         store.setUuid((String)params.get("uuid"));
         store.setUrl((String)params.get("url"));
+        store.setRole(DataStoreRole.getRole((String)params.get("role")));
         store = imageStoreDao.persist(store);
         return store;
     }
@@ -68,6 +70,7 @@ public class ImageStoreHelper {
         store.setScope((ScopeType)params.get("scope"));
         store.setUuid((String)params.get("uuid"));
         store.setUrl((String)params.get("url"));
+        store.setRole(DataStoreRole.getRole((String)params.get("role")));
         store = imageStoreDao.persist(store);
 
         // persist details

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
index 2026346..f8fa281 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreProviderManager.java
@@ -31,5 +31,6 @@ public interface ImageStoreProviderManager {
     List<DataStore> listImageStores();
     List<DataStore> listImageStoresByScope(ZoneScope scope);
     List<DataStore> listImageStoreByProvider(String provider);
+    List<DataStore> listImageCacheStores(Scope scope);
     boolean registerDriver(String uuid, ImageStoreDriver driver);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java b/engine/storage/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
deleted file mode 100644
index 3602bb1..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java
+++ /dev/null
@@ -1,725 +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.motion;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
-import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
-import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.BackupSnapshotAnswer;
-import com.cloud.agent.api.BackupSnapshotCommand;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
-import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
-import com.cloud.agent.api.CreateVolumeFromSnapshotAnswer;
-import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
-import com.cloud.agent.api.UpgradeSnapshotCommand;
-import com.cloud.agent.api.storage.CopyVolumeAnswer;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.CreateAnswer;
-import com.cloud.agent.api.storage.CreateCommand;
-import com.cloud.agent.api.storage.CreatePrivateTemplateAnswer;
-import com.cloud.agent.api.to.S3TO;
-import com.cloud.agent.api.to.StorageFilerTO;
-import com.cloud.agent.api.to.SwiftTO;
-import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.storage.DiskOfferingVO;
-import com.cloud.storage.SnapshotVO;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.StorageManager;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateStoragePoolVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VolumeHostVO;
-import com.cloud.storage.VolumeManager;
-import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.DiskOfferingDao;
-import com.cloud.storage.dao.SnapshotDao;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplateHostDao;
-import com.cloud.storage.dao.VMTemplatePoolDao;
-import com.cloud.storage.dao.VolumeDao;
-import com.cloud.storage.dao.VolumeHostDao;
-import com.cloud.storage.s3.S3Manager;
-import com.cloud.storage.snapshot.SnapshotManager;
-import com.cloud.storage.swift.SwiftManager;
-import com.cloud.template.TemplateManager;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.DiskProfile;
-
-@Component
-public class AncientDataMotionStrategy implements DataMotionStrategy {
-    private static final Logger s_logger = Logger
-            .getLogger(AncientDataMotionStrategy.class);
-    @Inject
-    TemplateManager templateMgr;
-    @Inject
-    VolumeHostDao volumeHostDao;
-    @Inject
-    HostDao hostDao;
-    @Inject
-    ConfigurationDao configDao;
-    @Inject
-    StorageManager storageMgr;
-    @Inject
-    VolumeDao volDao;
-    @Inject
-    VMTemplateDao templateDao;
-    @Inject
-    SnapshotManager snapshotMgr;
-    @Inject
-    SnapshotDao snapshotDao;
-    @Inject
-    PrimaryDataStoreDao primaryDataStoreDao;
-    @Inject
-    DataStoreManager dataStoreMgr;
-    @Inject
-    VMTemplateHostDao templateHostDao;
-    @Inject DiskOfferingDao diskOfferingDao;
-    @Inject VMTemplatePoolDao templatePoolDao;
-    @Inject
-    VolumeManager volumeMgr;
-    @Inject
-    private SwiftManager _swiftMgr;
-    @Inject 
-    private S3Manager _s3Mgr;
-
-    @Override
-    public boolean canHandle(DataObject srcData, DataObject destData) {
-        // TODO Auto-generated method stub
-        return true;
-    }
-
-    @DB
-    protected Answer copyVolumeFromImage(DataObject srcData, DataObject destData) {
-        String value = configDao.getValue(Config.RecreateSystemVmEnabled.key());
-        int _copyvolumewait = NumbersUtil.parseInt(value,
-                Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
-
-        VolumeHostVO volumeHostVO = volumeHostDao.findByVolumeId(srcData
-                .getId());
-        HostVO secStorage = hostDao.findById(volumeHostVO.getHostId());
-        String secondaryStorageURL = secStorage.getStorageUrl();
-        String[] volumePath = volumeHostVO.getInstallPath().split("/");
-        String volumeUUID = volumePath[volumePath.length - 1].split("\\.")[0];
-        StoragePool destPool = (StoragePool) destData.getDataStore();
-        CopyVolumeCommand cvCmd = new CopyVolumeCommand(srcData.getId(),
-                volumeUUID, destPool, secondaryStorageURL, false,
-                _copyvolumewait);
-        CopyVolumeAnswer cvAnswer = null;
-        String errMsg = null;
-        try {
-            cvAnswer = (CopyVolumeAnswer) this.storageMgr.sendToPool(destPool,
-                    cvCmd);
-        } catch (StorageUnavailableException e1) {
-            s_logger.debug("Failed to copy volume " + srcData.getId() + " to "
-                    + destData.getId(), e1);
-            errMsg = e1.toString();
-        }
-
-        if (cvAnswer == null || !cvAnswer.getResult()) {
-            errMsg = cvAnswer.getDetails();
-        }
-
-        VolumeVO vol = this.volDao.findById(destData.getId());
-        Transaction txn = Transaction.currentTxn();
-        txn.start();
-        vol.setPath(cvAnswer.getVolumePath());
-        vol.setFolder(destPool.getPath());
-        vol.setPodId(destPool.getPodId());
-        vol.setPoolId(destPool.getId());
-        vol.setPodId(destPool.getPodId());
-
-        this.volDao.update(vol.getId(), vol);
-        volumeHostDao.remove(volumeHostVO.getId());
-        txn.commit();
-        return cvAnswer;
-    }
-
-    private Answer copyTemplate(DataObject srcData, DataObject destData) {
-        VMTemplateVO template = this.templateDao.findById(srcData.getId());
-        templateMgr.prepareTemplateForCreate(template,
-                (StoragePool) destData.getDataStore());
-        return null;
-    }
-
-    protected Answer copyFromSnapshot(DataObject snapObj, DataObject volObj) {
-        SnapshotVO snapshot = this.snapshotDao.findById(snapObj.getId());
-        StoragePool pool = (StoragePool) volObj.getDataStore();
-        String vdiUUID = null;
-        Long snapshotId = snapshot.getId();
-        Long volumeId = snapshot.getVolumeId();
-        Long dcId = snapshot.getDataCenterId();
-        String secondaryStoragePoolUrl = this.snapshotMgr
-                .getSecondaryStorageURL(snapshot);
-        long accountId = snapshot.getAccountId();
-
-        String backedUpSnapshotUuid = snapshot.getBackupSnapshotId();
-        snapshot = snapshotDao.findById(snapshotId);
-        if (snapshot.getVersion().trim().equals("2.1")) {
-            VolumeVO volume = this.volDao.findByIdIncludingRemoved(volumeId);
-            if (volume == null) {
-                throw new CloudRuntimeException("failed to upgrade snapshot "
-                        + snapshotId + " due to unable to find orignal volume:"
-                        + volumeId + ", try it later ");
-            }
-            if (volume.getTemplateId() == null) {
-                snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2");
-            } else {
-                VMTemplateVO template = templateDao
-                        .findByIdIncludingRemoved(volume.getTemplateId());
-                if (template == null) {
-                    throw new CloudRuntimeException(
-                            "failed to upgrade snapshot "
-                                    + snapshotId
-                                    + " due to unalbe to find orignal template :"
-                                    + volume.getTemplateId()
-                                    + ", try it later ");
-                }
-                Long templateId = template.getId();
-                Long tmpltAccountId = template.getAccountId();
-                if (!snapshotDao.lockInLockTable(snapshotId.toString(), 10)) {
-                    throw new CloudRuntimeException(
-                            "failed to upgrade snapshot "
-                                    + snapshotId
-                                    + " due to this snapshot is being used, try it later ");
-                }
-                UpgradeSnapshotCommand cmd = new UpgradeSnapshotCommand(null,
-                        secondaryStoragePoolUrl, dcId, accountId, volumeId,
-                        templateId, tmpltAccountId, null,
-                        snapshot.getBackupSnapshotId(), snapshot.getName(),
-                        "2.1");
-                Answer answer = null;
-                try {
-                    answer = this.storageMgr.sendToPool(pool, cmd);
-                } catch (StorageUnavailableException e) {
-                } finally {
-                    snapshotDao.unlockFromLockTable(snapshotId.toString());
-                }
-                if ((answer != null) && answer.getResult()) {
-                    snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2");
-                } else {
-                    throw new CloudRuntimeException("Unable to upgrade snapshot from 2.1 to 2.2 for "
-                            + snapshot.getId());
-                }
-            }
-        }
-        String basicErrMsg = "Failed to create volume from "
-                + snapshot.getName() + " on pool " + pool;
-
-        try {
-            if (snapshot.getSwiftId() != null && snapshot.getSwiftId() != 0) {
-                snapshotMgr.downloadSnapshotsFromSwift(snapshot);
-            } else if (snapshot.getS3Id() != null && snapshot.getS3Id() != 0) {
-                snapshotMgr.downloadSnapshotsFromS3(snapshot);
-            }
-            String value = configDao
-                    .getValue(Config.CreateVolumeFromSnapshotWait.toString());
-            int _createVolumeFromSnapshotWait = NumbersUtil.parseInt(value,
-                    Integer.parseInt(Config.CreateVolumeFromSnapshotWait
-                            .getDefaultValue()));
-            CreateVolumeFromSnapshotCommand createVolumeFromSnapshotCommand = new CreateVolumeFromSnapshotCommand(
-                    pool, secondaryStoragePoolUrl, dcId, accountId, volumeId,
-                    backedUpSnapshotUuid, snapshot.getName(),
-                    _createVolumeFromSnapshotWait);
-            CreateVolumeFromSnapshotAnswer answer;
-            if (!snapshotDao.lockInLockTable(snapshotId.toString(), 10)) {
-                throw new CloudRuntimeException("failed to create volume from "
-                        + snapshotId
-                        + " due to this snapshot is being used, try it later ");
-            }
-            answer = (CreateVolumeFromSnapshotAnswer) this.storageMgr
-                    .sendToPool(pool, createVolumeFromSnapshotCommand);
-            if (answer != null && answer.getResult()) {
-                vdiUUID = answer.getVdi();
-                VolumeVO vol = this.volDao.findById(volObj.getId());
-                vol.setPath(vdiUUID);
-                this.volDao.update(vol.getId(), vol);
-                return null;
-            } else {
-                s_logger.error(basicErrMsg + " due to "
-                        + ((answer == null) ? "null" : answer.getDetails()));
-                throw new CloudRuntimeException(basicErrMsg);
-            }
-        } catch (StorageUnavailableException e) {
-            s_logger.error(basicErrMsg, e);
-            throw new CloudRuntimeException(basicErrMsg);
-        } finally {
-            if (snapshot.getSwiftId() != null) {
-                snapshotMgr.deleteSnapshotsDirForVolume(
-                        secondaryStoragePoolUrl, dcId, accountId, volumeId);
-            }
-        }
-    }
-    
-    protected Answer cloneVolume(DataObject template, DataObject volume) {
-        VolumeInfo volInfo = (VolumeInfo)volume;
-        DiskOfferingVO offering = diskOfferingDao.findById(volInfo.getDiskOfferingId());
-        VMTemplateStoragePoolVO  tmpltStoredOn =  templatePoolDao.findByPoolTemplate(template.getDataStore().getId(), template.getId());
-        
-        DiskProfile diskProfile = new DiskProfile(volInfo, offering,
-                null);
-        CreateCommand cmd = new CreateCommand(diskProfile,
-                tmpltStoredOn.getLocalDownloadPath(),
-                new StorageFilerTO((StoragePool)template.getDataStore()));
-        Answer answer = null;
-        StoragePool pool = (StoragePool)volume.getDataStore();
-        String errMsg = null;
-        try {
-            answer = storageMgr.sendToPool(pool, null, cmd);
-        } catch (StorageUnavailableException e) {
-            s_logger.debug("Failed to send to storage pool", e);
-            throw new CloudRuntimeException("Failed to send to storage pool", e);
-        }
-        
-        if (answer.getResult()) {
-            VolumeVO vol = this.volDao.findById(volume.getId());
-            CreateAnswer createAnswer = (CreateAnswer) answer;
-            vol.setFolder(pool.getPath());
-            vol.setPath(createAnswer.getVolume().getPath());
-            vol.setSize(createAnswer.getVolume().getSize());
-            vol.setPoolType(pool.getPoolType());
-            vol.setPoolId(pool.getId());
-            vol.setPodId(pool.getPodId());
-            this.volDao.update(vol.getId(), vol);
-           
-        } else {
-            if (tmpltStoredOn != null
-                    && (answer instanceof CreateAnswer)
-                    && ((CreateAnswer) answer)
-                            .templateReloadRequested()) {
-                if (!templateMgr
-                        .resetTemplateDownloadStateOnPool(tmpltStoredOn
-                                .getId())) {
-                   
-                }
-            }
-            errMsg = answer.getDetails();
-        }
-        
-        return answer;
-    }
-    
-    protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData) {
-        VolumeInfo volume = (VolumeInfo)srcData;
-        VolumeInfo destVolume = (VolumeInfo)destData;
-        String secondaryStorageURL = this.templateMgr.getSecondaryStorageURL(volume
-                .getDataCenterId());
-        StoragePool srcPool = (StoragePool)this.dataStoreMgr.getDataStore(volume
-                .getPoolId(), DataStoreRole.Primary);
-        
-        StoragePool destPool = (StoragePool)this.dataStoreMgr.getDataStore(destVolume.getPoolId(), DataStoreRole.Primary);
-        
-        String value = this.configDao.getValue(Config.CopyVolumeWait.toString());
-        int _copyvolumewait = NumbersUtil.parseInt(value,
-                Integer.parseInt(Config.CopyVolumeWait.getDefaultValue()));
-        CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(),
-                volume.getPath(), srcPool, secondaryStorageURL, true,
-                _copyvolumewait);
-        CopyVolumeAnswer cvAnswer;
-        try {
-            cvAnswer = (CopyVolumeAnswer) this.storageMgr.sendToPool(srcPool, cvCmd);
-        } catch (StorageUnavailableException e1) {
-            throw new CloudRuntimeException(
-                    "Failed to copy the volume from the source primary storage pool to secondary storage.",
-                    e1);
-        }
-
-        if (cvAnswer == null || !cvAnswer.getResult()) {
-            throw new CloudRuntimeException(
-                    "Failed to copy the volume from the source primary storage pool to secondary storage.");
-        }
-
-        String secondaryStorageVolumePath = cvAnswer.getVolumePath();
-        
-        cvCmd = new CopyVolumeCommand(volume.getId(),
-                secondaryStorageVolumePath, destPool,
-                secondaryStorageURL, false, _copyvolumewait);
-        try {
-            cvAnswer = (CopyVolumeAnswer) this.storageMgr.sendToPool(destPool, cvCmd);
-        } catch (StorageUnavailableException e1) {
-            throw new CloudRuntimeException(
-                    "Failed to copy the volume from secondary storage to the destination primary storage pool.");
-        }
-
-        if (cvAnswer == null || !cvAnswer.getResult()) {
-            throw new CloudRuntimeException(
-                    "Failed to copy the volume from secondary storage to the destination primary storage pool.");
-        }
-        
-        VolumeVO destVol = this.volDao.findById(destVolume.getId());
-        destVol.setPath(cvAnswer.getVolumePath());
-        this.volDao.update(destVol.getId(), destVol);
-        return cvAnswer;
-    }
-
-    @Override
-    public Void copyAsync(DataObject srcData, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback) {
-        Answer answer = null;
-        String errMsg = null;
-        try {
-            if (destData.getType() == DataObjectType.VOLUME
-                    && srcData.getType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Image) {
-            	answer = copyVolumeFromImage(srcData, destData);
-            } else if (destData.getType() == DataObjectType.TEMPLATE
-                    && srcData.getType() == DataObjectType.TEMPLATE) {
-            	answer = copyTemplate(srcData, destData);
-            } else if (srcData.getType() == DataObjectType.SNAPSHOT
-                    && destData.getType() == DataObjectType.VOLUME) {
-            	answer = copyFromSnapshot(srcData, destData);
-            } else if (srcData.getType() == DataObjectType.SNAPSHOT
-                    && destData.getType() == DataObjectType.TEMPLATE) {
-            	answer = createTemplateFromSnashot(srcData, destData);
-            } else if (srcData.getType() == DataObjectType.VOLUME
-                    && destData.getType() == DataObjectType.TEMPLATE) {
-            	answer = createTemplateFromVolume(srcData, destData);
-            } else if (srcData.getType() == DataObjectType.TEMPLATE 
-                    && destData.getType() == DataObjectType.VOLUME) {
-            	answer = cloneVolume(srcData, destData);
-            } else if (destData.getType() == DataObjectType.VOLUME
-                    && srcData.getType() == DataObjectType.VOLUME && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
-            	answer = copyVolumeBetweenPools(srcData, destData);
-            } else if (srcData.getType() == DataObjectType.SNAPSHOT &&
-            		destData.getType() == DataObjectType.SNAPSHOT) {
-            	answer = copySnapshot(srcData, destData);
-            }
-        } catch (Exception e) {
-            s_logger.debug("copy failed", e);
-            errMsg = e.toString();
-        }
-        CopyCommandResult result = new CopyCommandResult(null, answer);
-        result.setResult(errMsg);
-        callback.complete(result);
-
-        return null;
-    }
-
-    @DB
-    protected Answer createTemplateFromSnashot(DataObject srcData,
-            DataObject destData) {
-        long snapshotId = srcData.getId();
-        SnapshotVO snapshot = snapshotDao.findById(snapshotId);
-        if (snapshot == null) {
-            throw new CloudRuntimeException("Unable to find Snapshot for Id "
-                    + srcData.getId());
-        }
-        Long zoneId = snapshot.getDataCenterId();
-        HostVO secondaryStorageHost = this.templateMgr
-                .getSecondaryStorageHost(zoneId);
-        String secondaryStorageURL = snapshotMgr
-                .getSecondaryStorageURL(snapshot);
-        VMTemplateVO template = this.templateDao.findById(destData.getId());
-        String name = template.getName();
-        String backupSnapshotUUID = snapshot.getBackupSnapshotId();
-        if (backupSnapshotUUID == null) {
-            throw new CloudRuntimeException(
-                    "Unable to create private template from snapshot "
-                            + snapshotId
-                            + " due to there is no backupSnapshotUUID for this snapshot");
-        }
-
-        Long dcId = snapshot.getDataCenterId();
-        Long accountId = snapshot.getAccountId();
-        Long volumeId = snapshot.getVolumeId();
-
-        String origTemplateInstallPath = null;
-        List<StoragePoolVO> pools = this.storageMgr
-                .ListByDataCenterHypervisor(zoneId,
-                        snapshot.getHypervisorType());
-        if (pools == null || pools.size() == 0) {
-            throw new CloudRuntimeException(
-                    "Unable to find storage pools in zone " + zoneId);
-        }
-        StoragePoolVO poolvo = pools.get(0);
-        StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
-                poolvo.getId(), DataStoreRole.Primary);
-        if (snapshot.getVersion() != null
-                && snapshot.getVersion().equalsIgnoreCase("2.1")) {
-            VolumeVO volume = this.volDao.findByIdIncludingRemoved(volumeId);
-            if (volume == null) {
-                throw new CloudRuntimeException("failed to upgrade snapshot "
-                        + snapshotId + " due to unable to find orignal volume:"
-                        + volumeId + ", try it later ");
-            }
-            if (volume.getTemplateId() == null) {
-                snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2");
-            } else {
-                template = templateDao.findByIdIncludingRemoved(volume
-                        .getTemplateId());
-                if (template == null) {
-                    throw new CloudRuntimeException(
-                            "failed to upgrade snapshot "
-                                    + snapshotId
-                                    + " due to unalbe to find orignal template :"
-                                    + volume.getTemplateId()
-                                    + ", try it later ");
-                }
-                Long origTemplateId = template.getId();
-                Long origTmpltAccountId = template.getAccountId();
-                if (!this.volDao.lockInLockTable(volumeId.toString(), 10)) {
-                    throw new CloudRuntimeException(
-                            "failed to upgrade snapshot " + snapshotId
-                                    + " due to volume:" + volumeId
-                                    + " is being used, try it later ");
-                }
-                UpgradeSnapshotCommand cmd = new UpgradeSnapshotCommand(null,
-                        secondaryStorageURL, dcId, accountId, volumeId,
-                        origTemplateId, origTmpltAccountId, null,
-                        snapshot.getBackupSnapshotId(), snapshot.getName(),
-                        "2.1");
-                if (!this.volDao.lockInLockTable(volumeId.toString(), 10)) {
-                    throw new CloudRuntimeException(
-                            "Creating template failed due to volume:"
-                                    + volumeId
-                                    + " is being used, try it later ");
-                }
-                Answer answer = null;
-                try {
-                    answer = this.storageMgr.sendToPool(pool, cmd);
-                    cmd = null;
-                } catch (StorageUnavailableException e) {
-                } finally {
-                    this.volDao.unlockFromLockTable(volumeId.toString());
-                }
-                if ((answer != null) && answer.getResult()) {
-                    snapshotDao.updateSnapshotVersion(volumeId, "2.1", "2.2");
-                } else {
-                    throw new CloudRuntimeException(
-                            "Unable to upgrade snapshot");
-                }
-            }
-        }
-        if (snapshot.getSwiftId() != null && snapshot.getSwiftId() != 0) {
-            snapshotMgr.downloadSnapshotsFromSwift(snapshot);
-        }
-        String value = configDao
-                .getValue(Config.CreatePrivateTemplateFromSnapshotWait
-                        .toString());
-        int _createprivatetemplatefromsnapshotwait = NumbersUtil.parseInt(
-                value, Integer
-                        .parseInt(Config.CreatePrivateTemplateFromSnapshotWait
-                                .getDefaultValue()));
-
-        CreatePrivateTemplateFromSnapshotCommand cmd = new CreatePrivateTemplateFromSnapshotCommand(
-                pool, secondaryStorageURL, dcId, accountId,
-                snapshot.getVolumeId(), backupSnapshotUUID, snapshot.getName(),
-                origTemplateInstallPath, template.getId(), name,
-                _createprivatetemplatefromsnapshotwait);
-
-        return sendCommand(cmd, pool, template.getId(), dcId,
-                secondaryStorageHost.getId());
-    }
-
-    @DB
-    protected Answer sendCommand(Command cmd, StoragePool pool,
-            long templateId, long zoneId, long hostId) {
-
-        CreatePrivateTemplateAnswer answer = null;
-        try {
-            answer = (CreatePrivateTemplateAnswer) this.storageMgr.sendToPool(
-                    pool, cmd);
-        } catch (StorageUnavailableException e) {
-            throw new CloudRuntimeException(
-                    "Failed to execute CreatePrivateTemplateFromSnapshotCommand",
-                    e);
-        }
-
-        if (answer == null || !answer.getResult()) {
-        	return answer;
-        }
-
-        VMTemplateVO privateTemplate = templateDao.findById(templateId);
-        String answerUniqueName = answer.getUniqueName();
-        if (answerUniqueName != null) {
-            privateTemplate.setUniqueName(answerUniqueName);
-        }
-        ImageFormat format = answer.getImageFormat();
-        if (format != null) {
-            privateTemplate.setFormat(format);
-        } else {
-            // This never occurs.
-            // Specify RAW format makes it unusable for snapshots.
-            privateTemplate.setFormat(ImageFormat.RAW);
-        }
-
-        String checkSum = this.templateMgr
-                .getChecksum(hostId, answer.getPath());
-
-        Transaction txn = Transaction.currentTxn();
-
-        txn.start();
-
-        privateTemplate.setChecksum(checkSum);
-        templateDao.update(privateTemplate.getId(), privateTemplate);
-
-        // add template zone ref for this template
-        templateDao.addTemplateToZone(privateTemplate, zoneId);
-        VMTemplateHostVO templateHostVO = new VMTemplateHostVO(hostId,
-                privateTemplate.getId());
-        templateHostVO.setDownloadPercent(100);
-        templateHostVO.setDownloadState(Status.DOWNLOADED);
-        templateHostVO.setInstallPath(answer.getPath());
-        templateHostVO.setLastUpdated(new Date());
-        templateHostVO.setSize(answer.getVirtualSize());
-        templateHostVO.setPhysicalSize(answer.getphysicalSize());
-        templateHostDao.persist(templateHostVO);
-        txn.close();
-        return answer;
-    }
-
-    private Answer createTemplateFromVolume(DataObject srcObj,
-            DataObject destObj) {
-        long volumeId = srcObj.getId();
-        VolumeVO volume = this.volDao.findById(volumeId);
-        if (volume == null) {
-            throw new CloudRuntimeException("Unable to find volume for Id "
-                    + volumeId);
-        }
-        long accountId = volume.getAccountId();
-
-        String vmName = this.volumeMgr.getVmNameOnVolume(volume);
-        Long zoneId = volume.getDataCenterId();
-        HostVO secondaryStorageHost = this.templateMgr
-                .getSecondaryStorageHost(zoneId);
-        if (secondaryStorageHost == null) {
-            throw new CloudRuntimeException(
-                    "Can not find the secondary storage for zoneId " + zoneId);
-        }
-        String secondaryStorageURL = secondaryStorageHost.getStorageUrl();
-        VMTemplateVO template = this.templateDao.findById(destObj.getId());
-        StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(
-                volume.getPoolId(), DataStoreRole.Primary);
-        String value = configDao
-                .getValue(Config.CreatePrivateTemplateFromVolumeWait.toString());
-        int _createprivatetemplatefromvolumewait = NumbersUtil.parseInt(value,
-                Integer.parseInt(Config.CreatePrivateTemplateFromVolumeWait
-                        .getDefaultValue()));
-
-        CreatePrivateTemplateFromVolumeCommand cmd = new CreatePrivateTemplateFromVolumeCommand(
-                pool, secondaryStorageURL, destObj.getId(), accountId,
-                template.getName(), template.getUniqueName(), volume.getPath(),
-                vmName, _createprivatetemplatefromvolumewait);
-
-        return sendCommand(cmd, pool, template.getId(), zoneId,
-                secondaryStorageHost.getId());
-    }
-    
-    private HostVO getSecHost(long volumeId, long dcId) {
-        Long id = snapshotDao.getSecHostId(volumeId);
-        if ( id != null) { 
-            return hostDao.findById(id);
-        }
-        return this.templateMgr.getSecondaryStorageHost(dcId);
-    }
-    
-    protected Answer copySnapshot(DataObject srcObject, DataObject destObject) {
-    	SnapshotInfo srcSnapshot = (SnapshotInfo)srcObject;
-    	VolumeInfo baseVolume = srcSnapshot.getBaseVolume();
-    	 Long dcId = baseVolume.getDataCenterId();
-         Long accountId = baseVolume.getAccountId();
-         
-         HostVO secHost = getSecHost(baseVolume.getId(), baseVolume.getDataCenterId());
-         Long secHostId = secHost.getId();
-         String secondaryStoragePoolUrl = secHost.getStorageUrl();
-         String snapshotUuid = srcSnapshot.getPath();
-         // In order to verify that the snapshot is not empty,
-         // we check if the parent of the snapshot is not the same as the parent of the previous snapshot.
-         // We pass the uuid of the previous snapshot to the plugin to verify this.
-         SnapshotVO prevSnapshot = null;
-         String prevSnapshotUuid = null;
-         String prevBackupUuid = null;
-
-
-         SwiftTO swift = _swiftMgr.getSwiftTO();
-         S3TO s3 = _s3Mgr.getS3TO();
-         
-         long prevSnapshotId = srcSnapshot.getPrevSnapshotId();
-         if (prevSnapshotId > 0) {
-             prevSnapshot = snapshotDao.findByIdIncludingRemoved(prevSnapshotId);
-             if ( prevSnapshot.getBackupSnapshotId() != null && swift == null) {
-                 if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2")) {                   
-                     prevBackupUuid = prevSnapshot.getBackupSnapshotId();
-                     prevSnapshotUuid = prevSnapshot.getPath();
-                 }
-             } else if ((prevSnapshot.getSwiftId() != null && swift != null)
-                     || (prevSnapshot.getS3Id() != null && s3 != null)) {
-                 prevBackupUuid = prevSnapshot.getBackupSnapshotId();
-                 prevSnapshotUuid = prevSnapshot.getPath();
-             }
-         }
-         boolean isVolumeInactive = this.volumeMgr.volumeInactive(baseVolume);
-         String vmName = this.volumeMgr.getVmNameOnVolume(baseVolume);
-         StoragePool srcPool = (StoragePool)dataStoreMgr.getPrimaryDataStore(baseVolume.getPoolId());
-         String value = configDao.getValue(Config.BackupSnapshotWait.toString());
-         int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
-         BackupSnapshotCommand backupSnapshotCommand = new BackupSnapshotCommand(secondaryStoragePoolUrl, dcId, accountId, baseVolume.getId(), srcSnapshot.getId(), secHostId, baseVolume.getPath(), srcPool, snapshotUuid,
-        		 srcSnapshot.getName(), prevSnapshotUuid, prevBackupUuid, isVolumeInactive, vmName, _backupsnapshotwait);
-
-         if ( swift != null ) {
-             backupSnapshotCommand.setSwift(swift);
-         } else if (s3 != null) {
-             backupSnapshotCommand.setS3(s3);
-         }
-         BackupSnapshotAnswer answer = (BackupSnapshotAnswer) this.snapshotMgr.sendToPool(baseVolume, backupSnapshotCommand);
-         if (answer != null && answer.getResult()) {
-        	 SnapshotVO snapshotVO = this.snapshotDao.findById(srcSnapshot.getId());
-        	 if (backupSnapshotCommand.getSwift() != null ) {
-        		 snapshotVO.setSwiftId(swift.getId());
-        		 snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-        	 } else if (backupSnapshotCommand.getS3() != null) {
-        		 snapshotVO.setS3Id(s3.getId());
-        		 snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-        	 } else {
-        		 snapshotVO.setSecHostId(secHost.getId());
-        		 snapshotVO.setBackupSnapshotId(answer.getBackupSnapshotName());
-        	 }
- 			if (answer.isFull()) {
- 				snapshotVO.setPrevSnapshotId(0L);
-			}
-        	 this.snapshotDao.update(srcSnapshot.getId(), snapshotVO);
-         }
-         return answer;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java b/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java
deleted file mode 100644
index 3a59b21..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionDriver.java
+++ /dev/null
@@ -1,25 +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.motion;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-
-public interface DataMotionDriver {
-    public void copy(DataObject srcObj, DataObject destObj);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionService.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionService.java b/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionService.java
deleted file mode 100644
index db36f64..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionService.java
+++ /dev/null
@@ -1,28 +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.motion;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-
-public interface DataMotionService {
-    public void copyAsync(DataObject srcData, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java
deleted file mode 100644
index 343140f..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java
+++ /dev/null
@@ -1,61 +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.motion;
-
-import java.util.List;
-
-import javax.inject.Inject;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-import org.springframework.stereotype.Component;
-
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Component
-public class DataMotionServiceImpl implements DataMotionService {
-    @Inject
-    List<DataMotionStrategy> strategies;
-
-    @Override
-    public void copyAsync(DataObject srcData, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback) {
-
-        if (srcData.getDataStore().getDriver().canCopy(srcData, destData)) {
-            srcData.getDataStore().getDriver()
-                    .copyAsync(srcData, destData, callback);
-            return;
-        } else if (destData.getDataStore().getDriver()
-                .canCopy(srcData, destData)) {
-            destData.getDataStore().getDriver()
-                    .copyAsync(srcData, destData, callback);
-            return;
-        }
-
-        for (DataMotionStrategy strategy : strategies) {
-            if (strategy.canHandle(srcData, destData)) {
-                strategy.copyAsync(srcData, destData, callback);
-                return;
-            }
-        }
-        throw new CloudRuntimeException("can't find strategy to move data");
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionStrategy.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionStrategy.java b/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionStrategy.java
deleted file mode 100644
index ba40c6d..0000000
--- a/engine/storage/src/org/apache/cloudstack/storage/motion/DataMotionStrategy.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.motion;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
-import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
-import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
-
-public interface DataMotionStrategy {
-    public boolean canHandle(DataObject srcData, DataObject destData);
-
-    public Void copyAsync(DataObject srcData, DataObject destData,
-            AsyncCompletionCallback<CopyCommandResult> callback);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/volume/src/org/apache/cloudstack/storage/volume/TemplateInstallStrategyImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/TemplateInstallStrategyImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/TemplateInstallStrategyImpl.java
index 5f1735c..69979e5 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/TemplateInstallStrategyImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/TemplateInstallStrategyImpl.java
@@ -20,12 +20,12 @@ package org.apache.cloudstack.storage.volume;
 
 import javax.inject.Inject;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
 import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
-import org.apache.cloudstack.storage.motion.DataMotionService;
 import org.apache.cloudstack.storage.volume.VolumeServiceImpl.CreateBaseImageResult;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
index 32e7d27..ff504eb 100644
--- a/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
+++ b/engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java
@@ -24,6 +24,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
 import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
 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.DataObject;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
@@ -40,7 +41,6 @@ import org.apache.cloudstack.storage.datastore.DataObjectManager;
 import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
 import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
-import org.apache.cloudstack.storage.motion.DataMotionService;
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
@@ -52,7 +52,6 @@ import com.cloud.storage.VolumeVO;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.utils.db.DB;
-import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.VMInstanceDao;
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/provider/CloudStackImageStoreProviderImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/provider/CloudStackImageStoreProviderImpl.java b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/provider/CloudStackImageStoreProviderImpl.java
index e025cf4..fdeba4d 100644
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/provider/CloudStackImageStoreProviderImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/provider/CloudStackImageStoreProviderImpl.java
@@ -83,6 +83,7 @@ public class CloudStackImageStoreProviderImpl implements ImageStoreProvider {
     public Set<DataStoreProviderType> getTypes() {
         Set<DataStoreProviderType> types =  new HashSet<DataStoreProviderType>();
         types.add(DataStoreProviderType.IMAGE);
+        types.add(DataStoreProviderType.ImageCache);
         return types;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java
index 7724968..78b26bb 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -42,6 +42,7 @@ import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
+import org.apache.cloudstack.api.command.admin.storage.CreateCacheStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeleteImageStoreCmd;
 import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
@@ -1966,6 +1967,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         params.put("details", details);
         params.put("scope", scopeType);
         params.put("providerName", storeProvider.getName());
+        params.put("role", DataStoreRole.Image);
 
         DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
         DataStore store = null;
@@ -2017,6 +2019,74 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
         txn.commit();
         return true;
     }
+    @Override
+    public ImageStore createCacheStore(CreateCacheStoreCmd cmd) {
+        String providerName = cmd.getProviderName();
+        DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);
+
+        if (storeProvider == null) {
+            storeProvider = _dataStoreProviderMgr.getDefaultCacheDataStoreProvider();
+            if (storeProvider == null) {
+                throw new InvalidParameterValueException("can't find cache store provider: " + providerName);
+            }
+        }
+
+        Long dcId = cmd.getZoneId();
+
+        ScopeType scopeType = null;
+        String scope = cmd.getScope();
+        if (scope != null) {
+            try {
+                scopeType = Enum.valueOf(ScopeType.class, scope.toUpperCase());
+             
+            } catch (Exception e) {
+                throw new InvalidParameterValueException("invalid scope" + scope);
+            }
+            
+            if (scopeType != ScopeType.ZONE) {
+                throw new InvalidParameterValueException("Only zone wide cache storage is supported");
+            }
+        }
+        
+        if (scopeType == ScopeType.ZONE && dcId == null) {
+            throw new InvalidParameterValueException("zone id can't be null, if scope is zone");
+        }
+
+
+        // Check if the zone exists in the system
+        DataCenterVO zone = _dcDao.findById(dcId);
+        if (zone == null) {
+            throw new InvalidParameterValueException("Can't find zone by id " + dcId);
+        }
+
+        Account account = UserContext.current().getCaller();
+        if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
+            PermissionDeniedException ex = new PermissionDeniedException(
+                    "Cannot perform this operation, Zone with specified id is currently disabled");
+            ex.addProxyObject(zone, dcId, "dcId");
+            throw ex;
+        }
+
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("zoneId", dcId);
+        params.put("url", cmd.getUrl());
+        params.put("name", cmd.getUrl());
+        params.put("details", cmd.getDetails());
+        params.put("scope", scopeType);
+        params.put("providerName", storeProvider.getName());
+        params.put("role", DataStoreRole.ImageCache);
+
+        DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
+        DataStore store = null;
+        try {
+            store = lifeCycle.initialize(params);
+        } catch (Exception e) {
+            s_logger.debug("Failed to add data store", e);
+            throw new CloudRuntimeException("Failed to add data store", e);
+        }
+
+        return (ImageStore) _dataStoreMgr.getDataStore(store.getId(), DataStoreRole.ImageCache);
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e5bf38ed/tools/apidoc/gen_toc.py
----------------------------------------------------------------------
diff --git a/tools/apidoc/gen_toc.py b/tools/apidoc/gen_toc.py
index ab2456d..e41e883 100644
--- a/tools/apidoc/gen_toc.py
+++ b/tools/apidoc/gen_toc.py
@@ -95,6 +95,7 @@ known_categories = {
     'InstanceGroup': 'VM Group',
     'StorageMaintenance': 'Storage Pool',
     'StoragePool': 'Storage Pool',
+    'CacheStore': 'Storage Pool',
     'StorageProvider': 'Storage Pool',
     'SecurityGroup': 'Security Group',
     'SSH': 'SSH',


Mime
View raw message