cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [2/2] git commit: updated refs/heads/object_store to 9c584b5
Date Mon, 22 Apr 2013 20:21:57 GMT
Use EndPoint to send local/remote command, and hide agentMgr message
passing.


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

Branch: refs/heads/object_store
Commit: 9c584b550058ecf186aef133b308392eaa2a3d0e
Parents: ffdf567
Author: Min Chen <min.chen@citrix.com>
Authored: Mon Apr 22 11:57:28 2013 -0700
Committer: Min Chen <min.chen@citrix.com>
Committed: Mon Apr 22 13:21:28 2013 -0700

----------------------------------------------------------------------
 .../subsystem/api/storage/EndPointSelector.java    |    3 ++
 .../storage/image/TemplateServiceImpl.java         |   24 +++++---------
 .../storage/endpoint/DefaultEndPointSelector.java  |    7 ++++-
 .../storage/volume/VolumeServiceImpl.java          |   22 +++++--------
 .../driver/CloudStackImageStoreDriverImpl.java     |    6 +++-
 .../datastore/driver/S3ImageStoreDriverImpl.java   |    6 +++-
 .../driver/SwiftImageStoreDriverImpl.java          |    6 +++-
 server/src/com/cloud/agent/AgentManager.java       |    3 --
 .../com/cloud/agent/manager/AgentManagerImpl.java  |   17 +----------
 .../src/com/cloud/storage/StorageManagerImpl.java  |   24 ++++++++-------
 .../cloud/storage/download/DownloadListener.java   |    8 ++--
 .../secondary/SecondaryStorageManagerImpl.java     |   20 ------------
 .../secondary/SecondaryStorageVmManager.java       |    1 -
 .../com/cloud/template/TemplateManagerImpl.java    |   10 ++++--
 .../test/com/cloud/agent/MockAgentManagerImpl.java |   12 -------
 15 files changed, 67 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
index fe3a1b7..d3eb1ec 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/EndPointSelector.java
@@ -29,6 +29,9 @@ public interface EndPointSelector {
      * @return
      */
     EndPoint select(DataObject object);
+
+    EndPoint select(DataStore store);
+
     /**
      * @param store
      * @return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
index 0057012..2e0da4d 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java
@@ -34,6 +34,8 @@ 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.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
@@ -58,14 +60,12 @@ import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.storage.DeleteTemplateCommand;
 import com.cloud.agent.api.storage.ListTemplateAnswer;
 import com.cloud.agent.api.storage.ListTemplateCommand;
 import com.cloud.alert.AlertManager;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.StoragePool;
@@ -129,6 +129,8 @@ public class TemplateServiceImpl implements TemplateService {
     @Inject
     TemplateDataFactory _templateFactory;
     @Inject VMTemplatePoolDao _tmpltPoolDao;
+    @Inject
+    EndPointSelector _epSelector;
 
     class TemplateOpContext<T> extends AsyncRpcConext<T> {
         final TemplateObject template;
@@ -179,7 +181,7 @@ public class TemplateServiceImpl implements TemplateService {
             }
         }
     }
-    
+
     @Override
     public void handleSysTemplateDownload(HypervisorType hostHyper, Long dcId) {
         Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
@@ -377,17 +379,8 @@ public class TemplateServiceImpl implements TemplateService {
             List<UserVmVO> userVmUsingIso = _userVmDao.listByIsoId(tInfo.getId());
             //check if there is any Vm using this ISO.
             if (userVmUsingIso == null || userVmUsingIso.isEmpty()) {
-                VMTemplateVO template = _templateDao.findById(tInfo.getId());
-                DeleteTemplateCommand dtCommand = new DeleteTemplateCommand(store.getTO(),
store.getUri(), tInfo.getInstallPath(), template.getId(), template.getAccountId());
-                try {
-                    _agentMgr.sendToSecStorage(store, dtCommand, null);
-                } catch (AgentUnavailableException e) {
-                    String err = "Failed to delete " + tInfo.getTemplateName() + " on secondary
storage " + storeId + " which isn't in the database";
-                    s_logger.error(err);
-                    return;
-                }
-
-                String description = "Deleted template " + tInfo.getTemplateName() + " on
secondary storage " + storeId + " since it isn't in the database";
+                deleteTemplateAsync(_templateFactory.getTemplate(tInfo.getId(), store));
+                String description = "Deleted template " + tInfo.getTemplateName() + " on
secondary storage " + storeId;
                 s_logger.info(description);
             }
         }
@@ -423,7 +416,8 @@ public class TemplateServiceImpl implements TemplateService {
 
     private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
         ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getUri());
-        Answer answer = _agentMgr.sendToSecStorage(ssStore, cmd);
+        EndPoint ep = _epSelector.select(ssStore);
+        Answer answer = ep.sendMessage(cmd);
         if (answer != null && answer.getResult()) {
             ListTemplateAnswer tanswer = (ListTemplateAnswer)answer;
             return tanswer.getTemplateInfo();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
index 37ebccd..f48c8e9 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java
@@ -210,6 +210,12 @@ public class DefaultEndPointSelector implements EndPointSelector {
     @Override
     public EndPoint select(DataObject object) {
         DataStore store = object.getDataStore();
+        return select(store);
+    }
+
+
+    @Override
+    public EndPoint select(DataStore store) {
         if (store.getRole() == DataStoreRole.Primary) {
             return findEndpointForPrimaryStorage(store);
         } else if (store.getRole() == DataStoreRole.Image) {
@@ -219,7 +225,6 @@ public class DefaultEndPointSelector implements EndPointSelector {
         }else {
             throw new CloudRuntimeException("not implemented yet");
         }
-
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/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 42c61f3..99ac50a 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
@@ -32,6 +32,8 @@ 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.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
@@ -53,14 +55,12 @@ import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.storage.DeleteVolumeCommand;
 import com.cloud.agent.api.storage.ListVolumeAnswer;
 import com.cloud.agent.api.storage.ListVolumeCommand;
 import com.cloud.alert.AlertManager;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.storage.StoragePool;
@@ -119,6 +119,8 @@ public class VolumeServiceImpl implements VolumeService {
     VolumeDataStoreDao _volumeStoreDao;
     @Inject
     VolumeDao _volumeDao;
+    @Inject
+    EndPointSelector _epSelector;
 
     public VolumeServiceImpl() {
     }
@@ -659,7 +661,7 @@ public class VolumeServiceImpl implements VolumeService {
         } else {
             vo.stateTransit(Volume.Event.OperationSucceeded);
         }*/
-        
+
     	_resourceLimitMgr.incrementResourceCount(vo.getAccountId(), ResourceType.secondary_storage,
               	vo.getSize());
         VolumeApiResult res = new VolumeApiResult(vo);
@@ -815,16 +817,9 @@ public class VolumeServiceImpl implements VolumeService {
         //Delete volumes which are not present on DB.
         for (Long uniqueName : volumeInfos.keySet()) {
             TemplateProp vInfo = volumeInfos.get(uniqueName);
-            DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(store.getUri(), vInfo.getInstallPath());
-            try {
-                _agentMgr.sendToSecStorage(store, dtCommand, null);
-            } catch (AgentUnavailableException e) {
-                String err = "Failed to delete " + vInfo.getTemplateName() + " on image store
" + storeId + " which isn't in the database";
-                s_logger.error(err);
-                return;
-            }
+            this.expungeVolumeAsync(this.volFactory.getVolume(vInfo.getId(), store));
 
-            String description = "Deleted volume " + vInfo.getTemplateName() + " on image
store " + storeId + " since it isn't in the database";
+            String description = "Deleted volume " + vInfo.getTemplateName() + " on image
store " + storeId;
             s_logger.info(description);
         }
 
@@ -832,7 +827,8 @@ public class VolumeServiceImpl implements VolumeService {
 
     private Map<Long, TemplateProp> listVolume(DataStore store) {
         ListVolumeCommand cmd = new ListVolumeCommand(store.getUri());
-        Answer answer = _agentMgr.sendToSecStorage(store, cmd);
+        EndPoint ep = _epSelector.select(store);
+        Answer answer = ep.sendMessage(cmd);
         if (answer != null && answer.getResult()) {
             ListVolumeAnswer tanswer = (ListVolumeAnswer)answer;
             return tanswer.getTemplateInfo();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
index 46aae56..d9113b4 100644
--- a/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
+++ b/plugins/storage/image/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackImageStoreDriverImpl.java
@@ -32,6 +32,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
 import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
@@ -115,6 +116,7 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
     @Inject
     private AgentManager _agentMgr;
     @Inject TemplateDataStoreDao _templateStoreDao;
+    @Inject EndPointSelector _epSelector;
 
 
     @Override
@@ -295,7 +297,9 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver
{
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                Answer answer = _agentMgr.sendToSecStorage(store, new DeleteTemplateCommand(store.getTO(),
store.getUri(), installPath, template.getId(), template.getAccountId()));
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                EndPoint ep = _epSelector.select(templateObj);
+                Answer answer = ep.sendMessage(cmd);
 
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to deleted template at store: " + store.getName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
index 6f5d554..366d2e5 100644
--- a/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
+++ b/plugins/storage/image/s3/src/org/apache/cloudstack/storage/datastore/driver/S3ImageStoreDriverImpl.java
@@ -33,6 +33,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcConext;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
@@ -110,6 +111,7 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
     @Inject
     private AgentManager _agentMgr;
     @Inject TemplateDataStoreDao _templateStoreDao;
+    @Inject EndPointSelector _epSelector;
 
     @Override
     public String grantAccess(DataObject data, EndPoint ep) {
@@ -243,7 +245,9 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                Answer answer = _agentMgr.sendToSecStorage(store, new DeleteTemplateCommand(store.getTO(),
store.getUri(), installPath, template.getId(), template.getAccountId()));
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                EndPoint ep = _epSelector.select(templateObj);
+                Answer answer = ep.sendMessage(cmd);
 
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to deleted template at store: " + store.getName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
index 1b9ab2d..1493616 100644
--- a/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
+++ b/plugins/storage/image/swift/src/org/apache/cloudstack/storage/datastore/driver/SwiftImageStoreDriverImpl.java
@@ -33,6 +33,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataTO;
 import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
 import org.apache.cloudstack.framework.async.AsyncRpcConext;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
@@ -110,6 +111,7 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
     @Inject
     private AgentManager _agentMgr;
     @Inject TemplateDataStoreDao _templateStoreDao;
+    @Inject EndPointSelector _epSelector;
 
     @Override
     public String grantAccess(DataObject data, EndPoint ep) {
@@ -236,7 +238,9 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
             TemplateDataStoreVO tmplStore = _templateStoreDao.findByStoreTemplate(storeId,
templateId);
             String installPath = tmplStore.getInstallPath();
             if (installPath != null) {
-                Answer answer = _agentMgr.sendToSecStorage(store, new DeleteTemplateCommand(store.getTO(),
store.getUri(), installPath, template.getId(), template.getAccountId()));
+                DeleteTemplateCommand cmd = new DeleteTemplateCommand(store.getTO(), store.getUri(),
installPath, template.getId(), template.getAccountId());
+                EndPoint ep = _epSelector.select(templateObj);
+                Answer answer = ep.sendMessage(cmd);
 
                 if (answer == null || !answer.getResult()) {
                     s_logger.debug("Failed to deleted template at store: " + store.getName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/agent/AgentManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/AgentManager.java b/server/src/com/cloud/agent/AgentManager.java
index 8071f28..e4d5597 100755
--- a/server/src/com/cloud/agent/AgentManager.java
+++ b/server/src/com/cloud/agent/AgentManager.java
@@ -141,9 +141,6 @@ public interface AgentManager extends Manager {
 
     Answer sendToSecStorage(HostVO ssHost, Command cmd);
 
-    void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws AgentUnavailableException;
-
-    Answer sendToSecStorage(DataStore ssStore, Command cmd);
 
     /* working as a lock while agent is being loaded */
     public boolean tapLoadingAgents(Long hostId, TapAgentsAction action);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
index c839b82..a32e010 100755
--- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -39,11 +39,8 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
 import com.cloud.agent.StartupCommandProcessor;
@@ -99,7 +96,6 @@ import com.cloud.resource.Discoverer;
 import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceState;
 import com.cloud.resource.ServerResource;
-import com.cloud.server.ManagementService;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StorageService;
 import com.cloud.storage.dao.StoragePoolHostDao;
@@ -110,7 +106,6 @@ import com.cloud.user.AccountManager;
 import com.cloud.utils.ActionDelegate;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
 import com.cloud.utils.db.DB;
@@ -381,17 +376,6 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager,
Handl
         return attache;
     }
 
-    @Override
-    public Answer sendToSecStorage(DataStore ssStore, Command cmd) {
-        HostVO ssAhost = _ssvmMgr.pickSsvmHost(ssStore);
-        return easySend(ssAhost.getId(), cmd);
-    }
-
-    @Override
-    public void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws
AgentUnavailableException {
-        HostVO ssAhost = _ssvmMgr.pickSsvmHost(ssStore);
-        send(ssAhost.getId(), new Commands(cmd), listener);
-    }
 
     @Override
     public Answer sendToSecStorage(HostVO ssHost, Command cmd) {
@@ -1496,6 +1480,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager,
Handl
         }
     }
 
+    @Override
     public void disconnectWithInvestigation(final long hostId, final Status.Event event)
{
         disconnectInternal(hostId, event, true);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/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 2236575..1a59f66 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -53,6 +53,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
 import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
@@ -328,6 +330,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
     DataStoreProviderManager _dataStoreProviderMgr;
     @Inject
     private TemplateService _imageSrv;
+    @Inject EndPointSelector _epSelector;
 
     protected List<StoragePoolAllocator> _storagePoolAllocators;
     public List<StoragePoolAllocator> getStoragePoolAllocators() {
@@ -1270,17 +1273,16 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager,
C
                                 .getInstallPath();
 
                         if (installPath != null) {
-
-                            Answer answer = _agentMgr.sendToSecStorage(store,
-                                    new DeleteTemplateCommand(
-                                            store.getTO(),
-                                            store.getUri(),
-                                            destroyedTemplateStoreVO
-                                                    .getInstallPath(),
-                                            destroyedTemplate.getId(),
-                                            destroyedTemplate.getAccountId()
-
-                                            ));
+                            EndPoint ep = _epSelector.select(store);
+                            Command cmd = new DeleteTemplateCommand(
+                                    store.getTO(),
+                                    store.getUri(),
+                                    destroyedTemplateStoreVO
+                                            .getInstallPath(),
+                                    destroyedTemplate.getId(),
+                                    destroyedTemplate.getAccountId()
+                                    );
+                            Answer answer = ep.sendMessage(cmd);
 
                             if (answer == null || !answer.getResult()) {
                                 s_logger.debug("Failed to delete "

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/storage/download/DownloadListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/download/DownloadListener.java b/server/src/com/cloud/storage/download/DownloadListener.java
index e54e879..aeb5397 100755
--- a/server/src/com/cloud/storage/download/DownloadListener.java
+++ b/server/src/com/cloud/storage/download/DownloadListener.java
@@ -152,7 +152,7 @@ public class DownloadListener implements Listener {
         DownloadAnswer answer = new DownloadAnswer("", Status.NOT_DOWNLOADED);
         callback(answer);
     }
-    
+
     public AsyncCompletionCallback<DownloadAnswer> getCallback() {
     	return this._callback;
     }
@@ -201,7 +201,7 @@ public class DownloadListener implements Listener {
 	}
 
 	public void logDisconnect() {
-			s_logger.warn("Unable to monitor download progress of " + this.object.getType() + ": "
+ 
+			s_logger.warn("Unable to monitor download progress of " + this.object.getType() + ": "
+
 					this.object.getId() + " at host " + _ssAgent.getId());
 	}
 
@@ -260,7 +260,7 @@ public class DownloadListener implements Listener {
 	public void callback(DownloadAnswer answer) {
 		this._callback.complete(answer);
 	}
-	
+
 	@Override
 	public boolean processCommands(long agentId, long seq, Command[] req) {
 		return false;
@@ -287,7 +287,7 @@ public class DownloadListener implements Listener {
 	        }
 	        _imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId());
 	    }
-	    /* This can be removed since
+	    /* This can be removed
 	    else if ( cmd instanceof StartupStorageCommand) {
 	        StartupStorageCommand storage = (StartupStorageCommand)cmd;
             if( storage.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE
||

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
index 1b50083..7f729c3 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
@@ -1474,26 +1474,6 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements
Secondar
 
 
     @Override
-    public HostVO pickSsvmHost(DataStore store) {
-        if ( store.getRole() == DataStoreRole.Image){
-            Long dcId = null;
-            Scope storeScope = store.getScope();
-            if ( storeScope.getScopeType() == ScopeType.ZONE ){
-                dcId = storeScope.getScopeId();
-            }
-            // find ssvm that can be used to download data to store. For zone-wide image
store, use SSVM for that zone. For region-wide store,
-            // we can arbitrarily pick one ssvm to do that task
-            List<HostVO> ssAHosts = listUpAndConnectingSecondaryStorageVmHost(dcId);
-            if (ssAHosts == null || ssAHosts.isEmpty() ) {
-                return null;
-            }
-            Collections.shuffle(ssAHosts);
-            return ssAHosts.get(0);
-        }
-        return null;
-    }
-
-    @Override
     public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
             ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException,
             InsufficientCapacityException {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java b/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java
index 8565c38..444727b 100755
--- a/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java
+++ b/server/src/com/cloud/storage/secondary/SecondaryStorageVmManager.java
@@ -55,5 +55,4 @@ public interface SecondaryStorageVmManager extends Manager {
     public List<HostVO> listAllTypesSecondaryStorageHostsInOneZone(long dataCenterId);
     public List<HostVO> listUpAndConnectingSecondaryStorageVmHost(Long dcId);
     public HostVO pickSsvmHost(HostVO ssHost);
-    public HostVO pickSsvmHost(DataStore store);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/src/com/cloud/template/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java
index a8d524b..0266995 100755
--- a/server/src/com/cloud/template/TemplateManagerImpl.java
+++ b/server/src/com/cloud/template/TemplateManagerImpl.java
@@ -59,6 +59,8 @@ import org.apache.cloudstack.api.command.user.template.UpdateTemplatePermissions
 import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
+import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
@@ -266,6 +268,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     @Inject VolumeManager volumeMgr;
     @Inject VMTemplateHostDao templateHostDao;
     @Inject ImageStoreDao _imageStoreDao;
+    @Inject EndPointSelector _epSelector;
 
 
     int _primaryStorageDownloadWait;
@@ -807,9 +810,10 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
     public String getChecksum(DataStore store, String templatePath) {
 
         String secUrl = store.getUri();
-        Answer answer;
-        answer = _agentMgr.sendToSecStorage(store, new ComputeChecksumCommand(
-                secUrl, templatePath));
+        EndPoint ep = _epSelector.select(store);
+        ComputeChecksumCommand cmd = new ComputeChecksumCommand(
+                secUrl, templatePath);
+        Answer answer = ep.sendMessage(cmd);
         if (answer != null && answer.getResult()) {
             return answer.getDetails();
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9c584b55/server/test/com/cloud/agent/MockAgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/agent/MockAgentManagerImpl.java b/server/test/com/cloud/agent/MockAgentManagerImpl.java
index 9e7e163..3ebb549 100755
--- a/server/test/com/cloud/agent/MockAgentManagerImpl.java
+++ b/server/test/com/cloud/agent/MockAgentManagerImpl.java
@@ -143,18 +143,6 @@ public class MockAgentManagerImpl extends ManagerBase implements AgentManager
{
 
 
     @Override
-    public void sendToSecStorage(DataStore ssStore, Command cmd, Listener listener) throws
AgentUnavailableException {
-        // TODO Auto-generated method stub
-
-    }
-
-    @Override
-    public Answer sendToSecStorage(DataStore ssStore, Command cmd) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    @Override
     public boolean tapLoadingAgents(Long hostId, TapAgentsAction action) {
         // TODO Auto-generated method stub
         return false;


Mime
View raw message