From b2a7811fe79e0d54d77c6e944a57b715976ff643 Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Tue, 1 Oct 2013 22:28:02 +0000 Subject: [PATCH] YARN-1215. Yarn URL should include userinfo. Contributed by Chuan Liu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1528233 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 2 ++ .../apache/hadoop/yarn/api/records/URL.java | 16 +++++++++++++++ .../src/main/proto/yarn_protos.proto | 1 + .../yarn/api/records/impl/pb/URLPBImpl.java | 20 +++++++++++++++++++ .../hadoop/yarn/util/ConverterUtils.java | 6 ++++++ .../hadoop/yarn/util/TestConverterUtils.java | 8 ++++++++ 6 files changed, 53 insertions(+) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 30b56f67232..3501ed423d2 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -54,6 +54,8 @@ Release 2.3.0 - UNRELEASED YARN-1188. The context of QueueMetrics becomes default when using FairScheduler (Tsuyoshi Ozawa via Sandy Ryza) + YARN-1215. Yarn URL should include userinfo. (Chuan Liu via cnauroth) + Release 2.2.0 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/URL.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/URL.java index 769494e2e9e..4261117b108 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/URL.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/URL.java @@ -56,6 +56,22 @@ public abstract class URL { @Stable public abstract void setScheme(String scheme); + /** + * Get the user info of the URL. + * @return user info of the URL + */ + @Public + @Stable + public abstract String getUserInfo(); + + /** + * Set the user info of the URL. + * @param userInfo user info of the URL + */ + @Public + @Stable + public abstract void setUserInfo(String userInfo); + /** * Get the host of the URL. * @return host of the URL diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto index f49b1653b9c..31923068cbd 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto @@ -100,6 +100,7 @@ message URLProto { optional string host = 2; optional int32 port = 3; optional string file = 4; + optional string userInfo = 5; } enum LocalResourceVisibilityProto { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/URLPBImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/URLPBImpl.java index c5586c766d5..ab31d0c32f4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/URLPBImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/URLPBImpl.java @@ -113,6 +113,26 @@ public class URLPBImpl extends URL { } builder.setScheme((scheme)); } + + @Override + public String getUserInfo() { + URLProtoOrBuilder p = viaProto ? proto : builder; + if (!p.hasUserInfo()) { + return null; + } + return (p.getUserInfo()); + } + + @Override + public void setUserInfo(String userInfo) { + maybeInitBuilder(); + if (userInfo == null) { + builder.clearUserInfo(); + return; + } + builder.setUserInfo((userInfo)); + } + @Override public String getHost() { URLProtoOrBuilder p = viaProto ? proto : builder; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ConverterUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ConverterUtils.java index 596ae28d25f..5fff8f4e779 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ConverterUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/util/ConverterUtils.java @@ -69,6 +69,9 @@ public class ConverterUtils { String authority = ""; if (url.getHost() != null) { authority = url.getHost(); + if (url.getUserInfo() != null) { + authority = url.getUserInfo() + "@" + authority; + } if (url.getPort() > 0) { authority += ":" + url.getPort(); } @@ -102,6 +105,9 @@ public class ConverterUtils { if (uri.getHost() != null) { url.setHost(uri.getHost()); } + if (uri.getUserInfo() != null) { + url.setUserInfo(uri.getUserInfo()); + } url.setPort(uri.getPort()); url.setScheme(uri.getScheme()); url.setFile(uri.getPath()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java index 2d6793b926b..21af4555e37 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestConverterUtils.java @@ -38,6 +38,14 @@ public class TestConverterUtils { assertEquals(expectedPath, actualPath); } + @Test + public void testConvertUrlWithUserinfo() throws URISyntaxException { + Path expectedPath = new Path("foo://username:password@example.com:8042"); + URL url = ConverterUtils.getYarnUrlFromPath(expectedPath); + Path actualPath = ConverterUtils.getPathFromYarnURL(url); + assertEquals(expectedPath, actualPath); + } + @Test public void testContainerId() throws URISyntaxException { ContainerId id = TestContainerId.newContainerId(0, 0, 0, 0);