|
| 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 | +} |
0 commit comments