You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by to...@apache.org on 2008/11/14 20:16:53 UTC
svn commit: r714107 - in /hadoop/core/trunk: CHANGES.txt
src/core/org/apache/hadoop/net/ScriptBasedMapping.java
src/test/org/apache/hadoop/net/TestScriptBasedMapping.java
Author: tomwhite
Date: Fri Nov 14 11:16:52 2008
New Revision: 714107
URL: http://svn.apache.org/viewvc?rev=714107&view=rev
Log:
HADOOP-4141. Fix bug in ScriptBasedMapping causing potential infinite loop on misconfigured hadoop-site. Contributed by Aaron Kimball.
Added:
hadoop/core/trunk/src/test/org/apache/hadoop/net/TestScriptBasedMapping.java
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/core/org/apache/hadoop/net/ScriptBasedMapping.java
Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=714107&r1=714106&r2=714107&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Fri Nov 14 11:16:52 2008
@@ -158,6 +158,9 @@
HADOOP-4606. Fix cygpath error if the log directory does not exist.
(szetszwo via omalley)
+ HADOOP-4141. Fix bug in ScriptBasedMapping causing potential infinite
+ loop on misconfigured hadoop-site. (Aaron Kimball via tomwhite)
+
Release 0.19.0 - 2008-11-18
INCOMPATIBLE CHANGES
Modified: hadoop/core/trunk/src/core/org/apache/hadoop/net/ScriptBasedMapping.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/core/org/apache/hadoop/net/ScriptBasedMapping.java?rev=714107&r1=714106&r2=714107&view=diff
==============================================================================
--- hadoop/core/trunk/src/core/org/apache/hadoop/net/ScriptBasedMapping.java (original)
+++ hadoop/core/trunk/src/core/org/apache/hadoop/net/ScriptBasedMapping.java Fri Nov 14 11:16:52 2008
@@ -38,6 +38,14 @@
super(new RawScriptBasedMapping());
}
+ // script must accept at least this many args
+ static final int MIN_ALLOWABLE_ARGS = 1;
+
+ static final int DEFAULT_ARG_COUNT = 100;
+
+ static final String SCRIPT_FILENAME_KEY = "topology.script.file.name";
+ static final String SCRIPT_ARG_COUNT_KEY = "topology.script.number.args";
+
public ScriptBasedMapping(Configuration conf) {
this();
setConf(conf);
@@ -59,8 +67,8 @@
private static Log LOG =
LogFactory.getLog(ScriptBasedMapping.class);
public void setConf (Configuration conf) {
- this.scriptName = conf.get("topology.script.file.name");
- this.maxArgs = conf.getInt("topology.script.number.args", 100);
+ this.scriptName = conf.get(SCRIPT_FILENAME_KEY);
+ this.maxArgs = conf.getInt(SCRIPT_ARG_COUNT_KEY, DEFAULT_ARG_COUNT);
this.conf = conf;
}
public Configuration getConf () {
@@ -90,7 +98,20 @@
String switchInfo = allSwitchInfo.nextToken();
m.add(switchInfo);
}
+
+ if (m.size() != names.size()) {
+ // invalid number of entries returned by the script
+ LOG.warn("Script " + scriptName + " returned "
+ + Integer.toString(m.size()) + " values when "
+ + Integer.toString(names.size()) + " were expected.");
+ return null;
+ }
+ } else {
+ // an error occurred. return null to signify this.
+ // (exn was already logged in runResolveCommand)
+ return null;
}
+
return m;
}
@@ -101,6 +122,13 @@
}
StringBuffer allOutput = new StringBuffer();
int numProcessed = 0;
+ if (maxArgs < MIN_ALLOWABLE_ARGS) {
+ LOG.warn("Invalid value " + Integer.toString(maxArgs)
+ + " for " + SCRIPT_ARG_COUNT_KEY + "; must be >= "
+ + Integer.toString(MIN_ALLOWABLE_ARGS));
+ return null;
+ }
+
while (numProcessed != args.size()) {
int start = maxArgs * loopCount;
List <String> cmdList = new ArrayList<String>();
Added: hadoop/core/trunk/src/test/org/apache/hadoop/net/TestScriptBasedMapping.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/net/TestScriptBasedMapping.java?rev=714107&view=auto
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/net/TestScriptBasedMapping.java (added)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/net/TestScriptBasedMapping.java Fri Nov 14 11:16:52 2008
@@ -0,0 +1,46 @@
+/**
+ * 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.net;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.conf.Configuration;
+
+import junit.framework.TestCase;
+
+public class TestScriptBasedMapping extends TestCase {
+
+ public void testNoArgsMeansNoResult() {
+ ScriptBasedMapping mapping = new ScriptBasedMapping();
+
+ Configuration conf = new Configuration();
+ conf.setInt(ScriptBasedMapping.SCRIPT_ARG_COUNT_KEY,
+ ScriptBasedMapping.MIN_ALLOWABLE_ARGS - 1);
+ conf.set(ScriptBasedMapping.SCRIPT_FILENAME_KEY, "any-filename");
+
+ mapping.setConf(conf);
+
+ List<String> names = new ArrayList<String>();
+ names.add("some.machine.name");
+ names.add("other.machine.name");
+
+ List<String> result = mapping.resolve(names);
+ assertNull(result);
+ }
+}