Class AbstractDNSToSwitchMapping
- java.lang.Object
-
- org.apache.bookkeeper.net.AbstractDNSToSwitchMapping
-
- All Implemented Interfaces:
Configurable
,DNSToSwitchMapping
- Direct Known Subclasses:
CachedDNSToSwitchMapping
public abstract class AbstractDNSToSwitchMapping extends java.lang.Object implements DNSToSwitchMapping, Configurable
This is a base class for DNS to Switch mappings.It is not mandatory to derive
DNSToSwitchMapping
implementations from it, but it is strongly recommended, as it makes it easy for the Hadoop developers to add new methods to this base class that are automatically picked up by all implementations.This class does not extend the
Configured
base class, and should not be changed to do so, as it causes problems for subclasses. The constructor of theConfigured
calls thesetConf(Configuration)
method, which will call into the subclasses before they have been fully constructed.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractDNSToSwitchMapping()
Create an unconfigured instance.protected
AbstractDNSToSwitchMapping(org.apache.commons.configuration.Configuration conf)
Create an instance, caching the configuration file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
dumpTopology()
Generate a string listing the switch mapping implementation, the mapping for every known node and the number of nodes and unique switches known about -each entry to a separate line.BookieAddressResolver
getBookieAddressResolver()
org.apache.commons.configuration.Configuration
getConf()
Return the configuration used by this object.java.util.Map<java.lang.String,java.lang.String>
getSwitchMap()
Get a copy of the map (for diagnostics).static boolean
isMappingSingleSwitch(DNSToSwitchMapping mapping)
Query for aDNSToSwitchMapping
instance being on a single switch.boolean
isSingleSwitch()
Predicate that indicates that the switch mapping is known to be single-switch.protected boolean
isSingleSwitchByScriptPolicy()
void
setBookieAddressResolver(BookieAddressResolver bookieAddressResolver)
Receives the current BookieAddressResolver.void
setConf(org.apache.commons.configuration.Configuration conf)
Set the configuration to be used by this object.protected void
validateConf()
when setConf is called it should do sanity checking of the conf/env.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.bookkeeper.net.DNSToSwitchMapping
reloadCachedMappings, resolve, useHostName
-
-
-
-
Constructor Detail
-
AbstractDNSToSwitchMapping
protected AbstractDNSToSwitchMapping()
Create an unconfigured instance.
-
AbstractDNSToSwitchMapping
protected AbstractDNSToSwitchMapping(org.apache.commons.configuration.Configuration conf)
Create an instance, caching the configuration file. This constructor does not callsetConf(Configuration)
; if a subclass extracts information in that method, it must call it explicitly.- Parameters:
conf
- the configuration
-
-
Method Detail
-
getBookieAddressResolver
public BookieAddressResolver getBookieAddressResolver()
-
setBookieAddressResolver
public void setBookieAddressResolver(BookieAddressResolver bookieAddressResolver)
Description copied from interface:DNSToSwitchMapping
Receives the current BookieAddressResolver.- Specified by:
setBookieAddressResolver
in interfaceDNSToSwitchMapping
-
getConf
public org.apache.commons.configuration.Configuration getConf()
Description copied from interface:Configurable
Return the configuration used by this object.- Specified by:
getConf
in interfaceConfigurable
- Returns:
- configuration used by this object.
-
setConf
public void setConf(org.apache.commons.configuration.Configuration conf)
Description copied from interface:Configurable
Set the configuration to be used by this object.- Specified by:
setConf
in interfaceConfigurable
- Parameters:
conf
- Configuration object to use
-
isSingleSwitch
public boolean isSingleSwitch()
Predicate that indicates that the switch mapping is known to be single-switch. The base class returns false: it assumes all mappings are multi-rack. Subclasses may override this with methods that are more aware of their topologies.This method is used when parts of Hadoop need know whether to apply single rack vs multi-rack policies, such as during block placement. Such algorithms behave differently if they are on multi-switch systems.
- Returns:
- true if the mapping thinks that it is on a single switch
-
getSwitchMap
public java.util.Map<java.lang.String,java.lang.String> getSwitchMap()
Get a copy of the map (for diagnostics).- Returns:
- a clone of the map or null for none known
-
dumpTopology
public java.lang.String dumpTopology()
Generate a string listing the switch mapping implementation, the mapping for every known node and the number of nodes and unique switches known about -each entry to a separate line.- Returns:
- a string that can be presented to the ops team or used in debug messages.
-
isSingleSwitchByScriptPolicy
protected boolean isSingleSwitchByScriptPolicy()
-
isMappingSingleSwitch
public static boolean isMappingSingleSwitch(DNSToSwitchMapping mapping)
Query for aDNSToSwitchMapping
instance being on a single switch.This predicate simply assumes that all mappings not derived from this class are multi-switch.
- Parameters:
mapping
- the mapping to query- Returns:
- true if the base class says it is single switch, or the mapping is not derived from this class.
-
validateConf
protected void validateConf()
when setConf is called it should do sanity checking of the conf/env. and throw RuntimeException if things are not valid.
-
-