Переглянути джерело

AMBARI-17711. Updating jetty version from 6 to 9.2 for Log Search (Hayat Behlim via oleewere)

oleewere 9 роки тому
батько
коміт
2c26dbab2e

+ 57 - 14
ambari-logsearch/ambari-logsearch-portal/pom.xml

@@ -34,6 +34,7 @@
     <spring.security.version>4.0.4.RELEASE</spring.security.version>
     <spring.ldap.version>2.0.4.RELEASE</spring.ldap.version>
     <jersey.version>1.19</jersey.version>
+    <jetty-version>9.2.11.v20150529</jetty-version>
   </properties>
   <profiles>
     <!-- Dev Profile Start -->
@@ -518,16 +519,16 @@
     <artifactId>jersey-apache-client</artifactId>
     <version>${jersey.version}</version>
   </dependency>
-    <dependency>
-      <groupId>javax.servlet</groupId>
-      <artifactId>javax.servlet-api</artifactId>
-      <version>3.1.0</version>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <version>1.2.17</version>
-    </dependency>
+  <dependency>
+    <groupId>javax.servlet</groupId>
+    <artifactId>javax.servlet-api</artifactId>
+    <version>3.1.0</version>
+  </dependency>
+      <dependency>
+    <groupId>log4j</groupId>
+    <artifactId>log4j</artifactId>
+    <version>1.2.17</version>
+  </dependency>
     <dependency>
       <groupId>org.apache.solr</groupId>
       <artifactId>solr-solrj</artifactId>
@@ -543,16 +544,26 @@
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-common</artifactId>
       <version>2.7.0</version>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.servlet</groupId>
+          <artifactId>servlet-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.mortbay.jetty</groupId>
+          <artifactId>jetty</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.mortbay.jetty</groupId>
+          <artifactId>jetty-util</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>2.4</version>
     </dependency>
-    <dependency>
-      <groupId>commons-codec</groupId>
-      <artifactId>commons-codec</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.apache.ambari</groupId>
       <artifactId>ambari-logsearch-appender</artifactId>
@@ -568,5 +579,37 @@
       <artifactId>ambari-metrics-common</artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+      <version>1.3.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-webapp</artifactId>
+      <version>${jetty-version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-annotations</artifactId>
+      <version>${jetty-version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.springframework</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib</artifactId>
+      <version>3.2.4</version>
+    </dependency>
   </dependencies>
 </project>

+ 121 - 48
ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java

@@ -18,9 +18,11 @@
  */
 package org.apache.ambari.logsearch;
 
+import java.io.IOException;
+import java.net.ServerSocket;
 import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.Timer;
 
 import org.apache.ambari.logsearch.common.ManageStartEndTime;
@@ -28,8 +30,18 @@ import org.apache.ambari.logsearch.solr.metrics.SolrMetricsLoader;
 import org.apache.ambari.logsearch.util.ConfigUtil;
 import org.apache.ambari.logsearch.util.PropertiesUtil;
 import org.apache.commons.lang.StringUtils;
-import org.apache.hadoop.http.HttpServer2;
 import org.apache.log4j.Logger;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.SecureRequestCustomizer;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SslConnectionFactory;
+import org.eclipse.jetty.util.resource.Resource;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+import org.eclipse.jetty.webapp.WebAppContext;
+
 
 public class LogSearch {
   private static final Logger logger = Logger.getLogger(LogSearch.class);
@@ -48,67 +60,128 @@ public class LogSearch {
   private static final String HTTP_PROTOCOL = "http";
   private static final String HTTPS_PORT = "61889";
   private static final String HTTP_PORT = "61888";
+  
+  private static final String WEB_RESOURCE_FOLDER = "webapps/app";
+  private static final String ROOT_CONTEXT = "/";
 
+ 
   public static void main(String[] argv) {
-    HttpServer2.Builder builder = new HttpServer2.Builder();
-    builder.setName("app");
-
-    URI logsearchURI = addUri(argv, builder);
-    builder.setFindPort(false);
-    List<String> pathList = new ArrayList<String>();
-    pathList.add("/*");
-    builder.setPathSpec(pathList.toArray(new String[0]));
-    builder.needsClientAuth(false);
+    LogSearch logSearch = new LogSearch();
     Timer timer = new Timer();
     timer.schedule(new ManageStartEndTime(), 0, 40000);
     try {
-      logger.info("Starting logsearch server URI=" + logsearchURI);
-      HttpServer2 server = builder.build();
-      server.start();
       ConfigUtil.initializeApplicationConfig();
-      logger.info(server.toString());
+      logSearch.run(argv);
     } catch (Throwable e) {
       logger.error("Error running logsearch server", e);
     }
-
     SolrMetricsLoader.startSolrMetricsLoaderTasks();
   }
-
-  private static URI addUri(String[] argv, HttpServer2.Builder builder) {
+  
+  public void run(String[] argv) throws Exception {
+    Server server = buildSever(argv);
+    URI webResourceBase = findWebResourceBase(server.getClass()
+        .getClassLoader());
+    WebAppContext context = new WebAppContext();
+    context.setBaseResource(Resource.newResource(webResourceBase));
+    context.setContextPath(ROOT_CONTEXT);
+    context.setParentLoaderPriority(true);
+    server.setHandler(context);
+    server.start();
+    logger
+        .debug("============================Server Dump=======================================");
+    logger.debug(server.dump());
+    logger
+        .debug("==============================================================================");
+    server.join();
+  }
+  
+  public Server buildSever(String argv[]) {
+    Server server = new Server();
+    ServerConnector connector = new ServerConnector(server);
     boolean portSpecified = argv.length > 0;
-    String port = portSpecified ? argv[0] : HTTP_PORT;
-    String protocol = HTTP_PROTOCOL;
-
-    String protcolProperty = PropertiesUtil.getProperty(LOGSEARCH_PROTOCOL_PROP);
-    if (HTTPS_PROTOCOL.equals(protcolProperty)) {
-      String keystoreLocation = System.getProperty(KEYSTORE_LOCATION_ARG);
-      String keystorePassword = System.getProperty(KEYSTORE_PASSWORD_ARG);
-      String keystoreType = System.getProperty(KEYSTORE_TYPE_ARG, DEFAULT_KEYSTORE_TYPE);
-
-      String trustoreLocation = System.getProperty(TRUSTSTORE_LOCATION_ARG);
-      String trustorePassword = System.getProperty(TRUSTSTORE_PASSWORD_ARG);
-      String truststoreType = System.getProperty(TRUSTSTORE_TYPE_ARG, DEFAULT_TRUSTSTORE_TYPE);
+    String protcolProperty = PropertiesUtil.getProperty(LOGSEARCH_PROTOCOL_PROP,HTTP_PROTOCOL);
+    if (StringUtils.isEmpty(protcolProperty)) {
+      protcolProperty = HTTP_PROTOCOL;
+    }
+    String port = null;
+    String keystoreLocation = System.getProperty(KEYSTORE_LOCATION_ARG);
+    String keystorePassword = System.getProperty(KEYSTORE_PASSWORD_ARG);
+    String keystoreType = System.getProperty(KEYSTORE_TYPE_ARG,DEFAULT_KEYSTORE_TYPE);
+    String trustStoreLocation = System.getProperty(TRUSTSTORE_LOCATION_ARG);
+    String trustStorePassword = System.getProperty(TRUSTSTORE_PASSWORD_ARG);
+    String trustStoreType = System.getProperty(TRUSTSTORE_TYPE_ARG,DEFAULT_TRUSTSTORE_TYPE);
+    if (HTTPS_PROTOCOL.equals(protcolProperty) 
+        && !StringUtils.isEmpty(keystoreLocation) && !StringUtils.isEmpty(keystorePassword)) {
+      logger.info("Building https server...........");
+      port = portSpecified ? argv[0] : HTTPS_PORT;
+      checkPort(Integer.parseInt(port));
+      HttpConfiguration https = new HttpConfiguration();
+      https.addCustomizer(new SecureRequestCustomizer());
+      SslContextFactory sslContextFactory = new SslContextFactory();
+      sslContextFactory.setKeyStorePath(keystoreLocation);
+      sslContextFactory.setKeyStorePassword(keystorePassword);
+      sslContextFactory.setKeyStoreType(keystoreType);
+      if (!StringUtils.isEmpty(trustStoreLocation) && !StringUtils.isEmpty(trustStorePassword)) {
+        sslContextFactory.setTrustStorePath(trustStoreLocation);
+        sslContextFactory.setTrustStorePassword(trustStorePassword);
+        sslContextFactory.setTrustStoreType(trustStoreType);
+      }
+      ServerConnector sslConnector = new ServerConnector(server,
+          new SslConnectionFactory(sslContextFactory, "http/1.1"),
+          new HttpConnectionFactory(https));
+      sslConnector.setPort(Integer.parseInt(port));
+      server.setConnectors(new Connector[] { sslConnector });
+    } else {
+      logger.info("Building http server...........");
+      port = portSpecified ? argv[0] : HTTP_PORT;
+      checkPort(Integer.parseInt(port));
+      connector.setPort(Integer.parseInt(port));
+      server.setConnectors(new Connector[] { connector });
+    }
+    URI logsearchURI = URI.create(String.format("%s://0.0.0.0:%s", protcolProperty,
+        port));
+    logger.info("Starting logsearch server URI=" + logsearchURI);
+    return server;
+  }
 
-      if (!StringUtils.isEmpty(keystoreLocation) && !StringUtils.isEmpty(keystorePassword)) {
-        builder.keyPassword(keystorePassword);
-        builder.keyStore(keystoreLocation, keystorePassword, keystoreType);
-        
-        if (!StringUtils.isEmpty(trustoreLocation) && !StringUtils.isEmpty(trustorePassword)) {
-          builder.trustStore(trustoreLocation, trustorePassword, truststoreType);
-        }
+  private URI findWebResourceBase(ClassLoader classLoader) {
+    URL fileCompleteUrl = Thread.currentThread().getContextClassLoader()
+        .getResource(WEB_RESOURCE_FOLDER);
+    if (fileCompleteUrl != null) {
+      try {
+        return fileCompleteUrl.toURI().normalize();
+      } catch (URISyntaxException e) {
+        logger.error("Web Resource Folder " + WEB_RESOURCE_FOLDER+ " not found in classpath", e);
+        System.exit(1);
+      }
+    }else{
+      logger.error("Web Resource Folder " + WEB_RESOURCE_FOLDER+ " not found in classpath");
+      System.exit(1);
+    }
+    return null;
+  }
 
-        protocol = HTTPS_PROTOCOL;
-        if (!portSpecified) {
-          port = HTTPS_PORT;
+  private void checkPort(int port) {
+    ServerSocket serverSocket = null;
+    boolean portBusy = false;
+    try {
+      new ServerSocket(port);
+    } catch (IOException ex) {
+      portBusy = true;
+      logger.error(ex.getLocalizedMessage() + " PORT :" + port);
+    } finally {
+      if (serverSocket != null) {
+        try {
+          serverSocket.close();
+        } catch (Exception exception) {
+          // ignore
         }
-      } else{
-        logger.warn("starting logsearch in with http protocol as keystore location or password was not present");
+      }
+      if (portBusy) {
+        System.exit(1);
       }
     }
-
-    URI logsearchURI = URI.create(String.format("%s://0.0.0.0:%s", protocol, port));
-    builder.addEndpoint(logsearchURI);
-
-    return logsearchURI;
   }
+
 }

+ 6 - 7
ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/authenticate/LogsearchAuthSuccessHandler.java

@@ -26,17 +26,16 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.apache.log4j.Logger;
 import org.springframework.security.core.Authentication;
-import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
+import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
 
-public class LogsearchAuthSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {
+public class LogsearchAuthSuccessHandler implements AuthenticationSuccessHandler {
   private static final Logger logger = Logger.getLogger(LogsearchAuthSuccessHandler.class);
 
-  private String HOME_PAGE = "/index.html";
 
   @Override
-  public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
-                                      Authentication authentication) throws ServletException, IOException {
-    logger.debug("Login successfully !!!!!! Redirecting to home page :" + HOME_PAGE);
-    response.sendRedirect(HOME_PAGE);
+  public void onAuthenticationSuccess(HttpServletRequest request,
+      HttpServletResponse response, Authentication authentication)
+      throws ServletException, IOException {
+    response.setStatus(HttpServletResponse.SC_OK);
   }
 }

+ 3 - 4
ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/authenticate/LogsearchLogoutSuccessHandler.java

@@ -35,8 +35,7 @@ public class LogsearchLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler
     @Override
     public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
       throws IOException, ServletException {
-  logger.debug("LogsearchLogoutSuccessHandler ::: onLogoutSuccess");
-//  super.onLogoutSuccess(request, response, authentication);
-  response.sendRedirect("/login.jsp");
-    }
+      logger.debug("LogsearchLogoutSuccessHandler ::: onLogoutSuccess");
+      response.sendRedirect("/login.html");
+  }
 }

+ 2 - 0
ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/web/security/LogsearchAuthenticationProvider.java

@@ -103,6 +103,8 @@ public class LogsearchAuthenticationProvider extends
             // Let's save the first one
             authException = ex;
           }
+        }catch(Exception e){
+          logger.error(e,e.getCause());
         }
       }
       auditRecord.put("result", "denied");

+ 0 - 5
ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties

@@ -51,11 +51,6 @@ logsearch.roles.allowed=AMBARI.ADMINISTRATOR
 
 #communication protocol i.e http or https etc.
 logsearch.protocol=
-logsearch.https.keystore=
-logsearch.https.trustore=
-logsearch.https.keystore.password=
-logsearch.https.trustore.password=
-logsearch.https.keystore.type=
 
 logsearch.solr.kerberos.enable=false
 logsearch.solr.jaas.file=/usr/lib/ambari-logsearch-portal/logsearch_solr_jaas.conf

+ 13 - 10
ambari-logsearch/ambari-logsearch-portal/src/main/webapp/META-INF/security-applicationContext.xml

@@ -23,14 +23,17 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
 http://www.springframework.org/schema/security
 http://www.springframework.org/schema/security/spring-security-4.0.xsd">
-
-	<security:http pattern="/login.jsp" security="none" />
-	<security:http pattern="/**/*.css" security="none" />
-	<security:http pattern="/**/jquery.*.js" security="none" />
-	<security:http pattern="/**/*.css.map" security="none" />
-	<security:http pattern="/service/public/**" security="none" />
-	<security:http pattern="/images/**" security="none" />
-	
+  
+    <security:http pattern="/login.html" security="none" />
+    <security:http pattern="/styles/**" security="none" />
+    <security:http pattern="/fonts/**" security="none" />
+    <security:http pattern="/scripts/**" security="none" />
+    <security:http pattern="/libs/**" security="none" />
+    <security:http pattern="/images/**" security="none" />
+    <security:http pattern="/templates/**" security="none" />
+    <security:http pattern="/service/public/**" security="none" />
+    <security:http pattern="/favicon.ico" security="none" />
+  	
 	<security:http disable-url-rewriting="true" use-expressions="true" create-session="always" entry-point-ref="authenticationProcessingFilterEntryPoint">
 		<csrf disabled="true"/> 
 		<security:session-management session-fixation-protection="newSession" />
@@ -48,9 +51,9 @@ http://www.springframework.org/schema/security/spring-security-4.0.xsd">
 		<beans:property name="authenticationSuccessHandler" ref="authSuccessHandler"/>
 		<beans:property name="authenticationFailureHandler"	ref="authFailureHandler"/>
 	</beans:bean>
-
+  
 	<beans:bean id="authenticationProcessingFilterEntryPoint" class="org.apache.ambari.logsearch.web.filters.LogsearchAuthenticationEntryPoint">
-		<beans:constructor-arg index="0" value="/login.jsp"/>
+		<beans:constructor-arg index="0" value="/login.html"/>
 		<beans:property name="forceHttps" value="false"/>
 	</beans:bean>
 

+ 1 - 1
ambari-logsearch/ambari-logsearch-portal/src/main/webapp/WEB-INF/web.xml

@@ -50,7 +50,7 @@
 		<servlet-name>REST service</servlet-name>
 		<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
 		<init-param>
-			<param-name>com.sun.jersey.config.property.packages</param-name>
+			<param-name>jersey.config.server.provider.packages</param-name>
 			<param-value>org.apache.ambari.logsearch.rest</param-value>
 		</init-param>
 		<init-param>

+ 0 - 0
ambari-logsearch/ambari-logsearch-portal/src/main/webapp/login.jsp → ambari-logsearch/ambari-logsearch-portal/src/main/webapp/login.html


+ 2 - 2
ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/utils/Utils.js

@@ -433,13 +433,13 @@ define(['require',
 		        }
 		    } catch (e) {}
 		} else if (error.status == 401) {
-		    window.location = 'login.jsp' + window.location.search;
+		    window.location = 'login.html' + window.location.search;
 		    // App.rContent.show(new vError({
 		    // 	status : error.status
 		    // }));
 
 		} else if (error.status == 419) {
-		    window.location = 'login.jsp' + window.location.search;
+		    window.location = 'login.html' + window.location.search;
 
 		} else if (error.status == "0") {
 		    var diffTime = (new Date().getTime() - prevNetworkErrorTime);

+ 1 - 1
ambari-logsearch/ambari-logsearch-portal/src/main/webapp/scripts/views/common/ProfileBar.js

@@ -60,7 +60,7 @@ define(['require',
 					"cache-control" : "no-cache"
 				},
 				success : function() {
-					window.location.replace('login.jsp');
+					window.location.replace('login.html');
 				},
 				error : function(jqXHR, textStatus, err ) {
 				}

+ 1 - 1
ambari-server/src/main/resources/common-services/LOGSEARCH/0.5.0/package/scripts/params.py

@@ -364,4 +364,4 @@ logsearch_server_hosts = config['clusterHostInfo']['logsearch_server_hosts']
 logsearch_server_host = ""
 if logsearch_server_hosts is not None and len(logsearch_server_hosts) > 0:
   logsearch_server_host = logsearch_server_hosts[0]
-smoke_logsearch_cmd = format('curl -k -s -o /dev/null -w "%{{http_code}}" {logsearch_ui_protocol}://{logsearch_server_host}:{logsearch_ui_port}/login.jsp | grep 200')
+smoke_logsearch_cmd = format('curl -k -s -o /dev/null -w "%{{http_code}}" {logsearch_ui_protocol}://{logsearch_server_host}:{logsearch_ui_port}/login.html | grep 200')