Skip to content

Commit 7f5e2a7

Browse files
committed
continue UI component work, fix minor issue with apis
1 parent c74a579 commit 7f5e2a7

File tree

12 files changed

+275
-76
lines changed

12 files changed

+275
-76
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/dns/CreateDnsZoneCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class CreateDnsZoneCmd extends BaseAsyncCreateCmd {
6363
description = "The type of zone (Public, Private). Defaults to Public.")
6464
private String type;
6565

66-
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Display text for the zone")
66+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the DNS zone")
6767
private String description;
6868

6969
/////////////////////////////////////////////////////

api/src/main/java/org/apache/cloudstack/api/command/user/dns/DeleteDnsServerCmd.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.Parameter;
2828
import org.apache.cloudstack.api.ServerApiException;
2929
import org.apache.cloudstack.api.response.DnsServerResponse;
30+
import org.apache.cloudstack.api.response.DnsZoneResponse;
3031
import org.apache.cloudstack.api.response.SuccessResponse;
3132
import org.apache.cloudstack.dns.DnsServer;
3233

@@ -51,6 +52,10 @@ public class DeleteDnsServerCmd extends BaseAsyncCmd {
5152
required = true, description = "the ID of the DNS server")
5253
private Long id;
5354

55+
@Parameter(name = ApiConstants.CLEANUP, type = CommandType.BOOLEAN,
56+
entityType = DnsZoneResponse.class, description = "True if all associated DNS zones have to be cleaned up with this server")
57+
private Boolean cleanup;
58+
5459
/////////////////////////////////////////////////////
5560
/////////////////// Accessors ///////////////////////
5661
/////////////////////////////////////////////////////
@@ -93,4 +98,8 @@ public long getEntityOwnerId() {
9398

9499
@Override
95100
public String getEventDescription() { return "Deleting DNS server ID: " + getId(); }
101+
102+
public Boolean getCleanup() {
103+
return Boolean.TRUE.equals(cleanup);
104+
}
96105
}

api/src/main/java/org/apache/cloudstack/api/command/user/dns/UpdateDnsZoneCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class UpdateDnsZoneCmd extends BaseCmd {
4545
required = true, description = "The ID of the DNS zone")
4646
private Long id;
4747

48-
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "Display text for the zone")
48+
@Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "The description of the DNS zone to be updated")
4949
private String description;
5050

5151
/////////////////////////////////////////////////////

plugins/dns/powerdns/src/main/java/org/apache/cloudstack/dns/powerdns/PowerDnsClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.http.client.methods.HttpGet;
4141
import org.apache.http.client.methods.HttpPatch;
4242
import org.apache.http.client.methods.HttpPost;
43+
import org.apache.http.client.methods.HttpPut;
4344
import org.apache.http.client.methods.HttpUriRequest;
4445
import org.apache.http.entity.StringEntity;
4546
import org.apache.http.impl.client.CloseableHttpClient;
@@ -185,8 +186,8 @@ public void updateZone(String baseUrl, Integer port, String apiKey, String exter
185186
nsArray.add(ns.endsWith(".") ? ns : ns + ".");
186187
}
187188
}
188-
HttpPatch request = new HttpPatch(url);
189-
request.setEntity(new org.apache.http.entity.StringEntity(json.toString(), StandardCharsets.UTF_8));
189+
HttpPut request = new HttpPut(url);
190+
request.setEntity(new StringEntity(json.toString(), StandardCharsets.UTF_8));
190191
execute(request, apiKey, 204);
191192
}
192193

@@ -221,7 +222,7 @@ public String modifyRecord(String baseUrl, Integer port, String apiKey, String e
221222
}
222223
String encodedZone = URLEncoder.encode(normalizedZone, StandardCharsets.UTF_8);
223224
HttpPatch request = new HttpPatch(buildUrl(baseUrl, port, "/servers/" + externalServerId + "/zones/" + encodedZone));
224-
request.setEntity(new org.apache.http.entity.StringEntity(root.toString(), StandardCharsets.UTF_8));
225+
request.setEntity(new StringEntity(root.toString(), StandardCharsets.UTF_8));
225226
execute(request, apiKey, 204);
226227
return normalizedRecord.endsWith(".") ? normalizedRecord.substring(0, normalizedRecord.length() - 1) : normalizedRecord;
227228
}

server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
import org.apache.cloudstack.dns.dao.DnsZoneDao;
5252
import org.apache.cloudstack.dns.dao.DnsZoneJoinDao;
5353
import org.apache.cloudstack.dns.dao.DnsZoneNetworkMapDao;
54+
import org.apache.cloudstack.dns.exception.DnsConflictException;
5455
import org.apache.cloudstack.dns.exception.DnsNotFoundException;
56+
import org.apache.cloudstack.dns.exception.DnsTransportException;
5557
import org.apache.cloudstack.dns.vo.DnsServerJoinVO;
5658
import org.apache.cloudstack.dns.vo.DnsServerVO;
5759
import org.apache.cloudstack.dns.vo.DnsZoneJoinVO;
@@ -176,18 +178,10 @@ public ListResponse<DnsServerResponse> listDnsServers(ListDnsServersCmd cmd) {
176178
}
177179

178180
private Pair<List<DnsServerVO>, Integer> searchForDnsServerInternal(ListDnsServersCmd cmd) {
179-
Long dnsServerId = cmd.getId();
180181
Account caller = CallContext.current().getCallingAccount();
181-
if (dnsServerId != null) {
182-
DnsServerVO dnsServerVO = dnsServerDao.findById(dnsServerId);
183-
if (dnsServerVO == null) {
184-
return null;
185-
}
186-
return new Pair<>(Collections.singletonList(dnsServerVO), 1);
187-
}
188182
Set<Long> parentDomainIds = domainDao.getDomainParentIds(caller.getDomainId());
189183
Filter searchFilter = new Filter(DnsServerVO.class, ApiConstants.ID, true, cmd.getStartIndex(), cmd.getPageSizeVal());
190-
return dnsServerDao.searchDnsServer(dnsServerId, caller.getAccountId(), parentDomainIds, cmd.getProviderType(), cmd.getKeyword(), searchFilter);
184+
return dnsServerDao.searchDnsServer(cmd.getId(), caller.getAccountId(), parentDomainIds, cmd.getProviderType(), cmd.getKeyword(), searchFilter);
191185
}
192186

193187
@Override
@@ -272,6 +266,9 @@ public boolean deleteDnsServer(DeleteDnsServerCmd cmd) {
272266
}
273267
Account caller = CallContext.current().getCallingAccount();
274268
accountMgr.checkAccess(caller, dnsServer);
269+
if (cmd.getCleanup()) {
270+
// ToDo cleanup associated dnsZones
271+
}
275272
return dnsServerDao.remove(dnsServerId);
276273
}
277274

@@ -322,6 +319,7 @@ public DnsZone updateDnsZone(UpdateDnsZoneCmd cmd) {
322319
try {
323320
DnsProvider provider = getProviderByType(server.getProviderType());
324321
provider.updateZone(server, dnsZone);
322+
dnsZoneDao.update(dnsZone.getId(), dnsZone);
325323
} catch (Exception ex) {
326324
logger.error("Failed to update DNS zone: {} on DNS server: {}", dnsZone.getName(), server.getName(), ex);
327325
throw new CloudRuntimeException("Failed to update DNS zone: " + dnsZone.getName());
@@ -375,20 +373,23 @@ public DnsRecordResponse createDnsRecord(CreateDnsRecordCmd cmd) {
375373
if (StringUtils.isBlank(recordName)) {
376374
throw new InvalidParameterValueException("Empty DNS record name is not allowed");
377375
}
378-
DnsZoneVO zone = dnsZoneDao.findById(cmd.getDnsZoneId());
379-
if (zone == null) {
376+
DnsZoneVO dnsZone = dnsZoneDao.findById(cmd.getDnsZoneId());
377+
if (dnsZone == null) {
380378
throw new InvalidParameterValueException("DNS zone not found.");
381379
}
382380
Account caller = CallContext.current().getCallingAccount();
383-
accountMgr.checkAccess(caller, null, true, zone);
384-
DnsServerVO server = dnsServerDao.findById(zone.getDnsServerId());
381+
accountMgr.checkAccess(caller, null, true, dnsZone);
382+
DnsServerVO server = dnsServerDao.findById(dnsZone.getDnsServerId());
383+
if (server == null) {
384+
throw new CloudRuntimeException("The underlying DNS server for this DNS zone is missing.");
385+
}
385386
try {
386387
DnsRecord.RecordType type = cmd.getType();
387388
List<String> normalizedContents = cmd.getContents().stream()
388389
.map(value -> DnsProviderUtil.normalizeDnsRecordValue(value, type)).collect(Collectors.toList());
389390
DnsRecord record = new DnsRecord(recordName, type, normalizedContents, cmd.getTtl());
390391
DnsProvider provider = getProviderByType(server.getProviderType());
391-
String normalizedRecordName = provider.addRecord(server, zone, record);
392+
String normalizedRecordName = provider.addRecord(server, dnsZone, record);
392393
record.setName(normalizedRecordName);
393394
return createDnsRecordResponse(record);
394395
} catch (Exception ex) {
@@ -507,7 +508,13 @@ public DnsZone provisionDnsZone(long dnsZoneId) {
507508
} catch (Exception ex) {
508509
dnsZoneDao.remove(dnsZoneId);
509510
logger.error("Failed to provision DNS zone: {} on DNS server: {}", dnsZone.getName(), server.getName(), ex);
510-
throw new CloudRuntimeException("Failed to provision DNS zone: " + dnsZone.getName());
511+
String errorMsg = "";
512+
if ( ex instanceof DnsConflictException) {
513+
errorMsg = String.format("DNS zone: %s already exists", dnsZone.getName());
514+
} else if (ex instanceof DnsTransportException){
515+
errorMsg = String.format("DNS server: %s not reachable", server.getName());
516+
}
517+
throw new CloudRuntimeException(errorMsg);
511518
}
512519
return dnsZone;
513520
}
@@ -562,6 +569,7 @@ public DnsRecordResponse createDnsRecordResponse(DnsRecord record) {
562569
res.setName(record.getName());
563570
res.setType(record.getType());
564571
res.setContent(record.getContents());
572+
res.setTtl(record.getTtl());
565573
return res;
566574
}
567575

ui/public/locales/en.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@
716716
"label.create.webhook": "Create Webhook",
717717
"label.created": "Created",
718718
"label.creating": "Creating",
719+
"label.creating.dns.zone": "Creating DNS zone",
719720
"label.creating.iprange": "Creating IP ranges",
720721
"label.nameservers": "DNS Nameservers",
721722
"label.credit": "Credit",
@@ -941,19 +942,22 @@
941942
"label.dns": "DNS",
942943
"label.dns1": "DNS 1",
943944
"label.dns2": "DNS 2",
944-
"label.dns.add.record": "Add DNS Record",
945+
"label.dns.create.record": "Create DNS Record",
945946
"label.dns.add.server": "Add DNS Server",
946-
"label.dns.add.zone": "Add DNS Zone",
947+
"label.dns.create.zone": "Create DNS Zone",
947948
"label.dns.credentials": "DNS API key",
948949
"label.dns.delete.server": "Delete DNS Server",
949950
"label.dns.delete.zone": "Delete DNS Zone",
951+
"label.dns.externalserverid": "DNS server ID",
952+
"label.dns.publicdomainsuffix": "Public domain suffix",
950953
"label.dns.records": "DNS Records",
951954
"label.dns.record.name.tooltip": "The hostname or subdomain for this record (e.g. www)",
952955
"label.dns.record.type.tooltip": "The DNS record type",
953956
"label.dns.record.contents.tooltip": "The content values for this DNS record (type and press Enter to add)",
954957
"label.dns.record.ttl.tooltip": "Time to live in seconds",
955958
"label.dns.record.url": "Instance URL",
956959
"label.dns.server": "DNS Server",
960+
"label.dnsserverid": "DNS Server ID",
957961
"label.dnsservername": "DNS Server name",
958962
"label.dns.servers": "DNS Servers",
959963
"label.dns.zone": "DNS Zone",
@@ -2252,6 +2256,7 @@
22522256
"label.scope": "Scope",
22532257
"label.scope.tooltip": "Primary Storage Pool Scope",
22542258
"label.search": "Search",
2259+
"label.seconds": "Seconds",
22552260
"label.secondary.isolated.vlan.type.isolated": "Isolated",
22562261
"label.secondary.isolated.vlan.type.promiscuous": "Promiscuous",
22572262
"label.secondary.storage": "Secondary Storage",
@@ -3540,6 +3545,7 @@
35403545
"message.error.remove.tungsten.routing.policy": "Removing Tungsten-Fabric Routing Policy from Network failed",
35413546
"message.error.remove.vm.schedule": "Removing Instance Schedule failed",
35423547
"message.error.required.input": "Please enter input",
3548+
"message.error.required.publicdomainsuffix": "Please enter the public domain suffix if the public server is enabled",
35433549
"message.error.reset.config": "Unable to reset config to default value",
35443550
"message.error.retrieve.kubeconfig": "Unable to retrieve Kubernetes Cluster config",
35453551
"message.error.routing.policy.term": "Community need to have the following format number:number",
@@ -3884,10 +3890,10 @@
38843890
"message.success.add.egress.rule": "Successfully added new egress rule",
38853891
"message.success.add.firewall.rule": "Successfully added new firewall rule",
38863892
"message.success.add.dns.server": "Successfully added DNS server",
3887-
"message.success.add.dns.zone": "Successfully added DNS zone",
3893+
"message.success.create.dns.zone": "Successfully created DNS zone",
3894+
"message.success.create.dns.record": "Successfully created DNS record",
38883895
"message.success.update.dns.server": "Successfully updated DNS server",
38893896
"message.success.update.dns.zone": "Successfully updated DNS zone",
3890-
"message.success.add.dns.record": "Successfully added DNS record",
38913897
"message.success.delete.dns.record": "Successfully deleted DNS record",
38923898
"message.success.add.guest.network": "Successfully created guest Network",
38933899
"message.success.add.gpu.device": "Successfully added GPU device",

ui/src/config/section/network.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,17 +1522,16 @@ export default {
15221522
label: 'label.dns.update.server',
15231523
dataView: true,
15241524
popup: true,
1525-
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/UpdateDnsServer.vue'))),
1526-
show: (record) => { return true }
1525+
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/UpdateDnsServer.vue')))
15271526
},
15281527
{
15291528
api: 'deleteDnsServer',
15301529
icon: 'delete-outlined',
15311530
label: 'label.dns.delete.server',
15321531
message: 'message.action.delete.dns.server',
15331532
dataView: true,
1534-
groupAction: true,
1535-
show: (record) => { return true },
1533+
popup: true,
1534+
groupAction: false,
15361535
groupMap: (selection) => { return selection.map(x => { return { id: x } }) }
15371536
}
15381537
]
@@ -1542,8 +1541,8 @@ export default {
15421541
title: 'label.dns.zones',
15431542
icon: 'global-outlined',
15441543
permission: ['listDnsZones'],
1545-
columns: ['name', 'state', 'dnsservername', 'account'],
1546-
details: ['name', 'id', 'state', 'dnsservername', 'dnsserverid', 'account', 'domainpath'],
1544+
columns: ['name', 'state', 'dnsservername', 'account', 'description'],
1545+
details: ['name', 'id', 'state', 'dnsservername', 'dnsserverid', 'account', 'domainpath', 'description'],
15471546
tabs: [{
15481547
name: 'details',
15491548
component: shallowRef(defineAsyncComponent(() => import('@/components/view/DetailsTab.vue')))
@@ -1557,11 +1556,10 @@ export default {
15571556
{
15581557
api: 'createDnsZone',
15591558
icon: 'plus-outlined',
1560-
label: 'label.dns.add.zone',
1559+
label: 'label.dns.create.zone',
15611560
listView: true,
15621561
popup: true,
1563-
disabled: (record) => false,
1564-
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/AddDnsZone.vue'))),
1562+
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/CreateDnsZone.vue'))),
15651563
show: () => {
15661564
return true
15671565
}
@@ -1572,7 +1570,6 @@ export default {
15721570
label: 'label.dns.update.zone',
15731571
dataView: true,
15741572
popup: true,
1575-
disabled: (record) => false,
15761573
component: shallowRef(defineAsyncComponent(() => import('@/views/network/dns/UpdateDnsZone.vue'))),
15771574
show: (record) => { return true }
15781575
},
@@ -1582,7 +1579,8 @@ export default {
15821579
label: 'label.dns.delete.zone',
15831580
message: 'message.action.delete.dns.zone',
15841581
dataView: true,
1585-
groupAction: true,
1582+
popup: true,
1583+
groupAction: false,
15861584
disabled: (record) => false,
15871585
show: (record) => { return true },
15881586
groupMap: (selection) => { return selection.map(x => { return { id: x } }) }

0 commit comments

Comments
 (0)