1818package org .apache .cloudstack .dns ;
1919
2020import java .util .ArrayList ;
21+ import java .util .Collections ;
2122import java .util .List ;
2223
2324import javax .inject .Inject ;
@@ -96,7 +97,7 @@ private DnsProvider getProvider(DnsProviderType type) {
9697 return provider ;
9798 }
9899 }
99- throw new CloudRuntimeException ("No plugin found for DNS Provider type: " + type );
100+ throw new CloudRuntimeException ("No plugin found for DNS provider type: " + type );
100101 }
101102
102103 @ Override
@@ -105,7 +106,7 @@ public DnsServer addDnsServer(AddDnsServerCmd cmd) {
105106 DnsServer existing = dnsServerDao .findByUrlAndAccount (cmd .getUrl (), caller .getId ());
106107 if (existing != null ) {
107108 throw new InvalidParameterValueException (
108- "This Account already has a DNS Server integration for URL: " + cmd .getUrl ());
109+ "This Account already has a DNS server integration for URL: " + cmd .getUrl ());
109110 }
110111 DnsProviderType type = DnsProviderType .fromString (cmd .getProvider ());
111112 DnsProvider provider = getProvider (type );
@@ -156,7 +157,7 @@ public DnsServer updateDnsServer(UpdateDnsServerCmd cmd) {
156157 Long dnsServerId = cmd .getId ();
157158 DnsServerVO dnsServer = dnsServerDao .findById (dnsServerId );
158159 if (dnsServer == null ) {
159- throw new InvalidParameterValueException (String .format ("DNS Server with ID: %s not found." , dnsServerId ));
160+ throw new InvalidParameterValueException (String .format ("DNS server with ID: %s not found." , dnsServerId ));
160161 }
161162
162163 Account caller = CallContext .current ().getCallingAccount ();
@@ -176,7 +177,7 @@ public DnsServer updateDnsServer(UpdateDnsServerCmd cmd) {
176177 if (!cmd .getUrl ().equals (originalUrl )) {
177178 DnsServer duplicate = dnsServerDao .findByUrlAndAccount (cmd .getUrl (), dnsServer .getAccountId ());
178179 if (duplicate != null && duplicate .getId () != dnsServer .getId ()) {
179- throw new InvalidParameterValueException ("Another DNS Server with this URL already exists." );
180+ throw new InvalidParameterValueException ("Another DNS server with this URL already exists." );
180181 }
181182 dnsServer .setUrl (cmd .getUrl ());
182183 validationRequired = true ;
@@ -230,7 +231,7 @@ public boolean deleteDnsServer(DeleteDnsServerCmd cmd) {
230231 Long dnsServerId = cmd .getId ();
231232 DnsServerVO dnsServer = dnsServerDao .findById (dnsServerId );
232233 if (dnsServer == null ) {
233- throw new InvalidParameterValueException (String .format ("DNS Server with ID: %s not found." , dnsServerId ));
234+ throw new InvalidParameterValueException (String .format ("DNS server with ID: %s not found." , dnsServerId ));
234235 }
235236 Account caller = CallContext .current ().getCallingAccount ();
236237 if (!accountMgr .isRootAdmin (caller .getId ()) && dnsServer .getAccountId () != caller .getId ()) {
@@ -260,7 +261,7 @@ public DnsServer getDnsServer(Long id) {
260261 public boolean deleteDnsZone (Long zoneId ) {
261262 DnsZoneVO zone = dnsZoneDao .findById (zoneId );
262263 if (zone == null ) {
263- throw new InvalidParameterValueException ("DNS Zone with ID " + zoneId + " not found." );
264+ throw new InvalidParameterValueException ("DNS zone with ID " + zoneId + " not found." );
264265 }
265266
266267 Account caller = CallContext .current ().getCallingAccount ();
@@ -269,10 +270,10 @@ public boolean deleteDnsZone(Long zoneId) {
269270 if (server != null && zone .getState () == DnsZone .State .Active ) {
270271 try {
271272 DnsProvider provider = getProvider (server .getProviderType ());
272- logger .debug ("Deleting DNS zone {} from provider." , zone .getName ());
273+ logger .debug ("Deleting DNS zone: {} from provider." , zone .getName ());
273274 provider .deleteZone (server , zone );
274275 } catch (Exception ex ) {
275- logger .error ("Failed to delete zone from provider" , ex );
276+ logger .error ("Failed to delete DNS zone from provider" , ex );
276277 throw new CloudRuntimeException ("Failed to delete DNS zone." );
277278 }
278279 }
@@ -336,7 +337,7 @@ public DnsZone getDnsZone(long id) {
336337 public DnsRecordResponse createDnsRecord (CreateDnsRecordCmd cmd ) {
337338 DnsZoneVO zone = dnsZoneDao .findById (cmd .getDnsZoneId ());
338339 if (zone == null ) {
339- throw new InvalidParameterValueException ("DNS Zone not found." );
340+ throw new InvalidParameterValueException ("DNS zone not found." );
340341 }
341342
342343 Account caller = CallContext .current ().getCallingAccount ();
@@ -358,7 +359,7 @@ public DnsRecordResponse createDnsRecord(CreateDnsRecordCmd cmd) {
358359 public boolean deleteDnsRecord (DeleteDnsRecordCmd cmd ) {
359360 DnsZoneVO zone = dnsZoneDao .findById (cmd .getDnsZoneId ());
360361 if (zone == null ) {
361- throw new InvalidParameterValueException ("DNS Zone not found." );
362+ throw new InvalidParameterValueException ("DNS zone not found." );
362363 }
363364
364365 Account caller = CallContext .current ().getCallingAccount ();
@@ -376,21 +377,21 @@ public boolean deleteDnsRecord(DeleteDnsRecordCmd cmd) {
376377 return true ;
377378 } catch (Exception ex ) {
378379 logger .error ("Failed to delete DNS record via provider" , ex );
379- throw new CloudRuntimeException (String .format ("Failed to delete record: %s" , cmd .getName ()));
380+ throw new CloudRuntimeException (String .format ("Failed to delete DNS record: %s" , cmd .getName ()));
380381 }
381382 }
382383
383384 @ Override
384385 public ListResponse <DnsRecordResponse > listDnsRecords (ListDnsRecordsCmd cmd ) {
385386 DnsZoneVO zone = dnsZoneDao .findById (cmd .getDnsZoneId ());
386387 if (zone == null ) {
387- throw new InvalidParameterValueException (String .format ("DNS Zone with ID %s not found." , cmd .getDnsZoneId ()));
388+ throw new InvalidParameterValueException (String .format ("DNS zone with ID %s not found." , cmd .getDnsZoneId ()));
388389 }
389390 Account caller = CallContext .current ().getCallingAccount ();
390391 accountMgr .checkAccess (caller , null , true , zone );
391392 DnsServerVO server = dnsServerDao .findById (zone .getDnsServerId ());
392393 if (server == null ) {
393- throw new CloudRuntimeException ("The underlying DNS Server for this zone is missing." );
394+ throw new CloudRuntimeException ("The underlying DNS server for this DNS zone is missing." );
394395 }
395396 try {
396397 DnsProvider provider = getProvider (server .getProviderType ());
@@ -425,23 +426,23 @@ public DnsZone allocateDnsZone(CreateDnsZoneCmd cmd) {
425426 Account caller = CallContext .current ().getCallingAccount ();
426427 DnsServerVO server = dnsServerDao .findById (cmd .getDnsServerId ());
427428 if (server == null ) {
428- throw new InvalidParameterValueException ("DNS Server not found" );
429+ throw new InvalidParameterValueException ("DNS server not found" );
429430 }
430431 boolean isOwner = (server .getAccountId () == caller .getId ());
431432 if (!server .isPublic () && !isOwner ) {
432- throw new PermissionDeniedException ("You do not have permission to use this DNS Server ." );
433+ throw new PermissionDeniedException ("You do not have permission to use this DNS server ." );
433434 }
434435 DnsZone .ZoneType type = DnsZone .ZoneType .Public ;
435436 if (cmd .getType () != null ) {
436437 try {
437438 type = DnsZone .ZoneType .valueOf (cmd .getType ());
438439 } catch (IllegalArgumentException e ) {
439- throw new InvalidParameterValueException ("Invalid Zone Type" );
440+ throw new InvalidParameterValueException ("Invalid DNS zone Type" );
440441 }
441442 }
442443 DnsZoneVO existing = dnsZoneDao .findByNameServerAndType (cmd .getName (), server .getId (), type );
443444 if (existing != null ) {
444- throw new InvalidParameterValueException ("Zone already exists on this server." );
445+ throw new InvalidParameterValueException ("DNS zone already exists on this server." );
445446 }
446447 DnsZoneVO dnsZoneVO = new DnsZoneVO (cmd .getName (), type , server .getId (), caller .getId (), caller .getDomainId (), cmd .getDescription ());
447448 return dnsZoneDao .persist (dnsZoneVO );
@@ -451,20 +452,20 @@ public DnsZone allocateDnsZone(CreateDnsZoneCmd cmd) {
451452 public DnsZone provisionDnsZone (long zoneId ) {
452453 DnsZoneVO dnsZone = dnsZoneDao .findById (zoneId );
453454 if (dnsZone == null ) {
454- throw new CloudRuntimeException ("DNS Zone not found during provisioning" );
455+ throw new CloudRuntimeException ("DNS zone not found during provisioning" );
455456 }
456457 DnsServerVO server = dnsServerDao .findById (dnsZone .getDnsServerId ());
457-
458458 try {
459459 DnsProvider provider = getProvider (server .getProviderType ());
460- logger . debug ( "Provision DNS zone: {} on DNS server: {}" , dnsZone . getName (), server . getName () );
461- provider . provisionZone ( server , dnsZone );
460+ String externalReferenceId = provider . provisionZone ( server , dnsZone );
461+ dnsZone . setExternalReference ( externalReferenceId );
462462 dnsZone .setState (DnsZone .State .Active );
463+ logger .debug ("DNS zone: {} created successfully on DNS server: {} with ID: {}" , dnsZone .getName (), server .getName (), zoneId );
463464 dnsZoneDao .update (dnsZone .getId (), dnsZone );
464465 } catch (Exception ex ) {
465- logger .error ("Failed to provision zone: {} on server: {}" , dnsZone .getName (), server .getName (), ex );
466+ logger .error ("Failed to provision DNS zone: {} on DNS server: {}" , dnsZone .getName (), server .getName (), ex );
466467 dnsZoneDao .remove (zoneId );
467- throw new CloudRuntimeException ("Failed to provision zone: " + dnsZone .getName ());
468+ throw new CloudRuntimeException ("Failed to provision DNS zone: " + dnsZone .getName ());
468469 }
469470 return dnsZone ;
470471 }
@@ -495,7 +496,7 @@ public DnsZoneNetworkMapResponse associateZoneToNetwork(AssociateDnsZoneToNetwor
495496 Account caller = CallContext .current ().getCallingAccount ();
496497 DnsZoneVO zone = dnsZoneDao .findById (cmd .getDnsZoneId ());
497498 if (zone == null ) {
498- throw new InvalidParameterValueException ("DNS Zone not found." );
499+ throw new InvalidParameterValueException ("DNS zone not found." );
499500 }
500501 accountMgr .checkAccess (caller , null , true , zone );
501502
@@ -510,7 +511,7 @@ public DnsZoneNetworkMapResponse associateZoneToNetwork(AssociateDnsZoneToNetwor
510511 accountMgr .checkAccess (caller , null , true , network );
511512 DnsZoneNetworkMapVO existing = dnsZoneNetworkMapDao .findByZoneAndNetwork (zone .getId (), network .getId ());
512513 if (existing != null ) {
513- throw new InvalidParameterValueException ("This DNS Zone is already associated with this Network." );
514+ throw new InvalidParameterValueException ("This DNS zone is already associated with this Network." );
514515 }
515516 DnsZoneNetworkMapVO mapping = new DnsZoneNetworkMapVO (zone .getId (), network .getId (), cmd .getSubDomain ());
516517 dnsZoneNetworkMapDao .persist (mapping );
@@ -556,7 +557,7 @@ private boolean processDnsRecordForInstance(Long instanceId, Long networkId, boo
556557 // 1. Fetch VM and verify access
557558 UserVmVO instance = userVmDao .findById (instanceId );
558559 if (instance == null ) {
559- throw new InvalidParameterValueException ("Instance not found." );
560+ throw new InvalidParameterValueException ("Provided Instance not found." );
560561 }
561562 accountMgr .checkAccess (CallContext .current ().getCallingAccount (), null , true , instance );
562563
@@ -599,7 +600,7 @@ private boolean processDnsRecordForInstance(Long instanceId, Long networkId, boo
599600 DnsProvider provider = getProvider (server .getProviderType ());
600601 // Handle IPv4 (A Record)
601602 if (nic .getIPv4Address () != null ) {
602- DnsRecord recordA = new DnsRecord (recordName , DnsRecord .RecordType .A , java . util . Arrays . asList (nic .getIPv4Address ()), 3600 );
603+ DnsRecord recordA = new DnsRecord (recordName , DnsRecord .RecordType .A , Collections . singletonList (nic .getIPv4Address ()), 3600 );
603604 if (isAdd ) {
604605 provider .addRecord (server , zone , recordA );
605606 } else {
@@ -610,7 +611,7 @@ private boolean processDnsRecordForInstance(Long instanceId, Long networkId, boo
610611
611612 // Handle IPv6 (AAAA Record) if it exists
612613 if (nic .getIPv6Address () != null ) {
613- DnsRecord recordAAAA = new DnsRecord (recordName , DnsRecord .RecordType .AAAA , java . util . Arrays . asList (nic .getIPv6Address ()), 3600 );
614+ DnsRecord recordAAAA = new DnsRecord (recordName , DnsRecord .RecordType .AAAA , Collections . singletonList (nic .getIPv6Address ()), 3600 );
614615 if (isAdd ) {
615616 provider .addRecord (server , zone , recordAAAA );
616617 } else {
0 commit comments