ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oleew...@apache.org
Subject ambari git commit: AMBARI-17092. LogSearch https support (Dharmesh Makwana via oleewere)
Date Tue, 07 Jun 2016 16:52:42 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 d99279f82 -> c7c843606


AMBARI-17092. LogSearch https support (Dharmesh Makwana via oleewere)


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

Branch: refs/heads/branch-2.4
Commit: c7c843606b7bbb0bcee495cf831edf49c5b24f23
Parents: d99279f
Author: oleewere <oleewere@gmail.com>
Authored: Tue Jun 7 18:44:57 2016 +0200
Committer: oleewere <oleewere@gmail.com>
Committed: Tue Jun 7 18:51:07 2016 +0200

----------------------------------------------------------------------
 .../org/apache/ambari/logsearch/LogSearch.java  | 57 ++++++++++++++++++--
 .../ambari/logsearch/util/PropertiesUtil.java   | 25 +++++++++
 .../src/main/resources/logsearch.properties     | 11 +++-
 3 files changed, 89 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c7c84360/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
index 2ebf981..993c532 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/LogSearch.java
@@ -18,6 +18,8 @@
  */
 package org.apache.ambari.logsearch;
 
+import java.io.File;
+import java.io.IOException;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
@@ -26,17 +28,66 @@ import java.util.Timer;
 import org.apache.ambari.logsearch.common.ManageStartEndTime;
 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.hadoop.http.HttpServer2;
 import org.apache.log4j.Logger;
 
 public class LogSearch {
   static Logger logger = Logger.getLogger(LogSearch.class);
+  
+  private static final String LOGSEARCH_PROTOCOL_PROP = "logsearch.protocol";
+  private static final String KEYSTORE_LOCATION_PROP = "logsearch.https.keystore";
+  private static final String TRUSTORE_LOCATION_PROP = "logsearch.https.trustore";
+  private static final String KEYSTORE_PASSWORD_PROP = "logsearch.https.keystore.password";
+  private static final String TRUSTORE_PASSWORD_PROP = "logsearch.https.trustore.password";
+  private static final String DEFAULT_KEYSTORE_TYPE = "JKS";
+  private static final String KEYSTORE_TYPE_PROP = "logsearch.https.keystore.type";
+  private static final String HTTPS_PROTOCOL = "https";
+  private static final String HTTPS_PORT = "61889";
+  private static final String HTTP_PORT = "61888";
 
   public static void main(String argv[]) {
-    String port = (argv.length > 0) ? argv[0] : "61888";
+    String port = (argv.length > 0) ? argv[0] : HTTP_PORT;
     HttpServer2.Builder builder = new HttpServer2.Builder();
     builder.setName("app");
-    builder.addEndpoint(URI.create("http://0.0.0.0:" + port));
+    
+    String keystorePassword = PropertiesUtil.getProperty(KEYSTORE_PASSWORD_PROP);
+    String trustorePassword = PropertiesUtil.getProperty(TRUSTORE_PASSWORD_PROP);
+    String keystoreType = PropertiesUtil.getProperty(KEYSTORE_TYPE_PROP);
+    
+    String protcol = PropertiesUtil.getProperty(LOGSEARCH_PROTOCOL_PROP);
+    String keystoreLocation = PropertiesUtil.getProperty(KEYSTORE_LOCATION_PROP);   
+    
+    String trustoreLocation = PropertiesUtil.getProperty(TRUSTORE_LOCATION_PROP);
+    URI logsearchURI = URI.create("http://0.0.0.0:" + port);
+ 
+    
+    if (HTTPS_PROTOCOL.equals(protcol)) {
+      if(keystoreType == null || keystoreType.isEmpty()){
+        keystoreType = DEFAULT_KEYSTORE_TYPE;
+      }
+
+      if (keystoreLocation != null && !keystoreLocation.isEmpty()
+          && keystorePassword != null && !keystorePassword.isEmpty()) {
+        
+        builder.keyPassword(keystorePassword);
+        builder.keyStore(keystoreLocation, keystorePassword, keystoreType);
+        
+        if (trustoreLocation != null && !trustoreLocation.isEmpty()
+            && trustorePassword != null && !trustorePassword.isEmpty()) {
+          
+          builder.trustStore(trustoreLocation, trustorePassword, keystoreType);
+        }
+        
+        if(HTTP_PORT.equals(port)){
+          port = HTTPS_PORT;
+        }
+        logsearchURI = URI.create("https://0.0.0.0:" + port);
+      } else{
+        logger.warn("starting logsearch in with http protocol as keystore location or password
was not present");
+      }
+    }
+    builder.addEndpoint(logsearchURI);
     builder.setFindPort(false);
     List<String> pathList = new ArrayList<String>();
     pathList.add("/*");
@@ -45,7 +96,7 @@ public class LogSearch {
     Timer timer = new Timer();
     timer.schedule(new ManageStartEndTime(), 0, 40000);
     try {
-      logger.info("Starting logsearch server...");
+      logger.info("Starting logsearch server URI="+logsearchURI);
       HttpServer2 server = builder.build();
       server.start();
       ConfigUtil.initializeApplicationConfig();

http://git-wip-us.apache.org/repos/asf/ambari/blob/c7c84360/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
index f31e8f8..f32152d 100644
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/java/org/apache/ambari/logsearch/util/PropertiesUtil.java
@@ -18,21 +18,46 @@
  */
 package org.apache.ambari.logsearch.util;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.log4j.Logger;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
 
 public class PropertiesUtil extends PropertyPlaceholderConfigurer {
+  static Logger logger = Logger.getLogger(PropertiesUtil.class);
   private static Map<String, String> propertiesMap;
+  private static final String LOGSEARCH_PROP_FILE="logsearch.properties";
 
   private PropertiesUtil() {
 
   }
+  
+ static {
+    propertiesMap = new HashMap<String, String>();
+    Properties properties = new Properties();
+    URL fileCompleteUrl = Thread.currentThread()
+        .getContextClassLoader().getResource(LOGSEARCH_PROP_FILE);
+    try {
+      File file = new File(fileCompleteUrl.toURI());
+      properties.load(new FileInputStream(file.getAbsoluteFile()));
+    } catch (IOException | URISyntaxException e) {
+      logger.error("error loading prop for protocol config",e);
+    }
+    for (String key : properties.stringPropertyNames()) {
+      String value = properties.getProperty(key);
+      propertiesMap.put(key, value);
+    }
+  }
 
   @Override
   protected void processProperties(

http://git-wip-us.apache.org/repos/asf/ambari/blob/c7c84360/ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties
----------------------------------------------------------------------
diff --git a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties
b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties
index f477c5a..37c8317 100755
--- a/ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties
+++ b/ambari-logsearch/ambari-logsearch-portal/src/main/resources/logsearch.properties
@@ -46,4 +46,13 @@ logsearch.auth.external_auth.enable=false
 logsearch.auth.external_auth.host_url=http://ip:port
 logsearch.auth.external_auth.login_url=/api/v1/users/$USERNAME/privileges?fields=*
 #Note: Use comma(,) for separation of multiple roles
-logsearch.roles.allowed=AMBARI.ADMINISTRATOR
\ No newline at end of file
+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=


Mime
View raw message