Skip to content

Commit 2ed94cb

Browse files
author
Edison Su
committed
fix compile
1 parent a76301b commit 2ed94cb

2 files changed

Lines changed: 82 additions & 4 deletions

File tree

plugins/storage-allocators/random/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
specific language governing permissions and limitations
1717
under the License.
1818
-->
19-
<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">
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2021
<modelVersion>4.0.0</modelVersion>
2122
<artifactId>cloud-plugin-storage-allocator-random</artifactId>
2223
<name>Apache CloudStack Plugin - Storage Allocator Random</name>
@@ -26,12 +27,11 @@
2627
<version>4.2.0-SNAPSHOT</version>
2728
<relativePath>../../pom.xml</relativePath>
2829
</parent>
29-
<dependencies>
30+
<dependencies>
3031
<dependency>
3132
<groupId>org.apache.cloudstack</groupId>
3233
<artifactId>cloud-engine-storage</artifactId>
3334
<version>${project.version}</version>
34-
<scope>test</scope>
3535
</dependency>
36-
</dependencies>
36+
</dependencies>
3737
</project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package org.apache.cloudstack.storage.allocator;
17+
18+
import java.util.ArrayList;
19+
import java.util.Collections;
20+
import java.util.List;
21+
22+
import javax.ejb.Local;
23+
24+
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
25+
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
26+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
27+
import org.apache.log4j.Logger;
28+
29+
import com.cloud.deploy.DeploymentPlan;
30+
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
31+
import com.cloud.storage.StoragePool;
32+
import com.cloud.vm.DiskProfile;
33+
import com.cloud.vm.VirtualMachine;
34+
import com.cloud.vm.VirtualMachineProfile;
35+
36+
@Local(value=StoragePoolAllocator.class)
37+
public class RandomStoragePoolAllocator extends AbstractStoragePoolAllocator {
38+
private static final Logger s_logger = Logger.getLogger(RandomStoragePoolAllocator.class);
39+
40+
@Override
41+
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
42+
43+
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
44+
45+
long dcId = plan.getDataCenterId();
46+
Long podId = plan.getPodId();
47+
Long clusterId = plan.getClusterId();
48+
s_logger.debug("Looking for pools in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
49+
List<StoragePoolVO> pools = _storagePoolDao.listBy(dcId, podId, clusterId, ScopeType.CLUSTER);
50+
if (pools.size() == 0) {
51+
if (s_logger.isDebugEnabled()) {
52+
s_logger.debug("No storage pools available for allocation, returning");
53+
}
54+
return suitablePools;
55+
}
56+
57+
Collections.shuffle(pools);
58+
if (s_logger.isDebugEnabled()) {
59+
s_logger.debug("RandomStoragePoolAllocator has " + pools.size() + " pools to check for allocation");
60+
}
61+
for (StoragePoolVO pool: pools) {
62+
if(suitablePools.size() == returnUpTo){
63+
break;
64+
}
65+
StoragePool pol = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
66+
67+
if (filter(avoid, pol, dskCh, plan)) {
68+
suitablePools.add(pol);
69+
}
70+
}
71+
72+
if (s_logger.isDebugEnabled()) {
73+
s_logger.debug("RandomStoragePoolAllocator returning "+suitablePools.size() +" suitable storage pools");
74+
}
75+
76+
return suitablePools;
77+
}
78+
}

0 commit comments

Comments
 (0)