This adds a new base class AbstractDNSToSwitchMapping to offer a common implementation class for the bundled DNS mappings, and a new predicate isSingleSwitch() which should be true if
a class believes that its topology is only on a single switch.
I initially tried to have the base class extend Configurable but that triggered calls to things like ScriptBasedMapping.setConf() from Configurable's constructor, which had lots of consequences as the subclasses weren't ready for that yet. I added the workarounds
checks for other fields being initialised but this left the code brittle and made it harder to make any custom mappers subclasses of this. I reverted those changes and now the AbstractDNSToSwitchMapping class just implements Configurable.
This base class (and the sub classes) do what I wanted, namely indicate whether or not they are single switch or not, with the presumption being "multi-switch unless stated".
- ScriptBasedMapping is single rack if it has no script.
- CachedDNSToSwitchMapping relays its query to the raw mapping.
- StaticMapping says it is single rack if its map is empty (that is, all resolved nodes
will be reported as being in the default rack).
There's tests for all this, and in TestSwitchMapping verification that implementations of DNSToSwitchMapping are always considered multi-switch. The tests also see what happens when you pass down null configurations (the existing stuff mostly broke)
Once committed I can fix HDFS BlockManager to use the switch predicate to decide whether to assume multi-rack placement or not.