Skip to content

Commit 9911c28

Browse files
committed
Changes done to AddDnsServer, ListDnsServer, DeleteDnsServer and UpdateDnsServer
1 parent 6ef7f9b commit 9911c28

16 files changed

Lines changed: 637 additions & 50 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,11 @@ public class ApiConstants {
13331333
public static final String OBJECT_STORAGE_LIMIT = "objectstoragelimit";
13341334
public static final String OBJECT_STORAGE_TOTAL = "objectstoragetotal";
13351335

1336+
// DNS provider related
1337+
public static final String NAME_SERVERS = "nameservers";
1338+
public static final String CREDENTIALS = "credentials";
1339+
public static final String PUBLIC_DOMAIN_SUFFIX = "publicdomainsuffix";
1340+
13361341
public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
13371342
"a boolean or a numeric value: if it results in a boolean value, the tariff value will be applied according to the result; if it results in a numeric value, the " +
13381343
"numeric value will be applied; if the result is neither a boolean nor a numeric value, the tariff will not be applied. If the rule is not informed, the tariff " +

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

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@
2121

2222
import org.apache.cloudstack.api.APICommand;
2323
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
2425
import org.apache.cloudstack.api.BaseCmd;
2526
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
2628
import org.apache.cloudstack.api.response.DnsServerResponse;
2729
import org.apache.cloudstack.context.CallContext;
2830
import org.apache.cloudstack.dns.DnsProviderManager;
2931
import org.apache.cloudstack.dns.DnsServer;
32+
import org.apache.commons.lang3.BooleanUtils;
3033

3134
@APICommand(name = "addDnsServer", description = "Adds a new external DNS server",
3235
responseObject = DnsServerResponse.class, requestHasSensitiveInfo = true)
@@ -45,14 +48,23 @@ public class AddDnsServerCmd extends BaseCmd {
4548
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "API URL of the provider")
4649
private String url;
4750

48-
@Parameter(name = "provider", type = CommandType.STRING, required = true, description = "Provider type (e.g., PowerDNS)")
51+
@Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, required = true, description = "Provider type (e.g., PowerDNS)")
4952
private String provider;
5053

51-
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "API Username")
52-
private String username;
54+
@Parameter(name = ApiConstants.CREDENTIALS, type = CommandType.STRING, required = false, description = "API Key or Credentials for the external provider")
55+
private String credentials;
5356

54-
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "API Password or Token")
55-
private String password;
57+
@Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, description = "Port number of the external DNS server")
58+
private Integer port;
59+
60+
@Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "Whether the DNS server is publicly accessible by other accounts")
61+
private Boolean isPublic;
62+
63+
@Parameter(name = ApiConstants.PUBLIC_DOMAIN_SUFFIX, type = CommandType.STRING, description = "The domain suffix used for public access (e.g. public.example.com)")
64+
private String publicDomainSuffix;
65+
66+
@Parameter(name = ApiConstants.NAME_SERVERS, type = CommandType.STRING, description = "Comma separated list of name servers")
67+
private String nameServers;
5668

5769
/////////////////////////////////////////////////////
5870
/////////////////// Accessors ///////////////////////
@@ -61,19 +73,45 @@ public class AddDnsServerCmd extends BaseCmd {
6173
public String getName() { return name; }
6274
public String getUrl() { return url; }
6375
public String getProvider() { return provider; }
64-
public String getUsername() { return username; }
65-
public String getPassword() { return password; }
76+
public String getCredentials() {
77+
return credentials;
78+
}
6679

67-
@Override
68-
public void execute() {
69-
DnsServer server = dnsProviderManager.addDnsServer(this);
70-
DnsServerResponse response = dnsProviderManager.createDnsServerResponse(server);
71-
response.setResponseName(getCommandName());
72-
setResponseObject(response);
80+
public Integer getPort() {
81+
return port;
82+
}
83+
84+
public Boolean isPublic() {
85+
return BooleanUtils.isTrue(isPublic);
86+
}
87+
88+
public String getPublicDomainSuffix() {
89+
return publicDomainSuffix;
90+
}
91+
92+
public String getNameServers() {
93+
return nameServers;
7394
}
7495

7596
@Override
7697
public long getEntityOwnerId() {
7798
return CallContext.current().getCallingAccount().getId();
7899
}
100+
101+
@Override
102+
public void execute() {
103+
try {
104+
DnsServer server = dnsProviderManager.addDnsServer(this);
105+
if (server != null) {
106+
DnsServerResponse response = dnsProviderManager.createDnsServerResponse(server);
107+
response.setResponseName(getCommandName());
108+
setResponseObject(response);
109+
} else {
110+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add DNS server");
111+
}
112+
} catch (Exception ex) {
113+
logger.error("Failed to add DNS server", ex);
114+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
115+
}
116+
}
79117
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ public long getEntityOwnerId() {
7676
public String getEventType() { return EventTypes.EVENT_DNS_SERVER_DELETE; }
7777

7878
@Override
79-
public String getEventDescription() { return "Deleting DNS Server ID: " + getId(); }
79+
public String getEventDescription() { return "Deleting DNS server ID: " + getId(); }
8080
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public String getProvider() {
5151
public void execute() {
5252
ListResponse<DnsServerResponse> response = dnsProviderManager.listDnsServers(this);
5353
response.setResponseName(getCommandName());
54+
response.setObjectName("dnsserver");
5455
setResponseObject(response);
5556
}
5657

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.api.command.user.dns;
19+
20+
import javax.inject.Inject;
21+
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.DnsServerResponse;
29+
import org.apache.cloudstack.context.CallContext;
30+
import org.apache.cloudstack.dns.DnsProviderManager;
31+
import org.apache.cloudstack.dns.DnsServer;
32+
import org.apache.commons.lang3.BooleanUtils;
33+
34+
@APICommand(name = "updateDnsServer", description = "Update DNS server",
35+
responseObject = DnsServerResponse.class, requestHasSensitiveInfo = true)
36+
public class UpdateDnsServerCmd extends BaseCmd {
37+
38+
@Inject
39+
DnsProviderManager dnsProviderManager;
40+
41+
/////////////////////////////////////////////////////
42+
//////////////// API parameters /////////////////////
43+
/////////////////////////////////////////////////////
44+
45+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = DnsServerResponse.class,
46+
required = true, description = "The ID of the DNS server to update")
47+
private Long id;
48+
49+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "Name of the DNS server")
50+
private String name;
51+
52+
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, description = "API URL of the provider")
53+
private String url;
54+
55+
@Parameter(name = ApiConstants.CREDENTIALS, type = CommandType.STRING, required = false, description = "API Key or Credentials for the external provider")
56+
private String credentials;
57+
58+
@Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, description = "Port number of the external DNS server")
59+
private Integer port;
60+
61+
@Parameter(name = ApiConstants.IS_PUBLIC, type = CommandType.BOOLEAN, description = "Whether the DNS server is publicly accessible by other accounts")
62+
private Boolean isPublic;
63+
64+
@Parameter(name = ApiConstants.PUBLIC_DOMAIN_SUFFIX, type = CommandType.STRING, description = "The domain suffix used for public access (e.g. public.example.com)")
65+
private String publicDomainSuffix;
66+
67+
@Parameter(name = ApiConstants.NAME_SERVERS, type = CommandType.STRING, description = "Comma separated list of name servers")
68+
private String nameServers;
69+
70+
/////////////////////////////////////////////////////
71+
/////////////////// Accessors ///////////////////////
72+
/////////////////////////////////////////////////////
73+
74+
public Long getId() { return id; }
75+
public String getName() { return name; }
76+
public String getUrl() { return url; }
77+
public String getCredentials() {
78+
return credentials;
79+
}
80+
public Integer getPort() {
81+
return port;
82+
}
83+
public Boolean isPublic() {
84+
return BooleanUtils.isTrue(isPublic);
85+
}
86+
public String getPublicDomainSuffix() {
87+
return publicDomainSuffix;
88+
}
89+
public String getNameServers() { return nameServers; }
90+
91+
@Override
92+
public long getEntityOwnerId() {
93+
return CallContext.current().getCallingAccount().getId();
94+
}
95+
96+
@Override
97+
public void execute() {
98+
try {
99+
DnsServer server = dnsProviderManager.updateDnsServer(this);
100+
if (server != null) {
101+
DnsServerResponse response = dnsProviderManager.createDnsServerResponse(server);
102+
response.setResponseName(getCommandName());
103+
setResponseObject(response);
104+
} else {
105+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update DNS server");
106+
}
107+
} catch (Exception ex) {
108+
logger.error("Failed to add update server", ex);
109+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
110+
}
111+
}
112+
}

api/src/main/java/org/apache/cloudstack/api/response/DnsServerResponse.java

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@
1717

1818
package org.apache.cloudstack.api.response;
1919

20+
import java.util.List;
21+
2022
import org.apache.cloudstack.api.ApiConstants;
2123
import org.apache.cloudstack.api.BaseResponse;
2224
import org.apache.cloudstack.api.EntityReference;
25+
import org.apache.cloudstack.dns.DnsProviderType;
2326
import org.apache.cloudstack.dns.DnsServer;
2427

2528
import com.cloud.serializer.Param;
@@ -29,39 +32,69 @@
2932
public class DnsServerResponse extends BaseResponse {
3033

3134
@SerializedName(ApiConstants.ID)
32-
@Param(description = "the ID of the DNS server")
35+
@Param(description = "ID of the DNS server")
3336
private String id;
3437

3538
@SerializedName(ApiConstants.NAME)
36-
@Param(description = "the name of the DNS server")
39+
@Param(description = "Name of the DNS server")
3740
private String name;
3841

3942
@SerializedName(ApiConstants.URL)
40-
@Param(description = "the URL of the DNS server API")
43+
@Param(description = "URL of the DNS server API")
4144
private String url;
4245

43-
@SerializedName(ApiConstants.PROVIDER)
44-
@Param(description = "the provider type of the DNS server")
45-
private String provider;
46+
@SerializedName(ApiConstants.PORT)
47+
@Param(description = "The port of the DNS server")
48+
private Integer port;
4649

47-
@SerializedName(ApiConstants.ACCOUNT)
48-
@Param(description = "the account associated with the DNS server")
49-
private String accountName;
50+
@SerializedName(ApiConstants.PROVIDER)
51+
@Param(description = "The provider type of the DNS server")
52+
private DnsProviderType provider;
5053

51-
@SerializedName(ApiConstants.PROJECT)
52-
@Param(description = "the project name of the DNS server")
53-
private String projectName;
54+
@SerializedName(ApiConstants.IS_PUBLIC)
55+
@Param(description = "Is the DNS server publicly available")
56+
private Boolean isPublic;
5457

55-
@SerializedName(ApiConstants.DOMAIN_ID)
56-
@Param(description = "the domain ID of the DNS server")
57-
private String domainId;
58+
@SerializedName(ApiConstants.PUBLIC_DOMAIN_SUFFIX) @Param(description = "The public domain suffix for the DNS server")
59+
private String publicDomainSuffix;
5860

59-
@SerializedName(ApiConstants.DOMAIN)
60-
@Param(description = "the domain name of the DNS server")
61-
private String domainName;
61+
@SerializedName(ApiConstants.NAME_SERVERS) @Param(description = "Name servers entries associated to DNS server")
62+
private List<String> nameServers;
6263

6364
public DnsServerResponse() {
6465
super();
65-
setObjectName("dnsserver");
66+
67+
}
68+
69+
public void setId(String id) {
70+
this.id = id;
71+
}
72+
73+
public void setName(String name) {
74+
this.name = name;
75+
}
76+
77+
public void setUrl(String url) {
78+
this.url = url;
79+
}
80+
81+
public void setProvider(DnsProviderType provider) {
82+
this.provider = provider;
83+
}
84+
85+
public void setPublic(Boolean value) {
86+
isPublic = value;
87+
}
88+
89+
public void setPort(Integer port) {
90+
this.port = port;
91+
}
92+
93+
public void setPublicDomainSuffix(String publicDomainSuffix) {
94+
this.publicDomainSuffix = publicDomainSuffix;
95+
}
96+
97+
public void setNameServers(List<String> nameServers) {
98+
this.nameServers = nameServers;
6699
}
67100
}

api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface DnsProvider extends Adapter {
2525
DnsProviderType getProviderType();
2626

2727
// Validates connectivity to the server
28-
boolean validate(DnsServer server);
28+
boolean validate(DnsServer server) throws Exception;
2929

3030
// Zone Operations
3131
boolean createZone(DnsServer server, DnsZone zone);

api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.cloudstack.api.command.user.dns.ListDnsRecordsCmd;
2929
import org.apache.cloudstack.api.command.user.dns.ListDnsServersCmd;
3030
import org.apache.cloudstack.api.command.user.dns.ListDnsZonesCmd;
31+
import org.apache.cloudstack.api.command.user.dns.UpdateDnsServerCmd;
3132
import org.apache.cloudstack.api.response.DnsRecordResponse;
3233
import org.apache.cloudstack.api.response.DnsServerResponse;
3334
import org.apache.cloudstack.api.response.DnsZoneResponse;
@@ -40,6 +41,7 @@ public interface DnsProviderManager extends Manager, PluggableService {
4041

4142
DnsServer addDnsServer(AddDnsServerCmd cmd);
4243
ListResponse<DnsServerResponse> listDnsServers(ListDnsServersCmd cmd);
44+
DnsServer updateDnsServer(UpdateDnsServerCmd cmd);
4345
boolean deleteDnsServer(DeleteDnsServerCmd cmd);
4446
DnsServerResponse createDnsServerResponse(DnsServer server);
4547

api/src/main/java/org/apache/cloudstack/dns/DnsServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ enum State {
3333

3434
DnsProviderType getProviderType();
3535

36-
String getAPIKey();
36+
String getApiKey();
3737

3838
long getAccountId();
3939

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ CREATE TABLE `cloud`.`dns_server` (
6060
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns server',
6161
`uuid` varchar(255) COMMENT 'uuid of the dns server',
6262
`name` varchar(255) NOT NULL COMMENT 'display name of the dns server',
63+
`provider_type` varchar(255) NOT NULL COMMENT 'Provider type such as PowerDns',
6364
`url` varchar(1024) NOT NULL COMMENT 'dns server url',
65+
`api_key` varchar(255) NOT NULL COMMENT 'dns server api_key',
6466
`port` int(11) DEFAULT NULL COMMENT 'optional dns server port',
67+
`name_servers` varchar(1024) DEFAULT NULL COMMENT 'Comma separated list of name servers',
6568
`is_public` tinyint(1) NOT NULL DEFAULT '0',
6669
`public_domain_suffix` VARCHAR(255),
6770
`state` ENUM('Enabled', 'Disabled') NOT NULL DEFAULT 'Disabled',

0 commit comments

Comments
 (0)