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

[1/4] CLOUDSTACK-724: add basic zone wide storage support, refactor storage allocator, need ui support

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpOssResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpOssResource.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpOssResource.java
index 357b433..57f5453 100644
--- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpOssResource.java
+++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XcpOssResource.java
@@ -57,7 +57,7 @@ public class XcpOssResource extends CitrixResourceBase {
     @Override
     protected List<File> getPatchFiles() {
         List<File> files = new ArrayList<File>();
-        String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";
+        String patch = "patch";
         String patchfilePath = Script.findScript("", patch);
         if (patchfilePath == null) {
             throw new CloudRuntimeException("Unable to find patch file " + patch);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/plugins/storage-allocators/random/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/storage-allocators/random/pom.xml b/plugins/storage-allocators/random/pom.xml
index 06754ff..223b7cd 100644
--- a/plugins/storage-allocators/random/pom.xml
+++ b/plugins/storage-allocators/random/pom.xml
@@ -26,4 +26,12 @@
     <version>4.2.0-SNAPSHOT</version>
     <relativePath>../../pom.xml</relativePath>
   </parent>
+    <dependencies>
+    <dependency>
+      <groupId>org.apache.cloudstack</groupId>
+      <artifactId>cloud-engine-storage</artifactId>
+      <version>${project.version}</version>
+      <scope>test</scope>
+    </dependency>
+    </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/plugins/storage-allocators/random/src/com/cloud/storage/allocator/RandomStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/plugins/storage-allocators/random/src/com/cloud/storage/allocator/RandomStoragePoolAllocator.java b/plugins/storage-allocators/random/src/com/cloud/storage/allocator/RandomStoragePoolAllocator.java
deleted file mode 100644
index af21f50..0000000
--- a/plugins/storage-allocators/random/src/com/cloud/storage/allocator/RandomStoragePoolAllocator.java
+++ /dev/null
@@ -1,91 +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 com.cloud.storage.allocator;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.server.StatsCollector;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Component
-@Local(value=StoragePoolAllocator.class)
-public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator {
-    private static final Logger s_logger = Logger.getLogger(RandomStoragePoolAllocator.class);
-    
-    @Override
-    public boolean allocatorIsCorrectType(DiskProfile dskCh) {
-    	return true;
-    }
-    
-    @Override
-    public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
-
-    	List<StoragePool> suitablePools = new ArrayList<StoragePool>();
-    	
-    	VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();    	
-    	// Check that the allocator type is correct
-        if (!allocatorIsCorrectType(dskCh)) {
-        	return suitablePools;
-        }
-		long dcId = plan.getDataCenterId();
-		Long podId = plan.getPodId();
-		Long clusterId = plan.getClusterId();
-        s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
-    	List<StoragePoolVO> pools = _storagePoolDao.listBy(dcId, podId, clusterId);
-        if (pools.size() == 0) {
-        	if (s_logger.isDebugEnabled()) {
-        		s_logger.debug("No storage pools available for allocation, returning");
-    		}
-            return suitablePools;
-        }
-        
-        StatsCollector sc = StatsCollector.getInstance();
-        
-        Collections.shuffle(pools);
-    	if (s_logger.isDebugEnabled()) {
-            s_logger.debug("RandomStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
-        }
-        for (StoragePoolVO pool: pools) {
-        	if(suitablePools.size() == returnUpTo){
-        		break;
-        	}        	
-        	if (checkPool(avoid, pool, dskCh, template, null, sc, plan)) {
-        	    StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
-        		suitablePools.add(pol);
-        	}
-        }
-
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("RandomStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools");
-        }
-
-        return suitablePools;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index beeccaf..0ee62cd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -161,9 +161,9 @@
     <module>usage</module>
     <module>utils</module>
     <module>deps/XenServerJava</module>
+    <module>engine</module>
     <module>plugins</module>
     <module>patches</module>
-    <module>engine</module>
     <module>framework</module>
     <module>services</module>
     <module>test</module>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java
index bf62989..cff4cfc 100644
--- a/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java
+++ b/server/src/com/cloud/cluster/agentlb/dao/HostTransferMapDaoImpl.java
@@ -19,6 +19,7 @@ package com.cloud.cluster.agentlb.dao;
 import java.util.Date;
 import java.util.List;
 
+import javax.annotation.PostConstruct;
 import javax.ejb.Local;
 
 import org.apache.log4j.Logger;
@@ -37,30 +38,35 @@ import com.cloud.utils.db.SearchCriteria;
 public class HostTransferMapDaoImpl extends GenericDaoBase<HostTransferMapVO, Long> implements HostTransferMapDao {
     private static final Logger s_logger = Logger.getLogger(HostTransferMapDaoImpl.class);
 
-    protected final SearchBuilder<HostTransferMapVO> AllFieldsSearch;
-    protected final SearchBuilder<HostTransferMapVO> IntermediateStateSearch;
-    protected final SearchBuilder<HostTransferMapVO> ActiveSearch;
+    protected  SearchBuilder<HostTransferMapVO> AllFieldsSearch;
+    protected  SearchBuilder<HostTransferMapVO> IntermediateStateSearch;
+    protected  SearchBuilder<HostTransferMapVO> ActiveSearch;
 
     public HostTransferMapDaoImpl() {
-        AllFieldsSearch = createSearchBuilder();
-        AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("initialOwner", AllFieldsSearch.entity().getInitialOwner(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("futureOwner", AllFieldsSearch.entity().getFutureOwner(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
-        AllFieldsSearch.done();
-        
-        IntermediateStateSearch = createSearchBuilder();
-        IntermediateStateSearch.and("futureOwner", IntermediateStateSearch.entity().getFutureOwner(), SearchCriteria.Op.EQ);
-        IntermediateStateSearch.and("initialOwner", IntermediateStateSearch.entity().getInitialOwner(), SearchCriteria.Op.EQ);
-        IntermediateStateSearch.and("state", IntermediateStateSearch.entity().getState(), SearchCriteria.Op.IN);
-        IntermediateStateSearch.done();
-        
-        ActiveSearch = createSearchBuilder();
-        ActiveSearch.and("created", ActiveSearch.entity().getCreated(),  SearchCriteria.Op.GT);
-        ActiveSearch.and("id", ActiveSearch.entity().getId(), SearchCriteria.Op.EQ);
-        ActiveSearch.and("state", ActiveSearch.entity().getState(), SearchCriteria.Op.EQ);
-        ActiveSearch.done();
-        
+       super();
+    }
+    
+    @PostConstruct
+    public void init() {
+    	 AllFieldsSearch = createSearchBuilder();
+         AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), SearchCriteria.Op.EQ);
+         AllFieldsSearch.and("initialOwner", AllFieldsSearch.entity().getInitialOwner(), SearchCriteria.Op.EQ);
+         AllFieldsSearch.and("futureOwner", AllFieldsSearch.entity().getFutureOwner(), SearchCriteria.Op.EQ);
+         AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), SearchCriteria.Op.EQ);
+         AllFieldsSearch.done();
+         
+         IntermediateStateSearch = createSearchBuilder();
+         IntermediateStateSearch.and("futureOwner", IntermediateStateSearch.entity().getFutureOwner(), SearchCriteria.Op.EQ);
+         IntermediateStateSearch.and("initialOwner", IntermediateStateSearch.entity().getInitialOwner(), SearchCriteria.Op.EQ);
+         IntermediateStateSearch.and("state", IntermediateStateSearch.entity().getState(), SearchCriteria.Op.IN);
+         IntermediateStateSearch.done();
+         
+         ActiveSearch = createSearchBuilder();
+         ActiveSearch.and("created", ActiveSearch.entity().getCreated(),  SearchCriteria.Op.GT);
+         ActiveSearch.and("id", ActiveSearch.entity().getId(), SearchCriteria.Op.EQ);
+         ActiveSearch.and("state", ActiveSearch.entity().getState(), SearchCriteria.Op.EQ);
+         ActiveSearch.done();
+         
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index eb6fb24..b6d49bc 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.consoleproxy.ConsoleProxyManager;
 import com.cloud.ha.HighAvailabilityManager;
@@ -28,7 +30,6 @@ import com.cloud.network.NetworkManager;
 import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
 import com.cloud.server.ManagementServer;
 import com.cloud.storage.StorageManager;
-import com.cloud.storage.allocator.StoragePoolAllocator;
 import com.cloud.storage.secondary.SecondaryStorageVmManager;
 import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.template.TemplateManager;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java
index 4933467..187ceab 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -28,17 +28,23 @@ import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
 import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import com.cloud.dc.*;
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.log4j.Logger;
 
 import com.cloud.agent.manager.allocator.HostAllocator;
-import com.cloud.api.ApiDBUtils;
 import com.cloud.capacity.Capacity;
 import com.cloud.capacity.CapacityManager;
 import com.cloud.capacity.CapacityVO;
 import com.cloud.capacity.dao.CapacityDao;
 import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.dc.Pod;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
@@ -58,7 +64,6 @@ import com.cloud.storage.StoragePool;
 import com.cloud.storage.StoragePoolHostVO;
 import com.cloud.storage.Volume;
 import com.cloud.storage.VolumeVO;
-import com.cloud.storage.allocator.StoragePoolAllocator;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.GuestOSCategoryDao;
 import com.cloud.storage.dao.GuestOSDao;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java
index 697c3dc..07a4232 100755
--- a/server/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/server/src/com/cloud/host/dao/HostDaoImpl.java
@@ -128,6 +128,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
     @Inject protected ClusterDao _clusterDao;
 
     public HostDaoImpl() {
+    	super();
     }
 
     @PostConstruct
@@ -261,7 +262,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
          * UnmanagedDirectConnectSearch.and("lastPinged", UnmanagedDirectConnectSearch.entity().getLastPinged(),
          * SearchCriteria.Op.LTEQ); UnmanagedDirectConnectSearch.cp(); UnmanagedDirectConnectSearch.cp();
          */
+        try {
         HostTransferSearch = _hostTransferDao.createSearchBuilder();
+        } catch (Throwable e) {
+        	s_logger.debug("error", e);
+        }
         HostTransferSearch.and("id", HostTransferSearch.entity().getId(), SearchCriteria.Op.NULL);
         UnmanagedDirectConnectSearch.join("hostTransferSearch", HostTransferSearch, HostTransferSearch.entity().getId(), UnmanagedDirectConnectSearch.entity().getId(), JoinType.LEFTOUTER);
         ClusterManagedSearch = _clusterDao.createSearchBuilder();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/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 9daf77d..ca21f62 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -58,6 +58,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService.VolumeApiResult;
@@ -69,7 +70,6 @@ import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
 import com.cloud.agent.AgentManager;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.BackupSnapshotCommand;
 import com.cloud.agent.api.CleanupSnapshotBackupCommand;
@@ -78,7 +78,6 @@ import com.cloud.agent.api.ManageSnapshotCommand;
 import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.agent.api.storage.DeleteTemplateCommand;
 import com.cloud.agent.api.storage.DeleteVolumeCommand;
-
 import com.cloud.agent.manager.Commands;
 import com.cloud.alert.AlertManager;
 import com.cloud.api.ApiDBUtils;
@@ -100,10 +99,10 @@ import com.cloud.dc.HostPodVO;
 import com.cloud.dc.dao.ClusterDao;
 import com.cloud.dc.dao.DataCenterDao;
 import com.cloud.dc.dao.HostPodDao;
+import com.cloud.deploy.DataCenterDeployment;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.domain.dao.DomainDao;
-
 import com.cloud.event.dao.EventDao;
-import com.cloud.event.dao.UsageEventDao;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConnectionException;
 import com.cloud.exception.InsufficientCapacityException;
@@ -113,7 +112,6 @@ import com.cloud.exception.PermissionDeniedException;
 import com.cloud.exception.ResourceInUseException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.exception.StorageUnavailableException;
-
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.Status;
@@ -132,8 +130,6 @@ import com.cloud.service.dao.ServiceOfferingDao;
 import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.Volume.Type;
-import com.cloud.storage.allocator.StoragePoolAllocator;
-
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.SnapshotPolicyDao;
@@ -146,7 +142,6 @@ import com.cloud.storage.dao.VMTemplateS3Dao;
 import com.cloud.storage.dao.VMTemplateSwiftDao;
 import com.cloud.storage.dao.VolumeDao;
 import com.cloud.storage.dao.VolumeHostDao;
-
 import com.cloud.storage.download.DownloadMonitor;
 import com.cloud.storage.listener.StoragePoolMonitor;
 import com.cloud.storage.listener.VolumeStateListener;
@@ -156,7 +151,11 @@ import com.cloud.storage.snapshot.SnapshotManager;
 import com.cloud.storage.snapshot.SnapshotScheduler;
 import com.cloud.tags.dao.ResourceTagDao;
 import com.cloud.template.TemplateManager;
-import com.cloud.user.*;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+import com.cloud.user.ResourceLimitService;
+import com.cloud.user.User;
+import com.cloud.user.UserContext;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.user.dao.UserDao;
 import com.cloud.utils.NumbersUtil;
@@ -165,20 +164,28 @@ import com.cloud.utils.UriUtils;
 import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.db.*;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.GlobalLock;
+import com.cloud.utils.db.JoinBuilder;
 import com.cloud.utils.db.JoinBuilder.JoinType;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
-
 import com.cloud.vm.DiskProfile;
 import com.cloud.vm.UserVmManager;
 import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine.State;
 import com.cloud.vm.VirtualMachineManager;
 import com.cloud.vm.VirtualMachineProfile;
 import com.cloud.vm.VirtualMachineProfileImpl;
-
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.dao.*;
+import com.cloud.vm.dao.ConsoleProxyDao;
+import com.cloud.vm.dao.DomainRouterDao;
+import com.cloud.vm.dao.SecondaryStorageVmDao;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
 
 @Component
 @Local(value = { StorageManager.class, StorageService.class })
@@ -193,24 +200,10 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
     @Inject
     protected TemplateManager _tmpltMgr;
     @Inject
-    protected AsyncJobManager _asyncMgr;
-    @Inject
-    protected SnapshotManager _snapshotMgr;
-    @Inject
-    protected SnapshotScheduler _snapshotScheduler;
-    @Inject
     protected AccountManager _accountMgr;
     @Inject
     protected ConfigurationManager _configMgr;
     @Inject
-    protected ConsoleProxyManager _consoleProxyMgr;
-    @Inject
-    protected SecondaryStorageVmManager _secStorageMgr;
-    @Inject
-    protected NetworkModel _networkMgr;
-    @Inject
-    protected ServiceOfferingDao _serviceOfferingDao;
-    @Inject
     protected VolumeDao _volsDao;
     @Inject
     protected HostDao _hostDao;
@@ -275,30 +268,14 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
     @Inject
     protected ClusterDao _clusterDao;
     @Inject
-    protected VirtualMachineManager _vmMgr;
-    @Inject
-    protected DomainRouterDao _domrDao;
-    @Inject
-    protected SecondaryStorageVmDao _secStrgDao;
-    @Inject
     protected StoragePoolWorkDao _storagePoolWorkDao;
     @Inject
     protected HypervisorGuruManager _hvGuruMgr;
     @Inject
     protected VolumeDao _volumeDao;
     @Inject
-    protected OCFS2Manager _ocfs2Mgr;
-    @Inject
-    protected ResourceLimitService _resourceLimitMgr;
-    @Inject
     protected SecondaryStorageVmManager _ssvmMgr;
     @Inject
-    protected ResourceManager _resourceMgr;
-    @Inject
-    protected DownloadMonitor _downloadMonitor;
-    @Inject
-    protected ResourceTagDao _resourceTagDao;
-    @Inject
     protected List<StoragePoolAllocator> _storagePoolAllocators;
     @Inject
     ConfigurationDao _configDao;
@@ -464,14 +441,19 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
             VMInstanceVO vm, final Set<StoragePool> avoid) {
 
         VirtualMachineProfile<VMInstanceVO> profile = new VirtualMachineProfileImpl<VMInstanceVO>(
-                vm);
+        		vm);
         for (StoragePoolAllocator allocator : _storagePoolAllocators) {
-            final List<StoragePool> poolList = allocator.allocateToPool(
-                    dskCh, profile, dc.getId(), pod.getId(), clusterId, hostId,
-                    avoid, 1);
-            if (poolList != null && !poolList.isEmpty()) {
-                return (StoragePool)this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
-            }
+        	
+        	ExcludeList avoidList = new ExcludeList();
+        	for(StoragePool pool : avoid){
+        		avoidList.addPool(pool.getId());
+        	}
+        	DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), pod.getId(), clusterId, hostId, null, null);
+        	
+        	final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
+        	if (poolList != null && !poolList.isEmpty()) {
+        		return (StoragePool)this.dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
+        	}
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/VolumeManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/VolumeManagerImpl.java b/server/src/com/cloud/storage/VolumeManagerImpl.java
index a69607f..336dbcb 100644
--- a/server/src/com/cloud/storage/VolumeManagerImpl.java
+++ b/server/src/com/cloud/storage/VolumeManagerImpl.java
@@ -51,6 +51,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
 import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
 import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
@@ -115,7 +116,6 @@ import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.Volume.Event;
 import com.cloud.storage.Volume.Type;
-import com.cloud.storage.allocator.StoragePoolAllocator;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.SnapshotDao;
 import com.cloud.storage.dao.SnapshotPolicyDao;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
deleted file mode 100755
index d747d25..0000000
--- a/server/src/com/cloud/storage/allocator/AbstractStoragePoolAllocator.java
+++ /dev/null
@@ -1,209 +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 com.cloud.storage.allocator;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-
-import com.cloud.capacity.CapacityManager;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.deploy.DataCenterDeployment;
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.host.Host;
-import com.cloud.server.StatsCollector;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.storage.StorageManager;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.StoragePoolStatus;
-import com.cloud.storage.VMTemplateStoragePoolVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Volume;
-import com.cloud.storage.Volume.Type;
-import com.cloud.storage.dao.StoragePoolDao;
-import com.cloud.storage.dao.StoragePoolHostDao;
-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.swift.SwiftManager;
-import com.cloud.template.TemplateManager;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.component.AdapterBase;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-public abstract class AbstractStoragePoolAllocator extends AdapterBase implements StoragePoolAllocator {
-	private static final Logger s_logger = Logger.getLogger(AbstractStoragePoolAllocator.class);
-    @Inject TemplateManager _tmpltMgr;
-    @Inject StorageManager _storageMgr;
-    @Inject StoragePoolDao _storagePoolDao;
-    @Inject VMTemplateHostDao _templateHostDao;
-    @Inject VMTemplatePoolDao _templatePoolDao;
-    @Inject VMTemplateDao _templateDao;
-    @Inject VolumeDao _volumeDao;
-    @Inject StoragePoolHostDao _poolHostDao;
-    @Inject ConfigurationDao _configDao;
-    @Inject ClusterDao _clusterDao;
-    @Inject SwiftManager _swiftMgr;
-    @Inject CapacityManager _capacityMgr;
-    @Inject DataStoreManager dataStoreMgr;
-    protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1);    
-    long _extraBytesPerVolume = 0;
-    Random _rand;
-    boolean _dontMatter;
-    
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-        
-        Map<String, String> configs = _configDao.getConfiguration(null, params);
-        
-        String globalStorageOverprovisioningFactor = configs.get("storage.overprovisioning.factor");
-        _storageOverprovisioningFactor = new BigDecimal(NumbersUtil.parseFloat(globalStorageOverprovisioningFactor, 2.0f));
-        
-        _extraBytesPerVolume = 0;
-        
-        _rand = new Random(System.currentTimeMillis());
-        
-        _dontMatter = Boolean.parseBoolean(configs.get("storage.overwrite.provisioning"));
-        
-        return true;
-    }
-    
-    abstract boolean allocatorIsCorrectType(DiskProfile dskCh);
-    
-	protected boolean templateAvailable(long templateId, long poolId) {
-    	VMTemplateStorageResourceAssoc thvo = _templatePoolDao.findByPoolTemplate(poolId, templateId);
-    	if (thvo != null) {
-    		if (s_logger.isDebugEnabled()) {
-    			s_logger.debug("Template id : " + templateId + " status : " + thvo.getDownloadState().toString());
-    		}
-    		return (thvo.getDownloadState()==Status.DOWNLOADED);
-    	} else {
-    		return false;
-    	}
-    }
-	
-	protected boolean localStorageAllocationNeeded(DiskProfile dskCh) {
-	    return dskCh.useLocalStorage();
-	}
-	
-	protected boolean poolIsCorrectType(DiskProfile dskCh, StoragePool pool) {
-		boolean localStorageAllocationNeeded = localStorageAllocationNeeded(dskCh);
-		if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Is localStorageAllocationNeeded? "+ localStorageAllocationNeeded);
-            s_logger.debug("Is storage pool shared? "+ pool.isShared());
-        }
-		
-		return ((!localStorageAllocationNeeded && pool.getPoolType().isShared()) || (localStorageAllocationNeeded && !pool.getPoolType().isShared()));
-	}
-	
-	protected boolean checkPool(ExcludeList avoid, StoragePoolVO pool, DiskProfile dskCh, VMTemplateVO template, List<VMTemplateStoragePoolVO> templatesInPool, 
-			StatsCollector sc, DeploymentPlan plan) {
-		
-		if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Checking if storage pool is suitable, name: " + pool.getName()+ " ,poolId: "+ pool.getId());
-        }
-		StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
-		if (avoid.shouldAvoid(pol)) {
-			if (s_logger.isDebugEnabled()) {
-                s_logger.debug("StoragePool is in avoid set, skipping this pool");
-            }			
-			return false;
-		}
-        if(dskCh.getType().equals(Type.ROOT) && pool.getPoolType().equals(StoragePoolType.Iscsi)){
-    		if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Disk needed for ROOT volume, but StoragePoolType is Iscsi, skipping this and trying other available pools");
-            }	
-            return false;
-        }
-        
-        //by default, all pools are up when successfully added
-		//don't return the pool if not up (if in maintenance/prepareformaintenance/errorinmaintenance)
-        if(!pool.getStatus().equals(StoragePoolStatus.Up)){
-    		if (s_logger.isDebugEnabled()) {
-                s_logger.debug("StoragePool status is not UP, status is: "+pool.getStatus().name()+", skipping this pool");
-            }
-        	return false;
-        }
-        
-		// Check that the pool type is correct
-		if (!poolIsCorrectType(dskCh, pol)) {
-    		if (s_logger.isDebugEnabled()) {
-                s_logger.debug("StoragePool is not of correct type, skipping this pool");
-            }
-			return false;
-		}
-		
-		/*hypervisor type is correct*/
-		// TODO : when creating a standalone volume, offering is passed as NULL, need to 
-		// refine the logic of checking hypervisorType based on offering info
-		Long clusterId = pool.getClusterId();
-		ClusterVO cluster = _clusterDao.findById(clusterId);
-		if (!(cluster.getHypervisorType() == dskCh.getHypersorType())) {
-    		if (s_logger.isDebugEnabled()) {
-                s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool");
-            }
-			return false;
-		}
-
-
-        // check capacity  
-        Volume volume =  _volumeDao.findById(dskCh.getVolumeId());
-        List<Volume> requestVolumes = new ArrayList<Volume>();
-        requestVolumes.add(volume);
-        return _storageMgr.storagePoolHasEnoughSpace(requestVolumes, pol);
-	}
-
-
-	
-	@Override
-	public String chooseStorageIp(VirtualMachine vm, Host host, Host storage) {
-		return storage.getStorageIpAddress();
-	}
-	
-	
-	@Override
-	public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, long dcId, long podId, Long clusterId, Long hostId, Set<? extends StoragePool> avoids, int returnUpTo) {
-	    
-	    ExcludeList avoid = new ExcludeList();
-	    for(StoragePool pool : avoids){
-	    	avoid.addPool(pool.getId());
-	    }
-	    
-	    DataCenterDeployment plan = new DataCenterDeployment(dcId, podId, clusterId, hostId, null, null);
-	    return allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java
deleted file mode 100644
index f0df3a6..0000000
--- a/server/src/com/cloud/storage/allocator/FirstFitStoragePoolAllocator.java
+++ /dev/null
@@ -1,175 +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 com.cloud.storage.allocator;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.server.StatsCollector;
-import com.cloud.storage.DiskOfferingVO;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Storage.StoragePoolType;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.dao.DiskOfferingDao;
-import com.cloud.user.Account;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Local(value=StoragePoolAllocator.class)
-public class FirstFitStoragePoolAllocator extends AbstractStoragePoolAllocator {
-    private static final Logger s_logger = Logger.getLogger(FirstFitStoragePoolAllocator.class);
-    protected String _allocationAlgorithm = "random";
-
-    @Inject
-    DiskOfferingDao _diskOfferingDao;
-    
-    @Override
-    public boolean allocatorIsCorrectType(DiskProfile dskCh) {
-    	return !localStorageAllocationNeeded(dskCh);
-    }
-
-    @Override
-	public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
-
- 
-	    VMTemplateVO template = (VMTemplateVO)vmProfile.getTemplate();
-	    Account account = null;
-	    if(vmProfile.getVirtualMachine() != null){
-	    	account = vmProfile.getOwner();
-	    }
-	    
-    	List<StoragePool> suitablePools = new ArrayList<StoragePool>();
-
-    	// Check that the allocator type is correct
-        if (!allocatorIsCorrectType(dskCh)) {
-        	return suitablePools;
-        }
-		long dcId = plan.getDataCenterId();
-		Long podId = plan.getPodId();
-		Long clusterId = plan.getClusterId();
-
-        if(dskCh.getTags() != null && dskCh.getTags().length != 0){
-        	s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId + " having tags:" + Arrays.toString(dskCh.getTags()));
-        }else{
-        	s_logger.debug("Looking for pools in dc: " + dcId + "  pod:" + podId + "  cluster:" + clusterId);
-        }
-
-        List<StoragePoolVO> pools = _storagePoolDao.findPoolsByTags(dcId, podId, clusterId, dskCh.getTags(), null);
-        if (pools.size() == 0) {
-            if (s_logger.isDebugEnabled()) {
-                String storageType = dskCh.useLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString();
-                s_logger.debug("No storage pools available for " + storageType + " volume allocation, returning");
-            }
-            return suitablePools;
-        }
-        
-        StatsCollector sc = StatsCollector.getInstance();
-
-        //FixMe: We are ignoring userdispersing algorithm when account is null. Find a way to get account ID when VMprofile is null
-        if(_allocationAlgorithm.equals("random") || _allocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
-            // Shuffle this so that we don't check the pools in the same order.
-            Collections.shuffle(pools);
-        }else if(_allocationAlgorithm.equals("userdispersing")){
-            pools = reorderPoolsByNumberOfVolumes(plan, pools, account);
-        }
-        
-    	if (s_logger.isDebugEnabled()) {
-            s_logger.debug("FirstFitStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
-        }
-    	
-        DiskOfferingVO diskOffering = _diskOfferingDao.findById(dskCh.getDiskOfferingId());
-        for (StoragePoolVO pool: pools) {
-        	if(suitablePools.size() == returnUpTo){
-        		break;
-        	}
-            if (diskOffering.getSystemUse() && pool.getPoolType() == StoragePoolType.RBD) {
-                s_logger.debug("Skipping RBD pool " + pool.getName() + " as a suitable pool. RBD is not supported for System VM's");
-                continue;
-            }
-
-        	if (checkPool(avoid, pool, dskCh, template, null, sc, plan)) {
-        	    StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
-        		suitablePools.add(pol);
-        	}
-        }
-        
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("FirstFitStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools");
-        }
-        
-        return suitablePools;
-	}
-    
-    private List<StoragePoolVO> reorderPoolsByNumberOfVolumes(DeploymentPlan plan, List<StoragePoolVO> pools, Account account) {
-        if(account == null){
-            return pools;
-        }
-        long dcId = plan.getDataCenterId();
-        Long podId = plan.getPodId();
-        Long clusterId = plan.getClusterId();
-            
-        List<Long> poolIdsByVolCount = _volumeDao.listPoolIdsByVolumeCount(dcId, podId, clusterId, account.getAccountId());
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("List of pools in ascending order of number of volumes for account id: "+ account.getAccountId() + " is: "+ poolIdsByVolCount);
-        }
-            
-        //now filter the given list of Pools by this ordered list
-        Map<Long, StoragePoolVO> poolMap = new HashMap<Long, StoragePoolVO>();        
-        for (StoragePoolVO pool : pools) {
-            poolMap.put(pool.getId(), pool);
-        }
-        List<Long> matchingPoolIds = new ArrayList<Long>(poolMap.keySet());
-        
-        poolIdsByVolCount.retainAll(matchingPoolIds);
-        
-        List<StoragePoolVO> reorderedPools = new ArrayList<StoragePoolVO>();
-        for(Long id: poolIdsByVolCount){
-            reorderedPools.add(poolMap.get(id));
-        }
-        
-        return reorderedPools;
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        if (_configDao != null) {
-            Map<String, String> configs = _configDao.getConfiguration(params);
-            String allocationAlgorithm = configs.get("vm.allocation.algorithm");
-            if (allocationAlgorithm != null) {
-                _allocationAlgorithm = allocationAlgorithm;
-            }
-        }
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java
deleted file mode 100644
index 4eeae28..0000000
--- a/server/src/com/cloud/storage/allocator/GarbageCollectingStoragePoolAllocator.java
+++ /dev/null
@@ -1,105 +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 com.cloud.storage.allocator;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.storage.StorageManager;
-import com.cloud.storage.StoragePool;
-import com.cloud.utils.component.ComponentContext;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Component
-@Local(value=StoragePoolAllocator.class)
-public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAllocator {
-    private static final Logger s_logger = Logger.getLogger(GarbageCollectingStoragePoolAllocator.class);
-
-    StoragePoolAllocator _firstFitStoragePoolAllocator;
-    StoragePoolAllocator _localStoragePoolAllocator;
-    @Inject StorageManager _storageMgr;
-    @Inject ConfigurationDao _configDao;
-    boolean _storagePoolCleanupEnabled;
-
-    @Override
-    public boolean allocatorIsCorrectType(DiskProfile dskCh) {
-        return true;
-    }
-
-    public Integer getStorageOverprovisioningFactor() {
-        return null;
-    }
-
-    public Long getExtraBytesPerVolume() {
-        return null;
-    }
-
-    @Override
-    public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
-
-        if (!_storagePoolCleanupEnabled) {
-            s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");
-            return null;
-        }
-
-        // Clean up all storage pools
-        _storageMgr.cleanupStorage(false);
-        // Determine what allocator to use
-        StoragePoolAllocator allocator;
-        if (localStorageAllocationNeeded(dskCh)) {
-            allocator = _localStoragePoolAllocator;
-        } else {
-            allocator = _firstFitStoragePoolAllocator;
-        }
-
-        // Try to find a storage pool after cleanup
-        ExcludeList myAvoids = new ExcludeList(avoid.getDataCentersToAvoid(), avoid.getPodsToAvoid(), avoid.getClustersToAvoid(), avoid.getHostsToAvoid(), avoid.getPoolsToAvoid());
-
-        return allocator.allocateToPool(dskCh, vmProfile, plan, myAvoids, returnUpTo);
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        _firstFitStoragePoolAllocator = ComponentContext.inject(FirstFitStoragePoolAllocator.class);
-        _firstFitStoragePoolAllocator.configure("GCFirstFitStoragePoolAllocator", params);
-        _localStoragePoolAllocator = ComponentContext.inject(LocalStoragePoolAllocator.class);
-        _localStoragePoolAllocator.configure("GCLocalStoragePoolAllocator", params);
-
-        String storagePoolCleanupEnabled = _configDao.getValue("storage.pool.cleanup.enabled");
-        _storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled);
-
-        return true;
-    }
-
-    public GarbageCollectingStoragePoolAllocator() {
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java
deleted file mode 100644
index 24b4dab..0000000
--- a/server/src/com/cloud/storage/allocator/LocalStoragePoolAllocator.java
+++ /dev/null
@@ -1,288 +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 com.cloud.storage.allocator;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
-import org.apache.log4j.Logger;
-
-import com.cloud.capacity.CapacityVO;
-import com.cloud.capacity.dao.CapacityDao;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.StoragePoolHostVO;
-import com.cloud.storage.Volume;
-import com.cloud.storage.VolumeVO;
-import com.cloud.storage.dao.StoragePoolHostDao;
-import com.cloud.utils.DateUtil;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.db.GenericSearchBuilder;
-import com.cloud.utils.db.JoinBuilder;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Func;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.dao.UserVmDao;
-import com.cloud.vm.dao.VMInstanceDao;
-
-//
-// TODO
-// Rush to make LocalStoragePoolAllocator use static allocation status, we should revisit the overall
-// allocation process to make it more reliable in next release. The code put in here is pretty ugly
-//
-@Local(value = StoragePoolAllocator.class)
-public class LocalStoragePoolAllocator extends FirstFitStoragePoolAllocator {
-    private static final Logger s_logger = Logger.getLogger(LocalStoragePoolAllocator.class);
-
-    @Inject
-    StoragePoolHostDao _poolHostDao;
-    @Inject
-    VMInstanceDao _vmInstanceDao;
-    @Inject
-    UserVmDao _vmDao;
-    @Inject
-    ServiceOfferingDao _offeringDao;
-    @Inject
-    CapacityDao _capacityDao;
-    @Inject
-    ConfigurationDao _configDao;
-
-    protected GenericSearchBuilder<VMInstanceVO, Long> VmsOnPoolSearch;
-
-    private int _secondsToSkipStoppedVMs = 86400;
-
-    @Override
-    public boolean allocatorIsCorrectType(DiskProfile dskCh) {
-        return localStorageAllocationNeeded(dskCh);
-    }
-
-    @Override
-    public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
-
-        List<StoragePool> suitablePools = new ArrayList<StoragePool>();
-
-        // Check that the allocator type is correct
-        if (!allocatorIsCorrectType(dskCh)) {
-            return suitablePools;
-        }
-
-        ExcludeList myAvoids = new ExcludeList(avoid.getDataCentersToAvoid(), avoid.getPodsToAvoid(), avoid.getClustersToAvoid(), avoid.getHostsToAvoid(), avoid.getPoolsToAvoid());
-
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("LocalStoragePoolAllocator trying to find storage pool to fit the vm");
-        }
-
-        // data disk and host identified from deploying vm (attach volume case)
-        if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) {
-            List<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId());
-            for (StoragePoolHostVO hostPool: hostPools) {
-                StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId());
-                if (pool != null && pool.isLocal()) {
-                    s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
-                    StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
-                    suitablePools.add(pol);
-                }
-
-                if (suitablePools.size() == returnUpTo) {
-                    break;
-                }
-            }
-        } else {
-            List<StoragePool> availablePool;
-            while (!(availablePool = super.allocateToPool(dskCh, vmProfile, plan, myAvoids, 1)).isEmpty()) {
-                StoragePool pool = availablePool.get(0);
-                myAvoids.addPool(pool.getId());
-                List<StoragePoolHostVO> hostsInSPool = _poolHostDao.listByPoolId(pool.getId());
-                assert (hostsInSPool.size() == 1) : "Local storage pool should be one host per pool";
-
-                s_logger.debug("Found suitable local storage pool " + pool.getId() + ", adding to list");
-                suitablePools.add(pool);
-
-                if (suitablePools.size() == returnUpTo) {
-                    break;
-                }
-            }
-        }
-
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("LocalStoragePoolAllocator returning " + suitablePools.size() + " suitable storage pools");
-        }
-
-        if (suitablePools.isEmpty()) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Unable to find storage pool to fit the vm");
-            }
-        }
-        return suitablePools;
-    }
-
-    // we don't need to check host capacity now, since hostAllocators will do that anyway
-    private boolean hostHasCpuMemoryCapacity(long hostId, List<Long> vmOnHost, VMInstanceVO vm) {
-
-        ServiceOffering so = _offeringDao.findById(vm.getServiceOfferingId());
-
-        long usedMemory = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_MEMORY);
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Calculated static-allocated memory for VMs on host " + hostId + ": " + usedMemory + " bytes, requesting memory: " + (so != null ? so.getRamSize() * 1024L * 1024L : "")
-                    + " bytes");
-        }
-
-        SearchCriteria<CapacityVO> sc = _capacityDao.createSearchCriteria();
-        sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
-        sc.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_MEMORY);
-        List<CapacityVO> capacities = _capacityDao.search(sc, null);
-        if (capacities.size() > 0) {
-            if (capacities.get(0).getTotalCapacity() < usedMemory + (so != null ? so.getRamSize() * 1024L * 1024L : 0)) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Host " + hostId + " runs out of memory capacity");
-                }
-                return false;
-            }
-        } else {
-            s_logger.warn("Host " + hostId + " has not reported memory capacity yet");
-            return false;
-        }
-
-        long usedCpu = calcHostAllocatedCpuMemoryCapacity(vmOnHost, CapacityVO.CAPACITY_TYPE_CPU);
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Calculated static-allocated CPU for VMs on host " + hostId + ": " + usedCpu + " GHz, requesting cpu: " + (so != null ? so.getCpu() * so.getSpeed() : "") + " GHz");
-        }
-
-        sc = _capacityDao.createSearchCriteria();
-        sc.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, hostId);
-        sc.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU);
-        capacities = _capacityDao.search(sc, null);
-        if (capacities.size() > 0) {
-            if (capacities.get(0).getTotalCapacity() < usedCpu + (so != null ? so.getCpu() * so.getSpeed() : 0)) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Host " + hostId + " runs out of CPU capacity");
-                }
-                return false;
-            }
-        } else {
-            s_logger.warn("Host " + hostId + " has not reported CPU capacity yet");
-            return false;
-        }
-
-        return true;
-    }
-
-    private boolean skipCalculation(VMInstanceVO vm) {
-        if (vm == null) {
-            return true;
-        }
-
-        if (vm.getState() == State.Expunging) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("Skip counting capacity for Expunging VM : " + vm.getInstanceName());
-            }
-            return true;
-        }
-
-        if (vm.getState() == State.Destroyed && vm.getType() != VirtualMachine.Type.User) {
-            return true;
-        }
-
-        if (vm.getState() == State.Stopped || vm.getState() == State.Destroyed) {
-            // for stopped/Destroyed VMs, we will skip counting it if it hasn't been used for a while
-
-            long millisecondsSinceLastUpdate = DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime();
-            if (millisecondsSinceLastUpdate > _secondsToSkipStoppedVMs * 1000L) {
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("Skip counting vm " + vm.getInstanceName() + " in capacity allocation as it has been stopped for " + millisecondsSinceLastUpdate / 60000 + " minutes");
-                }
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private long calcHostAllocatedCpuMemoryCapacity(List<Long> vmOnHost, short capacityType) {
-        assert (capacityType == CapacityVO.CAPACITY_TYPE_MEMORY || capacityType == CapacityVO.CAPACITY_TYPE_CPU) : "Invalid capacity type passed in calcHostAllocatedCpuCapacity()";
-
-        long usedCapacity = 0;
-        for (Long vmId : vmOnHost) {
-            VMInstanceVO vm = _vmInstanceDao.findById(vmId);
-            if (skipCalculation(vm)) {
-                continue;
-            }
-
-            ServiceOffering so = _offeringDao.findById(vm.getServiceOfferingId());
-            if (vm.getType() == VirtualMachine.Type.User) {
-                UserVmVO userVm = _vmDao.findById(vm.getId());
-                if (userVm == null) {
-                    continue;
-                }
-            } 
-
-            if (capacityType == CapacityVO.CAPACITY_TYPE_MEMORY) {
-                usedCapacity += so.getRamSize() * 1024L * 1024L;
-            } else if (capacityType == CapacityVO.CAPACITY_TYPE_CPU) {
-                usedCapacity += so.getCpu() * so.getSpeed();
-            }
-        }
-
-        return usedCapacity;
-    }
-
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-
-        _storageOverprovisioningFactor = new BigDecimal(1);
-        _extraBytesPerVolume = NumbersUtil.parseLong((String) params.get("extra.bytes.per.volume"), 50 * 1024L * 1024L);
-
-        Map<String, String> configs = _configDao.getConfiguration("management-server", params);
-        String value = configs.get("vm.resource.release.interval");
-        _secondsToSkipStoppedVMs = NumbersUtil.parseInt(value, 86400);
-
-        VmsOnPoolSearch = _vmInstanceDao.createSearchBuilder(Long.class);
-        VmsOnPoolSearch.select(null, Func.DISTINCT, VmsOnPoolSearch.entity().getId());
-        VmsOnPoolSearch.and("removed", VmsOnPoolSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
-        VmsOnPoolSearch.and("state", VmsOnPoolSearch.entity().getState(), SearchCriteria.Op.NIN);
-
-        SearchBuilder<VolumeVO> sbVolume = _volumeDao.createSearchBuilder();
-        sbVolume.and("poolId", sbVolume.entity().getPoolId(), SearchCriteria.Op.EQ);
-
-        VmsOnPoolSearch.join("volumeJoin", sbVolume, VmsOnPoolSearch.entity().getId(), sbVolume.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
-
-        sbVolume.done();
-        VmsOnPoolSearch.done();
-
-        return true;
-    }
-
-    public LocalStoragePoolAllocator() {
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/StoragePoolAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/StoragePoolAllocator.java b/server/src/com/cloud/storage/allocator/StoragePoolAllocator.java
deleted file mode 100644
index 1c02c6c..0000000
--- a/server/src/com/cloud/storage/allocator/StoragePoolAllocator.java
+++ /dev/null
@@ -1,53 +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 com.cloud.storage.allocator;
-
-import java.util.List;
-import java.util.Set;
-
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.host.Host;
-import com.cloud.storage.StoragePool;
-import com.cloud.utils.component.Adapter;
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-/**
- */
-public interface StoragePoolAllocator extends Adapter {
-	
-	//keeping since storageMgr is using this API for some existing functionalities
-	List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, long dcId, long podId, Long clusterId, Long hostId, Set<? extends StoragePool> avoids, int returnUpTo);
-	
-	String chooseStorageIp(VirtualMachine vm, Host host, Host storage);
-
-	/** 
-	* Determines which storage pools are suitable for the guest virtual machine 
-	* 
-	* @param DiskProfile dskCh
-	* @param VirtualMachineProfile vmProfile
-	* @param DeploymentPlan plan
-	* @param ExcludeList avoid
-	* @param int returnUpTo (use -1 to return all possible pools)
-	* @return List<StoragePool> List of storage pools that are suitable for the VM 
-	**/ 
-	List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo);	
-	
-	public static int RETURN_UPTO_ALL = -1;
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/allocator/UseLocalForRootAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/allocator/UseLocalForRootAllocator.java b/server/src/com/cloud/storage/allocator/UseLocalForRootAllocator.java
deleted file mode 100644
index 2c19406..0000000
--- a/server/src/com/cloud/storage/allocator/UseLocalForRootAllocator.java
+++ /dev/null
@@ -1,83 +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 com.cloud.storage.allocator;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.springframework.stereotype.Component;
-
-import com.cloud.configuration.Config;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.host.Host;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.Volume.Type;
-
-import com.cloud.vm.DiskProfile;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Component
-@Local(value=StoragePoolAllocator.class)
-public class UseLocalForRootAllocator extends LocalStoragePoolAllocator implements StoragePoolAllocator {
-
-    @Inject
-    DataCenterDao _dcDao;
-
-    @Override
-    public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
-        DataCenterVO dc = _dcDao.findById(plan.getDataCenterId());
-        if (!dc.isLocalStorageEnabled()) {
-            return null;
-        }
-        
-        return super.allocateToPool(dskCh, vmProfile, plan, avoid, returnUpTo);
-    }
-
-    @Override
-    public String chooseStorageIp(VirtualMachine vm, Host host, Host storage) {
-        return null;
-    }
-    
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        super.configure(name, params);
-        return true;
-    }
-    
-    @Override
-    protected boolean localStorageAllocationNeeded(DiskProfile dskCh) {
-        if (dskCh.getType() == Type.ROOT) {
-            return true;
-        } else if (dskCh.getType() == Type.DATADISK) {
-            return false;
-        } else {
-            return super.localStorageAllocationNeeded(dskCh);
-        }
-    }
-    
-    protected UseLocalForRootAllocator() {
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/dao/StoragePoolDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/StoragePoolDao.java b/server/src/com/cloud/storage/dao/StoragePoolDao.java
index 64bbd5f..28ead9c 100644
--- a/server/src/com/cloud/storage/dao/StoragePoolDao.java
+++ b/server/src/com/cloud/storage/dao/StoragePoolDao.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 
 import com.cloud.storage.StoragePoolStatus;
@@ -37,7 +38,7 @@ public interface StoragePoolDao extends GenericDao<StoragePoolVO, Long> {
 	/**
 	 * @param datacenterId -- the id of the datacenter (availability zone)
 	 */
-	List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId);
+	List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope);
     
 	/**
 	 * Set capacity of storage pool in bytes
@@ -71,9 +72,9 @@ public interface StoragePoolDao extends GenericDao<StoragePoolVO, Long> {
      * @param details details to match.  All must match for the pool to be returned.
      * @return List of StoragePoolVO
      */
-    List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
+    List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details, ScopeType scope);
     
-    List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
+    List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags);
     
     /**
      * Find pool by UUID.
@@ -104,4 +105,9 @@ public interface StoragePoolDao extends GenericDao<StoragePoolVO, Long> {
 	List<StoragePoolVO> listByStatusInZone(long dcId, StoragePoolStatus status);
     
     List<StoragePoolVO> listPoolsByCluster(long clusterId);
+
+	List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId,
+			Long clusterId, String[] tags);
+
+	List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java
index ebf2943..28b4dbc 100644
--- a/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java
+++ b/server/src/com/cloud/storage/dao/StoragePoolDaoImpl.java
@@ -28,14 +28,13 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
+import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.springframework.stereotype.Component;
 
 import com.cloud.host.Status;
-import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.StoragePoolDetailVO;
 import com.cloud.storage.StoragePoolStatus;
-
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GenericDaoBase;
 import com.cloud.utils.db.GenericSearchBuilder;
@@ -43,6 +42,8 @@ import com.cloud.utils.db.SearchBuilder;
 import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.SearchCriteria2;
+import com.cloud.utils.db.SearchCriteriaService;
 import com.cloud.utils.db.Transaction;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -59,8 +60,11 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
     
     @Inject protected StoragePoolDetailsDao _detailsDao;
 	
-    private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
+    private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.status = 'Up' and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and storage_pool.scope = ? and (";
 	private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
+	private final String ZoneWideDetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.status = 'Up' and storage_pool.data_center_id = ? and storage_pool.scope = ? and (";
+	private final String ZoneWideDetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
+		
 	private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?";
 	
     protected StoragePoolDaoImpl() {
@@ -77,6 +81,8 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
         
     	DcPodSearch = createSearchBuilder();
     	DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+    	DcPodSearch.and("status", DcPodSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+    	DcPodSearch.and("scope", DcPodSearch.entity().getScope(), SearchCriteria.Op.EQ);
     	DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL);
     	DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
     	DcPodSearch.cp();
@@ -87,6 +93,8 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
     	
     	DcPodAnyClusterSearch = createSearchBuilder();
         DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+        DcPodAnyClusterSearch.and("status", DcPodAnyClusterSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+        DcPodAnyClusterSearch.and("scope", DcPodAnyClusterSearch.entity().getScope(), SearchCriteria.Op.EQ);
         DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL);
         DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ);
         DcPodAnyClusterSearch.cp();
@@ -192,11 +200,13 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
     }
 
 	@Override
-	public List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId) {
+	public List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId, ScopeType scope) {
 	    if (clusterId != null) {
     		SearchCriteria<StoragePoolVO> sc = DcPodSearch.create();
             sc.setParameters("datacenterId", datacenterId);
             sc.setParameters("podId", podId);
+            sc.setParameters("status", Status.Up);
+            sc.setParameters("scope", scope);
            
             sc.setParameters("cluster", clusterId);
             return listBy(sc);
@@ -204,6 +214,8 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
 	        SearchCriteria<StoragePoolVO> sc = DcPodAnyClusterSearch.create();
 	        sc.setParameters("datacenterId", datacenterId);
 	        sc.setParameters("podId", podId);
+	        sc.setParameters("status", Status.Up);
+	        sc.setParameters("scope", scope);
 	        return listBy(sc);
 	    }
 	}
@@ -242,11 +254,12 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
 	
 	@DB
 	@Override
-	public List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
+	public List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details, ScopeType scope) {
 	    StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
 	    if (clusterId != null) {
 	        sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
 	    }
+	    
 	    for (Map.Entry<String, String> detail : details.entrySet()) {
 	        sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
 	    }
@@ -259,6 +272,7 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
 	        int i = 1;
 	        pstmt.setLong(i++, dcId);
 	        pstmt.setLong(i++, podId);
+	        pstmt.setString(i++, scope.toString());
 	        if (clusterId != null) {
 	            pstmt.setLong(i++, clusterId);
 	        }
@@ -283,26 +297,67 @@ public class StoragePoolDaoImpl extends GenericDaoBase<StoragePoolVO, Long>  imp
 	}
 	
 	@Override
-	public List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
+	public List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags) {
 		List<StoragePoolVO> storagePools = null;
 	    if (tags == null || tags.length == 0) {
-	        storagePools = listBy(dcId, podId, clusterId);
+	        storagePools = listBy(dcId, podId, clusterId, ScopeType.CLUSTER);
 	    } else {
 	        Map<String, String> details = tagsToDetails(tags);
-	        storagePools =  findPoolsByDetails(dcId, podId, clusterId, details);
+	        storagePools =  findPoolsByDetails(dcId, podId, clusterId, details, ScopeType.CLUSTER);
 	    }
-	    
-	    if (shared == null) {
-	    	return storagePools;
+
+	    return storagePools;
+	}
+	
+	@Override
+	public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Long clusterId, String[] tags) {
+		List<StoragePoolVO> storagePools = null;
+	    if (tags == null || tags.length == 0) {
+	        storagePools = listBy(dcId, podId, clusterId, ScopeType.HOST);
 	    } else {
-	    	List<StoragePoolVO> filteredStoragePools = new ArrayList<StoragePoolVO>(storagePools);
-	    	for (StoragePoolVO pool : storagePools) {
-	    		if (shared != pool.isShared()) {
-	    			filteredStoragePools.remove(pool);
-	    		}
-	    	}
-	    	
-	    	return filteredStoragePools;
+	        Map<String, String> details = tagsToDetails(tags);
+	        storagePools =  findPoolsByDetails(dcId, podId, clusterId, details, ScopeType.HOST);
+	    }
+
+	    return storagePools;
+	}
+	
+	@Override
+	public List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags) {
+		List<StoragePoolVO> storagePools = null;
+	    if (tags == null || tags.length == 0) {
+	    	SearchCriteriaService<StoragePoolVO, StoragePoolVO> sc =  SearchCriteria2.create(StoragePoolVO.class);
+	    	sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, dcId);
+	    	sc.addAnd(sc.getEntity().getStatus(), Op.EQ, Status.Up);
+	    	sc.addAnd(sc.getEntity().getScope(), Op.EQ, ScopeType.ZONE);
+	    	return sc.list();
+	    } else {
+	        Map<String, String> details = tagsToDetails(tags);
+	        
+	        StringBuilder sql = new StringBuilder(ZoneWideDetailsSqlPrefix);
+		    
+		    for (Map.Entry<String, String> detail : details.entrySet()) {
+		        sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
+		    }
+		    sql.delete(sql.length() - 4, sql.length());
+		    sql.append(ZoneWideDetailsSqlSuffix);
+		    Transaction txn = Transaction.currentTxn();
+		    PreparedStatement pstmt = null;
+		    try {
+		        pstmt = txn.prepareAutoCloseStatement(sql.toString());
+		        int i = 1;
+		        pstmt.setLong(i++, dcId);
+		        pstmt.setString(i++, ScopeType.ZONE.toString());
+		        pstmt.setInt(i++, details.size());
+		        ResultSet rs = pstmt.executeQuery();
+		        List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
+		        while (rs.next()) {
+		            pools.add(toEntityBean(rs, false));
+		        }
+		        return pools;
+		    } catch (SQLException e) {
+		        throw new CloudRuntimeException("Unable to execute " + pstmt, e);
+		    }
 	    }
 	}
 	

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/utils/src/com/cloud/utils/db/Transaction.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/Transaction.java b/utils/src/com/cloud/utils/db/Transaction.java
index c1f157e..c151044 100755
--- a/utils/src/com/cloud/utils/db/Transaction.java
+++ b/utils/src/com/cloud/utils/db/Transaction.java
@@ -97,8 +97,8 @@ public class Transaction {
         /* FIXME: We need a better solution for this
          * Initialize encryption if we need it for db.properties
          */ 
-        EncryptionSecretKeyChecker enc = new EncryptionSecretKeyChecker();
-        enc.check();        
+        /*EncryptionSecretKeyChecker enc = new EncryptionSecretKeyChecker();
+        enc.check();   */     
     }
 
     private final LinkedList<StackElement> _stack;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8e360f34/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
index c8a7f7a..9b474d5 100644
--- a/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
+++ b/utils/src/com/cloud/utils/db/TransactionContextBuilder.java
@@ -20,10 +20,13 @@ import java.lang.reflect.Method;
 
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
+import org.apache.log4j.Logger;
 import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
 import org.aspectj.lang.reflect.MethodSignature;
 
 public class TransactionContextBuilder implements MethodInterceptor {
+	private static final Logger s_logger = Logger.getLogger(TransactionContextBuilder.class);
 	public TransactionContextBuilder() {
 	}
 	
@@ -31,7 +34,15 @@ public class TransactionContextBuilder implements MethodInterceptor {
 		MethodSignature methodSignature = (MethodSignature)call.getSignature();
         Method targetMethod = methodSignature.getMethod();	
         if(needToIntercept(targetMethod)) {
-			Transaction txn = Transaction.open(call.getSignature().getName());
+        	Transaction txn = null;
+        	try {
+        		Signature s = call.getSignature();
+        		String name = s.getName();
+        		txn = Transaction.open(name);
+        	} catch (Throwable e) {
+        		s_logger.debug("Failed to open transaction: " + e.toString());
+        		throw e;
+        	}
 			Object ret = null;
 			try {
 				 ret = call.proceed();