ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject git commit: AMBARI-5742. View: Files support for optional username view parameter. (jaimin)
Date Mon, 12 May 2014 19:33:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-1.6.0 ba392ad73 -> f17692f86


AMBARI-5742. View: Files support for optional username view parameter. (jaimin)


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

Branch: refs/heads/branch-1.6.0
Commit: f17692f865c31fe925f9e10c4b45cb24d5bb9224
Parents: ba392ad
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Mon May 12 12:32:14 2014 -0700
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Mon May 12 12:33:05 2014 -0700

----------------------------------------------------------------------
 .../apache/ambari/view/filebrowser/HdfsService.java   | 14 +++++++++++++-
 contrib/views/files/src/main/resources/view.xml       |  6 +++++-
 .../ambari/view/filebrowser/FilebrowserTest.java      |  7 +++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f17692f8/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
index 6765de0..9ece468 100644
--- a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
+++ b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
@@ -66,9 +66,21 @@ public abstract class HdfsService {
   public HdfsApi getApi(ViewContext context) throws IOException, Exception {
     if (_api == null) {
       Thread.currentThread().setContextClassLoader(null);
-      _api = new HdfsApi(context.getProperties().get("dataworker.defaultFs"), context.getUsername());
+      _api = new HdfsApi(context.getProperties().get("dataworker.defaultFs"), getUsername(context));
     }
     return _api;
   }
 
+  /**
+   * Get username to use in HDFS
+   * @param context View Context instance
+   * @return user name
+   */
+  public String getUsername(ViewContext context) {
+    String username = context.getProperties().get("dataworker.username");
+    if (username == null || username.isEmpty())
+      username = context.getUsername();
+    return username;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/f17692f8/contrib/views/files/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/view.xml b/contrib/views/files/src/main/resources/view.xml
index 1922fa3..3d9b610 100644
--- a/contrib/views/files/src/main/resources/view.xml
+++ b/contrib/views/files/src/main/resources/view.xml
@@ -24,7 +24,11 @@
         <description>FileSystem URI</description>
         <required>true</required>
     </parameter>
-
+    <parameter>
+        <name>dataworker.username</name>
+        <description>The username (defaults to ViewContext username)</description>
+        <required>false</required>
+    </parameter>
     
     <resource>
         <name>files</name>

http://git-wip-us.apache.org/repos/asf/ambari/blob/f17692f8/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
index ba5f316..6eb10e3 100644
--- a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
+++ b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
@@ -155,6 +155,13 @@ public class FilebrowserTest{
     Response result = fileBrowserService.download().downloadGZip(dr);
   }
 
+  @Test
+  public void testUsername() throws Exception {
+    Assert.assertEquals(System.getProperty("user.name"), fileBrowserService.upload().getUsername(context));
+    properties.put("dataworker.username", "test-user");
+    Assert.assertEquals("test-user", fileBrowserService.upload().getUsername(context));
+  }
+
   private static <T> T getService(Class<T> clazz,
                                   final ViewResourceHandler viewResourceHandler,
                                   final ViewContext viewInstanceContext) {


Mime
View raw message