|
50 | 50 | import com.cloud.host.Status; |
51 | 51 | import com.cloud.host.Status.Event; |
52 | 52 | import com.cloud.hypervisor.Hypervisor; |
| 53 | +import com.cloud.hypervisor.Hypervisor.HypervisorType; |
53 | 54 | import com.cloud.info.RunningHostCountInfo; |
54 | 55 | import com.cloud.org.Grouping; |
55 | 56 | import com.cloud.org.Managed; |
@@ -85,7 +86,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao |
85 | 86 |
|
86 | 87 | protected SearchBuilder<HostVO> IdStatusSearch; |
87 | 88 | protected SearchBuilder<HostVO> TypeDcSearch; |
88 | | - protected SearchBuilder<HostVO> TypeDcStatusSearch; |
89 | 89 | protected SearchBuilder<HostVO> TypeClusterStatusSearch; |
90 | 90 | protected SearchBuilder<HostVO> MsStatusSearch; |
91 | 91 | protected SearchBuilder<HostVO> DcPrivateIpAddressSearch; |
@@ -128,6 +128,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao |
128 | 128 | protected GenericSearchBuilder<HostVO, Long> ClustersForHostsNotOwnedByAnyMSSearch; |
129 | 129 | protected GenericSearchBuilder<ClusterVO, Long> AllClustersSearch; |
130 | 130 | protected SearchBuilder<HostVO> HostsInClusterSearch; |
| 131 | + protected SearchBuilder<HostVO> HostByHypervisor; |
131 | 132 |
|
132 | 133 | protected Attribute _statusAttr; |
133 | 134 | protected Attribute _resourceStateAttr; |
@@ -188,13 +189,6 @@ public void init() { |
188 | 189 | SecondaryStorageVMSearch.and("status", SecondaryStorageVMSearch.entity().getStatus(), SearchCriteria.Op.EQ); |
189 | 190 | SecondaryStorageVMSearch.done(); |
190 | 191 |
|
191 | | - TypeDcStatusSearch = createSearchBuilder(); |
192 | | - TypeDcStatusSearch.and("type", TypeDcStatusSearch.entity().getType(), SearchCriteria.Op.EQ); |
193 | | - TypeDcStatusSearch.and("dc", TypeDcStatusSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); |
194 | | - TypeDcStatusSearch.and("status", TypeDcStatusSearch.entity().getStatus(), SearchCriteria.Op.EQ); |
195 | | - TypeDcStatusSearch.and("resourceState", TypeDcStatusSearch.entity().getResourceState(), SearchCriteria.Op.EQ); |
196 | | - TypeDcStatusSearch.done(); |
197 | | - |
198 | 192 | TypeClusterStatusSearch = createSearchBuilder(); |
199 | 193 | TypeClusterStatusSearch.and("type", TypeClusterStatusSearch.entity().getType(), SearchCriteria.Op.EQ); |
200 | 194 | TypeClusterStatusSearch.and("cluster", TypeClusterStatusSearch.entity().getClusterId(), SearchCriteria.Op.EQ); |
@@ -410,6 +404,14 @@ public void init() { |
410 | 404 | HostIdSearch.and("dataCenterId", HostIdSearch.entity().getDataCenterId(), Op.EQ); |
411 | 405 | HostIdSearch.done(); |
412 | 406 |
|
| 407 | + HostByHypervisor = createSearchBuilder(); |
| 408 | + HostByHypervisor.and("hypervisorType", HostByHypervisor.entity().getHypervisorType(), Op.EQ); |
| 409 | + HostByHypervisor.and("status", HostByHypervisor.entity().getStatus(), Op.EQ); |
| 410 | + HostByHypervisor.and("zoneId", HostByHypervisor.entity().getDataCenterId(), Op.EQ); |
| 411 | + HostByHypervisor.and("resourceState", HostByHypervisor.entity().getResourceState(), Op.EQ); |
| 412 | + HostByHypervisor.and("type", HostByHypervisor.entity().getType(), Op.EQ); |
| 413 | + HostByHypervisor.done(); |
| 414 | + |
413 | 415 | _statusAttr = _allAttributes.get("status"); |
414 | 416 | _msIdAttr = _allAttributes.get("managementServerId"); |
415 | 417 | _pingTimeAttr = _allAttributes.get("lastPinged"); |
@@ -695,6 +697,32 @@ public void markHostsAsDisconnected(long msId, long lastPing) { |
695 | 697 | update(ub, sc, null); |
696 | 698 | } |
697 | 699 |
|
| 700 | + @Override |
| 701 | + public HostVO findOneByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType) { |
| 702 | + return findOneByZoneAndHypervisorAndResourceState(zoneId, hypervisorType, ResourceState.Enabled); |
| 703 | + } |
| 704 | + |
| 705 | + private HostVO findOneByZoneAndHypervisorAndResourceState(long zoneId, HypervisorType hypervisorType, ResourceState enabled) { |
| 706 | + SearchCriteria<HostVO> sc = HostByHypervisor.create(); |
| 707 | + sc.setParameters("hypervisorType", hypervisorType); |
| 708 | + sc.setParameters("zoneId", zoneId); |
| 709 | + sc.setParameters("status", Status.Up); |
| 710 | + sc.setParameters("resourceState", enabled); |
| 711 | + sc.setParameters("type", Type.Routing); |
| 712 | + |
| 713 | + Filter filter = new Filter(1); |
| 714 | + List<HostVO> hostVOList = listBy(sc, filter); |
| 715 | + if (hostVOList.isEmpty()) { |
| 716 | + return null; |
| 717 | + } |
| 718 | + return hostVOList.get(0); |
| 719 | + } |
| 720 | + |
| 721 | + @Override |
| 722 | + public HostVO findOneDisabledByZoneAndHypervisor(long zoneId, HypervisorType hypervisorType) { |
| 723 | + return findOneByZoneAndHypervisorAndResourceState(zoneId, hypervisorType, ResourceState.Disabled); |
| 724 | + } |
| 725 | + |
698 | 726 | @Override |
699 | 727 | public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, long dcId, String hostTag) { |
700 | 728 |
|
|
0 commit comments