@@ -111,7 +111,6 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
111111
112112 protected SearchBuilder <HostVO > GuidSearch ;
113113 protected SearchBuilder <HostVO > DcSearch ;
114- protected GenericSearchBuilder <HostVO , Long > IdsDcSearch ;
115114 protected SearchBuilder <HostVO > PodSearch ;
116115 protected SearchBuilder <HostVO > ClusterSearch ;
117116 protected SearchBuilder <HostVO > TypeSearch ;
@@ -138,8 +137,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
138137 protected SearchBuilder <HostVO > ManagedRoutingServersSearch ;
139138 protected SearchBuilder <HostVO > SecondaryStorageVMSearch ;
140139
141- protected GenericSearchBuilder <HostVO , Long > HostIdSearch ;
142- protected GenericSearchBuilder <HostVO , Long > HostsInStatusSearch ;
140+ protected GenericSearchBuilder <HostVO , Long > HostsInStatusesSearch ;
143141 protected GenericSearchBuilder <HostVO , Long > CountRoutingByDc ;
144142 protected SearchBuilder <HostTransferMapVO > HostTransferSearch ;
145143 protected SearchBuilder <ClusterVO > ClusterManagedSearch ;
@@ -289,13 +287,6 @@ public void init() {
289287 DcSearch .and ("resourceState" , DcSearch .entity ().getResourceState (), Op .EQ );
290288 DcSearch .done ();
291289
292- IdsDcSearch = createSearchBuilder (Long .class );
293- IdsDcSearch .and ("zoneId" , IdsDcSearch .entity ().getDataCenterId (), SearchCriteria .Op .EQ );
294- IdsDcSearch .and ("resourceState" , IdsDcSearch .entity ().getResourceState (), SearchCriteria .Op .EQ );
295- IdsDcSearch .and ("status" , IdsDcSearch .entity ().getStatus (), Op .EQ );
296- IdsDcSearch .and ("type" , IdsDcSearch .entity ().getType (), SearchCriteria .Op .EQ );
297- IdsDcSearch .done ();
298-
299290 ClusterStatusSearch = createSearchBuilder ();
300291 ClusterStatusSearch .and ("cluster" , ClusterStatusSearch .entity ().getClusterId (), SearchCriteria .Op .EQ );
301292 ClusterStatusSearch .and ("status" , ClusterStatusSearch .entity ().getStatus (), SearchCriteria .Op .EQ );
@@ -396,14 +387,14 @@ public void init() {
396387 AvailHypevisorInZone .groupBy (AvailHypevisorInZone .entity ().getHypervisorType ());
397388 AvailHypevisorInZone .done ();
398389
399- HostsInStatusSearch = createSearchBuilder (Long .class );
400- HostsInStatusSearch .selectFields (HostsInStatusSearch .entity ().getId ());
401- HostsInStatusSearch .and ("dc" , HostsInStatusSearch .entity ().getDataCenterId (), Op .EQ );
402- HostsInStatusSearch .and ("pod" , HostsInStatusSearch .entity ().getPodId (), Op .EQ );
403- HostsInStatusSearch .and ("cluster" , HostsInStatusSearch .entity ().getClusterId (), Op .EQ );
404- HostsInStatusSearch .and ("type" , HostsInStatusSearch .entity ().getType (), Op .EQ );
405- HostsInStatusSearch .and ("statuses" , HostsInStatusSearch .entity ().getStatus (), Op .IN );
406- HostsInStatusSearch .done ();
390+ HostsInStatusesSearch = createSearchBuilder (Long .class );
391+ HostsInStatusesSearch .selectFields (HostsInStatusesSearch .entity ().getId ());
392+ HostsInStatusesSearch .and ("dc" , HostsInStatusesSearch .entity ().getDataCenterId (), Op .EQ );
393+ HostsInStatusesSearch .and ("pod" , HostsInStatusesSearch .entity ().getPodId (), Op .EQ );
394+ HostsInStatusesSearch .and ("cluster" , HostsInStatusesSearch .entity ().getClusterId (), Op .EQ );
395+ HostsInStatusesSearch .and ("type" , HostsInStatusesSearch .entity ().getType (), Op .EQ );
396+ HostsInStatusesSearch .and ("statuses" , HostsInStatusesSearch .entity ().getStatus (), Op .IN );
397+ HostsInStatusesSearch .done ();
407398
408399 CountRoutingByDc = createSearchBuilder (Long .class );
409400 CountRoutingByDc .select (null , Func .COUNT , null );
@@ -466,12 +457,6 @@ public void init() {
466457 HostsInClusterSearch .and ("server" , HostsInClusterSearch .entity ().getManagementServerId (), SearchCriteria .Op .NNULL );
467458 HostsInClusterSearch .done ();
468459
469- HostIdSearch = createSearchBuilder (Long .class );
470- HostIdSearch .selectFields (HostIdSearch .entity ().getId ());
471- HostIdSearch .and ("dataCenterId" , HostIdSearch .entity ().getDataCenterId (), Op .EQ );
472- HostIdSearch .and ("clusterId" , HostIdSearch .entity ().getClusterId (), Op .EQ );
473- HostIdSearch .done ();
474-
475460 _statusAttr = _allAttributes .get ("status" );
476461 _msIdAttr = _allAttributes .get ("managementServerId" );
477462 _pingTimeAttr = _allAttributes .get ("lastPinged" );
@@ -531,38 +516,26 @@ public Integer countUpAndEnabledHostsInZone(long zoneId) {
531516
532517 @ Override
533518 public Integer countAllCPUSockets () {
534- final String sql = "SELECT SUM(host.cpu_sockets) FROM host WHERE host.type = 'Routing' AND host.removed IS NULL" ;
535- int cpuSockets = 0 ;
536- TransactionLegacy txn = TransactionLegacy .currentTxn ();
537- try (PreparedStatement pstmt = txn .prepareAutoCloseStatement (sql )) {
538- try (ResultSet rs = pstmt .executeQuery ()) {
539- if (rs .next ()) {
540- cpuSockets = rs .getInt (1 );
541- }
542- }
543- } catch (SQLException e ) {
544- s_logger .debug ("SQLException caught" , e );
545- }
546- return cpuSockets ;
519+ GenericSearchBuilder <HostVO , Integer > sb = createSearchBuilder (Integer .class );
520+ sb .and ("type" , sb .entity ().getType (), SearchCriteria .Op .EQ );
521+ sb .select (null , Func .SUM , sb .entity ().getCpuSockets ());
522+ sb .done ();
523+ SearchCriteria <Integer > sc = sb .create ();
524+ return customSearch (sc , null ).get (0 );
547525 }
548526
549- private List <Long > listIdsByDataCenterIdAndResourceState (long id , ResourceState state ) {
550- SearchCriteria <Long > sc = IdsDcSearch .create ();
551- sc .setParameters ("zoneId" , id );
552- sc .setParameters ("resourceState" , state );
553- sc .setParameters ("status" , Status .Up );
554- sc .setParameters ("type" , Type .Routing );
555- return customSearch (sc , null );
527+ private List <Long > listIdsForRoutingByZoneIdAndResourceState (long zoneId , ResourceState state ) {
528+ return listIdsBy (Type .Routing , Status .Up , state , null , zoneId , null , null );
556529 }
557530
558531 @ Override
559532 public List <Long > listEnabledIdsByDataCenterId (long id ) {
560- return listIdsByDataCenterIdAndResourceState (id , ResourceState .Enabled );
533+ return listIdsForRoutingByZoneIdAndResourceState (id , ResourceState .Enabled );
561534 }
562535
563536 @ Override
564537 public List <Long > listDisabledIdsByDataCenterId (long id ) {
565- return listIdsByDataCenterIdAndResourceState (id , ResourceState .Disabled );
538+ return listIdsForRoutingByZoneIdAndResourceState (id , ResourceState .Disabled );
566539 }
567540
568541 @ Override
@@ -1199,10 +1172,7 @@ public List<HostVO> findByDataCenterId(Long zoneId) {
11991172
12001173 @ Override
12011174 public List <Long > listIdsByDataCenterId (Long zoneId ) {
1202- SearchCriteria <Long > sc = IdsDcSearch .create ();
1203- sc .setParameters ("dc" , zoneId );
1204- sc .setParameters ("type" , Type .Routing );
1205- return customSearch (sc , null );
1175+ return listIdsBy (Type .Routing , null , null , null , zoneId , null , null );
12061176 }
12071177
12081178 @ Override
@@ -1214,12 +1184,7 @@ public List<HostVO> findByPodId(Long podId) {
12141184
12151185 @ Override
12161186 public List <Long > listIdsByPodId (Long podId ) {
1217- GenericSearchBuilder <HostVO , Long > sb = createSearchBuilder (Long .class );
1218- sb .and ("podId" , sb .entity ().getPodId (), SearchCriteria .Op .EQ );
1219- sb .done ();
1220- SearchCriteria <Long > sc = sb .create ();
1221- sc .setParameters ("podId" , podId );
1222- return customSearch (sc , null );
1187+ return listIdsBy (null , null , null , null , null , podId , null );
12231188 }
12241189
12251190 @ Override
@@ -1229,16 +1194,58 @@ public List<HostVO> findByClusterId(Long clusterId) {
12291194 return listBy (sc );
12301195 }
12311196
1232- @ Override
1233- public List < Long > listIdsByClusterId ( Long clusterId ) {
1197+ private List < Long > listIdsBy ( Host . Type type , Status status , ResourceState resourceState ,
1198+ HypervisorType hypervisorType , Long zoneId , Long podId , Long clusterId ) {
12341199 GenericSearchBuilder <HostVO , Long > sb = createSearchBuilder (Long .class );
1200+ sb .selectFields (sb .entity ().getId ());
1201+ sb .and ("type" , sb .entity ().getType (), SearchCriteria .Op .EQ );
1202+ sb .and ("status" , sb .entity ().getStatus (), SearchCriteria .Op .EQ );
1203+ sb .and ("resourceState" , sb .entity ().getResourceState (), SearchCriteria .Op .EQ );
1204+ sb .and ("hypervisorType" , sb .entity ().getHypervisorType (), SearchCriteria .Op .EQ );
1205+ sb .and ("zoneId" , sb .entity ().getDataCenterId (), SearchCriteria .Op .EQ );
1206+ sb .and ("podId" , sb .entity ().getPodId (), SearchCriteria .Op .EQ );
12351207 sb .and ("clusterId" , sb .entity ().getClusterId (), SearchCriteria .Op .EQ );
12361208 sb .done ();
12371209 SearchCriteria <Long > sc = sb .create ();
1238- sc .setParameters ("clusterId" , clusterId );
1210+ if (type != null ) {
1211+ sc .setParameters ("type" , type );
1212+ }
1213+ if (status != null ) {
1214+ sc .setParameters ("status" , status );
1215+ }
1216+ if (resourceState != null ) {
1217+ sc .setParameters ("resourceState" , resourceState );
1218+ }
1219+ if (hypervisorType != null ) {
1220+ sc .setParameters ("hypervisorType" , hypervisorType );
1221+ }
1222+ if (zoneId != null ) {
1223+ sc .setParameters ("zoneId" , zoneId );
1224+ }
1225+ if (podId != null ) {
1226+ sc .setParameters ("podId" , podId );
1227+ }
1228+ if (clusterId != null ) {
1229+ sc .setParameters ("clusterId" , clusterId );
1230+ }
12391231 return customSearch (sc , null );
12401232 }
12411233
1234+ @ Override
1235+ public List <Long > listIdsByClusterId (Long clusterId ) {
1236+ return listIdsBy (null , null , null , null , null , null , clusterId );
1237+ }
1238+
1239+ @ Override
1240+ public List <Long > listIdsForUpRouting (Long zoneId , Long podId , Long clusterId ) {
1241+ return listIdsBy (Type .Routing , Status .Up , null , null , zoneId , podId , clusterId );
1242+ }
1243+
1244+ @ Override
1245+ public List <Long > listIdsForUpEnabledByZoneAndHypervisor (Long zoneId , HypervisorType hypervisorType ) {
1246+ return listIdsBy (null , Status .Up , ResourceState .Enabled , hypervisorType , zoneId , null , null );
1247+ }
1248+
12421249 @ Override
12431250 public List <HostVO > findByClusterIdAndEncryptionSupport (Long clusterId ) {
12441251 SearchBuilder <DetailVO > hostCapabilitySearch = _detailsDao .createSearchBuilder ();
@@ -1319,9 +1326,7 @@ public HostVO findOldestExistentHypervisorHostInCluster(long clusterId) {
13191326
13201327 @ Override
13211328 public List <Long > listAllHosts (long zoneId ) {
1322- SearchCriteria <Long > sc = HostIdSearch .create ();
1323- sc .addAnd ("dataCenterId" , SearchCriteria .Op .EQ , zoneId );
1324- return customSearch (sc , null );
1329+ return listIdsBy (null , null , null , null , zoneId , null , null );
13251330 }
13261331
13271332 @ Override
@@ -1445,15 +1450,6 @@ public List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacent
14451450 return result ;
14461451 }
14471452
1448- @ Override
1449- public List <HostVO > listAllHostsByType (Host .Type type ) {
1450- SearchCriteria <HostVO > sc = TypeSearch .create ();
1451- sc .setParameters ("type" , type );
1452- sc .setParameters ("resourceState" , ResourceState .Enabled );
1453-
1454- return listBy (sc );
1455- }
1456-
14571453 @ Override
14581454 public List <HostVO > listByType (Host .Type type ) {
14591455 SearchCriteria <HostVO > sc = TypeSearch .create ();
@@ -1602,7 +1598,7 @@ public List<Long> findHostIdsByZoneClusterResourceStateTypeAndHypervisorType(fin
16021598
16031599 @ Override
16041600 public List <Long > listAllIds () {
1605- return customSearch ( HostIdSearch . create () , null );
1601+ return listIdsBy ( null , null , null , null , null , null , null );
16061602 }
16071603
16081604 @ Override
0 commit comments