http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/package-info.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/package-info.java deleted file mode 100644 index 1c926be..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/package-info.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ - -/** - * This package contains all the data types which can be saved to the registry - * and/or marshalled to and from JSON. - * <p> - * The core datatypes, {@link org.apache.hadoop.registry.client.types.ServiceRecord}, - * and {@link org.apache.hadoop.registry.client.types.Endpoint} are - * what is used to describe services and their protocol endpoints in the registry. - * <p> - * Some adjacent interfaces exist to list attributes of the fields: - * <ul> - * <li>{@link org.apache.hadoop.registry.client.types.AddressTypes}</li> - * <li>{@link org.apache.hadoop.registry.client.types.yarn.PersistencePolicies}</li> - * <li>{@link org.apache.hadoop.registry.client.types.ProtocolTypes}</li> - * </ul> - * - * The {@link org.apache.hadoop.registry.client.types.RegistryPathStatus} - * class is not saved to the registry âit is the status of a registry - * entry that can be retrieved from the API call. It is still - * designed to be marshalled to and from JSON, as it can be served up - * from REST front ends to the registry. - * - */ -package org.apache.hadoop.registry.client.types;
http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/PersistencePolicies.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/PersistencePolicies.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/PersistencePolicies.java deleted file mode 100644 index e4c7272..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/PersistencePolicies.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.hadoop.registry.client.types.yarn; - -import org.apache.hadoop.registry.client.types.ServiceRecord; - -/** - * Persistence policies for {@link ServiceRecord} - */ - -public interface PersistencePolicies { - - /** - * The record persists until removed manually: {@value}. - */ - String PERMANENT = "permanent"; - - /** - * Remove when the YARN application defined in the id field - * terminates: {@value}. - */ - String APPLICATION = "application"; - - /** - * Remove when the current YARN application attempt ID finishes: {@value}. - */ - String APPLICATION_ATTEMPT = "application-attempt"; - - /** - * Remove when the YARN container in the ID field finishes: {@value} - */ - String CONTAINER = "container"; - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/YarnRegistryAttributes.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/YarnRegistryAttributes.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/YarnRegistryAttributes.java deleted file mode 100644 index b6e7a20..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/client/types/yarn/YarnRegistryAttributes.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.hadoop.registry.client.types.yarn; - -/** - * YARN specific attributes in the registry. - */ -public final class YarnRegistryAttributes { - - /** - * Hidden constructor. - */ - private YarnRegistryAttributes() { - } - - /** - * ID. For containers: container ID. For application instances, - * application ID. - */ - public static final String YARN_ID = "yarn:id"; - public static final String YARN_PERSISTENCE = "yarn:persistence"; - public static final String YARN_PATH = "yarn:path"; - public static final String YARN_HOSTNAME = "yarn:hostname"; - public static final String YARN_IP = "yarn:ip"; - public static final String YARN_COMPONENT = "yarn:component"; -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ApplicationServiceRecordProcessor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ApplicationServiceRecordProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ApplicationServiceRecordProcessor.java deleted file mode 100644 index 0b5f724..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ApplicationServiceRecordProcessor.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import org.apache.hadoop.registry.client.types.Endpoint; -import org.apache.hadoop.registry.client.types.ServiceRecord; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.xbill.DNS.Name; -import org.xbill.DNS.Type; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; - -/** - * A processor for generating application DNS records from registry service - * records. - */ -public class ApplicationServiceRecordProcessor extends - BaseServiceRecordProcessor { - private static final Logger LOG = - LoggerFactory.getLogger(ApplicationServiceRecordProcessor.class); - /** - * Create an application service record processor. - * - * @param record the service record - * @param path the service record registry node path - * @param domain the DNS zone/domain name - * @param zoneSelector returns the zone associated with the provided name. - * @throws Exception if an issue is generated during instantiation. - */ - public ApplicationServiceRecordProcessor( - ServiceRecord record, String path, String domain, - ZoneSelector zoneSelector) throws Exception { - super(record, path, domain, zoneSelector); - } - - /** - * Initializes the DNS record type to descriptor mapping based on the - * provided service record. - * - * @param serviceRecord the registry service record. - * @throws Exception if an issue is encountered. - */ - @Override public void initTypeToInfoMapping(ServiceRecord serviceRecord) - throws Exception { - if (serviceRecord.external.isEmpty()) { - LOG.info(serviceRecord.description + ": No external endpoints defined."); - return; - } - for (int type : getRecordTypes()) { - switch (type) { - case Type.A: - createAInfo(serviceRecord); - break; - case Type.AAAA: - createAAAAInfo(serviceRecord); - break; - case Type.TXT: - createTXTInfo(serviceRecord); - break; - case Type.CNAME: - createCNAMEInfo(serviceRecord); - break; - case Type.SRV: - createSRVInfo(serviceRecord); - break; - default: - throw new IllegalArgumentException("Unknown type " + type); - - } - } - } - - /** - * Create an application TXT record descriptor. - * - * @param serviceRecord the service record. - * @throws Exception if there is an issue during descriptor creation. - */ - protected void createTXTInfo(ServiceRecord serviceRecord) throws Exception { - List<Endpoint> endpoints = serviceRecord.external; - List<RecordDescriptor> recordDescriptors = new ArrayList<>(); - TXTApplicationRecordDescriptor txtInfo; - for (Endpoint endpoint : endpoints) { - txtInfo = new TXTApplicationRecordDescriptor( - serviceRecord, endpoint); - recordDescriptors.add(txtInfo); - } - registerRecordDescriptor(Type.TXT, recordDescriptors); - } - - /** - * Create an application SRV record descriptor. - * - * @param serviceRecord the service record. - * @throws Exception if there is an issue during descriptor creation. - */ - protected void createSRVInfo(ServiceRecord serviceRecord) throws Exception { - List<Endpoint> endpoints = serviceRecord.external; - List<RecordDescriptor> recordDescriptors = new ArrayList<>(); - SRVApplicationRecordDescriptor srvInfo; - for (Endpoint endpoint : endpoints) { - srvInfo = new SRVApplicationRecordDescriptor( - serviceRecord, endpoint); - recordDescriptors.add(srvInfo); - } - registerRecordDescriptor(Type.SRV, recordDescriptors); - } - - /** - * Create an application CNAME record descriptor. - * - * @param serviceRecord the service record. - * @throws Exception if there is an issue during descriptor creation. - */ - protected void createCNAMEInfo(ServiceRecord serviceRecord) throws Exception { - List<Endpoint> endpoints = serviceRecord.external; - List<RecordDescriptor> recordDescriptors = new ArrayList<>(); - CNAMEApplicationRecordDescriptor cnameInfo; - for (Endpoint endpoint : endpoints) { - cnameInfo = new CNAMEApplicationRecordDescriptor( - serviceRecord, endpoint); - recordDescriptors.add(cnameInfo); - } - registerRecordDescriptor(Type.CNAME, recordDescriptors); - } - - /** - * Create an application AAAA record descriptor. - * - * @param record the service record. - * @throws Exception if there is an issue during descriptor creation. - */ - protected void createAAAAInfo(ServiceRecord record) - throws Exception { - AAAAApplicationRecordDescriptor - recordInfo = new AAAAApplicationRecordDescriptor( - getPath(), record); - registerRecordDescriptor(Type.AAAA, recordInfo); - } - - /** - * Create an application A record descriptor. - * - * @param record the service record. - * @throws Exception if there is an issue during descriptor creation. - */ - protected void createAInfo(ServiceRecord record) throws Exception { - AApplicationRecordDescriptor recordInfo = new AApplicationRecordDescriptor( - getPath(), record); - registerRecordDescriptor(Type.A, recordInfo); - } - - /** - * Returns the record types associated with a container service record. - * - * @return the record type array - */ - @Override public int[] getRecordTypes() { - return new int[] {Type.A, Type.AAAA, Type.CNAME, Type.SRV, Type.TXT}; - } - - /** - * An application TXT record descriptor. - */ - class TXTApplicationRecordDescriptor - extends ApplicationRecordDescriptor<List<String>> { - - /** - * Creates an application TXT record descriptor. - * - * @param record service record - * @throws Exception - */ - public TXTApplicationRecordDescriptor(ServiceRecord record, - Endpoint endpoint) throws Exception { - super(record, endpoint); - } - - /** - * Initializes the descriptor parameters. - * - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) - throws Exception { - if (getEndpoint() != null) { - this.setNames(new Name[] {getServiceName(), getEndpointName()}); - this.setTarget(getTextRecords(getEndpoint())); - } - } - - } - - /** - * An application SRV record descriptor. - */ - class SRVApplicationRecordDescriptor extends - ApplicationRecordDescriptor<RecordCreatorFactory.HostPortInfo> { - - /** - * Creates an application SRV record descriptor. - * - * @param record service record - * @throws Exception - */ - public SRVApplicationRecordDescriptor(ServiceRecord record, - Endpoint endpoint) throws Exception { - super(record, endpoint); - } - - /** - * Initializes the descriptor parameters. - * - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) - throws Exception { - if (getEndpoint() != null) { - this.setNames(new Name[] {getServiceName(), getEndpointName()}); - this.setTarget(new RecordCreatorFactory.HostPortInfo( - Name.fromString(getHost(getEndpoint()) + "."), getPort( - getEndpoint()))); - } - } - - } - - /** - * An application CNAME record descriptor. - */ - class CNAMEApplicationRecordDescriptor extends - ApplicationRecordDescriptor<Name> { - - /** - * Creates an application CNAME record descriptor. - * - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public CNAMEApplicationRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(record); - } - - /** - * Creates an application CNAME record descriptor. This descriptor is the - * source for API related CNAME records. - * - * @param record service record - * @param endpoint the API endpoint - * @throws Exception - */ - public CNAMEApplicationRecordDescriptor(ServiceRecord record, - Endpoint endpoint) throws Exception { - super(record, endpoint); - } - - /** - * Initializes the descriptor parameters. - * - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) - throws Exception { - if (getEndpoint() != null) { - this.setNames(new Name[] {getEndpointName()}); - this.setTarget(getServiceName()); - } - } - - } - - /** - * An application A record descriptor. - */ - class AApplicationRecordDescriptor - extends ApplicationRecordDescriptor<InetAddress> { - - /** - * Creates an application A record descriptor. - * - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public AApplicationRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(record); - } - - /** - * Initializes the descriptor parameters. - * - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) - throws Exception { - this.setNames(new Name[] {getServiceName()}); - List<Endpoint> endpoints = serviceRecord.external; - if (endpoints.isEmpty()) { - return; - } - // TODO: do we need a "hostname" attribute for an application record or - // can we rely on the first endpoint record. - this.setTarget(InetAddress.getByName( - getHost(endpoints.get(0)))); - } - - } - - /** - * An application AAAA record descriptor. - */ - class AAAAApplicationRecordDescriptor extends AApplicationRecordDescriptor { - - /** - * Creates an application AAAA record descriptor. - * - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public AAAAApplicationRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(path, record); - } - - /** - * Initializes the descriptor parameters. - * - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) - throws Exception { - super.init(serviceRecord); - if (getTarget() == null) { - return; - } - try { - this.setTarget(getIpv6Address(getTarget())); - } catch (UnknownHostException e) { - throw new IllegalStateException(e); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/BaseServiceRecordProcessor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/BaseServiceRecordProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/BaseServiceRecordProcessor.java deleted file mode 100644 index f30c0c2..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/BaseServiceRecordProcessor.java +++ /dev/null @@ -1,470 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import org.apache.hadoop.fs.PathNotFoundException; -import org.apache.hadoop.registry.client.binding.RegistryPathUtils; -import org.apache.hadoop.registry.client.types.AddressTypes; -import org.apache.hadoop.registry.client.types.Endpoint; -import org.apache.hadoop.registry.client.types.ServiceRecord; -import org.xbill.DNS.Name; -import org.xbill.DNS.ReverseMap; -import org.xbill.DNS.TextParseException; - -import java.io.IOException; -import java.net.Inet6Address; -import java.net.InetAddress; -import java.net.URI; -import java.net.UnknownHostException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Provides common service record processing logic. - */ -public abstract class BaseServiceRecordProcessor - implements ServiceRecordProcessor { - - private final ZoneSelector zoneSelctor; - private Map<Integer, List<RecordDescriptor>> typeToDescriptorMap = - new HashMap<>(); - private String path; - private String domain; - - private static final String YARN_SERVICE_API_PREFIX = - "classpath:org.apache.hadoop.yarn.service."; - private static final String HTTP_API_TYPE = "http://"; - - /** - * Creates a service record processor. - * - * @param record the service record. - * @param path the node path for the record in the registry. - * @param domain the target DNS domain for the service record - * associated DNS records. - * @param zoneSelector A selector of the best zone for a given DNS name. - * @throws Exception if an issue is generated during instantiation. - */ - public BaseServiceRecordProcessor(ServiceRecord record, String path, - String domain, ZoneSelector zoneSelector) - throws Exception { - this.setPath(path); - this.domain = domain; - this.zoneSelctor = zoneSelector; - initTypeToInfoMapping(record); - } - - /** - * Return the IPv6 mapped address for the provided IPv4 address. Utilized - * to create corresponding AAAA records. - * - * @param address the IPv4 address. - * @return the mapped IPv6 address. - * @throws UnknownHostException - */ - static InetAddress getIpv6Address(InetAddress address) - throws UnknownHostException { - String[] octets = address.getHostAddress().split("\\."); - byte[] octetBytes = new byte[4]; - for (int i = 0; i < 4; ++i) { - octetBytes[i] = (byte) Integer.parseInt(octets[i]); - } - - byte[] ipv4asIpV6addr = new byte[16]; - ipv4asIpV6addr[10] = (byte) 0xff; - ipv4asIpV6addr[11] = (byte) 0xff; - ipv4asIpV6addr[12] = octetBytes[0]; - ipv4asIpV6addr[13] = octetBytes[1]; - ipv4asIpV6addr[14] = octetBytes[2]; - ipv4asIpV6addr[15] = octetBytes[3]; - - return Inet6Address.getByAddress(null, ipv4asIpV6addr, 0); - } - - /** - * Reverse the string representation of the input IP address. - * - * @param ip the string representation of the IP address. - * @return the reversed IP address. - * @throws UnknownHostException if the ip is unknown. - */ - protected Name reverseIP(String ip) throws UnknownHostException { - return ReverseMap.fromAddress(ip); - } - - /** - * Manages the creation and registration of service record generated DNS - * records. - * - * @param command the DNS registration command object (e.g. add_record, - * remove record) - * @throws IOException if the creation or registration generates an issue. - */ - @SuppressWarnings({"unchecked"}) - public void manageDNSRecords(RegistryDNS.RegistryCommand command) - throws IOException { - for (Map.Entry<Integer, List<RecordDescriptor>> entry : - typeToDescriptorMap.entrySet()) { - for (RecordDescriptor recordDescriptor : entry.getValue()) { - for (Name name : recordDescriptor.getNames()) { - RecordCreatorFactory.RecordCreator recordCreator = - RecordCreatorFactory.getRecordCreator(entry.getKey()); - command.exec(zoneSelctor.findBestZone(name), - recordCreator.create(name, recordDescriptor.getTarget())); - } - } - } - } - - /** - * Add the DNS record descriptor object to the record type to descriptor - * mapping. - * - * @param type the DNS record type. - * @param recordDescriptor the DNS record descriptor - */ - protected void registerRecordDescriptor(int type, - RecordDescriptor recordDescriptor) { - List<RecordDescriptor> infos = new ArrayList<>(); - infos.add(recordDescriptor); - typeToDescriptorMap.put(type, infos); - } - - /** - * Add the DNS record descriptor objects to the record type to descriptor - * mapping. - * - * @param type the DNS record type. - * @param recordDescriptors the DNS record descriptors - */ - protected void registerRecordDescriptor(int type, - List<RecordDescriptor> recordDescriptors) { - typeToDescriptorMap.put(type, recordDescriptors); - } - - /** - * Return the path associated with the record. - * @return the path. - */ - protected String getPath() { - return path; - } - - /** - * Set the path associated with the record. - * @param path the path. - */ - protected void setPath(String path) { - this.path = path; - } - - /** - * A descriptor container the information to be populated into a DNS record. - * - * @param <T> the DNS record type/class. - */ - abstract class RecordDescriptor<T> { - private final ServiceRecord record; - private Name[] names; - private T target; - - /** - * Creates a DNS record descriptor. - * - * @param record the associated service record. - */ - public RecordDescriptor(ServiceRecord record) { - this.record = record; - } - - /** - * Returns the DNS names associated with the record type and information. - * - * @return the array of names. - */ - public Name[] getNames() { - return names; - } - - /** - * Return the target object for the DNS record. - * - * @return the DNS record target. - */ - public T getTarget() { - return target; - } - - /** - * Initializes the names and information for this DNS record descriptor. - * - * @param serviceRecord the service record. - * @throws Exception - */ - protected abstract void init(ServiceRecord serviceRecord) throws Exception; - - /** - * Returns the service record. - * @return the service record. - */ - public ServiceRecord getRecord() { - return record; - } - - /** - * Sets the names associated with the record type and information. - * @param names the names. - */ - public void setNames(Name[] names) { - this.names = names; - } - - /** - * Sets the target object associated with the record. - * @param target the target. - */ - public void setTarget(T target) { - this.target = target; - } - } - - /** - * A container-based DNS record descriptor. - * - * @param <T> the DNS record type/class. - */ - abstract class ContainerRecordDescriptor<T> extends RecordDescriptor<T> { - - public ContainerRecordDescriptor(String path, ServiceRecord record) - throws Exception { - super(record); - init(record); - } - - /** - * Returns the DNS name constructed from the YARN container ID. - * - * @return the container ID name. - * @throws TextParseException - */ - protected Name getContainerIDName() throws TextParseException { - String containerID = RegistryPathUtils.lastPathEntry(getPath()); - return Name.fromString(String.format("%s.%s", containerID, domain)); - } - - /** - * Returns the DNS name constructed from the container role/component name. - * - * @return the DNS naem. - * @throws PathNotFoundException - * @throws TextParseException - */ - protected Name getContainerName() - throws PathNotFoundException, TextParseException { - String service = RegistryPathUtils.lastPathEntry( - RegistryPathUtils.parentOf(RegistryPathUtils.parentOf(getPath()))); - String description = getRecord().description.toLowerCase(); - String user = RegistryPathUtils.getUsername(getPath()); - return Name.fromString(MessageFormat.format("{0}.{1}.{2}.{3}", - description, - service, - user, - domain)); - } - - /** - * Return the DNS name constructed from the component name. - * - * @return the DNS naem. - * @throws PathNotFoundException - * @throws TextParseException - */ - protected Name getComponentName() - throws PathNotFoundException, TextParseException { - String service = RegistryPathUtils.lastPathEntry( - RegistryPathUtils.parentOf(RegistryPathUtils.parentOf(getPath()))); - String component = getRecord().get("yarn:component").toLowerCase(); - String user = RegistryPathUtils.getUsername(getPath()); - return Name.fromString(MessageFormat.format("{0}.{1}.{2}.{3}", - component, - service, - user, - domain)); - } - - } - - /** - * An application-based DNS record descriptor. - * - * @param <T> the DNS record type/class. - */ - abstract class ApplicationRecordDescriptor<T> extends RecordDescriptor<T> { - - private Endpoint srEndpoint; - - /** - * Creates an application associated DNS record descriptor. - * - * @param record the service record. - * @throws Exception - */ - public ApplicationRecordDescriptor(ServiceRecord record) - throws Exception { - this(record, null); - } - - /** - * Creates an application associated DNS record descriptor. The endpoint - * is leverated to create an associated application API record. - * - * @param record the service record. - * @param endpoint an API endpoint. - * @throws Exception - */ - public ApplicationRecordDescriptor(ServiceRecord record, - Endpoint endpoint) throws Exception { - super(record); - this.setEndpoint(endpoint); - init(record); - } - - /** - * Get the service's DNS name for registration. - * - * @return the service DNS name. - * @throws TextParseException - */ - protected Name getServiceName() throws TextParseException { - String user = RegistryPathUtils.getUsername(getPath()); - String service = - String.format("%s.%s.%s", - RegistryPathUtils.lastPathEntry(getPath()), - user, - domain); - return Name.fromString(service); - } - - /** - * Get the host from the provided endpoint record. - * - * @param endpoint the endpoint info. - * @return the host name. - */ - protected String getHost(Endpoint endpoint) { - String host = null; - // assume one address for now - Map<String, String> address = endpoint.addresses.get(0); - if (endpoint.addressType.equals(AddressTypes.ADDRESS_HOSTNAME_AND_PORT)) { - host = address.get(AddressTypes.ADDRESS_HOSTNAME_FIELD); - } else if (endpoint.addressType.equals(AddressTypes.ADDRESS_URI)) { - URI uri = URI.create(address.get("uri")); - host = uri.getHost(); - } - return host; - } - - /** - * Get the post from the provided endpoint record. - * - * @param endpoint the endpoint info. - * @return the port. - */ - protected int getPort(Endpoint endpoint) { - int port = -1; - // assume one address for now - Map<String, String> address = endpoint.addresses.get(0); - if (endpoint.addressType.equals(AddressTypes.ADDRESS_HOSTNAME_AND_PORT)) { - port = Integer.parseInt(address.get(AddressTypes.ADDRESS_PORT_FIELD)); - } else if (endpoint.addressType.equals(AddressTypes.ADDRESS_URI)) { - URI uri = URI.create(address.get("uri")); - port = uri.getPort(); - } - return port; - } - - /** - * Get the list of strings that can be related in a TXT record for the given - * endpoint. - * - * @param endpoint the endpoint information. - * @return the list of strings relating endpoint info. - */ - protected List<String> getTextRecords(Endpoint endpoint) { - Map<String, String> address = endpoint.addresses.get(0); - List<String> txtRecs = new ArrayList<String>(); - txtRecs.add("api=" + getDNSApiFragment(endpoint.api)); - if (endpoint.addressType.equals(AddressTypes.ADDRESS_URI)) { - URI uri = URI.create(address.get("uri")); - txtRecs.add("path=" + uri.getPath()); - } - return txtRecs; - } - - /** - * Get an API name that is compatible with DNS standards (and shortened). - * - * @param api the api indicator. - * @return the shortened and compatible api name. - */ - protected String getDNSApiFragment(String api) { - String dnsApi = null; - if (api.startsWith(YARN_SERVICE_API_PREFIX)) { - dnsApi = api.substring(YARN_SERVICE_API_PREFIX.length()); - } else if (api.startsWith(HTTP_API_TYPE)) { - dnsApi = "http"; - } - assert dnsApi != null; - dnsApi = dnsApi.replace('.', '-'); - return dnsApi; - } - - /** - * Return the DNS name associated with the API endpoint. - * - * @return the name. - * @throws TextParseException - */ - protected Name getEndpointName() throws TextParseException { - return Name.fromString(String.format("%s-api.%s", - getDNSApiFragment( - getEndpoint().api), - getServiceName())); - } - - /** - * Returns the endpoint. - * @return the endpoint. - */ - public Endpoint getEndpoint() { - return srEndpoint; - } - - /** - * Sets the endpoint. - * @param endpoint the endpoint. - */ - public void setEndpoint( - Endpoint endpoint) { - this.srEndpoint = endpoint; - } - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ContainerServiceRecordProcessor.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ContainerServiceRecordProcessor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ContainerServiceRecordProcessor.java deleted file mode 100644 index e40a177..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/ContainerServiceRecordProcessor.java +++ /dev/null @@ -1,284 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import org.apache.hadoop.fs.PathNotFoundException; -import org.apache.hadoop.registry.client.types.ServiceRecord; -import org.apache.hadoop.registry.client.types.yarn.YarnRegistryAttributes; -import org.xbill.DNS.Name; -import org.xbill.DNS.TextParseException; -import org.xbill.DNS.Type; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; - -/** - * A processor for generating container DNS records from registry service - * records. - */ -public class ContainerServiceRecordProcessor extends - BaseServiceRecordProcessor { - - /** - * Create a container service record processor. - * @param record the service record - * @param path the service record registry node path - * @param domain the DNS zone/domain name - * @param zoneSelector returns the zone associated with the provided name. - * @throws Exception if an issue is generated during instantiation. - */ - public ContainerServiceRecordProcessor( - ServiceRecord record, String path, String domain, - ZoneSelector zoneSelector) throws Exception { - super(record, path, domain, zoneSelector); - } - - /** - * Initializes the DNS record type to descriptor mapping based on the - * provided service record. - * @param serviceRecord the registry service record. - * @throws Exception if an issue arises. - */ - @Override public void initTypeToInfoMapping(ServiceRecord serviceRecord) - throws Exception { - if (serviceRecord.get(YarnRegistryAttributes.YARN_IP) != null) { - for (int type : getRecordTypes()) { - switch (type) { - case Type.A: - createAInfo(serviceRecord); - break; - case Type.AAAA: - createAAAAInfo(serviceRecord); - break; - case Type.PTR: - createPTRInfo(serviceRecord); - break; - case Type.TXT: - createTXTInfo(serviceRecord); - break; - default: - throw new IllegalArgumentException("Unknown type " + type); - - } - } - } - } - - /** - * Create a container TXT record descriptor. - * @param serviceRecord the service record. - * @throws Exception if the descriptor creation yields an issue. - */ - protected void createTXTInfo(ServiceRecord serviceRecord) throws Exception { - TXTContainerRecordDescriptor txtInfo = - new TXTContainerRecordDescriptor(getPath(), serviceRecord); - registerRecordDescriptor(Type.TXT, txtInfo); - } - - /** - * Creates a container PTR record descriptor. - * @param record the service record. - * @throws Exception if the descriptor creation yields an issue. - */ - protected void createPTRInfo(ServiceRecord record) throws Exception { - PTRContainerRecordDescriptor - ptrInfo = new PTRContainerRecordDescriptor(getPath(), record); - registerRecordDescriptor(Type.PTR, ptrInfo); - } - - /** - * Creates a container AAAA (IPv6) record descriptor. - * @param record the service record - * @throws Exception if the descriptor creation yields an issue. - */ - protected void createAAAAInfo(ServiceRecord record) - throws Exception { - AAAAContainerRecordDescriptor - recordInfo = new AAAAContainerRecordDescriptor( - getPath(), record); - registerRecordDescriptor(Type.AAAA, recordInfo); - } - - /** - * Creates a container A (IPv4) record descriptor. - * @param record service record. - * @throws Exception if the descriptor creation yields an issue. - */ - protected void createAInfo(ServiceRecord record) throws Exception { - AContainerRecordDescriptor recordInfo = new AContainerRecordDescriptor( - getPath(), record); - registerRecordDescriptor(Type.A, recordInfo); - } - - /** - * Returns the record types associated with a container service record. - * @return the record type array - */ - @Override public int[] getRecordTypes() { - return new int[] {Type.A, Type.AAAA, Type.PTR, Type.TXT}; - } - - /** - * A container TXT record descriptor. - */ - class TXTContainerRecordDescriptor - extends ContainerRecordDescriptor<List<String>> { - - /** - * Creates a container TXT record descriptor. - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public TXTContainerRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(path, record); - } - - /** - * Initializes the descriptor parameters. - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) { - try { - this.setNames(new Name[] {getContainerName()}); - } catch (TextParseException e) { - // log - } catch (PathNotFoundException e) { - // log - } - List<String> txts = new ArrayList<>(); - txts.add("id=" + serviceRecord.get(YarnRegistryAttributes.YARN_ID)); - this.setTarget(txts); - } - - } - - /** - * A container PTR record descriptor. - */ - class PTRContainerRecordDescriptor extends ContainerRecordDescriptor<Name> { - - /** - * Creates a container PTR record descriptor. - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public PTRContainerRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(path, record); - } - - /** - * Initializes the descriptor parameters. - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) { - String host = serviceRecord.get(YarnRegistryAttributes.YARN_HOSTNAME); - String ip = serviceRecord.get(YarnRegistryAttributes.YARN_IP); - Name reverseLookupName = null; - if (host != null && ip != null) { - try { - reverseLookupName = reverseIP(ip); - } catch (UnknownHostException e) { - //LOG - } - } - this.setNames(new Name[] {reverseLookupName}); - try { - this.setTarget(getContainerName()); - } catch (TextParseException e) { - //LOG - } catch (PathNotFoundException e) { - //LOG - } - } - - } - - - /** - * A container A record descriptor. - */ - class AContainerRecordDescriptor - extends ContainerRecordDescriptor<InetAddress> { - - /** - * Creates a container A record descriptor. - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public AContainerRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(path, record); - } - - /** - * Initializes the descriptor parameters. - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) { - String ip = serviceRecord.get(YarnRegistryAttributes.YARN_IP); - if (ip == null) { - throw new IllegalArgumentException("No IP specified"); - } - try { - this.setTarget(InetAddress.getByName(ip)); - this.setNames(new Name[] {getContainerName(), getContainerIDName(), - getComponentName()}); - } catch (Exception e) { - throw new IllegalStateException(e); - } - - } - - } - - /** - * A container AAAA record descriptor. - */ - class AAAAContainerRecordDescriptor extends AContainerRecordDescriptor { - - /** - * Creates a container AAAA record descriptor. - * @param path registry path for service record - * @param record service record - * @throws Exception - */ - public AAAAContainerRecordDescriptor(String path, - ServiceRecord record) throws Exception { - super(path, record); - } - - /** - * Initializes the descriptor parameters. - * @param serviceRecord the service record. - */ - @Override protected void init(ServiceRecord serviceRecord) { - super.init(serviceRecord); - try { - this.setTarget(getIpv6Address(getTarget())); - } catch (UnknownHostException e) { - throw new IllegalStateException(e); - } - } - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java deleted file mode 100644 index c2fc4a9..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/LookupTask.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import java.util.concurrent.Callable; - -import org.xbill.DNS.Lookup; -import org.xbill.DNS.Name; -import org.xbill.DNS.Record; - -public class LookupTask implements Callable<Record[]> { - - private Name name; - private int type; - - public LookupTask(Name name, int type) { - this.name = name; - this.type = type; - } - - @Override - public Record[] call() throws Exception { - return new Lookup(name, type).run(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/PrivilegedRegistryDNSStarter.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/PrivilegedRegistryDNSStarter.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/PrivilegedRegistryDNSStarter.java deleted file mode 100644 index dd4e1b8..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/PrivilegedRegistryDNSStarter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import org.apache.commons.daemon.Daemon; -import org.apache.commons.daemon.DaemonContext; -import org.apache.hadoop.registry.client.api.DNSOperationsFactory; -import org.apache.hadoop.util.GenericOptionsParser; -import org.apache.hadoop.util.StringUtils; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.apache.hadoop.registry.client.api.RegistryConstants.DEFAULT_DNS_PORT; -import static org.apache.hadoop.registry.client.api.RegistryConstants.KEY_DNS_PORT; - -/** - * This class is used to allow the RegistryDNSServer to run on a privileged - * port (e.g. 53). - */ -public class PrivilegedRegistryDNSStarter implements Daemon { - private static final Logger LOG = - LoggerFactory.getLogger(PrivilegedRegistryDNSStarter.class); - - private YarnConfiguration conf; - private RegistryDNS registryDNS; - private RegistryDNSServer registryDNSServer; - - @Override - public void init(DaemonContext context) throws Exception { - String[] args = context.getArguments(); - StringUtils.startupShutdownMessage(RegistryDNSServer.class, args, LOG); - conf = new YarnConfiguration(); - new GenericOptionsParser(conf, args); - - int port = conf.getInt(KEY_DNS_PORT, DEFAULT_DNS_PORT); - if (port < 1 || port > 1023) { - throw new RuntimeException("Must start privileged registry DNS server " + - "with '" + KEY_DNS_PORT + "' configured to a privileged port."); - } - - try { - registryDNS = (RegistryDNS) DNSOperationsFactory.createInstance(conf); - registryDNS.initializeChannels(conf); - } catch (Exception e) { - LOG.error("Error initializing Registry DNS", e); - throw e; - } - } - - @Override - public void start() throws Exception { - registryDNSServer = RegistryDNSServer.launchDNSServer(conf, registryDNS); - } - - @Override - public void stop() throws Exception { - } - - @Override - public void destroy() { - registryDNSServer.stop(); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/e2a9fa84/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RecordCreatorFactory.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RecordCreatorFactory.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RecordCreatorFactory.java deleted file mode 100644 index 23f9501..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-registry/src/main/java/org/apache/hadoop/registry/server/dns/RecordCreatorFactory.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * 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.hadoop.registry.server.dns; - -import org.xbill.DNS.AAAARecord; -import org.xbill.DNS.ARecord; -import org.xbill.DNS.CNAMERecord; -import org.xbill.DNS.DClass; -import org.xbill.DNS.Name; -import org.xbill.DNS.PTRRecord; -import org.xbill.DNS.Record; -import org.xbill.DNS.SRVRecord; -import org.xbill.DNS.TXTRecord; - -import java.net.InetAddress; -import java.util.List; - -import static org.xbill.DNS.Type.*; - -/** - * A factory for creating DNS records. - */ -public final class RecordCreatorFactory { - private static long ttl; - - /** - * Private constructor. - */ - private RecordCreatorFactory() { - } - - /** - * Returns the DNS record creator for the provided type. - * - * @param type the DNS record type. - * @return the record creator. - */ - static RecordCreator getRecordCreator(int type) { - switch (type) { - case A: - return new ARecordCreator(); - case CNAME: - return new CNAMERecordCreator(); - case TXT: - return new TXTRecordCreator(); - case AAAA: - return new AAAARecordCreator(); - case PTR: - return new PTRRecordCreator(); - case SRV: - return new SRVRecordCreator(); - default: - throw new IllegalArgumentException("No type " + type); - - } - } - - /** - * Set the TTL value for the records created by the factory. - * - * @param ttl the ttl value, in seconds. - */ - public static void setTtl(long ttl) { - RecordCreatorFactory.ttl = ttl; - } - - /** - * A DNS Record creator. - * - * @param <R> the record type - * @param <T> the record's target type - */ - public interface RecordCreator<R extends Record, T> { - R create(Name name, T target); - } - - /** - * An A Record creator. - */ - static class ARecordCreator implements RecordCreator<ARecord, InetAddress> { - /** - * Creates an A record creator. - */ - public ARecordCreator() { - } - - /** - * Creates a DNS A record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public ARecord create(Name name, InetAddress target) { - return new ARecord(name, DClass.IN, ttl, target); - } - } - - /** - * An AAAA Record creator. - */ - static class AAAARecordCreator - implements RecordCreator<AAAARecord, InetAddress> { - /** - * Creates an AAAA record creator. - */ - public AAAARecordCreator() { - } - - /** - * Creates a DNS AAAA record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public AAAARecord create(Name name, InetAddress target) { - return new AAAARecord(name, DClass.IN, ttl, target); - } - } - - static class CNAMERecordCreator implements RecordCreator<CNAMERecord, Name> { - /** - * Creates a CNAME record creator. - */ - public CNAMERecordCreator() { - } - - /** - * Creates a DNS CNAME record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public CNAMERecord create(Name name, Name target) { - return new CNAMERecord(name, DClass.IN, ttl, target); - } - } - - /** - * A TXT Record creator. - */ - static class TXTRecordCreator - implements RecordCreator<TXTRecord, List<String>> { - /** - * Creates a TXT record creator. - */ - public TXTRecordCreator() { - } - - /** - * Creates a DNS TXT record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public TXTRecord create(Name name, List<String> target) { - return new TXTRecord(name, DClass.IN, ttl, target); - } - } - - /** - * A PTR Record creator. - */ - static class PTRRecordCreator implements RecordCreator<PTRRecord, Name> { - /** - * Creates a PTR record creator. - */ - public PTRRecordCreator() { - } - - /** - * Creates a DNS PTR record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public PTRRecord create(Name name, Name target) { - return new PTRRecord(name, DClass.IN, ttl, target); - } - } - - /** - * A SRV Record creator. - */ - static class SRVRecordCreator - implements RecordCreator<SRVRecord, HostPortInfo> { - /** - * Creates a SRV record creator. - */ - public SRVRecordCreator() { - } - - /** - * Creates a DNS SRV record. - * - * @param name the record name. - * @param target the record target/value. - * @return an A record. - */ - @Override public SRVRecord create(Name name, HostPortInfo target) { - return new SRVRecord(name, DClass.IN, ttl, 1, 1, target.getPort(), - target.getHost()); - } - } - - /** - * An object for storing the host and port info used to generate SRV records. - */ - public static class HostPortInfo { - private Name host; - private int port; - - /** - * Creates an object with a host and port pair. - * - * @param host the hostname/ip - * @param port the port value - */ - public HostPortInfo(Name host, int port) { - this.setHost(host); - this.setPort(port); - } - - /** - * Return the host name. - * @return the host name. - */ - Name getHost() { - return host; - } - - /** - * Set the host name. - * @param host the host name. - */ - void setHost(Name host) { - this.host = host; - } - - /** - * Get the port. - * @return the port. - */ - int getPort() { - return port; - } - - /** - * Set the port. - * @param port the port. - */ - void setPort(int port) { - this.port = port; - } - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
