Skip to content

Commit eb195d0

Browse files
Sakshamskoushik-das
authored andcommitted
CLOUDSTACK-6151: Local data disk with tag goes to the wrong local storage pool
Signed-off-by: Koushik Das <koushik@apache.org>
1 parent f3cf85b commit eb195d0

5 files changed

Lines changed: 56 additions & 8 deletions

File tree

engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
<bean id="PortableIpRangeDaoImpl" class="org.apache.cloudstack.region.PortableIpRangeDaoImpl" />
222222
<bean id="portForwardingRulesDaoImpl" class="com.cloud.network.rules.dao.PortForwardingRulesDaoImpl" />
223223
<bean id="portProfileDaoImpl" class="com.cloud.network.dao.PortProfileDaoImpl" />
224+
<bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl" />
224225
<bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl" />
225226
<bean id="primaryDataStoreDetailsDaoImpl" class="org.apache.cloudstack.storage.volume.db.PrimaryDataStoreDetailsDaoImpl" />
226227
<bean id="privateIpDaoImpl" class="com.cloud.network.vpc.dao.PrivateIpDaoImpl" />
@@ -258,7 +259,6 @@
258259
<bean id="storageNetworkIpAddressDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpAddressDaoImpl" />
259260
<bean id="storageNetworkIpRangeDaoImpl" class="com.cloud.dc.dao.StorageNetworkIpRangeDaoImpl" />
260261
<bean id="storagePoolDetailsDaoImpl" class="com.cloud.storage.dao.StoragePoolDetailsDaoImpl" />
261-
<bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl" />
262262
<bean id="storagePoolJoinDaoImpl" class="com.cloud.api.query.dao.StoragePoolJoinDaoImpl" />
263263
<bean id="storagePoolWorkDaoImpl" class="com.cloud.storage.dao.StoragePoolWorkDaoImpl" />
264264
<bean id="templatePrimaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.volume.db.TemplatePrimaryDataStoreDaoImpl" />

engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,6 @@ public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
113113
List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags);
114114

115115
List<StoragePoolVO> findZoneWideStoragePoolsByHypervisor(long dataCenterId, HypervisorType hypervisorType);
116+
117+
List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags);
116118
}

engine/schema/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,21 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27+
import javax.annotation.PostConstruct;
2728
import javax.ejb.Local;
2829
import javax.inject.Inject;
2930
import javax.naming.ConfigurationException;
3031

3132
import com.cloud.host.Status;
3233
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3334
import com.cloud.storage.ScopeType;
35+
import com.cloud.storage.StoragePoolHostVO;
3436
import com.cloud.storage.StoragePoolStatus;
37+
import com.cloud.storage.dao.StoragePoolHostDao;
3538
import com.cloud.utils.db.DB;
3639
import com.cloud.utils.db.GenericDaoBase;
3740
import com.cloud.utils.db.GenericSearchBuilder;
41+
import com.cloud.utils.db.JoinBuilder;
3842
import com.cloud.utils.db.QueryBuilder;
3943
import com.cloud.utils.db.SearchBuilder;
4044
import com.cloud.utils.db.SearchCriteria;
@@ -51,9 +55,14 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
5155
protected final SearchBuilder<StoragePoolVO> DcPodAnyClusterSearch;
5256
protected final SearchBuilder<StoragePoolVO> DeleteLvmSearch;
5357
protected final GenericSearchBuilder<StoragePoolVO, Long> StatusCountSearch;
58+
protected SearchBuilder<StoragePoolVO> HostSearch;
59+
protected SearchBuilder<StoragePoolHostVO> HostPoolSearch;
60+
protected SearchBuilder<StoragePoolDetailVO> TagPoolSearch;
5461

5562
@Inject
5663
protected StoragePoolDetailsDao _detailsDao;
64+
@Inject
65+
protected StoragePoolHostDao _hostDao;
5766

5867
private final String DetailsSqlPrefix =
5968
"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 (";
@@ -111,6 +120,26 @@ public PrimaryDataStoreDaoImpl() {
111120

112121
}
113122

123+
@PostConstruct
124+
void init() {
125+
HostSearch = createSearchBuilder();
126+
TagPoolSearch = _detailsDao.createSearchBuilder();
127+
HostPoolSearch = _hostDao.createSearchBuilder();
128+
// Search for pools on the host
129+
HostPoolSearch.and("hostId", HostPoolSearch.entity().getHostId(), Op.EQ);
130+
// Set criteria for pools
131+
HostSearch.and("scope", HostSearch.entity().getScope(), Op.EQ);
132+
HostSearch.and("removed", HostSearch.entity().getRemoved(), Op.NULL);
133+
HostSearch.and("status", HostSearch.entity().getStatus(), Op.EQ);
134+
HostSearch.join("hostJoin", HostPoolSearch, HostSearch.entity().getId(), HostPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER);
135+
// Set criteria for tags
136+
TagPoolSearch.and("name", TagPoolSearch.entity().getName(), Op.EQ);
137+
TagPoolSearch.and("value", TagPoolSearch.entity().getValue(), Op.EQ);
138+
139+
HostSearch.join("tagJoin", TagPoolSearch, HostSearch.entity().getId(), TagPoolSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
140+
HostSearch.done();
141+
}
142+
114143
@Override
115144
public List<StoragePoolVO> findPoolByName(String name) {
116145
SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
@@ -314,6 +343,23 @@ public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Lo
314343
return storagePools;
315344
}
316345

346+
@Override
347+
public List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags) {
348+
349+
SearchCriteria<StoragePoolVO> sc = HostSearch.create();
350+
sc.setJoinParameters("hostJoin", "hostId", hostId );
351+
sc.setParameters("scope", ScopeType.HOST.toString());
352+
sc.setParameters("status", Status.Up.toString());
353+
if (!(tags == null || tags.length == 0 )) {
354+
Map<String, String> details = tagsToDetails(tags);
355+
for (Map.Entry<String, String> detail : details.entrySet()) {
356+
sc.setJoinParameters("tagJoin","name", detail.getKey());
357+
sc.setJoinParameters("tagJoin", "value", detail.getValue());
358+
}
359+
}
360+
return listBy(sc);
361+
}
362+
317363
@Override
318364
public List<StoragePoolVO> findZoneWideStoragePoolsByTags(long dcId, String[] tags) {
319365
List<StoragePoolVO> storagePools = null;

engine/storage/src/org/apache/cloudstack/storage/allocator/LocalStoragePoolAllocator.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@
2525
import javax.inject.Inject;
2626
import javax.naming.ConfigurationException;
2727

28-
import org.apache.log4j.Logger;
29-
import org.springframework.stereotype.Component;
30-
3128
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
3229
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3330
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
31+
import org.apache.log4j.Logger;
32+
import org.springframework.stereotype.Component;
3433

3534
import com.cloud.capacity.dao.CapacityDao;
3635
import com.cloud.deploy.DeploymentPlan;
3736
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3837
import com.cloud.service.dao.ServiceOfferingDao;
3938
import com.cloud.storage.StoragePool;
40-
import com.cloud.storage.StoragePoolHostVO;
4139
import com.cloud.storage.Volume;
4240
import com.cloud.storage.dao.StoragePoolHostDao;
4341
import com.cloud.utils.NumbersUtil;
@@ -76,9 +74,9 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
7674

7775
// data disk and host identified from deploying vm (attach volume case)
7876
if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) {
79-
List<StoragePoolHostVO> hostPools = _poolHostDao.listByHostId(plan.getHostId());
80-
for (StoragePoolHostVO hostPool : hostPools) {
81-
StoragePoolVO pool = _storagePoolDao.findById(hostPool.getPoolId());
77+
List<StoragePoolVO> hostTagsPools = null;
78+
hostTagsPools =_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags());
79+
for (StoragePoolVO pool : hostTagsPools) {
8280
if (pool != null && pool.isLocal()) {
8381
StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());
8482
if (filter(avoid, storagePool, dskCh, plan)) {

server/test/resources/createNetworkOffering.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,6 @@
4848
<bean id="vGPUTypesDaoImpl" class="com.cloud.gpu.dao.VGPUTypesDaoImpl" />
4949
<bean id="usageEventDaoImpl" class="com.cloud.event.dao.UsageEventDaoImpl" />
5050
<bean id="usageEventDetailsDaoImpl" class="com.cloud.event.dao.UsageEventDetailsDaoImpl" />
51+
<bean id="storagePoolHostDaoImpl" class="com.cloud.storage.dao.StoragePoolHostDaoImpl" />
52+
<bean id="primaryDataStoreDaoImpl" class="org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDaoImpl" />
5153
</beans>

0 commit comments

Comments
 (0)