Skip to content

Commit fcb60f0

Browse files
committed
YARN-1201. TestAMAuthorization fails with local hostname cannot be resolved. (Wangda Tan via junping_du)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1592197 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1f26f0a commit fcb60f0

File tree

2 files changed

+53
-8
lines changed
  • hadoop-yarn-project

2 files changed

+53
-8
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ Release 2.4.1 - UNRELEASED
170170
YARN-1929. Fixed a deadlock in ResourceManager that occurs when failover
171171
happens right at the time of shutdown. (Karthik Kambatla via vinodkv)
172172

173+
YARN-1201. TestAMAuthorization fails with local hostname cannot be resolved.
174+
(Wangda Tan via junping_du)
175+
173176
Release 2.4.0 - 2014-04-07
174177

175178
INCOMPATIBLE CHANGES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestAMAuthorization.java

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.apache.hadoop.conf.Configuration;
3333
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
3434
import org.apache.hadoop.io.DataInputByteBuffer;
35+
import org.apache.hadoop.security.AccessControlException;
3536
import org.apache.hadoop.security.Credentials;
3637
import org.apache.hadoop.security.SecurityUtil;
3738
import org.apache.hadoop.security.UserGroupInformation;
@@ -272,21 +273,62 @@ public ApplicationMasterProtocol run() {
272273
client.registerApplicationMaster(request);
273274
Assert.fail("Should fail with authorization error");
274275
} catch (Exception e) {
275-
// Because there are no tokens, the request should be rejected as the
276-
// server side will assume we are trying simple auth.
277-
String expectedMessage = "";
278-
if (UserGroupInformation.isSecurityEnabled()) {
279-
expectedMessage = "Client cannot authenticate via:[TOKEN]";
276+
if (isCause(AccessControlException.class, e)) {
277+
// Because there are no tokens, the request should be rejected as the
278+
// server side will assume we are trying simple auth.
279+
String expectedMessage = "";
280+
if (UserGroupInformation.isSecurityEnabled()) {
281+
expectedMessage = "Client cannot authenticate via:[TOKEN]";
282+
} else {
283+
expectedMessage =
284+
"SIMPLE authentication is not enabled. Available:[TOKEN]";
285+
}
286+
Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage));
280287
} else {
281-
expectedMessage =
282-
"SIMPLE authentication is not enabled. Available:[TOKEN]";
288+
throw e;
283289
}
284-
Assert.assertTrue(e.getCause().getMessage().contains(expectedMessage));
285290
}
286291

287292
// TODO: Add validation of invalid authorization when there's more data in
288293
// the AMRMToken
289294
}
295+
296+
/**
297+
* Identify if an expected throwable included in an exception stack. We use
298+
* this because sometimes, an exception will be wrapped to another exception
299+
* before thrown. Like,
300+
*
301+
* <pre>
302+
* {@code
303+
* void methodA() throws IOException {
304+
* try {
305+
* // something
306+
* } catch (AccessControlException e) {
307+
* // do process
308+
* throw new IOException(e)
309+
* }
310+
* }
311+
* </pre>
312+
*
313+
* So we cannot simply catch AccessControlException by using
314+
* <pre>
315+
* {@code
316+
* try {
317+
* methodA()
318+
* } catch (AccessControlException e) {
319+
* // do something
320+
* }
321+
* </pre>
322+
*
323+
* This method is useful in such cases.
324+
*/
325+
private static boolean isCause(
326+
Class<? extends Throwable> expected,
327+
Throwable e
328+
) {
329+
return (e != null)
330+
&& (expected.isInstance(e) || isCause(expected, e.getCause()));
331+
}
290332

291333
private void waitForLaunchedState(RMAppAttempt attempt)
292334
throws InterruptedException {

0 commit comments

Comments
 (0)