diff --git a/api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java b/api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java index 9b558b007ef..38c155fc72a 100644 --- a/api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java +++ b/api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java @@ -19,9 +19,10 @@ package org.apache.cloudstack.dns; import java.util.List; -public interface DnsProvider { - // Returns the provider type string (e.g., "PowerDNS") - String getProviderType(); +import com.cloud.utils.component.Adapter; + +public interface DnsProvider extends Adapter { + DnsProviderType getProviderType(); // Validates connectivity to the server boolean validate(DnsServer server); diff --git a/api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java b/api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java index cd232d511b1..0703c559f61 100644 --- a/api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java +++ b/api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java @@ -34,8 +34,10 @@ import org.apache.cloudstack.api.response.DnsZoneResponse; import org.apache.cloudstack.api.response.ListResponse; import com.cloud.utils.component.Manager; +import com.cloud.utils.component.PluggableService; + +public interface DnsProviderManager extends Manager, PluggableService { -public interface DnsProviderManager extends Manager { DnsServer addDnsServer(AddDnsServerCmd cmd); ListResponse listDnsServers(ListDnsServersCmd cmd); boolean deleteDnsServer(DeleteDnsServerCmd cmd); diff --git a/api/src/main/java/org/apache/cloudstack/dns/DnsProviderType.java b/api/src/main/java/org/apache/cloudstack/dns/DnsProviderType.java new file mode 100644 index 00000000000..0b8f88d6745 --- /dev/null +++ b/api/src/main/java/org/apache/cloudstack/dns/DnsProviderType.java @@ -0,0 +1,34 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns; + +public enum DnsProviderType { + PowerDNS; +// Cloudflare + + // Helper to validate and return Enum from String safely + public static DnsProviderType fromString(String type) { + if (type == null) return null; + for (DnsProviderType t : DnsProviderType.values()) { + if (t.name().equalsIgnoreCase(type)) { + return t; + } + } + throw new IllegalArgumentException("Invalid DNS Provider type: " + type); + } +} diff --git a/api/src/main/java/org/apache/cloudstack/dns/DnsServer.java b/api/src/main/java/org/apache/cloudstack/dns/DnsServer.java index 616399f870a..b399a974701 100644 --- a/api/src/main/java/org/apache/cloudstack/dns/DnsServer.java +++ b/api/src/main/java/org/apache/cloudstack/dns/DnsServer.java @@ -17,23 +17,29 @@ package org.apache.cloudstack.dns; +import java.util.Date; + import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; public interface DnsServer extends InternalIdentity, Identity { - enum ProviderType { - PowerDNS - } + enum State { + Enabled, Disabled; + }; String getName(); String getUrl(); - ProviderType getProviderType(); + DnsProviderType getProviderType(); - String getKey(); - - long getDomainId(); + String getAPIKey(); long getAccountId(); + + boolean isPublic(); + + Date getCreated(); + + Date getRemoved(); } diff --git a/api/src/main/java/org/apache/cloudstack/dns/DnsZone.java b/api/src/main/java/org/apache/cloudstack/dns/DnsZone.java index 0aa5a819dcb..1e8e8010689 100644 --- a/api/src/main/java/org/apache/cloudstack/dns/DnsZone.java +++ b/api/src/main/java/org/apache/cloudstack/dns/DnsZone.java @@ -26,6 +26,9 @@ public interface DnsZone extends InternalIdentity, Identity { enum ZoneType { Public, Private } + enum State { + Active, Inactive + } String getName(); @@ -33,8 +36,6 @@ public interface DnsZone extends InternalIdentity, Identity { long getAccountId(); - String getDescription(); - ZoneType getType(); List getAssociatedNetworks(); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql b/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql index d330ecd0c0d..f549ec44145 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql @@ -49,3 +49,54 @@ CREATE TABLE IF NOT EXISTS `cloud`.`webhook_filter` ( INDEX `i_webhook_filter__webhook_id`(`webhook_id`), CONSTRAINT `fk_webhook_filter__webhook_id` FOREIGN KEY(`webhook_id`) REFERENCES `webhook`(`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +-- ====================================================================== +-- DNS Framework Schema +-- ====================================================================== + +-- 1. DNS Server Table (Stores DNS Server Configurations) +CREATE TABLE `cloud`.`dns_server` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns server', + `uuid` varchar(255) COMMENT 'uuid of the dns server', + `name` varchar(255) NOT NULL COMMENT 'display name of the dns server', + `url` varchar(1024) NOT NULL COMMENT 'dns server url', + `port` int(11) DEFAULT NULL COMMENT 'optional dns server port', + `is_public` tinyint(1) NOT NULL DEFAULT '0', + `public_domain_suffix` VARCHAR(255), + `state` ENUM('Enabled', 'Disabled') NOT NULL DEFAULT 'Disabled', + `account_id` bigint(20) unsigned NOT NULL, + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'Date removed (soft delete)', + PRIMARY KEY (`id`), + KEY `i_dns_server__account_id` (`account_id`), + CONSTRAINT `fk_dns_server__account_id` FOREIGN KEY (`account_id`) REFERENCES `account` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- 2. DNS Zone Table (Stores DNS Zone Metadata) +CREATE TABLE `cloud`.`dns_zone` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns zone', + `uuid` varchar(255) COMMENT 'uuid of the dns zone', + `name` varchar(255) NOT NULL COMMENT 'dns zone name (e.g. example.com)', + `dns_server_id` bigint unsigned NOT NULL COMMENT 'fk to dns_server.id', + `external_reference` VARCHAR(255) COMMENT 'id of external provider resource', + `state` ENUM('Active', 'Inactive') NOT NULL DEFAULT 'Inactive', + `created` datetime NOT NULL COMMENT 'date created', + `removed` datetime DEFAULT NULL COMMENT 'Date removed (soft delete)', + PRIMARY KEY (`id`), + KEY `i_dns_zone__dns_server` (`dns_server_id`), + CONSTRAINT `fk_dns_zone__dns_server_id` FOREIGN KEY (`dns_server_id`) REFERENCES `dns_server` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +-- 3. DNS Zone Network Map (One-to-Many Link) +CREATE TABLE `cloud`.`dns_zone_network_map` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id of the dns zone to network mapping', + `dns_zone_id` bigint(20) unsigned NOT NULL, + `network_id` bigint(20) unsigned NOT NULL COMMENT 'network to which dns zone is associated to', + `sub_domain` varchar(255) DEFAULT NULL COMMENT 'Subdomain for auto-registration', + PRIMARY KEY (`id`), + KEY `fk_dns_map__zone_id` (`dns_zone_id`), + KEY `fk_dns_map__network_id` (`network_id`), + CONSTRAINT `fk_dns_map__zone_id` FOREIGN KEY (`dns_zone_id`) REFERENCES `dns_zone` (`id`) ON DELETE CASCADE, + CONSTRAINT `fk_dns_map__network_id` FOREIGN KEY (`network_id`) REFERENCES `networks` (`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java b/server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java new file mode 100644 index 00000000000..09293f2c859 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/DnsProviderManagerImpl.java @@ -0,0 +1,177 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.api.command.user.dns.AddDnsServerCmd; +import org.apache.cloudstack.api.command.user.dns.CreateDnsRecordCmd; +import org.apache.cloudstack.api.command.user.dns.CreateDnsZoneCmd; +import org.apache.cloudstack.api.command.user.dns.DeleteDnsRecordCmd; +import org.apache.cloudstack.api.command.user.dns.DeleteDnsServerCmd; +import org.apache.cloudstack.api.command.user.dns.DeleteDnsZoneCmd; +import org.apache.cloudstack.api.command.user.dns.ListDnsProvidersCmd; +import org.apache.cloudstack.api.command.user.dns.ListDnsRecordsCmd; +import org.apache.cloudstack.api.command.user.dns.ListDnsServersCmd; +import org.apache.cloudstack.api.command.user.dns.ListDnsZonesCmd; +import org.apache.cloudstack.api.response.DnsRecordResponse; +import org.apache.cloudstack.api.response.DnsServerResponse; +import org.apache.cloudstack.api.response.DnsZoneResponse; +import org.apache.cloudstack.api.response.ListResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.cloud.utils.component.ManagerBase; +import com.cloud.utils.component.PluggableService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Component +public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderManager, PluggableService { + @Autowired(required = false) + List dnsProviders; + + private DnsProvider getProvider(DnsProviderType type) { + if (type == null) { + throw new CloudRuntimeException("Provider type cannot be null"); + } + for (DnsProvider provider : dnsProviders) { + if (provider.getProviderType() == type) { + return provider; + } + } + throw new CloudRuntimeException("No plugin found for DNS Provider type: " + type); + } + + @Override + public DnsServer addDnsServer(AddDnsServerCmd cmd) { + return null; + } + + @Override + public ListResponse listDnsServers(ListDnsServersCmd cmd) { + return null; + } + + @Override + public boolean deleteDnsServer(DeleteDnsServerCmd cmd) { + return false; + } + + @Override + public DnsServerResponse createDnsServerResponse(DnsServer server) { + return null; + } + + @Override + public DnsServer getDnsServer(Long id) { + return null; + } + + @Override + public DnsZone createDnsZone(CreateDnsZoneCmd cmd) { + return null; + } + + @Override + public boolean deleteDnsZone(DeleteDnsZoneCmd cmd) { + return false; + } + + @Override + public ListResponse listDnsZones(ListDnsZonesCmd cmd) { + return null; + } + + @Override + public DnsZone getDnsZone(long id) { + return null; + } + + @Override + public DnsRecordResponse createDnsRecord(CreateDnsRecordCmd cmd) { + return null; + } + + @Override + public boolean deleteDnsRecord(DeleteDnsRecordCmd cmd) { + return false; + } + + @Override + public ListResponse listDnsRecords(ListDnsRecordsCmd cmd) { + return null; + } + + @Override + public List listProviderNames() { + List providerNames = new ArrayList<>(); + if (dnsProviders != null) { + for (DnsProvider provider : dnsProviders) { + providerNames.add(provider.getProviderType().toString()); + } + } + return providerNames; + } + + @Override + public DnsZone allocDnsZone(CreateDnsZoneCmd cmd) { + return null; + } + + @Override + public DnsZone provisionDnsZone(long zoneId) { + return null; + } + + @Override + public DnsZoneResponse createDnsZoneResponse(DnsZone zone) { + return null; + } + + @Override + public boolean start() { + if (dnsProviders == null || dnsProviders.isEmpty()) { + logger.warn("DNS Framework started but no provider plugins were found!"); + } else { + logger.info("DNS Framework started with: {} providers.", dnsProviders.size()); + } + return true; + } + + @Override + public List> getCommands() { + List> cmdList = new ArrayList<>(); + // DNS Server Commands + cmdList.add(AddDnsServerCmd.class); + cmdList.add(ListDnsServersCmd.class); + cmdList.add(DeleteDnsServerCmd.class); + cmdList.add(ListDnsProvidersCmd.class); + + // DNS Zone Commands + cmdList.add(CreateDnsZoneCmd.class); + cmdList.add(ListDnsZonesCmd.class); + cmdList.add(DeleteDnsZoneCmd.class); + + // DNS Record Commands + cmdList.add(CreateDnsRecordCmd.class); + cmdList.add(ListDnsRecordsCmd.class); + cmdList.add(DeleteDnsRecordCmd.class); + return cmdList; + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDao.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDao.java new file mode 100644 index 00000000000..5fada010f62 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDao.java @@ -0,0 +1,30 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsServerVO; + +import com.cloud.utils.db.GenericDao; + +public interface DnsServerDao extends GenericDao { + + List listByProviderType(String providerType); + +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDaoImpl.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDaoImpl.java new file mode 100644 index 00000000000..8967aa25d52 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsServerDaoImpl.java @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsServerVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +public class DnsServerDaoImpl extends GenericDaoBase implements DnsServerDao { + static final String PROVIDER_TYPE = "providerType"; + SearchBuilder ProviderSearch; + + public DnsServerDaoImpl() { + super(); + ProviderSearch = createSearchBuilder(); + ProviderSearch.and(PROVIDER_TYPE, ProviderSearch.entity().getProviderType(), SearchCriteria.Op.EQ); + ProviderSearch.done(); + } + + @Override + public List listByProviderType(String providerType) { + SearchCriteria sc = ProviderSearch.create(); + sc.setParameters(PROVIDER_TYPE, providerType); + return listBy(sc); + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDao.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDao.java new file mode 100644 index 00000000000..30d34102143 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDao.java @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsZoneVO; + +import com.cloud.utils.db.GenericDao; + +public interface DnsZoneDao extends GenericDao { + List listByServerId(long serverId); +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDaoImpl.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDaoImpl.java new file mode 100644 index 00000000000..1a573e4132a --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneDaoImpl.java @@ -0,0 +1,47 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsZoneVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +public class DnsZoneDaoImpl extends GenericDaoBase implements DnsZoneDao { + static final String DNS_SERVER_ID = "dnsServerId"; + SearchBuilder ServerSearch; + + public DnsZoneDaoImpl() { + super(); + ServerSearch = createSearchBuilder(); + ServerSearch.and(DNS_SERVER_ID, ServerSearch.entity().getDnsServerId(), SearchCriteria.Op.EQ); + ServerSearch.done(); + } + + @Override + public List listByServerId(long serverId) { + SearchCriteria sc = ServerSearch.create(); + sc.setParameters(DNS_SERVER_ID, serverId); + return listBy(sc); + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDao.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDao.java new file mode 100644 index 00000000000..9d79a0e8708 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDao.java @@ -0,0 +1,11 @@ +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsZoneNetworkMapVO; + +import com.cloud.utils.db.GenericDao; + +public interface DnsZoneNetworkMapDao extends GenericDao { + List listByDnsZoneId(long dnsZoneId); +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDaoImpl.java b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDaoImpl.java new file mode 100644 index 00000000000..adf1a09111f --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/dao/DnsZoneNetworkMapDaoImpl.java @@ -0,0 +1,28 @@ +package org.apache.cloudstack.dns.dao; + +import java.util.List; + +import org.apache.cloudstack.dns.vo.DnsZoneNetworkMapVO; +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; + +@Component +public class DnsZoneNetworkMapDaoImpl extends GenericDaoBase implements DnsZoneNetworkMapDao { + final SearchBuilder ZoneSearch; + + public DnsZoneNetworkMapDaoImpl() { + super(); + ZoneSearch = createSearchBuilder(); + ZoneSearch.and("dnsZoneId", ZoneSearch.entity().getDnsZoneId(), SearchCriteria.Op.EQ); + ZoneSearch.done(); + } + @Override + public List listByDnsZoneId(long dnsZoneId) { + SearchCriteria sc = ZoneSearch.create(); + sc.setParameters("dnsZoneId", dnsZoneId); + return listBy(sc); + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/vo/DnsServerVO.java b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsServerVO.java new file mode 100644 index 00000000000..0b80f474a52 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsServerVO.java @@ -0,0 +1,157 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.vo; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.dns.DnsProviderType; +import org.apache.cloudstack.dns.DnsServer; + +import com.cloud.utils.db.Encrypt; +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "dns_server") +public class DnsServerVO implements DnsServer { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "url") + private String url; + + @Column(name = "provider_type") + @Enumerated(EnumType.STRING) + private DnsProviderType providerType; + + @Encrypt + @Column(name = "api_key") + private String apiKey; + + @Column(name = "is_public") + private boolean isPublic; + + @Column(name = "public_domain_suffix") + private String publicDomainSuffix; + + @Column(name = "state") + @Enumerated(EnumType.STRING) + private State state; + + @Column(name = "account_id") + private long accountId; + + @Column(name = GenericDao.CREATED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date created = null; + + @Column(name = GenericDao.REMOVED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date removed = null; + + public DnsServerVO() { + this.uuid = UUID.randomUUID().toString(); + this.created = new Date(); + } + + public DnsServerVO(String name, String url, DnsProviderType providerType, String apiKey, long accountId, boolean isPublic) { + this(); + this.name = name; + this.url = url; + this.providerType = providerType; + this.apiKey = apiKey; + this.accountId = accountId; + this.isPublic = isPublic; + } + + @Override + public long getId() { + return id; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getUrl() { + return url; + } + + @Override + public DnsProviderType getProviderType() { + return providerType; + } + + @Override + public String getAPIKey() { + return apiKey; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public Date getCreated() { + return created; + } + + @Override + public Date getRemoved() { + return removed; + } + + @Override + public String getUuid() { + return uuid; + } + + public boolean isPublic() { + return isPublic; + } + + public State getState() { + return state; + } + + public void setState(State state) { + this.state = state; + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneNetworkMapVO.java b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneNetworkMapVO.java new file mode 100644 index 00000000000..9500240d81a --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneNetworkMapVO.java @@ -0,0 +1,96 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.vo; + +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.api.InternalIdentity; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "dns_zone_network_map") +public class DnsZoneNetworkMapVO implements InternalIdentity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "dns_zone_id") + private long dnsZoneId; + + @Column(name = "network_id") + private long networkId; + + @Column(name = "sub_domain") + private String subDomain; + + @Column(name = GenericDao.CREATED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date created = null; + + @Column(name = GenericDao.REMOVED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date removed = null; + + public DnsZoneNetworkMapVO() { + this.created = new Date(); + } + + public DnsZoneNetworkMapVO(long dnsZoneId, long networkId, String subDomain) { + this(); + this.dnsZoneId = dnsZoneId; + this.networkId = networkId; + this.subDomain = subDomain; + } + + @Override + public long getId() { + return id; + } + + public long getDnsZoneId() { + return dnsZoneId; + } + + public long getNetworkId() { + return networkId; + } + + public String getSubDomain() { + return subDomain; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } +} diff --git a/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneVO.java b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneVO.java new file mode 100644 index 00000000000..4495081cd20 --- /dev/null +++ b/server/src/main/java/org/apache/cloudstack/dns/vo/DnsZoneVO.java @@ -0,0 +1,125 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.cloudstack.dns.vo; + +import java.util.Date; +import java.util.List; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.dns.DnsZone; + +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name = "dns_zone") +public class DnsZoneVO implements DnsZone { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name = "uuid") + private String uuid; + + @Column(name = "name") + private String name; + + @Column(name = "dns_server_id") + private long dnsServerId; + + @Column(name = "external_reference") + private String externalReference; + + @Column(name = "type") + @Enumerated(EnumType.STRING) + private ZoneType type; + + @Column(name = "state") + @Enumerated(EnumType.STRING) + private State state; + + @Column(name = "account_id") + private long accountId; + + @Column(name = GenericDao.CREATED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date created = null; + + @Column(name = GenericDao.REMOVED_COLUMN) + @Temporal(value = TemporalType.TIMESTAMP) + private Date removed = null; + + public DnsZoneVO() { + this.uuid = UUID.randomUUID().toString(); + this.created = new Date(); + } + + public DnsZoneVO(String name, long dnsServerId, long accountId) { + this(); + this.name = name; + this.dnsServerId = dnsServerId; + this.accountId = accountId; + this.type = ZoneType.Public; + } + + @Override + public String getName() { + return name; + } + + @Override + public long getDnsServerId() { + return dnsServerId; + } + + @Override + public long getAccountId() { + return accountId; + } + + @Override + public ZoneType getType() { + return type; + } + + @Override + public List getAssociatedNetworks() { + return List.of(); + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public long getId() { + return id; + } +} diff --git a/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml b/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml index b90c40dc95e..3cec9737904 100644 --- a/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml +++ b/server/src/main/resources/META-INF/cloudstack/core/spring-server-core-managers-context.xml @@ -398,4 +398,10 @@ + + + + + +