Updated Branches: refs/heads/master a76301bbb -> 2ed94cbb6
fix compile Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/2ed94cbb Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/2ed94cbb Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/2ed94cbb Branch: refs/heads/master Commit: 2ed94cbb64b64fc11777409127495a4b19a77059 Parents: a76301b Author: Edison Su <[email protected]> Authored: Tue Feb 26 21:44:36 2013 -0800 Committer: Edison Su <[email protected]> Committed: Tue Feb 26 21:44:44 2013 -0800 ---------------------------------------------------------------------- plugins/storage-allocators/random/pom.xml | 8 +- .../allocator/RandomStoragePoolAllocator.java | 78 +++++++++++++++ 2 files changed, 82 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2ed94cbb/plugins/storage-allocators/random/pom.xml ---------------------------------------------------------------------- diff --git a/plugins/storage-allocators/random/pom.xml b/plugins/storage-allocators/random/pom.xml index 223b7cd..6b91908 100644 --- a/plugins/storage-allocators/random/pom.xml +++ b/plugins/storage-allocators/random/pom.xml @@ -16,7 +16,8 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-plugin-storage-allocator-random</artifactId> <name>Apache CloudStack Plugin - Storage Allocator Random</name> @@ -26,12 +27,11 @@ <version>4.2.0-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> - <dependencies> + <dependencies> <dependency> <groupId>org.apache.cloudstack</groupId> <artifactId>cloud-engine-storage</artifactId> <version>${project.version}</version> - <scope>test</scope> </dependency> - </dependencies> + </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/2ed94cbb/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java ---------------------------------------------------------------------- diff --git a/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java new file mode 100644 index 0000000..cbe6647 --- /dev/null +++ b/plugins/storage-allocators/random/src/org/apache/cloudstack/storage/allocator/RandomStoragePoolAllocator.java @@ -0,0 +1,78 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.apache.cloudstack.storage.allocator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.ejb.Local; + +import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType; +import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator; +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.storage.StoragePool; +import com.cloud.vm.DiskProfile; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachineProfile; + +@Local(value=StoragePoolAllocator.class) +public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator { + private static final Logger s_logger = Logger.getLogger(RandomStoragePoolAllocator.class); + + @Override + public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { + + List<StoragePool> suitablePools = new ArrayList<StoragePool>(); + + 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, ScopeType.CLUSTER); + if (pools.size() == 0) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("No storage pools available for allocation, returning"); + } + return suitablePools; + } + + 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; + } + StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId()); + + if (filter(avoid, pol, dskCh, plan)) { + suitablePools.add(pol); + } + } + + if (s_logger.isDebugEnabled()) { + s_logger.debug("RandomStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools"); + } + + return suitablePools; + } +}
