Class RegistryDNS

java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.registry.server.dns.RegistryDNS
All Implemented Interfaces:
Closeable, AutoCloseable, DNSOperations, ZoneSelector, org.apache.hadoop.service.Service

public class RegistryDNS extends org.apache.hadoop.service.AbstractService implements DNSOperations, ZoneSelector
A DNS service reflecting the state of the YARN registry. Records are created based on service records available in the YARN ZK-based registry.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An implementation allowing for obtaining and releasing a lock.

    Nested classes/interfaces inherited from interface org.apache.hadoop.service.Service

    org.apache.hadoop.service.Service.STATE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addNIOTCP(InetAddress addr, int port)
    Create the thread (Callable) monitoring the TCP listener.
    void
    addNIOUDP(InetAddress addr, int port)
    Create the thread monitoring the socket for inbound UDP requests.
    protected void
    addSplitReverseZones(org.apache.hadoop.conf.Configuration conf, long subnetCount)
    Create the zones based on the zone count.
    void
    delete(String path, ServiceRecord record)
    Delete the DNS records generated by the provided service record.
    byte[]
    errorMessage(org.xbill.DNS.Message query, int rcode)
    Generate an error message based on inbound query.
    org.xbill.DNS.Zone
    findBestZone(org.xbill.DNS.Name name)
    Find the zone that correlates to the provided name.
    org.xbill.DNS.RRset
    findExactMatch(org.xbill.DNS.Name name, int type)
    Find the record set that matches the requested name and type.
    byte[]
    formErrorMessage(byte[] in)
    Creates a DNS error response.
    protected org.xbill.DNS.Record[]
    getRecords(org.xbill.DNS.Name name, int type)
    Requests records for the given resource name.
    protected org.xbill.DNS.Name
    getReverseZoneName(org.apache.hadoop.conf.Configuration conf)
    Returns the list of reverse lookup zones.
    protected int
    Return the number of zones in the map.
    void
    initializeChannels(org.apache.hadoop.conf.Configuration conf)
     
    void
    Process a TCP request.
    void
    register(String path, ServiceRecord record)
    Register DNS records based on the provided service record.
    void
    serveNIOTCP(ServerSocketChannel serverSocketChannel, InetAddress addr, int port)
    Monitor the TCP socket for inbound requests.
    protected void
    serviceInit(org.apache.hadoop.conf.Configuration conf)
    Initializes the registry.
    protected void
    Stops the registry.
    protected void
    setDNSSECEnabled(org.apache.hadoop.conf.Configuration conf)
    Set the value of the DNSSEC enabled property.
    protected void
    Shuts down the leveraged executor service.

    Methods inherited from class org.apache.hadoop.service.AbstractService

    close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, noteFailure, putBlocker, registerGlobalListener, registerServiceListener, removeBlocker, serviceStart, setConfig, start, stop, toString, unregisterGlobalListener, unregisterServiceListener, waitForServiceToStop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.hadoop.service.Service

    close, getBlockers, getConfig, getFailureCause, getFailureState, getLifecycleHistory, getName, getServiceState, getStartTime, init, isInState, registerServiceListener, start, stop, unregisterServiceListener, waitForServiceToStop
  • Field Details

  • Constructor Details

    • RegistryDNS

      public RegistryDNS(String name)
      Construct the service.
      Parameters:
      name - service name
  • Method Details

    • initializeChannels

      public void initializeChannels(org.apache.hadoop.conf.Configuration conf) throws Exception
      Throws:
      Exception
    • serviceInit

      protected void serviceInit(org.apache.hadoop.conf.Configuration conf) throws Exception
      Initializes the registry.
      Overrides:
      serviceInit in class org.apache.hadoop.service.AbstractService
      Parameters:
      conf - the hadoop configuration
      Throws:
      Exception - if there are tcp/udp issues
    • getZoneCount

      @VisibleForTesting protected int getZoneCount()
      Return the number of zones in the map.
      Returns:
      number of zones in the map
    • addSplitReverseZones

      @VisibleForTesting protected void addSplitReverseZones(org.apache.hadoop.conf.Configuration conf, long subnetCount) throws IOException
      Create the zones based on the zone count.
      Parameters:
      conf - the Hadoop configuration.
      subnetCount - number of subnets to create reverse zones for.
      Throws:
      IOException - if the DNSSEC key can not be read.
    • getReverseZoneName

      protected org.xbill.DNS.Name getReverseZoneName(org.apache.hadoop.conf.Configuration conf)
      Returns the list of reverse lookup zones.
      Parameters:
      conf - the hadoop configuration.
      Returns:
      the list of reverse zone names required based on the configuration properties.
    • setDNSSECEnabled

      @VisibleForTesting protected void setDNSSECEnabled(org.apache.hadoop.conf.Configuration conf)
      Set the value of the DNSSEC enabled property.
      Parameters:
      conf - the Hadoop configuration.
    • serviceStop

      protected void serviceStop() throws Exception
      Stops the registry.
      Overrides:
      serviceStop in class org.apache.hadoop.service.AbstractService
      Throws:
      Exception - if the service stop generates an issue.
    • stopExecutor

      protected void stopExecutor()
      Shuts down the leveraged executor service.
    • formErrorMessage

      public byte[] formErrorMessage(byte[] in)
      Creates a DNS error response.
      Parameters:
      in - the byte array detailing the error.
      Returns:
      the error message, in bytes
    • nioTCPClient

      public void nioTCPClient(SocketChannel ch) throws IOException
      Process a TCP request.
      Parameters:
      ch - the socket channel for the request.
      Throws:
      IOException - if the tcp processing generates an issue.
    • serveNIOTCP

      public void serveNIOTCP(ServerSocketChannel serverSocketChannel, InetAddress addr, int port) throws Exception
      Monitor the TCP socket for inbound requests.
      Parameters:
      serverSocketChannel - the server socket channel
      addr - the local inet address
      port - the listener (local) port
      Throws:
      Exception - if the tcp processing fails.
    • addNIOTCP

      public void addNIOTCP(InetAddress addr, int port) throws Exception
      Create the thread (Callable) monitoring the TCP listener.
      Parameters:
      addr - host address.
      port - host port.
      Throws:
      Exception - if the tcp listener generates an error.
    • addNIOUDP

      public void addNIOUDP(InetAddress addr, int port) throws Exception
      Create the thread monitoring the socket for inbound UDP requests.
      Parameters:
      addr - host address.
      port - host port.
      Throws:
      Exception - if the UDP listener creation generates an error.
    • errorMessage

      public byte[] errorMessage(org.xbill.DNS.Message query, int rcode)
      Generate an error message based on inbound query.
      Parameters:
      query - the query.
      rcode - the response code for the specific error.
      Returns:
      the error message.
    • getRecords

      protected org.xbill.DNS.Record[] getRecords(org.xbill.DNS.Name name, int type)
      Requests records for the given resource name.
      Parameters:
      name - - query string
      type - - type of DNS record to lookup
      Returns:
      DNS records
    • findExactMatch

      public org.xbill.DNS.RRset findExactMatch(org.xbill.DNS.Name name, int type)
      Find the record set that matches the requested name and type.
      Parameters:
      name - the requested name.
      type - the record type.
      Returns:
      the set of records with the given name and type.
    • findBestZone

      public org.xbill.DNS.Zone findBestZone(org.xbill.DNS.Name name)
      Find the zone that correlates to the provided name.
      Specified by:
      findBestZone in interface ZoneSelector
      Parameters:
      name - the name to be matched to a zone.
      Returns:
      the zone.
    • register

      public void register(String path, ServiceRecord record) throws IOException
      Register DNS records based on the provided service record.
      Specified by:
      register in interface DNSOperations
      Parameters:
      path - the ZK path of the service record.
      record - record providing DNS registration info.
      Throws:
      IOException - if registration causes an error.
    • delete

      public void delete(String path, ServiceRecord record) throws IOException
      Delete the DNS records generated by the provided service record.
      Specified by:
      delete in interface DNSOperations
      Parameters:
      path - the ZK path for the given record.
      record - the service record
      Throws:
      IOException - if deletion causes and error.