ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbhowm...@apache.org
Subject ambari git commit: AMBARI-17647. Tez view throws a 401 when looking at live progress of a running job. (dipayanb)
Date Wed, 13 Jul 2016 10:25:48 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 842ec15ba -> 0e258b80c


AMBARI-17647. Tez view throws a 401 when looking at live progress of a running job. (dipayanb)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/0e258b80
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/0e258b80
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/0e258b80

Branch: refs/heads/branch-2.4
Commit: 0e258b80ca26e267499255b42d1841de7718df2d
Parents: 842ec15
Author: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Authored: Mon Jul 11 15:38:44 2016 +0530
Committer: Dipayan Bhowmick <dipayan.bhowmick@gmail.com>
Committed: Wed Jul 13 15:55:25 2016 +0530

----------------------------------------------------------------------
 .../apache/ambari/view/tez/ViewController.java  | 16 +++++++++++---
 .../ambari/view/tez/ViewControllerImpl.java     | 10 +++++++++
 .../ambari/view/tez/rest/AtsProxyResource.java  |  7 +++++-
 .../ambari/view/tez/rest/BaseProxyResource.java |  4 +++-
 .../view/tez/rest/BaseRedirectionResource.java  |  2 ++
 .../ambari/view/tez/rest/RMProxyResource.java   |  7 +++++-
 .../view/tez/rest/RMRedirectResource.java       |  7 +++++-
 .../ambari/view/tez/utils/ProxyHelper.java      | 14 +++++++++---
 contrib/views/tez/src/main/resources/view.xml   | 14 ++++++++++++
 .../ambari/view/tez/utils/ProxyHelperTest.java  | 23 +++++++++++++++-----
 .../ambari/view/utils/ambari/Services.java      | 16 ++++++++++++++
 11 files changed, 105 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewController.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewController.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewController.java
index 4ef1a43..dc73890 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewController.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewController.java
@@ -26,9 +26,9 @@ import com.google.inject.ImplementedBy;
 @ImplementedBy(ViewControllerImpl.class)
 public interface ViewController {
 
-  public static final String PARAM_YARN_ATS_URL = "yarn.ats.url";
-  public static final String PARAM_YARN_RESOURCEMANAGER_URL = "yarn.resourcemanager.url";
-  public static final String PARAM_YARN_PROTOCOL = "yarn.protocol";
+  String PARAM_YARN_ATS_URL = "yarn.ats.url";
+  String PARAM_YARN_RESOURCEMANAGER_URL = "yarn.resourcemanager.url";
+  String PARAM_YARN_PROTOCOL = "yarn.protocol";
 
   /**
    * @return Get the properties that any user is allowed to see, even non-admin users.
@@ -51,4 +51,14 @@ public interface ViewController {
    * @return The protocol used by YARN daemons.
    */
   String getYARNProtocol();
+
+  /**
+   * @return The authentication type for RM. Check: https://hadoop.apache.org/docs/r1.2.1/HttpAuthentication.html
+   */
+  String getRMAuthenticationType();
+
+  /**
+   * @return The authentication used for timeline server HTTP endpoint. Check: https://hadoop.apache.org/docs/r2.7.1/hadoop-yarn/hadoop-yarn-site/TimelineServer.html
+   */
+  String getATSAuthenticationType();
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java
index 8b023c2..9515e64 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/ViewControllerImpl.java
@@ -96,5 +96,15 @@ public class ViewControllerImpl implements ViewController {
       throw new TezWebAppException(message, ex);
     }
   }
+
+  @Override
+  public String getRMAuthenticationType() {
+    return ambariApi.getServices().getHadoopHttpWebAuthType();
+  }
+
+  @Override
+  public String getATSAuthenticationType() {
+    return ambariApi.getServices().getTimelineServerAuthType();
+  }
 }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/AtsProxyResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/AtsProxyResource.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/AtsProxyResource.java
index 9f88893..f17a01d 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/AtsProxyResource.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/AtsProxyResource.java
@@ -42,6 +42,11 @@ public class AtsProxyResource extends BaseProxyResource {
   @Override
   public String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams)
{
     String atsUrl = viewController.getActiveATSUrl();
-    return proxyHelper.getProxyUrl(atsUrl, endpoint, queryParams);
+    return proxyHelper.getProxyUrl(atsUrl, endpoint, queryParams, getAuthType());
+  }
+
+  @Override
+  public String getAuthType() {
+    return viewController.getATSAuthenticationType();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
index 2d89489..9c26816 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseProxyResource.java
@@ -61,7 +61,7 @@ public abstract class BaseProxyResource {
     String url = getProxyUrl(endpoint, uriInfo.getQueryParameters());
 
     LOG.debug("Proxying to URL: {}", url);
-    String response = proxyHelper.getResponse(url, new HashMap<String, String>());
+    String response = proxyHelper.getResponse(url, new HashMap<String, String>(), getAuthType());
 
     JSONObject jsonObject = (JSONObject) JSONValue.parse(response);
     if (jsonObject == null) {
@@ -84,4 +84,6 @@ public abstract class BaseProxyResource {
   }
 
   public abstract String getProxyUrl(String endpoint, MultivaluedMap<String, String>
queryParams);
+
+  public abstract String getAuthType();
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
index 14c2b75..9e035d9 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/BaseRedirectionResource.java
@@ -54,4 +54,6 @@ public abstract class BaseRedirectionResource {
   }
 
   public abstract String getProxyUrl(String endpoint, MultivaluedMap<String, String>
queryParams);
+
+  public abstract String getAuthType();
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMProxyResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMProxyResource.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMProxyResource.java
index e3b3688..a9f6d48 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMProxyResource.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMProxyResource.java
@@ -42,6 +42,11 @@ public class RMProxyResource extends BaseProxyResource {
   @Override
   public String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams)
{
     String activeRMUrl = viewController.getActiveRMUrl();
-    return proxyHelper.getProxyUrl(activeRMUrl, endpoint, queryParams);
+    return proxyHelper.getProxyUrl(activeRMUrl, endpoint, queryParams, getAuthType());
+  }
+
+  @Override
+  public String getAuthType() {
+    return viewController.getRMAuthenticationType();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
index 99faf88..079bb95 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/rest/RMRedirectResource.java
@@ -41,6 +41,11 @@ public class RMRedirectResource extends BaseRedirectionResource {
   @Override
   public String getProxyUrl(String endpoint, MultivaluedMap<String, String> queryParams)
{
     String activeRMUrl = viewController.getActiveRMUrl();
-    return proxyHelper.getProxyUrl(activeRMUrl, endpoint, queryParams);
+    return proxyHelper.getProxyUrl(activeRMUrl, endpoint, queryParams, getAuthType());
+  }
+
+  @Override
+  public String getAuthType() {
+    return viewController.getRMAuthenticationType();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
index 08eaa16..c6743c0 100644
--- a/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
+++ b/contrib/views/tez/src/main/java/org/apache/ambari/view/tez/utils/ProxyHelper.java
@@ -49,12 +49,17 @@ public class ProxyHelper {
   }
 
 
-  public String getResponse(String url, Map<String, String> headers) {
+  public String getResponse(String url, Map<String, String> headers, String authType)
{
     LOG.debug("Fetching the result from the URL: {} using proxy", url);
     InputStream inputStream = null;
     try {
+      HttpURLConnection connection;
       URLConnectionProvider provider = viewContext.getURLConnectionProvider();
-      HttpURLConnection connection = provider.getConnectionAsCurrent(url, "GET", (String)
null, headers);
+      if(authType == null || authType.equalsIgnoreCase("simple")) {
+        connection = provider.getConnection(url, "GET", (String) null, headers);
+      } else {
+        connection = provider.getConnectionAsCurrent(url, "GET", (String) null, headers);
+      }
 
       if (!(connection.getResponseCode() >= 200 && connection.getResponseCode()
< 300)) {
         LOG.error("Failure in fetching results for the URL: {}. Status: {}", url, connection.getResponseCode());
@@ -81,7 +86,7 @@ public class ProxyHelper {
     }
   }
 
-  public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String>
queryParameters) {
+  public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String>
queryParameters, String authType) {
     Set<String> keySet = queryParameters.keySet();
     URIBuilder builder;
     try {
@@ -89,6 +94,9 @@ public class ProxyHelper {
       for(String key: keySet) {
         builder.addParameter(key, queryParameters.getFirst(key));
       }
+      if(authType == null || authType.equalsIgnoreCase("simple")) {
+        builder.addParameter("user.name", viewContext.getUsername());
+      }
       return builder.build().toString();
     } catch (URISyntaxException e) {
       LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception:
{}", baseUrl, endPoint, e);

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/resources/view.xml b/contrib/views/tez/src/main/resources/view.xml
index 7bf19d5..2bb2bb0 100644
--- a/contrib/views/tez/src/main/resources/view.xml
+++ b/contrib/views/tez/src/main/resources/view.xml
@@ -42,6 +42,20 @@ limitations under the License. Kerberos, LDAP, Custom. Binary/Htt
     <required>false</required>
     <cluster-config>core-site/hadoop.security.auth_to_local</cluster-config>
   </parameter>
+  <parameter>
+    <name>timeline.http.auth.type</name>
+    <description>Authentication used for the timeline server HTTP endpoint. Supported
values are: simple / kerberos / #AUTHENTICATION_HANDLER_CLASSNAME#. Defaults to simple.</description>
+    <label>Timeline HTTP Auth</label>
+    <required>false</required>
+    <cluster-config>yarn-site/yarn.timeline-service.http-authentication.type</cluster-config>
+  </parameter>
+  <parameter>
+    <name>hadoop.http.auth.type</name>
+    <description>Defines authentication used for RM HTTP endpoint. Supported values
are: simple | kerberos | #AUTHENTICATION_HANDLER_CLASSNAME#. Default to simple.</description>
+    <label>RM HTTP Auth</label>
+    <required>false</required>
+    <cluster-config>core-site/hadoop.http.authentication.type</cluster-config>
+  </parameter>
 
   <!-- The status resource exists to show the subset of properties that any user is allowed
to see, not just an admin user. -->
   <resource>

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/tez/src/test/java/org/apache/ambari/view/tez/utils/ProxyHelperTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/test/java/org/apache/ambari/view/tez/utils/ProxyHelperTest.java
b/contrib/views/tez/src/test/java/org/apache/ambari/view/tez/utils/ProxyHelperTest.java
index 2160848..90573e2 100644
--- a/contrib/views/tez/src/test/java/org/apache/ambari/view/tez/utils/ProxyHelperTest.java
+++ b/contrib/views/tez/src/test/java/org/apache/ambari/view/tez/utils/ProxyHelperTest.java
@@ -26,6 +26,8 @@ import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 
 import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
 import static org.junit.Assert.assertEquals;
 
 public class ProxyHelperTest {
@@ -33,8 +35,8 @@ public class ProxyHelperTest {
   public void shouldBuildURLWithNoQueryParameters() throws Exception {
     ViewContext context = createNiceMock(ViewContext.class);
     ProxyHelper helper = new ProxyHelper(context);
-    assertEquals("http://abc.com/", helper.getProxyUrl("http://abc.com", "", new MultivaluedHashMap<String,
String>()));
-    assertEquals("http://abc.com/test/abcd", helper.getProxyUrl("http://abc.com", "test/abcd",
new MultivaluedHashMap<String, String>()));
+    assertEquals("http://abc.com/", helper.getProxyUrl("http://abc.com", "", new MultivaluedHashMap<String,
String>(), "kerberos"));
+    assertEquals("http://abc.com/test/abcd", helper.getProxyUrl("http://abc.com", "test/abcd",
new MultivaluedHashMap<String, String>(), "kerberos"));
   }
 
   @Test
@@ -43,16 +45,27 @@ public class ProxyHelperTest {
     ProxyHelper helper = new ProxyHelper(context);
     MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
     map.putSingle("data", "abcd/efgh");
-    assertEquals("http://abc.com/test/abcd?data=abcd%2Fefgh", helper.getProxyUrl("http://abc.com",
"test/abcd", map));
+    assertEquals("http://abc.com/test/abcd?data=abcd%2Fefgh", helper.getProxyUrl("http://abc.com",
"test/abcd", map, "kerberos"));
     map.putSingle("data", "abcd efgh");
-    assertEquals("http://abc.com/test/abcd?data=abcd+efgh", helper.getProxyUrl("http://abc.com",
"test/abcd", map));
+    assertEquals("http://abc.com/test/abcd?data=abcd+efgh", helper.getProxyUrl("http://abc.com",
"test/abcd", map, "kerberos"));
   }
 
   @Test(expected = TezWebAppException.class)
   public void shouldThrowExceptionIfWrongUrl() throws Exception {
     ViewContext context = createNiceMock(ViewContext.class);
     ProxyHelper helper = new ProxyHelper(context);
-    helper.getProxyUrl("####", "", new MultivaluedHashMap<String, String>());
+    helper.getProxyUrl("####", "", new MultivaluedHashMap<String, String>(), "kerberos");
   }
 
+  @Test
+  public void shouldAddUserIfAuthTypeIsSimple() throws Exception {
+    ViewContext context = createNiceMock(ViewContext.class);
+    expect(context.getUsername()).andReturn("admin").anyTimes();
+    ProxyHelper helper = new ProxyHelper(context);
+    MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
+
+    replay(context);
+    assertEquals("http://abc.com/test/abcd?user.name=admin", helper.getProxyUrl("http://abc.com",
"test/abcd", map, "simple"));
+    assertEquals("http://abc.com/test/abcd?user.name=admin", helper.getProxyUrl("http://abc.com",
"test/abcd", map, null));
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/0e258b80/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/Services.java
----------------------------------------------------------------------
diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/Services.java
b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/Services.java
index 57156e1..1896165 100644
--- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/Services.java
+++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/ambari/Services.java
@@ -55,6 +55,8 @@ public class Services {
   private final static String YARN_TIMELINE_WEBAPP_HTTP_ADDRESS_KEY = "yarn.timeline-service.webapp.address";
   private final static String YARN_TIMELINE_WEBAPP_HTTPS_ADDRESS_KEY = "yarn.timeline-service.webapp.https.address";
   public static final String RM_INFO_API_ENDPOINT = "/ws/v1/cluster/info";
+  public static final String TIMELINE_AUTH_TYPE_PROP_KEY = "timeline.http.auth.type";
+  public static final String HADOOP_HTTP_AUTH_TYPE_KEY = "hadoop.http.auth.type";
 
   private final AmbariApi ambariApi;
   private ViewContext context;
@@ -347,4 +349,18 @@ public class Services {
   private String getDefaultRMPort(String yarnHttpPolicy) {
     return (HTTPS_ONLY.equals(yarnHttpPolicy)) ? YARN_RESOURCEMANAGER_DEFAULT_HTTPS_PORT
: YARN_RESOURCEMANAGER_DEFAULT_HTTP_PORT;
   }
+
+  /**
+   * @return The authentication type for RM. Check: https://hadoop.apache.org/docs/r1.2.1/HttpAuthentication.html
+   */
+  public String getHadoopHttpWebAuthType() {
+    return context.getProperties().get(HADOOP_HTTP_AUTH_TYPE_KEY);
+  }
+
+  /**
+   * @return Authentication used for the timeline server HTTP endpoint. Check: https://hadoop.apache.org/docs/r2.7.1/hadoop-yarn/hadoop-yarn-site/TimelineServer.html
+   */
+  public String getTimelineServerAuthType() {
+    return context.getProperties().get(TIMELINE_AUTH_TYPE_PROP_KEY);
+  }
 }


Mime
View raw message