|
31 | 31 | import javax.inject.Inject; |
32 | 32 | import javax.naming.ConfigurationException; |
33 | 33 |
|
34 | | -import org.apache.log4j.Logger; |
35 | | -import org.springframework.stereotype.Component; |
36 | | - |
37 | 34 | import com.google.gson.Gson; |
38 | 35 |
|
| 36 | +import org.apache.log4j.Logger; |
| 37 | +import org.springframework.stereotype.Component; |
39 | 38 | import org.apache.cloudstack.api.ApiConstants; |
40 | 39 | import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd; |
41 | 40 | import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd; |
|
147 | 146 | import com.cloud.utils.component.Manager; |
148 | 147 | import com.cloud.utils.component.ManagerBase; |
149 | 148 | import com.cloud.utils.db.DB; |
| 149 | +import com.cloud.utils.db.GenericSearchBuilder; |
150 | 150 | import com.cloud.utils.db.GlobalLock; |
151 | 151 | import com.cloud.utils.db.SearchBuilder; |
152 | 152 | import com.cloud.utils.db.SearchCriteria; |
| 153 | +import com.cloud.utils.db.SearchCriteria.Func; |
153 | 154 | import com.cloud.utils.db.SearchCriteria.Op; |
154 | 155 | import com.cloud.utils.db.SearchCriteria2; |
155 | 156 | import com.cloud.utils.db.SearchCriteriaService; |
@@ -262,6 +263,8 @@ public void setPodAllocators(List<PodAllocator> _podAllocators) { |
262 | 263 |
|
263 | 264 | private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 30; // seconds |
264 | 265 |
|
| 266 | + private GenericSearchBuilder<HostVO, String> _hypervisorsInDC; |
| 267 | + |
265 | 268 | private void insertListener(Integer event, ResourceListener listener) { |
266 | 269 | List<ResourceListener> lst = _lifeCycleListeners.get(event); |
267 | 270 | if (lst == null) { |
@@ -1338,6 +1341,15 @@ public Cluster getCluster(Long clusterId) { |
1338 | 1341 | public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { |
1339 | 1342 | _defaultSystemVMHypervisor = HypervisorType.getType(_configDao.getValue(Config.SystemVMDefaultHypervisor.toString())); |
1340 | 1343 | _gson = GsonHelper.getGson(); |
| 1344 | + |
| 1345 | + _hypervisorsInDC = _hostDao.createSearchBuilder(String.class); |
| 1346 | + _hypervisorsInDC.select(null, Func.DISTINCT, _hypervisorsInDC.entity().getHypervisorType()); |
| 1347 | + _hypervisorsInDC.and("hypervisorType", _hypervisorsInDC.entity().getHypervisorType(), SearchCriteria.Op.NNULL); |
| 1348 | + _hypervisorsInDC.and("dataCenter", _hypervisorsInDC.entity().getDataCenterId(), SearchCriteria.Op.EQ); |
| 1349 | + _hypervisorsInDC.and("id", _hypervisorsInDC.entity().getId(), SearchCriteria.Op.NEQ); |
| 1350 | + _hypervisorsInDC.and("type", _hypervisorsInDC.entity().getType(), SearchCriteria.Op.EQ); |
| 1351 | + _hypervisorsInDC.done(); |
| 1352 | + |
1341 | 1353 | return true; |
1342 | 1354 | } |
1343 | 1355 |
|
@@ -2418,23 +2430,25 @@ public List<HostVO> listAllHostsInAllZonesByType(Type type) { |
2418 | 2430 |
|
2419 | 2431 | @Override |
2420 | 2432 | public List<HypervisorType> listAvailHypervisorInZone(Long hostId, Long zoneId) { |
2421 | | - SearchCriteriaService<HostVO, HostVO> sc = SearchCriteria2.create(HostVO.class); |
| 2433 | + SearchCriteria<String> sc = _hypervisorsInDC.create(); |
2422 | 2434 | if (zoneId != null) { |
2423 | | - sc.addAnd(sc.getEntity().getDataCenterId(), Op.EQ, zoneId); |
| 2435 | + sc.setParameters("dataCenter", zoneId); |
2424 | 2436 | } |
2425 | 2437 | if (hostId != null) { |
2426 | 2438 | // exclude the given host, since we want to check what hypervisor is already handled |
2427 | 2439 | // in adding this new host |
2428 | | - sc.addAnd(sc.getEntity().getId(), Op.NEQ, hostId); |
| 2440 | + sc.setParameters("id", hostId); |
2429 | 2441 | } |
2430 | | - sc.addAnd(sc.getEntity().getType(), Op.EQ, Host.Type.Routing); |
2431 | | - List<HostVO> hosts = sc.list(); |
| 2442 | + sc.setParameters("type", Host.Type.Routing); |
2432 | 2443 |
|
2433 | | - List<HypervisorType> hypers = new ArrayList<HypervisorType>(5); |
2434 | | - for (HostVO host : hosts) { |
2435 | | - hypers.add(host.getHypervisorType()); |
| 2444 | + // The search is not able to return list of enums, so getting |
| 2445 | + // list of hypervisors as strings and then converting them to enum |
| 2446 | + List<String> hvs = _hostDao.customSearch(sc, null); |
| 2447 | + List<HypervisorType> hypervisors = new ArrayList<HypervisorType>(); |
| 2448 | + for (String hv : hvs) { |
| 2449 | + hypervisors.add(HypervisorType.getType(hv)); |
2436 | 2450 | } |
2437 | | - return hypers; |
| 2451 | + return hypervisors; |
2438 | 2452 | } |
2439 | 2453 |
|
2440 | 2454 | @Override |
|
0 commit comments