Browse Source

AMBARI-15829. Files View: Extract the directory viewer UI component so that other views can use it. (dipayanb)

Dipayan Bhowmick 9 năm trước cách đây
mục cha
commit
827fb20697
68 tập tin đã thay đổi với 1841 bổ sung102 xóa
  1. 84 0
      contrib/views/commons/README.md
  2. 140 0
      contrib/views/commons/pom.xml
  3. 1 1
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/MisconfigurationFormattedException.java
  4. 1 1
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/NotFoundFormattedException.java
  5. 1 1
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/ServiceFormattedException.java
  6. 13 18
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/FileOperationService.java
  7. 2 2
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/HdfsService.java
  8. 3 2
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/UploadService.java
  9. 106 0
      contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/UserService.java
  10. 4 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.bowerrc
  11. 34 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.editorconfig
  12. 27 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.ember-cli
  13. 17 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.gitignore
  14. 32 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.jshintrc
  15. 30 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.npmignore
  16. 50 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.travis.yml
  17. 21 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.watchmanconfig
  18. 28 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/LICENSE.md
  19. 97 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/README.md
  20. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/.gitkeep
  21. 196 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/components/directory-viewer.js
  22. 18 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/templates/components/directory-viewer.hbs
  23. 59 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/utils/viewer-config.js
  24. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/.gitkeep
  25. 19 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/components/directory-viewer.js
  26. 19 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/utils/viewer-config.js
  27. 19 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/bower.json
  28. 54 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/config/ember-try.js
  29. 24 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/config/environment.js
  30. 36 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/ember-cli-build.js
  31. 32 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/index.js
  32. 51 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/package.json
  33. 12 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/testem.json
  34. 52 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/.jshintrc
  35. 36 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/app.js
  36. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/components/.gitkeep
  37. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/controllers/.gitkeep
  38. 32 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/controllers/application.js
  39. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/helpers/.gitkeep
  40. 43 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/index.html
  41. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/models/.gitkeep
  42. 29 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/router.js
  43. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/routes/.gitkeep
  44. 23 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/styles/app.css
  45. 36 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/templates/application.hbs
  46. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/templates/components/.gitkeep
  47. 35 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/utils/my-viewer-config.js
  48. 65 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/config/environment.js
  49. 15 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/public/crossdomain.xml
  50. 3 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/public/robots.txt
  51. 23 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/destroy-app.js
  52. 41 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/module-for-acceptance.js
  53. 29 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/resolver.js
  54. 36 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/start-app.js
  55. 52 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/index.html
  56. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/integration/.gitkeep
  57. 24 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/test-helper.js
  58. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/unit/.gitkeep
  59. 0 0
      contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/vendor/.gitkeep
  60. 5 0
      contrib/views/files/pom.xml
  61. 4 4
      contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
  62. 11 2
      contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileBrowserService.java
  63. 4 3
      contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FilePreviewService.java
  64. 1 66
      contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HelpService.java
  65. 2 2
      contrib/views/files/src/main/resources/ui/app/services/file-operation.js
  66. 1 0
      contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
  67. 1 0
      contrib/views/pom.xml
  68. 8 0
      pom.xml

+ 84 - 0
contrib/views/commons/README.md

@@ -0,0 +1,84 @@
+<!---
+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](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.
+-->
+
+#Ambari Views Commons Module
+
+Have this as a dependency in the view which need the functionality.
+
+This has common code for:
+
+* HDFS access
+
+**Note: More to be added later**
+
+### How to Include it in dependant project
+
+In the service class for the project use `commons` projects code in the way described in the below example for `files` view.
+
+```java
+package org.apache.ambari.view.filebrowser;
+
+import javax.ws.rs.Path;
+
+import org.apache.ambari.view.ViewContext;
+
+import com.google.inject.Inject;
+import org.apache.ambari.view.commons.hdfs.FileOperationService;
+import org.apache.ambari.view.commons.hdfs.UploadService;
+import org.apache.ambari.view.commons.hdfs.UserService;
+
+/**
+ * Root files service
+ */
+public class FileBrowserService {
+
+  @Inject
+  ViewContext context;
+
+  /**
+   * @see UploadService
+   * @return service
+   */
+  @Path("/upload")
+  public UploadService upload() {
+    return new UploadService(context);
+  }
+
+  /**
+   * @see org.apache.ambari.view.commons.hdfs.FileOperationService
+   * @return service
+   */
+  @Path("/fileops")
+  public FileOperationService fileOps() {
+    return new FileOperationService(context);
+  }
+
+  /**
+   * @see org.apache.ambari.view.commons.hdfs.UserService
+   * @return service
+   */
+  @Path("/user")
+  public UserService userService() { return new UserService(context); }
+
+}
+```
+
+
+####Also, look into the various ember addons that are included in `src/main/resources/ui`.
+Currently we have:
+
+* hdfs-directory-viewer
+
+**More to be added later**

+ 140 - 0
contrib/views/commons/pom.xml

@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>ambari-views-commons</artifactId>
+  <version>2.0.0.0-SNAPSHOT</version>
+  <name>Ambari View Commons</name>
+
+  <parent>
+    <artifactId>ambari-contrib-views</artifactId>
+    <groupId>org.apache.ambari.contrib.views</groupId>
+    <version>2.0.0.0-SNAPSHOT</version>
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.ambari.contrib.views</groupId>
+      <artifactId>ambari-views-utils</artifactId>
+      <version>2.0.0.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.ambari</groupId>
+      <artifactId>ambari-views</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-hdfs</artifactId>
+      <version>${hadoop.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>tomcat</groupId>
+          <artifactId>jasper-runtime</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-common</artifactId>
+      <version>${hadoop.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>tomcat</groupId>
+          <artifactId>jasper-runtime</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>com.googlecode.json-simple</groupId>
+      <artifactId>json-simple</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>com.sun.jersey.contribs</groupId>
+      <artifactId>jersey-multipart</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.glassfish.jersey.containers</groupId>
+      <artifactId>jersey-container-servlet</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.4</version>
+    </dependency>
+
+    <!-- Testing -->
+    <dependency>
+      <groupId>com.sun.jersey.jersey-test-framework</groupId>
+      <artifactId>jersey-test-framework-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-minicluster</artifactId>
+      <version>${hadoop.version}</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <resources>
+      <resource>
+        <directory>src/main/resources/</directory>
+        <filtering>false</filtering>
+        <excludes>
+          <exclude>ui/**</exclude>
+        </excludes>
+      </resource>
+    </resources>
+  </build>
+
+  <properties>
+    <ambari.dir>${project.parent.parent.parent.basedir}</ambari.dir>
+  </properties>
+</project>

+ 1 - 1
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/utils/MisconfigurationFormattedException.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/MisconfigurationFormattedException.java

@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser.utils;
+package org.apache.ambari.view.commons.exceptions;
 
 import org.json.simple.JSONObject;
 

+ 1 - 1
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/utils/NotFoundFormattedException.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/NotFoundFormattedException.java

@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser.utils;
+package org.apache.ambari.view.commons.exceptions;
 
 public class NotFoundFormattedException extends ServiceFormattedException {
   private final static int STATUS = 404;

+ 1 - 1
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/utils/ServiceFormattedException.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/exceptions/ServiceFormattedException.java

@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser.utils;
+package org.apache.ambari.view.commons.exceptions;
 
 import org.apache.commons.lang.exception.ExceptionUtils;
 import org.json.simple.JSONObject;

+ 13 - 18
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/FileOperationService.java

@@ -16,30 +16,25 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser;
+package org.apache.ambari.view.commons.hdfs;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.commons.exceptions.NotFoundFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
+import org.apache.ambari.view.utils.hdfs.HdfsApi;
+import org.apache.ambari.view.utils.hdfs.HdfsApiException;
+import org.json.simple.JSONObject;
 
 import javax.ws.rs.*;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.*;
 import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.filebrowser.utils.NotFoundFormattedException;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
-import org.apache.ambari.view.utils.hdfs.HdfsApi;
-import org.apache.ambari.view.utils.hdfs.HdfsApiException;
-import org.json.simple.JSONObject;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
 
 /**
  * File operations service

+ 2 - 2
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/HdfsService.java

@@ -16,13 +16,13 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser;
+package org.apache.ambari.view.commons.hdfs;
 
 import javax.ws.rs.WebApplicationException;
 import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsUtil;
 import org.apache.hadoop.security.UserGroupInformation;

+ 3 - 2
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/UploadService.java → contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/UploadService.java

@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.ambari.view.filebrowser;
+package org.apache.ambari.view.commons.hdfs;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -28,7 +28,8 @@ import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
+import org.apache.ambari.view.commons.hdfs.HdfsService;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.hadoop.fs.FSDataOutputStream;
 

+ 106 - 0
contrib/views/commons/src/main/java/org/apache/ambari/view/commons/hdfs/UserService.java

@@ -0,0 +1,106 @@
+/**
+ * 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.ambari.view.commons.hdfs;
+
+import org.apache.ambari.view.ViewContext;
+import org.apache.ambari.view.commons.exceptions.NotFoundFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
+import org.apache.ambari.view.utils.hdfs.HdfsApi;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.FileNotFoundException;
+
+/**
+ * User related info service
+ */
+public class UserService extends HdfsService {
+
+  /**
+   * Constructor
+   * @param context View Context instance
+   */
+  public UserService(ViewContext context) {
+    super(context);
+  }
+
+  /**
+   * Returns home directory
+   * @return home directory
+   */
+  @GET
+  @Path("/home")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response homeDir() {
+    try {
+      HdfsApi api = getApi(context);
+      return Response
+        .ok(getApi(context).fileStatusToJSON(api.getFileStatus(api.getHomeDir()
+          .toString()))).build();
+    } catch (WebApplicationException ex) {
+      throw ex;
+    } catch (Exception ex) {
+      throw new ServiceFormattedException(ex.getMessage(), ex);
+    }
+  }
+
+  /**
+   * Is trash enabled
+   * @return is trash enabled
+   */
+  @GET
+  @Path("/trash/enabled")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response trashEnabled() {
+    try {
+      HdfsApi api = getApi(context);
+      return Response.ok(new FileOperationResult(api.trashEnabled())).build();
+    } catch (WebApplicationException ex) {
+      throw ex;
+    } catch (Exception ex) {
+      throw new ServiceFormattedException(ex.getMessage(), ex);
+    }
+  }
+
+  /**
+   * Trash dir
+   * @return trash dir
+   */
+  @GET
+  @Path("/trashDir")
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response trashdir() {
+    try {
+      HdfsApi api = getApi(context);
+      return Response.ok(
+        getApi(context).fileStatusToJSON(api.getFileStatus(api.getTrashDir()
+          .toString()))).build();
+    } catch (WebApplicationException ex) {
+      throw ex;
+    } catch (FileNotFoundException ex) {
+      throw new NotFoundFormattedException(ex.getMessage(), ex);
+    } catch (Exception ex) {
+      throw new ServiceFormattedException(ex.getMessage(), ex);
+    }
+  }
+}

+ 4 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.bowerrc

@@ -0,0 +1,4 @@
+{
+  "directory": "bower_components",
+  "analytics": false
+}

+ 34 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.editorconfig

@@ -0,0 +1,34 @@
+# EditorConfig helps developers define and maintain consistent
+# coding styles between different editors and IDEs
+# editorconfig.org
+
+root = true
+
+
+[*]
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+
+[*.js]
+indent_style = space
+indent_size = 2
+
+[*.hbs]
+insert_final_newline = false
+indent_style = space
+indent_size = 2
+
+[*.css]
+indent_style = space
+indent_size = 2
+
+[*.html]
+indent_style = space
+indent_size = 2
+
+[*.{diff,md}]
+trim_trailing_whitespace = false

+ 27 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.ember-cli

@@ -0,0 +1,27 @@
+/**
+ * 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.
+ */
+
+{
+  /**
+    Ember CLI sends analytics information by default. The data is completely
+    anonymous, but there are times when you might want to disable this behavior.
+
+    Setting `disableAnalytics` to true will prevent any data from being sent.
+  */
+  "disableAnalytics": false
+}

+ 17 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.gitignore

@@ -0,0 +1,17 @@
+# See http://help.github.com/ignore-files/ for more about ignoring files.
+
+# compiled output
+/dist
+/tmp
+
+# dependencies
+/node_modules
+/bower_components
+
+# misc
+/.sass-cache
+/connect.lock
+/coverage/*
+/libpeerconnection.log
+npm-debug.log
+testem.log

+ 32 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.jshintrc

@@ -0,0 +1,32 @@
+{
+  "predef": [
+    "document",
+    "window",
+    "-Promise"
+  ],
+  "browser": true,
+  "boss": true,
+  "curly": true,
+  "debug": false,
+  "devel": true,
+  "eqeqeq": true,
+  "evil": true,
+  "forin": false,
+  "immed": false,
+  "laxbreak": false,
+  "newcap": true,
+  "noarg": true,
+  "noempty": false,
+  "nonew": false,
+  "nomen": false,
+  "onevar": false,
+  "plusplus": false,
+  "regexp": false,
+  "undef": true,
+  "sub": true,
+  "strict": false,
+  "white": false,
+  "eqnull": true,
+  "esnext": true,
+  "unused": true
+}

+ 30 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.npmignore

@@ -0,0 +1,30 @@
+# 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.
+
+bower_components/
+tests/
+tmp/
+dist/
+
+.bowerrc
+.editorconfig
+.ember-cli
+.travis.yml
+.npmignore
+**/.gitkeep
+bower.json
+Brocfile.js
+testem.json

+ 50 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.travis.yml

@@ -0,0 +1,50 @@
+# 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.
+
+---
+language: node_js
+node_js:
+  - "0.12"
+
+sudo: false
+
+cache:
+  directories:
+    - node_modules
+
+env:
+  - EMBER_TRY_SCENARIO=default
+  - EMBER_TRY_SCENARIO=ember-release
+  - EMBER_TRY_SCENARIO=ember-beta
+  - EMBER_TRY_SCENARIO=ember-canary
+
+matrix:
+  fast_finish: true
+  allow_failures:
+    - env: EMBER_TRY_SCENARIO=ember-canary
+
+before_install:
+  - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
+  - "npm config set spin false"
+  - "npm install -g npm@^2"
+
+install:
+  - npm install -g bower
+  - npm install
+  - bower install
+
+script:
+  - ember try $EMBER_TRY_SCENARIO test

+ 21 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/.watchmanconfig

@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+
+{
+  "ignore_dirs": ["tmp", "dist"]
+}

+ 28 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/LICENSE.md

@@ -0,0 +1,28 @@
+<!---
+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](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.
+-->
+
+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](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.
+

+ 97 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/README.md

@@ -0,0 +1,97 @@
+<!---
+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](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.
+-->
+
+# Hdfs-directory-viewer
+
+Ember Addon to view the HDFS file system.
+
+Different Ambari views can use this in their view. Common code should be usable in every view.
+
+# How to use it
+
+### Including it in dependant project
+Add the following code in package.json of the dependant view
+
+```javascript
+"name": "files",
+"ember-addon": {
+	"paths": [
+	  "../../../../../commons/src/main/resources/ui/hdfs-directory-viewer"
+	]
+}
+```
+
+`paths` is an array which includes all the addons shares in ```commons``` library. The entries should be the relative path to the addon in this ```commons``` repository.
+
+### Including the UI dependencies in the dependent project
+As we are going to include the component using the `ember-addon` config in `package.json` and not by the `ember install` way, the UI dependencies also has to be included in the dependent projects `bower.json` file if not already added.
+
+```
+"bootstrap": "~3.3.6",
+"bootstrap-treeview": "~1.2.0",
+"font-awesome": "~4.5.0"
+```
+
+### Overriding configs in dependant project
+
+Create a util object in `utils` directory using `ember generate util <object name>` and override it as follows:
+
+```javascript
+import ViewerConfig from 'hdfs-directory-viewer/utils/viewer-config';
+
+export default ViewerConfig.extend({
+  showOnlyDirectories: true,
+
+  expandIcon: 'fa fa-chevron-right',
+  collapseIcon: 'fa fa-chevron-down',
+
+  listDirectoryUrl(pathParams) {
+    return `/api/v1/views/FILES/versions/1.0.0/instances/files/resources/files/fileops/listdir?${pathParams}`;
+  }
+});
+```
+
+All the functions and attributes in `hdfs-directory-viewer/utils/viewer-config` can be overriden
+
+### Passing the object to the view template
+
+```javascript
+import Ember from 'ember';
+import MyViewerConfig from '../utils/my-viewer-config';
+
+export default Ember.Controller.extend({
+  config: MyViewerConfig.create(),
+  actions: {
+    viewerError: function() {
+      console.log("Failed to fetch the content!!!");
+    },
+    viewerSelectedPath: function(data) {
+      console.log(`User selected: path: ${data.path}, isDirectory: ${data.isDirectory}`);
+    }
+  }
+});
+```
+
+```html
+...
+<div class="directory-viewer-wrap">
+  {{directory-viewer
+    config=config
+    errorAction="viewerError"
+    pathSelectAction="viewerSelectedPath"
+  }}
+</div>
+...
+```

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/.gitkeep


+ 196 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/components/directory-viewer.js

@@ -0,0 +1,196 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import layout from '../templates/components/directory-viewer';
+
+export default Ember.Component.extend({
+  layout,
+  config: Ember.Object.create({}),
+  classNames: ['directory-viewer'],
+  startPath: '/',
+  treeData: Ember.A(),
+  currentPath: Ember.computed.oneWay('startPath'),
+  currentQueryParam: Ember.computed('currentPath', function() {
+    return Ember.$.param({path: this.get('currentPath')});
+  }),
+
+  startFetch: Ember.on('didInitAttrs', function() {
+    this.fetchData();
+  }),
+
+
+  fetchData: function() {
+    this.listPath(this.get('currentQueryParam')).then(
+      (response) => {
+        let list = this.filterDirectoriesIfRequired(response.files);
+        this.modifyTreeViewData(list);
+      }, (error) => {
+        this.sendAction('errorAction', error);
+      }
+    );
+  },
+
+  /**
+   * Makes a XHR call and returns a promise.
+   */
+  listPath: function(params) {
+    let config = this.get('config');
+    let listUrl = config.listDirectoryUrl(params);
+    let headers = config.getHeaders();
+    return Ember.$.ajax(listUrl, {
+      headers: headers
+    });
+  },
+
+  filterDirectoriesIfRequired: function(files) {
+    let showOnlyDirectories = this.get('config.showOnlyDirectories');
+    return files.filter((entry) => {
+      return (!(showOnlyDirectories) || entry.isDirectory);
+    });
+  },
+
+  modifyTreeViewData: function(response) {
+    let paths = response.map((entry) => {
+      let isDirectory = entry.isDirectory;
+      let icon = isDirectory ? this.get('config.folderIcon') : this.get('config.fileIcon');
+      let data = {
+        path: entry.path,
+        pathSegment: this.getNameForPath(entry.path),
+        isDirectory: isDirectory,
+        icon: icon,
+        text: this.getNameForPath(entry.path)
+      };
+      if(isDirectory) {
+        data.nodes = Ember.A();
+      }
+      return data;
+    });
+
+    var currentPath = this.get('currentPath');
+    var newTreeData = Ember.copy(this.get('treeData'), true);
+    if(currentPath === '/') {
+      newTreeData = paths;
+    } else {
+      this.insertPathToTreeData(newTreeData, paths, currentPath.substring(1));
+    }
+
+    this.set('treeData', newTreeData);
+    this.send('refreshTreeView');
+  },
+
+  insertPathToTreeData(treeData, paths, pathSegment) {
+    let firstPathSegment;
+    if (pathSegment.indexOf('/') !== -1) {
+      firstPathSegment = pathSegment.substring(0, pathSegment.indexOf('/'));
+    } else {
+      firstPathSegment = pathSegment;
+    }
+
+    if(treeData.length === 0) {
+      treeData.pushObjects(paths);
+    } else {
+      treeData.forEach((entry) => {
+        entry.state = {};
+        if (entry.pathSegment === firstPathSegment) {
+          entry.state.expanded = true;
+          if(entry.nodes.length === 0) {
+            paths.forEach((pathEntry) => {
+              entry.nodes.push(pathEntry);
+            });
+          } else {
+            this.insertPathToTreeData(entry.nodes, paths, pathSegment.substring(pathSegment.indexOf('/') + 1));
+          }
+        } else {
+          this.collapseAll(entry);
+        }
+      });
+    }
+  },
+
+  collapseAll: function(node) {
+    if (Ember.isNone(node.state)) {
+      node.state = {};
+    }
+    node.state.expanded = false;
+    if(!Ember.isNone(node.nodes)) {
+      node.nodes.forEach((entry) => {
+        this.collapseAll(entry);
+      });
+    }
+  },
+
+  getNameForPath: function(path) {
+    return path.substring(path.lastIndexOf("/") + 1);
+  },
+
+  collapseAllExceptPath: function(pathSegment) {
+    let collapseAll = function(nodes, pathSegment) {
+      var firstPathSegment;
+      if (pathSegment.indexOf('/') !== -1) {
+        firstPathSegment = pathSegment.substring(0, pathSegment.indexOf('/'));
+      } else {
+        firstPathSegment = pathSegment;
+      }
+
+      nodes.forEach((entry) => {
+        if (Ember.isNone(entry.state)) {
+          entry.state = {};
+        }
+        if(firstPathSegment !== entry.pathSegment) {
+          entry.state.expanded = false;
+        } else {
+          entry.state.expanded = true;
+          collapseAll(entry.nodes, pathSegment.substring(pathSegment.indexOf('/') + 1));
+        }
+      });
+    };
+    var newTreeData = this.get('treeData');
+    collapseAll(newTreeData, pathSegment);
+    this.set('treeData', newTreeData);
+    this.send('refreshTreeView');
+  },
+
+  actions: {
+    refreshTreeView() {
+      Ember.run.later(() => {
+        this.$().treeview({
+          data: this.get('treeData'),
+          expandIcon: this.get('config.expandIcon'),
+          collapseIcon: this.get('config.collapseIcon'),
+          //emptyIcon: "fa",
+          showBorder: false,
+          onNodeSelected: (event, data) => {
+            this.set('currentPath', data.path);
+            this.sendAction('pathSelectAction', {path: data.path, isDirectory: data.isDirectory});
+          },
+          onNodeExpanded: (event, data) => {
+            this.set('currentPath', data.path);
+            if (!Ember.isNone(data.nodes) && data.nodes.length === 0) {
+              var node = this.$().treeview('getNode', data.nodeId);
+              node.icon = "fa fa-refresh fa-spin";
+              this.fetchData();
+            } else {
+              this.collapseAllExceptPath(data.path.substring(1));
+            }
+          }
+        });
+      });
+    }
+  }
+});

+ 18 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/templates/components/directory-viewer.hbs

@@ -0,0 +1,18 @@
+{{!
+* 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.
+}}
+

+ 59 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/addon/utils/viewer-config.js

@@ -0,0 +1,59 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+
+export default Ember.Object.extend({
+
+  /**
+   * Set this to true, if only directory listing is required.
+   */
+  showOnlyDirectories: false,
+
+  /**
+   * Set this to true, if refresh of current path is required.
+   */
+  showRefreshButton: false,
+
+  /**
+   * Override these for different Icon. Refer https://github.com/jonmiles/bootstrap-treeview
+   */
+  expandIcon: "fa fa-plus",
+  collapseIcon: "fa fa-minus",
+  //Custom
+  fileIcon: "fa fa-file",
+  folderIcon: "fa fa-folder",
+
+  /**
+   * Override to return the headers add to the XHR call made for various operations.
+   * The Overriding object can also merge its result with the default in this object.
+   */
+  getHeaders() {
+    return {"X-Requested-By": "ambari"};
+  },
+
+  /**
+   * Return the URL endpoint for XHR call meant for listing Directories
+   * @param pathParams
+   * @returns {string}
+   */
+  listDirectoryUrl(pathParams) {
+    return `/listdir?${pathParams}`;
+  }
+
+});

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/.gitkeep


+ 19 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/components/directory-viewer.js

@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+export { default } from 'hdfs-directory-viewer/components/directory-viewer';

+ 19 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/app/utils/viewer-config.js

@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+export { default } from 'hdfs-directory-viewer/utils/viewer-config';

+ 19 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/bower.json

@@ -0,0 +1,19 @@
+{
+  "name": "hdfs-directory-viewer",
+  "dependencies": {
+    "ember": "2.2.0",
+    "ember-cli-shims": "0.1.0",
+    "ember-cli-test-loader": "0.2.2",
+    "ember-load-initializers": "0.1.7",
+    "ember-qunit-notifications": "0.1.0",
+    "jquery": "1.11.3",
+    "loader.js": "^3.5.0",
+    "qunit": "~1.20.0",
+    "bootstrap": "~3.3.6",
+    "bootstrap-treeview": "~1.2.0",
+    "font-awesome": "~4.5.0"
+  },
+  "resolutions": {
+    "ember": "2.2.0"
+  }
+}

+ 54 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/config/ember-try.js

@@ -0,0 +1,54 @@
+/**
+ * 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.
+ */
+
+/*jshint node:true*/
+module.exports = {
+  scenarios: [
+    {
+      name: 'default',
+      dependencies: { }
+    },
+    {
+      name: 'ember-release',
+      dependencies: {
+        'ember': 'components/ember#release'
+      },
+      resolutions: {
+        'ember': 'release'
+      }
+    },
+    {
+      name: 'ember-beta',
+      dependencies: {
+        'ember': 'components/ember#beta'
+      },
+      resolutions: {
+        'ember': 'beta'
+      }
+    },
+    {
+      name: 'ember-canary',
+      dependencies: {
+        'ember': 'components/ember#canary'
+      },
+      resolutions: {
+        'ember': 'canary'
+      }
+    }
+  ]
+};

+ 24 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/config/environment.js

@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+
+/*jshint node:true*/
+'use strict';
+
+module.exports = function(/* environment, appConfig */) {
+  return { };
+};

+ 36 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/ember-cli-build.js

@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+/*jshint node:true*/
+/* global require, module */
+var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
+
+module.exports = function(defaults) {
+  var app = new EmberAddon(defaults, {
+    // Add options here
+  });
+
+  /*
+    This build file specifies the options for the dummy test app of this
+    addon, located in `/tests/dummy`
+    This build file does *not* influence how the addon or the app using it
+    behave. You most likely want to be modifying `./index.js` or app's build file
+  */
+
+  return app.toTree();
+};

+ 32 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/index.js

@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+
+/* jshint node: true */
+'use strict';
+
+module.exports = {
+  name: 'hdfs-directory-viewer',
+  included: function(app) {
+    this._super.included(app);
+
+    app.import(app.bowerDirectory + '/bootstrap/dist/css/bootstrap.css');
+    app.import(app.bowerDirectory + '/bootstrap/dist/js/bootstrap.js');
+    app.import(app.bowerDirectory + '/bootstrap-treeview/src/js/bootstrap-treeview.js');
+    app.import(app.bowerDirectory + '/bootstrap-treeview/dist/bootstrap-treeview.min.css');
+  }
+};

+ 51 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/package.json

@@ -0,0 +1,51 @@
+{
+  "name": "hdfs-directory-viewer",
+  "version": "0.1.0",
+  "description": "The hdfs directory viewer addon to be used by ambari views",
+  "directories": {
+    "doc": "doc",
+    "test": "tests"
+  },
+  "scripts": {
+    "build": "ember build",
+    "start": "ember server",
+    "test": "ember try:testall"
+  },
+  "repository": "",
+  "engines": {
+    "node": ">= 0.10.0"
+  },
+  "author": "",
+  "license": "MIT",
+  "devDependencies": {
+    "broccoli-asset-rev": "^2.2.0",
+    "ember-ajax": "0.7.1",
+    "ember-cli": "2.2.0-beta.4",
+    "ember-cli-app-version": "^1.0.0",
+    "ember-cli-dependency-checker": "^1.2.0",
+    "ember-cli-font-awesome": "1.5.0",
+    "ember-cli-htmlbars": "^1.0.1",
+    "ember-cli-htmlbars-inline-precompile": "^0.3.1",
+    "ember-cli-inject-live-reload": "^1.3.1",
+    "ember-cli-qunit": "^1.1.0",
+    "ember-cli-release": "0.2.8",
+    "ember-cli-sri": "^2.0.0",
+    "ember-cli-uglify": "^1.2.0",
+    "ember-data": "^2.2.1",
+    "ember-disable-prototype-extensions": "^1.0.0",
+    "ember-disable-proxy-controllers": "^1.0.1",
+    "ember-export-application-global": "^1.0.4",
+    "ember-resolver": "^2.0.3",
+    "ember-try": "~0.0.8"
+  },
+  "keywords": [
+    "ember-addon"
+  ],
+  "dependencies": {
+    "ember-cli-babel": "^5.1.5",
+    "ember-cli-htmlbars": "^1.0.1"
+  },
+  "ember-addon": {
+    "configPath": "tests/dummy/config"
+  }
+}

+ 12 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/testem.json

@@ -0,0 +1,12 @@
+{
+  "framework": "qunit",
+  "test_page": "tests/index.html?hidepassed",
+  "disable_watching": true,
+  "launch_in_ci": [
+    "PhantomJS"
+  ],
+  "launch_in_dev": [
+    "PhantomJS",
+    "Chrome"
+  ]
+}

+ 52 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/.jshintrc

@@ -0,0 +1,52 @@
+{
+  "predef": [
+    "document",
+    "window",
+    "location",
+    "setTimeout",
+    "$",
+    "-Promise",
+    "define",
+    "console",
+    "visit",
+    "exists",
+    "fillIn",
+    "click",
+    "keyEvent",
+    "triggerEvent",
+    "find",
+    "findWithAssert",
+    "wait",
+    "DS",
+    "andThen",
+    "currentURL",
+    "currentPath",
+    "currentRouteName"
+  ],
+  "node": false,
+  "browser": false,
+  "boss": true,
+  "curly": true,
+  "debug": false,
+  "devel": false,
+  "eqeqeq": true,
+  "evil": true,
+  "forin": false,
+  "immed": false,
+  "laxbreak": false,
+  "newcap": true,
+  "noarg": true,
+  "noempty": false,
+  "nonew": false,
+  "nomen": false,
+  "onevar": false,
+  "plusplus": false,
+  "regexp": false,
+  "undef": true,
+  "sub": true,
+  "strict": false,
+  "white": false,
+  "eqnull": true,
+  "esnext": true,
+  "unused": true
+}

+ 36 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/app.js

@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import Resolver from 'ember-resolver';
+import loadInitializers from 'ember/load-initializers';
+import config from './config/environment';
+
+let App;
+
+Ember.MODEL_FACTORY_INJECTIONS = true;
+
+App = Ember.Application.extend({
+  modulePrefix: config.modulePrefix,
+  podModulePrefix: config.podModulePrefix,
+  Resolver
+});
+
+loadInitializers(App, config.modulePrefix);
+
+export default App;

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/components/.gitkeep


+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/controllers/.gitkeep


+ 32 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/controllers/application.js

@@ -0,0 +1,32 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import MyViewerConfig from '../utils/my-viewer-config';
+
+export default Ember.Controller.extend({
+  config: MyViewerConfig.create(),
+  actions: {
+    viewerError: function() {
+      console.log("Failed to fetch the content!!!");
+    },
+    viewerSelectedPath: function(data) {
+      console.log(`User selected: path: ${data.path}, isDirectory: ${data.isDirectory}`);
+    }
+  }
+});

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/helpers/.gitkeep


+ 43 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/index.html

@@ -0,0 +1,43 @@
+<!--
+ * 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.
+-->
+
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <title>Dummy</title>
+    <meta name="description" content="">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    {{content-for "head"}}
+
+    <link rel="stylesheet" href="assets/vendor.css">
+    <link rel="stylesheet" href="assets/dummy.css">
+
+    {{content-for "head-footer"}}
+  </head>
+  <body>
+    {{content-for "body"}}
+
+    <script src="assets/vendor.js"></script>
+    <script src="assets/dummy.js"></script>
+
+    {{content-for "body-footer"}}
+  </body>
+</html>

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/models/.gitkeep


+ 29 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/router.js

@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import config from './config/environment';
+
+const Router = Ember.Router.extend({
+  location: config.locationType
+});
+
+Router.map(function() {
+});
+
+export default Router;

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/routes/.gitkeep


+ 23 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/styles/app.css

@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+.directory-viewer-wrap {
+  width: 600px;
+  height: 500px;
+  border: 1px solid darkgray;
+}

+ 36 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/templates/application.hbs

@@ -0,0 +1,36 @@
+{{!
+* 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.
+}}
+
+<h2 id="title">Ambari HDFS Directory Viewer example</h2>
+<p>
+  This will require Ambari installation with a file view instance created.<br/>
+  <strong>Instance name: files
+  <br/>Files view version used is: 1.0.0</strong>
+</p>
+
+
+<div class="directory-viewer-wrap">
+  {{directory-viewer
+    config=config
+    errorAction="viewerError"
+    pathSelectAction="viewerSelectedPath"
+  }}
+</div>
+
+
+{{outlet}}

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/templates/components/.gitkeep


+ 35 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/app/utils/my-viewer-config.js

@@ -0,0 +1,35 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import ViewerConfig from 'hdfs-directory-viewer/utils/viewer-config';
+
+export default ViewerConfig.extend({
+  showOnlyDirectories: true,
+
+  expandIcon: 'fa fa-chevron-right',
+  collapseIcon: 'fa fa-chevron-down',
+
+  getHeaders() {
+    return Ember.merge({"Authorization": "Basic YWRtaW46YWRtaW4="}, this._super());
+  },
+
+  listDirectoryUrl(pathParams) {
+    return `/api/v1/views/FILES/versions/1.0.0/instances/files/resources/files/fileops/listdir?${pathParams}`;
+  }
+});

+ 65 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/config/environment.js

@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+
+/* jshint node: true */
+
+module.exports = function(environment) {
+  var ENV = {
+    modulePrefix: 'dummy',
+    environment: environment,
+    baseURL: '/',
+    locationType: 'auto',
+    EmberENV: {
+      FEATURES: {
+        // Here you can enable experimental features on an ember canary build
+        // e.g. 'with-controller': true
+      }
+    },
+
+    APP: {
+      // Here you can pass flags/options to your application instance
+      // when it is created
+    }
+  };
+
+  if (environment === 'development') {
+    // ENV.APP.LOG_RESOLVER = true;
+    // ENV.APP.LOG_ACTIVE_GENERATION = true;
+    // ENV.APP.LOG_TRANSITIONS = true;
+    // ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
+    // ENV.APP.LOG_VIEW_LOOKUPS = true;
+  }
+
+  if (environment === 'test') {
+    // Testem prefers this...
+    ENV.baseURL = '/';
+    ENV.locationType = 'none';
+
+    // keep test console output quieter
+    ENV.APP.LOG_ACTIVE_GENERATION = false;
+    ENV.APP.LOG_VIEW_LOOKUPS = false;
+
+    ENV.APP.rootElement = '#ember-testing';
+  }
+
+  if (environment === 'production') {
+
+  }
+
+  return ENV;
+};

+ 15 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/public/crossdomain.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
+<cross-domain-policy>
+  <!-- Read this: www.adobe.com/devnet/articles/crossdomain_policy_file_spec.html -->
+
+  <!-- Most restrictive policy: -->
+  <site-control permitted-cross-domain-policies="none"/>
+
+  <!-- Least restrictive policy: -->
+  <!--
+  <site-control permitted-cross-domain-policies="all"/>
+  <allow-access-from domain="*" to-ports="*" secure="false"/>
+  <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
+  -->
+</cross-domain-policy>

+ 3 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/dummy/public/robots.txt

@@ -0,0 +1,3 @@
+# http://www.robotstxt.org
+User-agent: *
+Disallow:

+ 23 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/destroy-app.js

@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+
+export default function destroyApp(application) {
+  Ember.run(application, 'destroy');
+}

+ 41 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/module-for-acceptance.js

@@ -0,0 +1,41 @@
+/**
+ * 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.
+ */
+
+import { module } from 'qunit';
+import startApp from '../helpers/start-app';
+import destroyApp from '../helpers/destroy-app';
+
+export default function(name, options = {}) {
+  module(name, {
+    beforeEach() {
+      this.application = startApp();
+
+      if (options.beforeEach) {
+        options.beforeEach.apply(this, arguments);
+      }
+    },
+
+    afterEach() {
+      destroyApp(this.application);
+
+      if (options.afterEach) {
+        options.afterEach.apply(this, arguments);
+      }
+    }
+  });
+}

+ 29 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/resolver.js

@@ -0,0 +1,29 @@
+/**
+ * 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.
+ */
+
+import Resolver from 'ember-resolver';
+import config from '../../config/environment';
+
+const resolver = Resolver.create();
+
+resolver.namespace = {
+  modulePrefix: config.modulePrefix,
+  podModulePrefix: config.podModulePrefix
+};
+
+export default resolver;

+ 36 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/helpers/start-app.js

@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+import Ember from 'ember';
+import Application from '../../app';
+import config from '../../config/environment';
+
+export default function startApp(attrs) {
+  let application;
+
+  let attributes = Ember.merge({}, config.APP);
+  attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
+
+  Ember.run(() => {
+    application = Application.create(attributes);
+    application.setupForTesting();
+    application.injectTestHelpers();
+  });
+
+  return application;
+}

+ 52 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/index.html

@@ -0,0 +1,52 @@
+<!--
+ * 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.
+-->
+
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <title>Dummy Tests</title>
+    <meta name="description" content="">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    {{content-for "head"}}
+    {{content-for "test-head"}}
+
+    <link rel="stylesheet" href="assets/vendor.css">
+    <link rel="stylesheet" href="assets/dummy.css">
+    <link rel="stylesheet" href="assets/test-support.css">
+
+    {{content-for "head-footer"}}
+    {{content-for "test-head-footer"}}
+  </head>
+  <body>
+    {{content-for "body"}}
+    {{content-for "test-body"}}
+
+    <script src="testem.js" integrity=""></script>
+    <script src="assets/vendor.js"></script>
+    <script src="assets/test-support.js"></script>
+    <script src="assets/dummy.js"></script>
+    <script src="assets/tests.js"></script>
+    <script src="assets/test-loader.js"></script>
+
+    {{content-for "body-footer"}}
+    {{content-for "test-body-footer"}}
+  </body>
+</html>

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/integration/.gitkeep


+ 24 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/test-helper.js

@@ -0,0 +1,24 @@
+/**
+ * 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.
+ */
+
+import resolver from './helpers/resolver';
+import {
+  setResolver
+} from 'ember-qunit';
+
+setResolver(resolver);

+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/tests/unit/.gitkeep


+ 0 - 0
contrib/views/commons/src/main/resources/ui/hdfs-directory-viewer/vendor/.gitkeep


+ 5 - 0
contrib/views/files/pom.xml

@@ -96,6 +96,11 @@
       <artifactId>ambari-views-utils</artifactId>
       <version>2.0.0.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.ambari.contrib.views</groupId>
+      <artifactId>ambari-views-commons</artifactId>
+      <version>2.0.0.0-SNAPSHOT</version>
+    </dependency>
     <dependency>
       <groupId>com.google.code.gson</groupId>
       <artifactId>gson</artifactId>

+ 4 - 4
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java

@@ -47,14 +47,14 @@ import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.annotation.XmlElement;
 
 import com.google.gson.Gson;
-import org.apache.ambari.view.filebrowser.utils.MisconfigurationFormattedException;
-import org.apache.ambari.view.filebrowser.utils.NotFoundFormattedException;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
+import org.apache.ambari.view.commons.exceptions.MisconfigurationFormattedException;
+import org.apache.ambari.view.commons.exceptions.NotFoundFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
+import org.apache.ambari.view.commons.hdfs.HdfsService;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.ambari.view.utils.hdfs.HdfsApiException;
 import org.apache.ambari.view.utils.hdfs.HdfsUtil;
 import org.apache.hadoop.fs.FSDataInputStream;
-import org.apache.hadoop.fs.FSDataOutputStream;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.ambari.view.ViewContext;
 import org.apache.hadoop.security.AccessControlException;

+ 11 - 2
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileBrowserService.java

@@ -23,6 +23,9 @@ import javax.ws.rs.Path;
 import org.apache.ambari.view.ViewContext;
 
 import com.google.inject.Inject;
+import org.apache.ambari.view.commons.hdfs.FileOperationService;
+import org.apache.ambari.view.commons.hdfs.UploadService;
+import org.apache.ambari.view.commons.hdfs.UserService;
 
 /**
  * Root files service
@@ -42,7 +45,7 @@ public class FileBrowserService {
   }
 
   /**
-   * @see org.apache.ambari.view.filebrowser.UploadService
+   * @see UploadService
    * @return service
    */
   @Path("/upload")
@@ -51,7 +54,7 @@ public class FileBrowserService {
   }
 
   /**
-   * @see org.apache.ambari.view.filebrowser.FileOperationService
+   * @see org.apache.ambari.view.commons.hdfs.FileOperationService
    * @return service
    */
   @Path("/fileops")
@@ -68,6 +71,12 @@ public class FileBrowserService {
     return new HelpService(context);
   }
 
+  /**
+   * @see org.apache.ambari.view.commons.hdfs.UserService
+   * @return service
+   */
+  @Path("/user")
+  public UserService userService() { return new UserService(context); }
 
   /**
    * @see org.apache.ambari.view.filebrowser.FilePreviewService

+ 4 - 3
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FilePreviewService.java

@@ -19,8 +19,9 @@
 package org.apache.ambari.view.filebrowser;
 
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.filebrowser.utils.NotFoundFormattedException;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
+import org.apache.ambari.view.commons.exceptions.NotFoundFormattedException;
+import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
+import org.apache.ambari.view.commons.hdfs.HdfsService;
 import org.apache.ambari.view.utils.hdfs.HdfsApi;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
@@ -37,7 +38,7 @@ import java.io.InputStream;
 /**
  * File Preview Service
  */
-public class FilePreviewService extends HdfsService{
+public class FilePreviewService extends HdfsService {
 
   private CompressionCodecFactory compressionCodecFactory;
 

+ 1 - 66
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HelpService.java

@@ -18,19 +18,14 @@
 
 package org.apache.ambari.view.filebrowser;
 
-import java.io.FileNotFoundException;
-
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
 import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.filebrowser.utils.NotFoundFormattedException;
-import org.apache.ambari.view.filebrowser.utils.ServiceFormattedException;
-import org.apache.ambari.view.utils.hdfs.HdfsApi;
+import org.apache.ambari.view.commons.hdfs.HdfsService;
 import org.json.simple.JSONObject;
 
 /**
@@ -100,64 +95,4 @@ public class HelpService extends HdfsService {
     return Response.ok().entity(response).type(MediaType.APPLICATION_JSON).build();
   }
 
-  /**
-   * Returns home directory
-   * @return home directory
-   */
-  @GET
-  @Path("/home")
-  @Produces(MediaType.APPLICATION_JSON)
-  public Response homeDir() {
-    try {
-      HdfsApi api = getApi(context);
-      return Response
-          .ok(getApi(context).fileStatusToJSON(api.getFileStatus(api.getHomeDir()
-              .toString()))).build();
-    } catch (WebApplicationException ex) {
-      throw ex;
-    } catch (Exception ex) {
-      throw new ServiceFormattedException(ex.getMessage(), ex);
-    }
-  }
-
-  /**
-   * Is trash enabled
-   * @return is trash enabled
-   */
-  @GET
-  @Path("/trash/enabled")
-  @Produces(MediaType.APPLICATION_JSON)
-  public Response trashEnabled() {
-    try {
-      HdfsApi api = getApi(context);
-      return Response.ok(new FileOperationResult(api.trashEnabled())).build();
-    } catch (WebApplicationException ex) {
-      throw ex;
-    } catch (Exception ex) {
-      throw new ServiceFormattedException(ex.getMessage(), ex);
-    }
-  }
-
-  /**
-   * Trash dir
-   * @return trash dir
-   */
-  @GET
-  @Path("/trashDir")
-  @Produces(MediaType.APPLICATION_JSON)
-  public Response trashdir() {
-    try {
-      HdfsApi api = getApi(context);
-      return Response.ok(
-          getApi(context).fileStatusToJSON(api.getFileStatus(api.getTrashDir()
-              .toString()))).build();
-    } catch (WebApplicationException ex) {
-      throw ex;
-    } catch (FileNotFoundException ex) {
-      throw new NotFoundFormattedException(ex.getMessage(), ex);
-    } catch (Exception ex) {
-      throw new ServiceFormattedException(ex.getMessage(), ex);
-    }
-  }
-
 }

+ 2 - 2
contrib/views/files/src/main/resources/ui/app/services/file-operation.js

@@ -170,12 +170,12 @@ export default Ember.Service.extend(FileOperationMixin, {
 
   getHome: function () {
     var adapter = this.get('store').adapterFor('file');
-    return adapter.ajax(this._getMiscUrl("/help/home"), "GET");
+    return adapter.ajax(this._getMiscUrl("/user/home"), "GET");
   },
 
   getTrash: function () {
     var adapter = this.get('store').adapterFor('file');
-    return adapter.ajax(this._getMiscUrl("/help/trashDir"), "GET");
+    return adapter.ajax(this._getMiscUrl("/user/trashDir"), "GET");
   },
 
   _getMiscUrl: function (segment) {

+ 1 - 0
contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java

@@ -38,6 +38,7 @@ import javax.ws.rs.core.UriInfo;
 
 import org.apache.ambari.view.ViewContext;
 import org.apache.ambari.view.ViewResourceHandler;
+import org.apache.ambari.view.commons.hdfs.FileOperationService;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileUtil;
 import org.apache.hadoop.hdfs.MiniDFSCluster;

+ 1 - 0
contrib/views/pom.xml

@@ -43,6 +43,7 @@
     <module>tez</module>
     <module>storm</module>
     <module>zeppelin</module>
+    <module>commons</module>
   </modules>
   <build>
     <pluginManagement>

+ 8 - 0
pom.xml

@@ -305,6 +305,14 @@
             <exclude>contrib/ambari-scom/*/rat.txt</exclude>
             <exclude>contrib/ambari-scom/metrics-sink/target/**</exclude>
             <exclude>contrib/views/*/target/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/.bowerrc</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/bower_components/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/node/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/node_modules/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/public/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/vendor/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/tests/**/public/**</exclude>
+            <exclude>contrib/views/commons/src/main/resources/ui/*/tests/**/vendor/**</exclude>
             <exclude>contrib/views/hive/src/main/resources/ui/hive-web/vendor/codemirror/**</exclude>
             <exclude>contrib/views/hive/src/main/resources/ui/hive-web/.bowerrc</exclude>
             <exclude>contrib/views/files/src/main/resources/ui/.bowerrc</exclude>