Skip to content

Commit b2d597c

Browse files
committed
add db schema, vo and dao classes
1 parent 7b9fc0e commit b2d597c

17 files changed

Lines changed: 860 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
import java.util.List;
2121

22-
public interface DnsProvider {
23-
// Returns the provider type string (e.g., "PowerDNS")
24-
String getProviderType();
22+
import com.cloud.utils.component.Adapter;
23+
24+
public interface DnsProvider extends Adapter {
25+
DnsProviderType getProviderType();
2526

2627
// Validates connectivity to the server
2728
boolean validate(DnsServer server);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import org.apache.cloudstack.api.response.ListResponse;
3535

3636
import com.cloud.utils.component.Manager;
37+
import com.cloud.utils.component.PluggableService;
38+
39+
public interface DnsProviderManager extends Manager, PluggableService {
3740

38-
public interface DnsProviderManager extends Manager {
3941
DnsServer addDnsServer(AddDnsServerCmd cmd);
4042
ListResponse<DnsServerResponse> listDnsServers(ListDnsServersCmd cmd);
4143
boolean deleteDnsServer(DeleteDnsServerCmd cmd);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.dns;
19+
20+
public enum DnsProviderType {
21+
PowerDNS;
22+
// Cloudflare
23+
24+
// Helper to validate and return Enum from String safely
25+
public static DnsProviderType fromString(String type) {
26+
if (type == null) return null;
27+
for (DnsProviderType t : DnsProviderType.values()) {
28+
if (t.name().equalsIgnoreCase(type)) {
29+
return t;
30+
}
31+
}
32+
throw new IllegalArgumentException("Invalid DNS Provider type: " + type);
33+
}
34+
}

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,29 @@
1717

1818
package org.apache.cloudstack.dns;
1919

20+
import java.util.Date;
21+
2022
import org.apache.cloudstack.api.Identity;
2123
import org.apache.cloudstack.api.InternalIdentity;
2224

2325
public interface DnsServer extends InternalIdentity, Identity {
24-
enum ProviderType {
25-
PowerDNS
26-
}
26+
enum State {
27+
Enabled, Disabled;
28+
};
2729

2830
String getName();
2931

3032
String getUrl();
3133

32-
ProviderType getProviderType();
33-
34-
String getKey();
34+
DnsProviderType getProviderType();
3535

36-
long getDomainId();
36+
String getAPIKey();
3737

3838
long getAccountId();
39+
40+
boolean isPublic();
41+
42+
Date getCreated();
43+
44+
Date getRemoved();
3945
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ public interface DnsZone extends InternalIdentity, Identity {
2626
enum ZoneType {
2727
Public, Private
2828
}
29+
enum State {
30+
Active, Inactive
31+
}
2932

3033
String getName();
3134

3235
long getDnsServerId();
3336

3437
long getAccountId();
3538

36-
String getDescription();
37-
3839
ZoneType getType();
3940

4041
List<Long> getAssociatedNetworks();

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,54 @@ CREATE TABLE IF NOT EXISTS `cloud`.`webhook_filter` (
4949
INDEX `i_webhook_filter__webhook_id`(`webhook_id`),
5050
CONSTRAINT `fk_webhook_filter__webhook_id` FOREIGN KEY(`webhook_id`) REFERENCES `webhook`(`id`) ON DELETE CASCADE
5151
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
52+
53+
54+
-- ======================================================================
55+
-- DNS Framework Schema
56+
-- ======================================================================
57+
58+
-- 1. DNS Server Table (Stores DNS Server Configurations)
59+
CREATE TABLE `cloud`.`dns_server` (
60+
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns server',
61+
`uuid` varchar(255) COMMENT 'uuid of the dns server',
62+
`name` varchar(255) NOT NULL COMMENT 'display name of the dns server',
63+
`url` varchar(1024) NOT NULL COMMENT 'dns server url',
64+
`port` int(11) DEFAULT NULL COMMENT 'optional dns server port',
65+
`is_public` tinyint(1) NOT NULL DEFAULT '0',
66+
`public_domain_suffix` VARCHAR(255),
67+
`state` ENUM('Enabled', 'Disabled') NOT NULL DEFAULT 'Disabled',
68+
`account_id` bigint(20) unsigned NOT NULL,
69+
`created` datetime NOT NULL COMMENT 'date created',
70+
`removed` datetime DEFAULT NULL COMMENT 'Date removed (soft delete)',
71+
PRIMARY KEY (`id`),
72+
KEY `i_dns_server__account_id` (`account_id`),
73+
CONSTRAINT `fk_dns_server__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE
74+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
75+
76+
-- 2. DNS Zone Table (Stores DNS Zone Metadata)
77+
CREATE TABLE `cloud`.`dns_zone` (
78+
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns zone',
79+
`uuid` varchar(255) COMMENT 'uuid of the dns zone',
80+
`name` varchar(255) NOT NULL COMMENT 'dns zone name (e.g. example.com)',
81+
`dns_server_id` bigint unsigned NOT NULL COMMENT 'fk to dns_server.id',
82+
`external_reference` VARCHAR(255) COMMENT 'id of external provider resource',
83+
`state` ENUM('Active', 'Inactive') NOT NULL DEFAULT 'Inactive',
84+
`created` datetime NOT NULL COMMENT 'date created',
85+
`removed` datetime DEFAULT NULL COMMENT 'Date removed (soft delete)',
86+
PRIMARY KEY (`id`),
87+
KEY `i_dns_zone__dns_server` (`dns_server_id`),
88+
CONSTRAINT `fk_dns_zone__dns_server_id` FOREIGN KEY (`dns_server_id`) REFERENCES `dns_server` (`id`) ON DELETE CASCADE
89+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
90+
91+
-- 3. DNS Zone Network Map (One-to-Many Link)
92+
CREATE TABLE `cloud`.`dns_zone_network_map` (
93+
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns zone to network mapping',
94+
`dns_zone_id` bigint(20) unsigned NOT NULL,
95+
`network_id` bigint(20) unsigned NOT NULL COMMENT 'network to which dns zone is associated to',
96+
`sub_domain` varchar(255) DEFAULT NULL COMMENT 'Subdomain for auto-registration',
97+
PRIMARY KEY (`id`),
98+
KEY `fk_dns_map__zone_id` (`dns_zone_id`),
99+
KEY `fk_dns_map__network_id` (`network_id`),
100+
CONSTRAINT `fk_dns_map__zone_id` FOREIGN KEY (`dns_zone_id`) REFERENCES `dns_zone` (`id`) ON DELETE CASCADE,
101+
CONSTRAINT `fk_dns_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE
102+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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.dns;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
import org.apache.cloudstack.api.command.user.dns.AddDnsServerCmd;
24+
import org.apache.cloudstack.api.command.user.dns.CreateDnsRecordCmd;
25+
import org.apache.cloudstack.api.command.user.dns.CreateDnsZoneCmd;
26+
import org.apache.cloudstack.api.command.user.dns.DeleteDnsRecordCmd;
27+
import org.apache.cloudstack.api.command.user.dns.DeleteDnsServerCmd;
28+
import org.apache.cloudstack.api.command.user.dns.DeleteDnsZoneCmd;
29+
import org.apache.cloudstack.api.command.user.dns.ListDnsProvidersCmd;
30+
import org.apache.cloudstack.api.command.user.dns.ListDnsRecordsCmd;
31+
import org.apache.cloudstack.api.command.user.dns.ListDnsServersCmd;
32+
import org.apache.cloudstack.api.command.user.dns.ListDnsZonesCmd;
33+
import org.apache.cloudstack.api.response.DnsRecordResponse;
34+
import org.apache.cloudstack.api.response.DnsServerResponse;
35+
import org.apache.cloudstack.api.response.DnsZoneResponse;
36+
import org.apache.cloudstack.api.response.ListResponse;
37+
import org.springframework.beans.factory.annotation.Autowired;
38+
import org.springframework.stereotype.Component;
39+
40+
import com.cloud.utils.component.ManagerBase;
41+
import com.cloud.utils.component.PluggableService;
42+
import com.cloud.utils.exception.CloudRuntimeException;
43+
44+
@Component
45+
public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderManager, PluggableService {
46+
@Autowired(required = false)
47+
List<DnsProvider> dnsProviders;
48+
49+
private DnsProvider getProvider(DnsProviderType type) {
50+
if (type == null) {
51+
throw new CloudRuntimeException("Provider type cannot be null");
52+
}
53+
for (DnsProvider provider : dnsProviders) {
54+
if (provider.getProviderType() == type) {
55+
return provider;
56+
}
57+
}
58+
throw new CloudRuntimeException("No plugin found for DNS Provider type: " + type);
59+
}
60+
61+
@Override
62+
public DnsServer addDnsServer(AddDnsServerCmd cmd) {
63+
return null;
64+
}
65+
66+
@Override
67+
public ListResponse<DnsServerResponse> listDnsServers(ListDnsServersCmd cmd) {
68+
return null;
69+
}
70+
71+
@Override
72+
public boolean deleteDnsServer(DeleteDnsServerCmd cmd) {
73+
return false;
74+
}
75+
76+
@Override
77+
public DnsServerResponse createDnsServerResponse(DnsServer server) {
78+
return null;
79+
}
80+
81+
@Override
82+
public DnsServer getDnsServer(Long id) {
83+
return null;
84+
}
85+
86+
@Override
87+
public DnsZone createDnsZone(CreateDnsZoneCmd cmd) {
88+
return null;
89+
}
90+
91+
@Override
92+
public boolean deleteDnsZone(DeleteDnsZoneCmd cmd) {
93+
return false;
94+
}
95+
96+
@Override
97+
public ListResponse<DnsZoneResponse> listDnsZones(ListDnsZonesCmd cmd) {
98+
return null;
99+
}
100+
101+
@Override
102+
public DnsZone getDnsZone(long id) {
103+
return null;
104+
}
105+
106+
@Override
107+
public DnsRecordResponse createDnsRecord(CreateDnsRecordCmd cmd) {
108+
return null;
109+
}
110+
111+
@Override
112+
public boolean deleteDnsRecord(DeleteDnsRecordCmd cmd) {
113+
return false;
114+
}
115+
116+
@Override
117+
public ListResponse<DnsRecordResponse> listDnsRecords(ListDnsRecordsCmd cmd) {
118+
return null;
119+
}
120+
121+
@Override
122+
public List<String> listProviderNames() {
123+
List<String> providerNames = new ArrayList<>();
124+
if (dnsProviders != null) {
125+
for (DnsProvider provider : dnsProviders) {
126+
providerNames.add(provider.getProviderType().toString());
127+
}
128+
}
129+
return providerNames;
130+
}
131+
132+
@Override
133+
public DnsZone allocDnsZone(CreateDnsZoneCmd cmd) {
134+
return null;
135+
}
136+
137+
@Override
138+
public DnsZone provisionDnsZone(long zoneId) {
139+
return null;
140+
}
141+
142+
@Override
143+
public DnsZoneResponse createDnsZoneResponse(DnsZone zone) {
144+
return null;
145+
}
146+
147+
@Override
148+
public boolean start() {
149+
if (dnsProviders == null || dnsProviders.isEmpty()) {
150+
logger.warn("DNS Framework started but no provider plugins were found!");
151+
} else {
152+
logger.info("DNS Framework started with: {} providers.", dnsProviders.size());
153+
}
154+
return true;
155+
}
156+
157+
@Override
158+
public List<Class<?>> getCommands() {
159+
List<Class<?>> cmdList = new ArrayList<>();
160+
// DNS Server Commands
161+
cmdList.add(AddDnsServerCmd.class);
162+
cmdList.add(ListDnsServersCmd.class);
163+
cmdList.add(DeleteDnsServerCmd.class);
164+
cmdList.add(ListDnsProvidersCmd.class);
165+
166+
// DNS Zone Commands
167+
cmdList.add(CreateDnsZoneCmd.class);
168+
cmdList.add(ListDnsZonesCmd.class);
169+
cmdList.add(DeleteDnsZoneCmd.class);
170+
171+
// DNS Record Commands
172+
cmdList.add(CreateDnsRecordCmd.class);
173+
cmdList.add(ListDnsRecordsCmd.class);
174+
cmdList.add(DeleteDnsRecordCmd.class);
175+
return cmdList;
176+
}
177+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.dns.dao;
19+
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.dns.vo.DnsServerVO;
23+
24+
import com.cloud.utils.db.GenericDao;
25+
26+
public interface DnsServerDao extends GenericDao<DnsServerVO, Long> {
27+
28+
List<DnsServerVO> listByProviderType(String providerType);
29+
30+
}

0 commit comments

Comments
 (0)