4747import org .apache .cloudstack .api .response .ListResponse ;
4848import org .apache .cloudstack .context .CallContext ;
4949import org .apache .cloudstack .dns .dao .DnsServerDao ;
50+ import org .apache .cloudstack .dns .dao .DnsServerJoinDao ;
5051import org .apache .cloudstack .dns .dao .DnsZoneDao ;
52+ import org .apache .cloudstack .dns .dao .DnsZoneJoinDao ;
5153import org .apache .cloudstack .dns .dao .DnsZoneNetworkMapDao ;
54+ import org .apache .cloudstack .dns .exception .DnsNotFoundException ;
55+ import org .apache .cloudstack .dns .vo .DnsServerJoinVO ;
5256import org .apache .cloudstack .dns .vo .DnsServerVO ;
57+ import org .apache .cloudstack .dns .vo .DnsZoneJoinVO ;
5358import org .apache .cloudstack .dns .vo .DnsZoneNetworkMapVO ;
5459import org .apache .cloudstack .dns .vo .DnsZoneVO ;
5560import org .springframework .stereotype .Component ;
@@ -95,6 +100,10 @@ public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderMa
95100 NicDao nicDao ;
96101 @ Inject
97102 DomainDao domainDao ;
103+ @ Inject
104+ DnsZoneJoinDao dnsZoneJoinDao ;
105+ @ Inject
106+ DnsServerJoinDao dnsServerJoinDao ;
98107
99108 private DnsProvider getProviderByType (DnsProviderType type ) {
100109 if (type == null ) {
@@ -149,9 +158,14 @@ public DnsServer addDnsServer(AddDnsServerCmd cmd) {
149158 @ Override
150159 public ListResponse <DnsServerResponse > listDnsServers (ListDnsServersCmd cmd ) {
151160 Pair <List <DnsServerVO >, Integer > result = searchForDnsServerInternal (cmd );
161+ List <String > serverIds = new ArrayList <>();
162+ for (DnsServer server : result .first ()) {
163+ serverIds .add (server .getUuid ());
164+ }
165+ List <DnsServerJoinVO > joinResult = dnsServerJoinDao .listByUuids (serverIds );
152166 ListResponse <DnsServerResponse > response = new ListResponse <>();
153167 List <DnsServerResponse > serverResponses = new ArrayList <>();
154- for (DnsServerVO server : result . first () ) {
168+ for (DnsServerJoinVO server : joinResult ) {
155169 serverResponses .add (createDnsServerResponse (server ));
156170 }
157171 response .setResponses (serverResponses , result .second ());
@@ -186,9 +200,7 @@ private Pair<List<DnsServerVO>, Integer> searchForDnsServerInternal(ListDnsServe
186200 SearchCriteria <DnsServerVO > sc = sb .create ();
187201 accountMgr .buildACLSearchCriteria (sc , domainId , isRecursive , permittedAccountIds , listProjectResourcesCriteria );
188202 sc .setParameters (ApiConstants .STATE , DnsServer .State .Enabled );
189- if (cmd .getProviderType () != null ) {
190- sc .setParameters (ApiConstants .PROVIDER_TYPE , cmd .getProviderType ());
191- }
203+ sc .setParameters (ApiConstants .PROVIDER_TYPE , cmd .getProviderType ());
192204
193205 Pair <List <DnsServerVO >, Integer > ownServersPair = dnsServerDao .searchAndCount (sc , searchFilter );
194206 List <DnsServerVO > dnsServers = new ArrayList <>(ownServersPair .first ());
@@ -206,9 +218,7 @@ private Pair<List<DnsServerVO>, Integer> searchForDnsServerInternal(ListDnsServe
206218 publicSc .setParameters (ApiConstants .IS_PUBLIC , 1 );
207219 publicSc .setParameters (ApiConstants .DOMAIN_IDS , parentDomainIds .toArray ());
208220 publicSc .setParameters (ApiConstants .STATE , DnsServer .State .Enabled );
209- if (cmd .getProviderType () != null ) {
210- publicSc .setParameters (ApiConstants .PROVIDER_TYPE , cmd .getProviderType ());
211- }
221+ publicSc .setParameters (ApiConstants .PROVIDER_TYPE , cmd .getProviderType ());
212222 List <DnsServerVO > publicServers = dnsServerDao .search (publicSc , null );
213223 List <Long > ownServerIds = dnsServers .stream ().map (DnsServerVO ::getId ).collect (Collectors .toList ());
214224 for (DnsServerVO publicServer : publicServers ) {
@@ -305,21 +315,6 @@ public boolean deleteDnsServer(DeleteDnsServerCmd cmd) {
305315 return dnsServerDao .remove (dnsServerId );
306316 }
307317
308- @ Override
309- public DnsServerResponse createDnsServerResponse (DnsServer server ) {
310- DnsServerResponse response = new DnsServerResponse ();
311- response .setId (server .getUuid ());
312- response .setName (server .getName ());
313- response .setUrl (server .getUrl ());
314- response .setPort (server .getPort ());
315- response .setProvider (server .getProviderType ());
316- response .setPublic (server .isPublicServer ());
317- response .setNameServers (server .getNameServers ());
318- response .setPublicDomainSuffix (server .getPublicDomainSuffix ());
319- response .setObjectName ("dnsserver" );
320- return response ;
321- }
322-
323318 @ Override
324319 public boolean deleteDnsZone (Long zoneId ) {
325320 DnsZoneVO zone = dnsZoneDao .findById (zoneId );
@@ -376,10 +371,14 @@ public DnsZone updateDnsZone(UpdateDnsZoneCmd cmd) {
376371 @ Override
377372 public ListResponse <DnsZoneResponse > listDnsZones (ListDnsZonesCmd cmd ) {
378373 Pair <List <DnsZoneVO >, Integer > result = searchForDnsZonesInternal (cmd );
379-
380- List <DnsZoneResponse > zoneResponses = new ArrayList <>();
374+ List <String > zoneIds = new ArrayList <>();
381375 for (DnsZoneVO zone : result .first ()) {
382- zoneResponses .add (createDnsZoneResponse (zone ));
376+ zoneIds .add (zone .getUuid ());
377+ }
378+ List <DnsZoneJoinVO > zoneJoinVos = dnsZoneJoinDao .listByUuids (zoneIds );
379+ List <DnsZoneResponse > zoneResponses = new ArrayList <>();
380+ for (DnsZoneJoinVO zoneJoin : zoneJoinVos ) {
381+ zoneResponses .add (createDnsZoneResponse (zoneJoin ));
383382 }
384383 ListResponse <DnsZoneResponse > response = new ListResponse <>();
385384 response .setResponses (zoneResponses , result .second ());
@@ -484,6 +483,9 @@ public ListResponse<DnsRecordResponse> listDnsRecords(ListDnsRecordsCmd cmd) {
484483 ListResponse <DnsRecordResponse > listResponse = new ListResponse <>();
485484 listResponse .setResponses (responses , responses .size ());
486485 return listResponse ;
486+ } catch (DnsNotFoundException ex ) {
487+ logger .error ("DNS zone is not found" , ex );
488+ throw new CloudRuntimeException ("DNS zone is not found, please register it first" );
487489 } catch (Exception ex ) {
488490 logger .error ("Failed to list DNS records from provider" , ex );
489491 throw new CloudRuntimeException ("Failed to fetch DNS records" );
@@ -551,16 +553,48 @@ public DnsZone provisionDnsZone(long dnsZoneId) {
551553 return dnsZone ;
552554 }
553555
556+
557+ public DnsServerResponse createDnsServerResponse (DnsServer dnsServer ) {
558+ DnsServerJoinVO serverJoin = dnsServerJoinDao .findById (dnsServer .getId ());
559+ return createDnsServerResponse (serverJoin );
560+ }
561+
562+ DnsServerResponse createDnsServerResponse (DnsServerJoinVO server ) {
563+ DnsServerResponse response = new DnsServerResponse ();
564+ response .setId (server .getUuid ());
565+ response .setName (server .getName ());
566+ response .setUrl (server .getUrl ());
567+ response .setPort (server .getPort ());
568+ response .setProvider (server .getProviderType ());
569+ response .setPublic (server .isPublicServer ());
570+ response .setNameServers (server .getNameServers ());
571+ response .setPublicDomainSuffix (server .getPublicDomainSuffix ());
572+ response .setAccountName (server .getAccountName ());
573+ response .setDomainId (server .getDomainUuid ()); // Note: APIs always return UUIDs, not internal DB IDs!
574+ response .setDomainName (server .getDomainName ());
575+ response .setObjectName ("dnsserver" );
576+ return response ;
577+ }
578+
554579 @ Override
555- public DnsZoneResponse createDnsZoneResponse (DnsZone zone ) {
556- DnsZoneResponse res = new DnsZoneResponse ();
557- res .setName (zone .getName ());
558- res .setDnsServerId (zone .getDnsServerId ());
559- res .setType (zone .getType ());
560- res .setState (zone .getState ());
561- res .setId (zone .getUuid ());
562- res .setDescription (zone .getDescription ());
563- return res ;
580+ public DnsZoneResponse createDnsZoneResponse (DnsZone dnsZone ) {
581+ DnsZoneJoinVO zoneJoinVO = dnsZoneJoinDao .findById (dnsZone .getId ());
582+ return createDnsZoneResponse (zoneJoinVO );
583+ }
584+
585+ DnsZoneResponse createDnsZoneResponse (DnsZoneJoinVO zone ) {
586+ DnsZoneResponse response = new DnsZoneResponse ();
587+ response .setId (zone .getUuid ());
588+ response .setName (zone .getName ());
589+ response .setDnsServerId (zone .getDnsServerUuid ());
590+ response .setAccountName (zone .getAccountName ());
591+ response .setDomainId (zone .getDomainUuid ());
592+ response .setDomainName (zone .getDomainName ());
593+ response .setDnsServerName (zone .getDnsServerName ());
594+ response .setDnsServerAccountName (zone .getDnsServerAccountName ());
595+ response .setState (zone .getState ());
596+ response .setDescription (zone .getDescription ());
597+ return response ;
564598 }
565599
566600 @ Override
0 commit comments