Skip to content

Commit f5ce280

Browse files
committed
CLOUDSTACK-6810: Fix storage migration of a vm with volume on local was failing. When a plan
with hostid included was passed to the local storage pool allocator, it returned all the local storage pools in the cluster, instead of just the local pool on the given host in the plan. This was happening the search at a host level was happening only for data disk. Fixed this. Additionally, the query to list the storage pools on a host was failing if the pool did have tags. Fixed the query too. CLOUDSTACK-6802: Fix for not being able to attach data disk on local. This issue gets fixed with the above issue too. The query to list pools on a host was failing if there were no tags on the storage pool.
1 parent 76c71c7 commit f5ce280

2 files changed

Lines changed: 21 additions & 29 deletions

File tree

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.List;
2525
import java.util.Map;
2626

27-
import javax.annotation.PostConstruct;
2827
import javax.ejb.Local;
2928
import javax.inject.Inject;
3029
import javax.naming.ConfigurationException;
@@ -55,9 +54,6 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long>
5554
protected final SearchBuilder<StoragePoolVO> DcPodAnyClusterSearch;
5655
protected final SearchBuilder<StoragePoolVO> DeleteLvmSearch;
5756
protected final GenericSearchBuilder<StoragePoolVO, Long> StatusCountSearch;
58-
protected SearchBuilder<StoragePoolVO> HostSearch;
59-
protected SearchBuilder<StoragePoolHostVO> HostPoolSearch;
60-
protected SearchBuilder<StoragePoolDetailVO> TagPoolSearch;
6157

6258
@Inject
6359
protected StoragePoolDetailsDao _detailsDao;
@@ -120,26 +116,6 @@ public PrimaryDataStoreDaoImpl() {
120116

121117
}
122118

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-
143119
@Override
144120
public List<StoragePoolVO> findPoolByName(String name) {
145121
SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
@@ -345,11 +321,29 @@ public List<StoragePoolVO> findLocalStoragePoolsByTags(long dcId, long podId, Lo
345321

346322
@Override
347323
public List<StoragePoolVO> findLocalStoragePoolsByHostAndTags(long hostId, String[] tags) {
324+
SearchBuilder<StoragePoolVO> hostSearch = createSearchBuilder();
325+
SearchBuilder<StoragePoolHostVO> hostPoolSearch = _hostDao.createSearchBuilder();
326+
SearchBuilder<StoragePoolDetailVO> tagPoolSearch = _detailsDao.createSearchBuilder();;
348327

349-
SearchCriteria<StoragePoolVO> sc = HostSearch.create();
328+
// Search for pools on the host
329+
hostPoolSearch.and("hostId", hostPoolSearch.entity().getHostId(), Op.EQ);
330+
// Set criteria for pools
331+
hostSearch.and("scope", hostSearch.entity().getScope(), Op.EQ);
332+
hostSearch.and("removed", hostSearch.entity().getRemoved(), Op.NULL);
333+
hostSearch.and("status", hostSearch.entity().getStatus(), Op.EQ);
334+
hostSearch.join("hostJoin", hostPoolSearch, hostSearch.entity().getId(), hostPoolSearch.entity().getPoolId(), JoinBuilder.JoinType.INNER);
335+
336+
if (!(tags == null || tags.length == 0 )) {
337+
tagPoolSearch.and("name", tagPoolSearch.entity().getName(), Op.EQ);
338+
tagPoolSearch.and("value", tagPoolSearch.entity().getValue(), Op.EQ);
339+
hostSearch.join("tagJoin", tagPoolSearch, hostSearch.entity().getId(), tagPoolSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
340+
}
341+
342+
SearchCriteria<StoragePoolVO> sc = hostSearch.create();
350343
sc.setJoinParameters("hostJoin", "hostId", hostId );
351344
sc.setParameters("scope", ScopeType.HOST.toString());
352345
sc.setParameters("status", Status.Up.toString());
346+
353347
if (!(tags == null || tags.length == 0 )) {
354348
Map<String, String> details = tagsToDetails(tags);
355349
for (Map.Entry<String, String> detail : details.entrySet()) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
3737
import com.cloud.service.dao.ServiceOfferingDao;
3838
import com.cloud.storage.StoragePool;
39-
import com.cloud.storage.Volume;
4039
import com.cloud.storage.dao.StoragePoolHostDao;
4140
import com.cloud.utils.NumbersUtil;
4241
import com.cloud.vm.DiskProfile;
@@ -73,9 +72,8 @@ protected List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmPr
7372
List<StoragePool> suitablePools = new ArrayList<StoragePool>();
7473

7574
// data disk and host identified from deploying vm (attach volume case)
76-
if (dskCh.getType() == Volume.Type.DATADISK && plan.getHostId() != null) {
77-
List<StoragePoolVO> hostTagsPools = null;
78-
hostTagsPools =_storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags());
75+
if (plan.getHostId() != null) {
76+
List<StoragePoolVO> hostTagsPools = _storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags());
7977
for (StoragePoolVO pool : hostTagsPools) {
8078
if (pool != null && pool.isLocal()) {
8179
StoragePool storagePool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(pool.getId());

0 commit comments

Comments
 (0)