chukwa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shre...@apache.org
Subject svn commit: r1662360 - in /chukwa/trunk: ./ src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/ src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ src/test/java/org/apache/hadoop/chukwa/datacollection/agent/
Date Thu, 26 Feb 2015 06:16:33 GMT
Author: shreyas
Date: Thu Feb 26 06:16:33 2015
New Revision: 1662360

URL: http://svn.apache.org/r1662360
Log:
CHUKWA-736. SSL support for chukwa

Added:
    chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaConstants.java
    chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaRestServer.java
    chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/TestChukwaSsl.java
Modified:
    chukwa/trunk/CHANGES.txt
    chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/RestAdaptor.java
    chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java

Modified: chukwa/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/chukwa/trunk/CHANGES.txt?rev=1662360&r1=1662359&r2=1662360&view=diff
==============================================================================
--- chukwa/trunk/CHANGES.txt (original)
+++ chukwa/trunk/CHANGES.txt Thu Feb 26 06:16:33 2015
@@ -4,6 +4,8 @@ Trunk (unreleased changes)
 
   NEW FEATURES
 
+    CHUKWA-736. SSL support for chukwa. (Shreyas Subramanya)
+
   IMPROVEMENTS
 
   CHUKWA-723. Update Chukwa code to use new HBase HConnection API.  (Sreepathi Prasanna via
Eric Yang)

Modified: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/RestAdaptor.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/RestAdaptor.java?rev=1662360&r1=1662359&r2=1662360&view=diff
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/RestAdaptor.java
(original)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/adaptor/RestAdaptor.java
Thu Feb 26 06:16:33 2015
@@ -18,6 +18,10 @@
 
 package org.apache.hadoop.chukwa.datacollection.adaptor;
 
+import java.io.FileInputStream;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+
 import java.util.Calendar;
 import java.util.TimeZone;
 import java.util.Timer;
@@ -25,11 +29,21 @@ import java.util.TimerTask;
 
 import org.apache.hadoop.chukwa.ChunkImpl;
 import org.apache.hadoop.chukwa.datacollection.ChunkReceiver;
+import org.apache.hadoop.chukwa.datacollection.agent.ChukwaAgent;
 import org.apache.log4j.Logger;
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
+import org.apache.hadoop.conf.Configuration;
+import static org.apache.hadoop.chukwa.datacollection.agent.ChukwaConstants.*;
 
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.client.urlconnection.HTTPSProperties;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
 
 import javax.ws.rs.core.MediaType;
 
@@ -128,8 +142,53 @@ public class RestAdaptor extends Abstrac
       log.warn("bad syntax in RestAdaptor args");
       return null;
     }
-    c = Client.create();
+    try {
+      initClient();
+    } catch (Exception e) {
+      log.error(ExceptionUtil.getStackTrace(e));
+      return null;
+    }    
     return s;
   }
+  
+  private void initClient() throws Exception {
+    if (uri.contains("https")) {
+      Configuration conf = ChukwaAgent.getAgent().getConfiguration();
+      String trustStoreFile = conf.get(TRUSTSTORE_STORE);
+      String trustStorePw = conf.get(TRUST_PASSWORD);
+      if (trustStoreFile == null || trustStorePw == null) {
+        throw new Exception(
+            "Cannot instantiate RestAdaptor to uri "
+                + uri
+                + " due to missing trust store configurations chukwa.ssl.truststore.store
and chukwa.ssl.trust.password");
+      }
+      String trustStoreType = conf.get(TRUSTSTORE_TYPE, DEFAULT_STORE_TYPE);
+      KeyStore trustStore = KeyStore.getInstance(trustStoreType);
+      FileInputStream fis = null;
+      try {
+        fis = new FileInputStream(trustStoreFile);
+        trustStore.load(fis, trustStorePw.toCharArray());
+      } finally {
+        if (fis != null) {
+          fis.close();
+        }
+      }
+      TrustManagerFactory tmf = TrustManagerFactory
+          .getInstance(TrustManagerFactory.getDefaultAlgorithm());
+      tmf.init(trustStore);
+      TrustManager[] trustManagers = tmf.getTrustManagers();
+
+      SSLContext ctx = null;
+      String protocol = conf.get(SSL_PROTOCOL, DEFAULT_SSL_PROTOCOL);
+      ctx = SSLContext.getInstance(protocol);
+      ctx.init(null, trustManagers, new SecureRandom());
+      ClientConfig cc = new DefaultClientConfig();
+      HTTPSProperties props = new HTTPSProperties(null, ctx);
+      cc.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, props);
+      c = Client.create(cc);
+    } else {
+      c = Client.create();
+    }
+  }
 
 }

Modified: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java?rev=1662360&r1=1662359&r2=1662360&view=diff
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java
(original)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaAgent.java
Thu Feb 26 06:16:33 2015
@@ -46,24 +46,13 @@ import org.apache.hadoop.chukwa.datacoll
 import org.apache.hadoop.chukwa.datacollection.agent.metrics.AgentMetrics;
 import org.apache.hadoop.chukwa.datacollection.connector.Connector;
 import org.apache.hadoop.chukwa.datacollection.connector.http.HttpConnector;
-import org.apache.hadoop.chukwa.datacollection.connector.PipelineConnector;
 import org.apache.hadoop.chukwa.datacollection.test.ConsoleOutConnector;
 import org.apache.hadoop.chukwa.util.AdaptorNamingUtils;
 import org.apache.hadoop.chukwa.util.ChukwaUtil;
 import org.apache.hadoop.chukwa.util.DaemonWatcher;
 import org.apache.hadoop.chukwa.util.ExceptionUtil;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.fs.Path;
 import org.apache.log4j.Logger;
-import org.mortbay.jetty.Server;
-import org.mortbay.jetty.servlet.Context;
-import org.mortbay.jetty.servlet.ServletHolder;
-import org.mortbay.jetty.nio.SelectChannelConnector;
-import org.mortbay.thread.BoundedThreadPool;
-
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-
-import edu.berkeley.confspell.*;
 
 /**
  * The local agent daemon that runs on each machine. This class is designed to
@@ -83,9 +72,7 @@ public class ChukwaAgent implements Adap
   // boolean WRITE_CHECKPOINTS = true;
   static AgentMetrics agentMetrics = new AgentMetrics("ChukwaAgent", "metrics");
 
-  private static Logger log = Logger.getLogger(ChukwaAgent.class);
-  private static final int HTTP_SERVER_THREADS = 120;
-  private static Server jettyServer = null;
+  private static Logger log = Logger.getLogger(ChukwaAgent.class);  
   private OffsetStatsManager adaptorStatsManager = null;
   private Timer statsCollector = null;
   private static volatile Configuration conf = null;
@@ -98,7 +85,7 @@ public class ChukwaAgent implements Adap
 
   public ChukwaAgent(Configuration conf) throws AlreadyRunningException {
     ChukwaAgent.agent = this;
-    this.conf = conf;
+    ChukwaAgent.conf = conf;
     
     // almost always just reading this; so use a ConcurrentHM.
     // since we wrapped the offset, it's not a structural mod.
@@ -335,49 +322,13 @@ public class ChukwaAgent implements Adap
   }
 
   private void startHttpServer(Configuration conf) throws Exception {
-    int portNum = conf.getInt("chukwaAgent.http.port", 9090);
-    String jaxRsAddlPackages = conf.get("chukwaAgent.http.rest.controller.packages");
-    StringBuilder jaxRsPackages = new StringBuilder(
-            "org.apache.hadoop.chukwa.datacollection.agent.rest");
-
-    // Allow the ability to add additional servlets to the server
-    if (jaxRsAddlPackages != null)
-      jaxRsPackages.append(';').append(jaxRsAddlPackages);
-
-    // Set up jetty connector
-    SelectChannelConnector jettyConnector = new SelectChannelConnector();
-    jettyConnector.setLowResourcesConnections(HTTP_SERVER_THREADS - 10);
-    jettyConnector.setLowResourceMaxIdleTime(1500);
-    jettyConnector.setPort(portNum);
-    jettyConnector.setReuseAddress(true);
-
-    // Set up jetty server, using connector
-    jettyServer = new Server(portNum);
-    jettyServer.setConnectors(new org.mortbay.jetty.Connector[] { jettyConnector });
-    BoundedThreadPool pool = new BoundedThreadPool();
-    pool.setMaxThreads(HTTP_SERVER_THREADS);
-    jettyServer.setThreadPool(pool);
-
-    // Create the controller servlets
-    ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
-    servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
-            "com.sun.jersey.api.core.PackagesResourceConfig");
-    servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
-            jaxRsPackages.toString());
-
-    // Create the server context and add the servlet
-    Context root = new Context(jettyServer, "/rest/v2", Context.SESSIONS);
-    root.setAttribute("ChukwaAgent", this);
-    root.addServlet(servletHolder, "/*");
-    root.setAllowNullPathInfo(false);
-
-    // And finally, fire up the server
-    jettyServer.start();
-    jettyServer.setStopAtShutdown(true);
-
-    log.info("started Chukwa http agent interface on port " + portNum);
+    ChukwaRestServer.startInstance(conf);
   }
-
+  
+  private void stopHttpServer() throws Exception {
+    ChukwaRestServer.stopInstance();
+  }
+  
   /**
    * Take snapshots of offset data so we can report flow rate stats.
    */
@@ -753,7 +704,7 @@ public class ChukwaAgent implements Adap
     }
 
     try {
-      jettyServer.stop();
+      stopHttpServer();
     } catch (Exception e) {
       log.error("Couldn't stop jetty server.", e);
     }

Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaConstants.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaConstants.java?rev=1662360&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaConstants.java
(added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaConstants.java
Thu Feb 26 06:16:33 2015
@@ -0,0 +1,33 @@
+/*
+ * 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.hadoop.chukwa.datacollection.agent;
+
+public class ChukwaConstants {
+  public static final String SSL_ENABLE = "chukwa.ssl.enable";
+  public static final String KEYSTORE_STORE = "chukwa.ssl.keystore.store";
+  public static final String KEYSTORE_PASSWORD = "chukwa.ssl.keystore.password";
+  public static final String KEYSTORE_KEY_PASSWORD = "chukwa.ssl.keystore.key.password";
+  public static final String KEYSTORE_TYPE = "chukwa.ssl.keystore.type";
+  public static final String TRUSTSTORE_STORE = "chukwa.ssl.truststore.store";
+  public static final String TRUST_PASSWORD = "chukwa.ssl.trust.password";
+  public static final String TRUSTSTORE_TYPE = "chukwa.ssl.truststore.type";
+  public static final String SSL_PROTOCOL = "chukwa.ssl.protocol";
+  public static final String DEFAULT_SSL_PROTOCOL = "TLS";
+  public static final String DEFAULT_STORE_TYPE = "JKS";
+}

Added: chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaRestServer.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaRestServer.java?rev=1662360&view=auto
==============================================================================
--- chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaRestServer.java
(added)
+++ chukwa/trunk/src/main/java/org/apache/hadoop/chukwa/datacollection/agent/ChukwaRestServer.java
Thu Feb 26 06:16:33 2015
@@ -0,0 +1,135 @@
+/*
+ * 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.hadoop.chukwa.datacollection.agent;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.log4j.Logger;
+import org.mortbay.jetty.AbstractConnector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.thread.QueuedThreadPool;
+
+import com.sun.jersey.spi.container.servlet.ServletContainer;
+import static org.apache.hadoop.chukwa.datacollection.agent.ChukwaConstants.*;
+
+public class ChukwaRestServer {
+  private Configuration conf;
+  private Server jettyServer;  
+  private final Logger log = Logger.getLogger(ChukwaRestServer.class);  
+  private final String AGENT_HTTP_PORT = "chukwaAgent.http.port";
+  private final String AGENT_REST_CONTROLLER_PACKAGES = "chukwaAgent.http.rest.controller.packages";
+  private final int HTTP_SERVER_THREADS = 120;
+  
+  private static ChukwaRestServer instance = null;
+  
+  public static void startInstance(Configuration conf) throws Exception{
+    if(instance == null){
+      synchronized(ChukwaRestServer.class) {
+        if(instance == null){
+          instance = new ChukwaRestServer(conf);
+          instance.start();
+        }        
+      }
+    }
+  }
+  
+  public static void stopInstance() throws Exception {
+    if(instance != null) {
+      synchronized(ChukwaRestServer.class) {
+        if(instance != null){
+          instance.stop();
+          instance = null;
+        }
+      }
+    }
+    
+  }
+  
+  private ChukwaRestServer(Configuration conf){
+    this.conf = conf;
+  }
+  
+  private void start() throws Exception{
+    int portNum = conf.getInt(AGENT_HTTP_PORT, 9090);
+    String jaxRsAddlPackages = conf.get(AGENT_REST_CONTROLLER_PACKAGES);
+    StringBuilder jaxRsPackages = new StringBuilder(
+            "org.apache.hadoop.chukwa.datacollection.agent.rest");
+  
+    // Allow the ability to add additional servlets to the server
+    if (jaxRsAddlPackages != null)
+      jaxRsPackages.append(';').append(jaxRsAddlPackages);
+  
+    // Set up jetty connector
+    AbstractConnector jettyConnector;
+    if("true".equals(conf.get(SSL_ENABLE))){
+      SslSocketConnector sslConnector = new SslSocketConnector();
+      sslConnector.setKeystore(conf.get(KEYSTORE_STORE));
+      sslConnector.setPassword(conf.get(KEYSTORE_PASSWORD));
+      sslConnector.setKeyPassword(conf.get(KEYSTORE_KEY_PASSWORD));
+      sslConnector.setKeystoreType(conf.get(KEYSTORE_TYPE, DEFAULT_STORE_TYPE));
+      String trustStore = conf.get(TRUSTSTORE_STORE);
+      if(trustStore != null){
+        sslConnector.setTruststore(trustStore);
+        sslConnector.setTrustPassword(conf.get(TRUST_PASSWORD));
+        sslConnector.setTruststoreType(conf.get(TRUSTSTORE_TYPE, DEFAULT_STORE_TYPE));
+        sslConnector.setNeedClientAuth(false);
+      }
+      jettyConnector = sslConnector;
+    } else {
+      jettyConnector = new SelectChannelConnector();
+    }
+    //jettyConnector.setLowResourcesConnections(HTTP_SERVER_THREADS - 10);
+    jettyConnector.setLowResourceMaxIdleTime(1500);
+    jettyConnector.setPort(portNum);
+    jettyConnector.setReuseAddress(true);
+    // Set up jetty server, using connector
+    jettyServer = new Server(portNum);
+    jettyServer.setConnectors(new org.mortbay.jetty.Connector[] { jettyConnector });
+    QueuedThreadPool pool = new QueuedThreadPool();
+    pool.setMaxThreads(HTTP_SERVER_THREADS);
+    jettyServer.setThreadPool(pool);
+  
+    // Create the controller servlets
+    ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
+    servletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
+            "com.sun.jersey.api.core.PackagesResourceConfig");
+    servletHolder.setInitParameter("com.sun.jersey.config.property.packages",
+            jaxRsPackages.toString());
+  
+    // Create the server context and add the servlet
+    Context root = new Context(jettyServer, "/rest/v2", Context.SESSIONS);
+    root.setAttribute("ChukwaAgent", ChukwaAgent.getAgent());
+    root.addServlet(servletHolder, "/*");
+    root.setAllowNullPathInfo(false);
+  
+    // And finally, fire up the server
+    jettyServer.start();
+    jettyServer.setStopAtShutdown(true);
+  
+    log.info("started Chukwa http agent interface on port " + portNum);
+  }
+  
+  private void stop() throws Exception{
+    jettyServer.stop();
+    log.info("Successfully stopped Chukwa http agent interface");
+  }
+}

Added: chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/TestChukwaSsl.java
URL: http://svn.apache.org/viewvc/chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/TestChukwaSsl.java?rev=1662360&view=auto
==============================================================================
--- chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/TestChukwaSsl.java
(added)
+++ chukwa/trunk/src/test/java/org/apache/hadoop/chukwa/datacollection/agent/TestChukwaSsl.java
Thu Feb 26 06:16:33 2015
@@ -0,0 +1,127 @@
+/*
+ * 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.hadoop.chukwa.datacollection.agent;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.hadoop.chukwa.Chunk;
+import org.apache.hadoop.chukwa.datacollection.ChunkQueue;
+import org.apache.hadoop.chukwa.datacollection.DataFactory;
+import org.apache.hadoop.conf.Configuration;
+
+import static org.apache.hadoop.chukwa.datacollection.agent.ChukwaConstants.*;
+import junit.framework.TestCase;
+
+public class TestChukwaSsl extends TestCase{
+  String keyStoreFile = "../../test-classes/chukwa.store";
+  @Override
+  protected void setUp() throws IOException, InterruptedException{
+    String[] cmd = new String[]{System.getenv("JAVA_HOME")+"/bin/keytool", "-genkeypair",
"-keyalg", "RSA",
+        "-alias", "monitoring", "-validity", "36500", "-keystore", keyStoreFile, "-keysize",
"1024",
+        "-keypass", "chukwa", "-storepass", "chukwa", "-dname", "cn=*,ou=chukwa,o=apache,c=US",
"-storetype", "jks"
+    };
+    Process p = Runtime.getRuntime().exec(cmd);
+    p.waitFor();
+    if(p.exitValue() != 0){
+      BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
+      String line;
+      while((line = reader.readLine()) != null){
+        System.out.println("Output:"+line);
+      }
+      reader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
+      while((line = reader.readLine()) != null){
+        System.out.println("Error:"+line);
+      }
+    }
+    System.out.println("keytool exit value:" + p.exitValue());
+  }
+  
+  @Override
+  protected void tearDown(){
+    new File(keyStoreFile).delete();
+  }
+    
+
+  public void testRestServer() throws Exception{
+    //keystore generated using the following command
+    //keytool -genkeypair -keyalg RSA -alias monitoring -validity 36500 -keystore src/test/resources/chukwa.store
-keysize 1024 -keypass chukwa -storepass chukwa -dname "cn=*, ou=chukwa, o=apache, c=US" -storetype
jks
+    Configuration conf = new Configuration();
+    conf.set(SSL_ENABLE, "true");
+    String keystore = new File(ClassLoader.getSystemResource("chukwa.store").getFile()).getAbsolutePath();
+    System.out.println("keystore = "+keystore);
+    String commonPassword = "chukwa";
+    
+    conf.set(KEYSTORE_STORE, keystore);
+    conf.set(KEYSTORE_PASSWORD, commonPassword);
+    conf.set(KEYSTORE_KEY_PASSWORD, commonPassword);
+    conf.set(TRUSTSTORE_STORE, keystore);    
+    conf.set(TRUST_PASSWORD, commonPassword);
+    /*
+    //optional properties     
+    String storeType = "pkcs12";
+    String sslProtocol = "TLS";   
+    conf.set(KEYSTORE_TYPE, storeType);
+    conf.set(TRUSTSTORE_TYPE, storeType);
+    conf.set(SSL_PROTOCOL, sslProtocol);
+    */
+    //start agent, which starts chukwa rest server
+    ChukwaAgent agent = new ChukwaAgent(conf);
+    System.out.println("Started ChukwaRestServer");
+    testSecureRestAdaptor(agent);
+    agent.shutdown();
+    System.out.println("Stopped ChukwaRestServer");
+  }
+  
+  private void testSecureRestAdaptor(ChukwaAgent agent) {
+    //add rest adaptor to collect the agent adaptor info through https
+    agent.processAddCommand("add RestAdaptor DebugProcessor https://localhost:9090/rest/v2/adaptor
5 0");
+    assertEquals(1, agent.adaptorCount());
+    final ChunkQueue eventQueue = DataFactory.getInstance().getEventQueue();
+    final List<Chunk> chunks = new ArrayList<Chunk>();
+    Thread collector = new Thread(){
+      @Override
+      public void run(){
+        try {
+          eventQueue.collect(chunks, 1);
+        } catch (InterruptedException e) {
+        }
+      }
+    };
+    
+    //wait 10s and interrupt the collector
+    collector.start();
+    try {
+      collector.join(10000);
+    } catch (InterruptedException e) {
+    }
+    collector.interrupt();    
+    
+    //make sure we collected atleast 1 chunk
+    assertTrue(chunks.size() > 0);
+    for(Chunk chunk: chunks){
+      String data = new String(chunk.getData());
+      System.out.println("Collected chunk - " + data);
+    }
+  }
+}



Mime
View raw message