@@ -78,7 +78,10 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
7878 protected GenericSearchBuilder <VMInstanceVO , Long > CountRunningByHost ;
7979 protected GenericSearchBuilder <VMInstanceVO , Long > CountRunningByAccount ;
8080 protected SearchBuilder <VMInstanceVO > NetworkTypeSearch ;
81+ protected GenericSearchBuilder <VMInstanceVO , String > DistinctHostNameSearch ;
82+
8183 ResourceTagsDaoImpl _tagsDao = ComponentLocator .inject (ResourceTagsDaoImpl .class );
84+ NicDao _nicDao = ComponentLocator .inject (NicDaoImpl .class );
8285
8386 protected final Attribute _updateTimeAttr ;
8487
@@ -98,6 +101,7 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
98101 protected final HostDaoImpl _hostDao = ComponentLocator .inject (HostDaoImpl .class );
99102
100103 protected VMInstanceDaoImpl () {
104+
101105 IdStatesSearch = createSearchBuilder ();
102106 IdStatesSearch .and ("id" , IdStatesSearch .entity ().getId (), Op .EQ );
103107 IdStatesSearch .and ("states" , IdStatesSearch .entity ().getState (), Op .IN );
@@ -533,7 +537,7 @@ public Long countRunningByAccount(long accountId){
533537 @ Override
534538 public List <VMInstanceVO > listNonRemovedVmsByTypeAndNetwork (long networkId , VirtualMachine .Type ... types ) {
535539 if (NetworkTypeSearch == null ) {
536- NicDao _nicDao = ComponentLocator . getLocator ( "management-server" ). getDao ( NicDao . class );
540+
537541 SearchBuilder <NicVO > nicSearch = _nicDao .createSearchBuilder ();
538542 nicSearch .and ("networkId" , nicSearch .entity ().getNetworkId (), SearchCriteria .Op .EQ );
539543
@@ -554,6 +558,34 @@ public List<VMInstanceVO> listNonRemovedVmsByTypeAndNetwork(long networkId, Virt
554558 return listBy (sc );
555559 }
556560
561+
562+
563+ @ Override
564+ public List <String > listDistinctHostNames (long networkId , VirtualMachine .Type ... types ) {
565+ if (DistinctHostNameSearch == null ) {
566+
567+ SearchBuilder <NicVO > nicSearch = _nicDao .createSearchBuilder ();
568+ nicSearch .and ("networkId" , nicSearch .entity ().getNetworkId (), SearchCriteria .Op .EQ );
569+
570+ DistinctHostNameSearch = createSearchBuilder (String .class );
571+ DistinctHostNameSearch .selectField (DistinctHostNameSearch .entity ().getHostName ());
572+
573+ DistinctHostNameSearch .and ("types" , DistinctHostNameSearch .entity ().getType (), SearchCriteria .Op .IN );
574+ DistinctHostNameSearch .and ("removed" , DistinctHostNameSearch .entity ().getRemoved (), SearchCriteria .Op .NULL );
575+ DistinctHostNameSearch .join ("nicSearch" , nicSearch , DistinctHostNameSearch .entity ().getId (),
576+ nicSearch .entity ().getInstanceId (), JoinBuilder .JoinType .INNER );
577+ DistinctHostNameSearch .done ();
578+ }
579+
580+ SearchCriteria <String > sc = DistinctHostNameSearch .create ();
581+ if (types != null && types .length != 0 ) {
582+ sc .setParameters ("types" , (Object []) types );
583+ }
584+ sc .setJoinParameters ("nicSearch" , "networkId" , networkId );
585+
586+ return customSearch (sc , null );
587+ }
588+
557589 @ Override
558590 @ DB
559591 public boolean remove (Long id ) {
0 commit comments