2727import javax .ejb .Local ;
2828import javax .inject .Inject ;
2929
30- import com .cloud .storage .*;
3130import org .apache .cloudstack .affinity .AffinityGroupResponse ;
3231import org .apache .cloudstack .affinity .AffinityGroupVMMapVO ;
3332import org .apache .cloudstack .affinity .dao .AffinityGroupVMMapDao ;
5655import org .apache .cloudstack .api .command .user .volume .ListResourceDetailsCmd ;
5756import org .apache .cloudstack .api .command .user .volume .ListVolumesCmd ;
5857import org .apache .cloudstack .api .command .user .zone .ListZonesByCmd ;
59- import org .apache .cloudstack .api .response .*;
58+ import org .apache .cloudstack .api .response .AccountResponse ;
59+ import org .apache .cloudstack .api .response .AsyncJobResponse ;
60+ import org .apache .cloudstack .api .response .DiskOfferingResponse ;
61+ import org .apache .cloudstack .api .response .DomainRouterResponse ;
62+ import org .apache .cloudstack .api .response .EventResponse ;
63+ import org .apache .cloudstack .api .response .HostResponse ;
64+ import org .apache .cloudstack .api .response .ImageStoreResponse ;
65+ import org .apache .cloudstack .api .response .InstanceGroupResponse ;
66+ import org .apache .cloudstack .api .response .ListResponse ;
67+ import org .apache .cloudstack .api .response .ProjectAccountResponse ;
68+ import org .apache .cloudstack .api .response .ProjectInvitationResponse ;
69+ import org .apache .cloudstack .api .response .ProjectResponse ;
70+ import org .apache .cloudstack .api .response .ResourceDetailResponse ;
71+ import org .apache .cloudstack .api .response .ResourceTagResponse ;
72+ import org .apache .cloudstack .api .response .SecurityGroupResponse ;
73+ import org .apache .cloudstack .api .response .ServiceOfferingResponse ;
74+ import org .apache .cloudstack .api .response .StoragePoolResponse ;
75+ import org .apache .cloudstack .api .response .TemplateResponse ;
76+ import org .apache .cloudstack .api .response .UserResponse ;
77+ import org .apache .cloudstack .api .response .UserVmResponse ;
78+ import org .apache .cloudstack .api .response .VolumeResponse ;
79+ import org .apache .cloudstack .api .response .ZoneResponse ;
6080import org .apache .cloudstack .engine .subsystem .api .storage .TemplateState ;
6181import org .apache .cloudstack .query .QueryService ;
6282import org .apache .log4j .Logger ;
132152import com .cloud .server .TaggedResourceService ;
133153import com .cloud .service .ServiceOfferingVO ;
134154import com .cloud .service .dao .ServiceOfferingDao ;
155+ import com .cloud .storage .DataStoreRole ;
156+ import com .cloud .storage .ScopeType ;
157+ import com .cloud .storage .Storage ;
135158import com .cloud .storage .Storage .ImageFormat ;
136159import com .cloud .storage .Storage .TemplateType ;
160+ import com .cloud .storage .VMTemplateVO ;
161+ import com .cloud .storage .Volume ;
162+ import com .cloud .storage .VolumeDetailVO ;
137163import com .cloud .storage .dao .VMTemplateDao ;
138164import com .cloud .storage .dao .VolumeDetailsDao ;
139165import com .cloud .template .VirtualMachineTemplate .TemplateFilter ;
@@ -729,7 +755,7 @@ private Pair<List<UserVmJoinVO>, Integer> searchForUserVMsByCriteria(Criteria c,
729755 // first search distinct vm id by using query criteria and pagination
730756 SearchBuilder <UserVmJoinVO > sb = _userVmJoinDao .createSearchBuilder ();
731757 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
732- // ids
758+ // ids
733759 _accountMgr .buildACLViewSearchBuilder (sb , domainId , isRecursive , permittedAccounts ,
734760 listProjectResourcesCriteria );
735761
@@ -951,7 +977,7 @@ private Pair<List<SecurityGroupJoinVO>, Integer> searchForSecurityGroupsInternal
951977 cmd .getPageSizeVal ());
952978 SearchBuilder <SecurityGroupJoinVO > sb = _securityGroupJoinDao .createSearchBuilder ();
953979 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
954- // ids
980+ // ids
955981 _accountMgr .buildACLViewSearchBuilder (sb , domainId , isRecursive , permittedAccounts ,
956982 listProjectResourcesCriteria );
957983
@@ -1474,7 +1500,7 @@ public Pair<List<HostJoinVO>, Integer> searchForServersInternal(ListHostsCmd cmd
14741500
14751501 SearchBuilder <HostJoinVO > sb = _hostJoinDao .createSearchBuilder ();
14761502 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
1477- // ids
1503+ // ids
14781504 sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
14791505 sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .LIKE );
14801506 sb .and ("type" , sb .entity ().getType (), SearchCriteria .Op .LIKE );
@@ -1935,7 +1961,7 @@ private Pair<List<StoragePoolJoinVO>, Integer> searchForStoragePoolsInternal(Lis
19351961
19361962 SearchBuilder <StoragePoolJoinVO > sb = _poolJoinDao .createSearchBuilder ();
19371963 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
1938- // ids
1964+ // ids
19391965 sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
19401966 sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .EQ );
19411967 sb .and ("path" , sb .entity ().getPath (), SearchCriteria .Op .EQ );
@@ -2025,7 +2051,7 @@ private Pair<List<ImageStoreJoinVO>, Integer> searchForImageStoresInternal(ListI
20252051
20262052 SearchBuilder <ImageStoreJoinVO > sb = _imageStoreJoinDao .createSearchBuilder ();
20272053 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
2028- // ids
2054+ // ids
20292055 sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
20302056 sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .EQ );
20312057 sb .and ("dataCenterId" , sb .entity ().getZoneId (), SearchCriteria .Op .EQ );
@@ -2105,7 +2131,7 @@ private Pair<List<ImageStoreJoinVO>, Integer> searchForCacheStoresInternal(ListC
21052131
21062132 SearchBuilder <ImageStoreJoinVO > sb = _imageStoreJoinDao .createSearchBuilder ();
21072133 sb .select (null , Func .DISTINCT , sb .entity ().getId ()); // select distinct
2108- // ids
2134+ // ids
21092135 sb .and ("id" , sb .entity ().getId (), SearchCriteria .Op .EQ );
21102136 sb .and ("name" , sb .entity ().getName (), SearchCriteria .Op .EQ );
21112137 sb .and ("dataCenterId" , sb .entity ().getZoneId (), SearchCriteria .Op .EQ );
@@ -2229,14 +2255,14 @@ private Pair<List<DiskOfferingJoinVO>, Integer> searchForDiskOfferingsInternal(L
22292255
22302256 spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
22312257 spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public
2232- // offering as where
2258+ // offering as where
22332259 sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
22342260 sc .addAnd ("systemUse" , SearchCriteria .Op .EQ , false ); // non-root
2235- // users should
2236- // not see
2237- // system
2238- // offering at
2239- // all
2261+ // users should
2262+ // not see
2263+ // system
2264+ // offering at
2265+ // all
22402266
22412267 }
22422268
@@ -2356,7 +2382,7 @@ private Pair<List<ServiceOfferingJoinVO>, Integer> searchForServiceOfferingsInte
23562382
23572383 spc .addOr ("domainId" , SearchCriteria .Op .IN , domainIds .toArray ());
23582384 spc .addOr ("domainId" , SearchCriteria .Op .NULL ); // include public
2359- // offering as where
2385+ // offering as where
23602386 sc .addAnd ("domainId" , SearchCriteria .Op .SC , spc );
23612387
23622388 } else {
@@ -2439,8 +2465,9 @@ private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesB
24392465 Filter searchFilter = new Filter (DataCenterJoinVO .class , null , false , cmd .getStartIndex (), cmd .getPageSizeVal ());
24402466 SearchCriteria <DataCenterJoinVO > sc = _dcJoinDao .createSearchCriteria ();
24412467
2442- if (networkType != null )
2468+ if (networkType != null ) {
24432469 sc .addAnd ("networkType" , SearchCriteria .Op .EQ , networkType );
2470+ }
24442471
24452472 if (id != null ) {
24462473 sc .addAnd ("id" , SearchCriteria .Op .EQ , id );
@@ -2550,8 +2577,8 @@ private Pair<List<DataCenterJoinVO>, Integer> listDataCentersInternal(ListZonesB
25502577 if (account != null ) {
25512578 if ((available != null ) && Boolean .FALSE .equals (available )) {
25522579 Set <Long > dcIds = new HashSet <Long >(); // data centers with
2553- // at least one VM
2554- // running
2580+ // at least one VM
2581+ // running
25552582 List <DomainRouterVO > routers = _routerDao .listBy (account .getId ());
25562583 for (DomainRouterVO router : routers ) {
25572584 dcIds .add (router .getDataCenterId ());
@@ -2664,6 +2691,9 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
26642691 Boolean isAscending = Boolean .parseBoolean (_configDao .getValue ("sortkey.algorithm" ));
26652692 isAscending = (isAscending == null ? true : isAscending );
26662693 Filter searchFilter = new Filter (TemplateJoinVO .class , "sortKey" , isAscending , startIndex , pageSize );
2694+
2695+ SearchBuilder <TemplateJoinVO > sb = _templateJoinDao .createSearchBuilder ();
2696+ sb .select (null , Func .DISTINCT , sb .entity ().getTempZonePair ()); // select distinct (templateId, zoneId) pair
26672697 SearchCriteria <TemplateJoinVO > sc = _templateJoinDao .createSearchCriteria ();
26682698
26692699 // verify templateId parameter and specially handle it
@@ -2846,7 +2876,14 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
28462876 }
28472877
28482878 if (zoneId != null ) {
2849- sc .addAnd ("dataCenterId" , SearchCriteria .Op .EQ , zoneId );
2879+ SearchCriteria <TemplateJoinVO > zoneSc = _templateJoinDao .createSearchCriteria ();
2880+ zoneSc .addAnd ("dataCenterId" , SearchCriteria .Op .EQ , zoneId );
2881+ // handle the case where xs-tools.iso and vmware-tools.iso do not have data_center information in template_view
2882+ SearchCriteria <TemplateJoinVO > isoPerhostSc = _templateJoinDao .createSearchCriteria ();
2883+ isoPerhostSc .addAnd ("format" , SearchCriteria .Op .EQ , ImageFormat .ISO );
2884+ isoPerhostSc .addAnd ("templateType" , SearchCriteria .Op .EQ , TemplateType .PERHOST );
2885+ zoneSc .addOr ("templateType" , SearchCriteria .Op .SC , isoPerhostSc );
2886+ sc .addAnd ("dataCenterId" , SearchCriteria .Op .SC , zoneSc );
28502887 }
28512888
28522889 if (!showDomr ) {
@@ -2867,12 +2904,12 @@ private Pair<List<TemplateJoinVO>, Integer> searchForTemplatesInternal(Long temp
28672904 return uniqueTmplPair ;
28682905 }
28692906 List <TemplateJoinVO > uniqueTmpls = uniqueTmplPair .first ();
2870- Long [] vrIds = new Long [uniqueTmpls .size ()];
2907+ String [] tzIds = new String [uniqueTmpls .size ()];
28712908 int i = 0 ;
28722909 for (TemplateJoinVO v : uniqueTmpls ) {
2873- vrIds [i ++] = v .getId ();
2910+ tzIds [i ++] = v .getTempZonePair ();
28742911 }
2875- List <TemplateJoinVO > vrs = _templateJoinDao .searchByIds ( vrIds );
2912+ List <TemplateJoinVO > vrs = _templateJoinDao .searchByTemplateZonePair ( tzIds );
28762913 return new Pair <List <TemplateJoinVO >, Integer >(vrs , count );
28772914
28782915 // TODO: revisit the special logic for iso search in
@@ -2926,6 +2963,7 @@ private Pair<List<TemplateJoinVO>, Integer> searchForIsosInternal(ListIsosCmd cm
29262963 cmd .listInReadyState (), permittedAccounts , caller , listProjectResourcesCriteria , tags );
29272964 }
29282965
2966+ @ Override
29292967 public ListResponse <AffinityGroupResponse > listAffinityGroups (Long affinityGroupId , String affinityGroupName ,
29302968 String affinityGroupType , Long vmId , String accountName , Long domainId , boolean isRecursive ,
29312969 boolean listAll , Long startIndex , Long pageSize ) {
@@ -2971,7 +3009,7 @@ public Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsInternal(Long
29713009 listProjectResourcesCriteria );
29723010
29733011 groupSearch .select (null , Func .DISTINCT , groupSearch .entity ().getId ()); // select
2974- // distinct
3012+ // distinct
29753013
29763014 SearchCriteria <AffinityGroupJoinVO > sc = groupSearch .create ();
29773015 _accountMgr .buildACLViewSearchCriteria (sc , domainId , isRecursive , permittedAccounts ,
@@ -3026,6 +3064,7 @@ private Pair<List<AffinityGroupJoinVO>, Integer> listAffinityGroupsByVM(long vmI
30263064 return new Pair <List <AffinityGroupJoinVO >, Integer >(ags , count );
30273065 }
30283066
3067+ @ Override
30293068 public List <ResourceDetailResponse > listResource (ListResourceDetailsCmd cmd ) {
30303069
30313070 String key = cmd .getKey ();
0 commit comments