Merge -r 1311519:1311520 from trunk to branch-2. Fixes MAPREDUCE-4105.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1311521 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Thomas White 2012-04-09 23:35:21 +00:00
parent f9e39d057e
commit de5069a6a1
4 changed files with 61 additions and 5 deletions

View File

@ -119,6 +119,9 @@ Release 2.0.0 - UNRELEASED
org.apache.hadoop.mapred.TestMiniMRWithDFSWithDistinctUsers (Devaraj K via
bobby)
MAPREDUCE-4105. Yarn RackResolver ignores rack configurations.
(Ahmed Radwan via tomwhite)
Release 0.23.3 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -31,6 +31,9 @@ import org.apache.hadoop.net.DNSToSwitchMapping;
import org.apache.hadoop.net.Node;
import org.apache.hadoop.net.NodeBase;
import org.apache.hadoop.net.ScriptBasedMapping;
import org.apache.hadoop.util.ReflectionUtils;
import com.google.common.annotations.VisibleForTesting;
public class RackResolver {
private static DNSToSwitchMapping dnsToSwitchMapping;
@ -49,10 +52,8 @@ public class RackResolver {
ScriptBasedMapping.class,
DNSToSwitchMapping.class);
try {
Constructor<? extends DNSToSwitchMapping> dnsToSwitchMappingConstructor
= dnsToSwitchMappingClass.getConstructor();
DNSToSwitchMapping newInstance =
dnsToSwitchMappingConstructor.newInstance();
DNSToSwitchMapping newInstance = ReflectionUtils.newInstance(
dnsToSwitchMappingClass, conf);
// Wrap around the configured class with the Cached implementation so as
// to save on repetitive lookups.
// Check if the impl is already caching, to avoid double caching.
@ -99,4 +100,12 @@ public class RackResolver {
LOG.info("Resolved " + hostName + " to " + rName);
return new NodeBase(hostName, rName);
}
/**
* Only used by tests
*/
@VisibleForTesting
static DNSToSwitchMapping getDnsToSwitchMapping(){
return dnsToSwitchMapping;
}
}

View File

@ -52,7 +52,7 @@ public class TestRackResolver {
Assert.assertTrue(numHost1 <= 1);
return returnList;
}
}
@Test

View File

@ -0,0 +1,44 @@
/**
* 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.yarn.util;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.net.DNSToSwitchMapping;
import org.apache.hadoop.net.ScriptBasedMapping;
import org.junit.Assert;
import org.junit.Test;
public class TestRackResolverScriptBasedMapping {
@Test
public void testScriptName() {
Configuration conf = new Configuration();
conf
.setClass(
CommonConfigurationKeysPublic.
NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
ScriptBasedMapping.class, DNSToSwitchMapping.class);
conf.set(CommonConfigurationKeysPublic.NET_TOPOLOGY_SCRIPT_FILE_NAME_KEY,
"testScript");
RackResolver.init(conf);
Assert.assertEquals(RackResolver.getDnsToSwitchMapping().toString(),
"script-based mapping with script testScript");
}
}