ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [45/50] [abbrv] ambari git commit: AMBARI-21087. Infra manger: Add static data folder servlet endpoint (oleewere)
Date Wed, 24 May 2017 02:40:02 GMT
AMBARI-21087. Infra manger: Add static data folder servlet endpoint (oleewere)


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 4fcdaae4ce7788620d9b6146dfaef10ad1e7c60e
Parents: 0d68810
Author: oleewere <oleewere@gmail.com>
Authored: Mon May 22 13:54:06 2017 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Tue May 23 12:49:25 2017 +0200

----------------------------------------------------------------------
 .../org/apache/ambari/infra/InfraManager.java   | 29 ++++++++++++++++++--
 .../infra/common/InfraManagerConstants.java     |  2 ++
 2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4fcdaae4/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/InfraManager.java
----------------------------------------------------------------------
diff --git a/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/InfraManager.java
b/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/InfraManager.java
index 227bab4..186f98c 100644
--- a/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/InfraManager.java
+++ b/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/InfraManager.java
@@ -32,6 +32,7 @@ import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.HandlerList;
 import org.eclipse.jetty.server.handler.ResourceHandler;
+import org.eclipse.jetty.servlet.DefaultServlet;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.resource.Resource;
@@ -48,6 +49,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 
+import static org.apache.ambari.infra.common.InfraManagerConstants.DATA_FOLDER_LOCATION_PARAM;
+import static org.apache.ambari.infra.common.InfraManagerConstants.DEFAULT_DATA_FOLDER_LOCATION;
 import static org.apache.ambari.infra.common.InfraManagerConstants.DEFAULT_PORT;
 import static org.apache.ambari.infra.common.InfraManagerConstants.DEFAULT_PROTOCOL;
 import static org.apache.ambari.infra.common.InfraManagerConstants.INFRA_MANAGER_SESSION_ID;
@@ -78,6 +81,13 @@ public class InfraManager {
       .argName("port_number")
       .build();
 
+    final Option dataFolderOption = Option.builder("df")
+      .longOpt("data-folder")
+      .desc("Infra Manager data folder location")
+      .numberOfArgs(1)
+      .argName("data_folder")
+      .build();
+
     final Option protocolOption = Option.builder("t")
       .longOpt("tls-enabled")
       .desc("TLS enabled for Infra Manager")
@@ -86,17 +96,21 @@ public class InfraManager {
     options.addOption(helpOption);
     options.addOption(portOption);
     options.addOption(protocolOption);
+    options.addOption(dataFolderOption);
 
     try {
       CommandLineParser cmdLineParser = new DefaultParser();
       CommandLine cli = cmdLineParser.parse(options, args);
       int port = cli.hasOption('p') ? Integer.parseInt(cli.getOptionValue('p')) : DEFAULT_PORT;
       String protocol = cli.hasOption("t") ? PROTOCOL_SSL : DEFAULT_PROTOCOL;
+      String dataFolder = cli.hasOption("df") ? cli.getOptionValue("df"): DEFAULT_DATA_FOLDER_LOCATION;
+
+      System.setProperty(DATA_FOLDER_LOCATION_PARAM, dataFolder); // be able to access it
from jobs
 
       Server server = buildServer(port, protocol);
       HandlerList handlers = new HandlerList();
       handlers.addHandler(createSwaggerContext());
-      handlers.addHandler(createBaseWebappContext());
+      handlers.addHandler(createBaseWebappContext(dataFolder));
 
       server.setHandler(handlers);
       server.start();
@@ -124,13 +138,22 @@ public class InfraManager {
     return server;
   }
 
-  private static WebAppContext createBaseWebappContext() throws MalformedURLException {
+  private static WebAppContext createBaseWebappContext(String dataFolder) throws MalformedURLException
{
     URI webResourceBase = findWebResourceBase();
     WebAppContext context = new WebAppContext();
-    context.setBaseResource(Resource.newResource(webResourceBase));
+    ResourceCollection resources = new ResourceCollection(Resource.newResource(webResourceBase));
+    context.setBaseResource(resources);
     context.setContextPath(ROOT_CONTEXT);
     context.setParentLoaderPriority(true);
 
+    // Data folder servlet
+    ServletHolder dataServlet = new ServletHolder("static-data", DefaultServlet.class);
+    dataServlet.setInitParameter("dirAllowed","true");
+    dataServlet.setInitParameter("pathInfoOnly","true");
+    dataServlet.setInitParameter("resourceBase", dataFolder);
+
+    context.addServlet(dataServlet,"/files/*");
+
     // Configure Spring
     context.addEventListener(new ContextLoaderListener());
     context.addEventListener(new RequestContextListener());

http://git-wip-us.apache.org/repos/asf/ambari/blob/4fcdaae4/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/common/InfraManagerConstants.java
----------------------------------------------------------------------
diff --git a/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/common/InfraManagerConstants.java
b/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/common/InfraManagerConstants.java
index 11714f3..77f7008 100644
--- a/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/common/InfraManagerConstants.java
+++ b/ambari-infra/ambari-infra-manager/src/main/java/org/apache/ambari/infra/common/InfraManagerConstants.java
@@ -25,5 +25,7 @@ public final class InfraManagerConstants {
   public static final String PROTOCOL_SSL = "https";
   public static final String ROOT_CONTEXT = "/";
   public static final String WEB_RESOURCE_FOLDER = "webapp";
+  public static final String DEFAULT_DATA_FOLDER_LOCATION = "/usr/ambari-infra-manager/data";
+  public static final String DATA_FOLDER_LOCATION_PARAM = "dataFolderLocation";
   public static final Integer SESSION_TIMEOUT = 60 * 30;
 }


Mime
View raw message