flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hshreedha...@apache.org
Subject git commit: FLUME-1867. Add an option to provide hostname for HTTPSource.
Date Tue, 07 May 2013 20:45:53 GMT
Updated Branches:
  refs/heads/flume-1.4 a4a4eb8b4 -> 26f3bc18e


FLUME-1867. Add an option to provide hostname for HTTPSource.

(Ivan via Hari Shreedharan)


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

Branch: refs/heads/flume-1.4
Commit: 26f3bc18e68b3a35d0cd247d99543683771a110f
Parents: a4a4eb8
Author: Hari Shreedharan <hshreedharan@apache.org>
Authored: Tue May 7 13:44:41 2013 -0700
Committer: Hari Shreedharan <hshreedharan@apache.org>
Committed: Tue May 7 13:45:38 2013 -0700

----------------------------------------------------------------------
 .../org/apache/flume/source/http/HTTPSource.java   |   33 +++++++++++----
 .../http/HTTPSourceConfigurationConstants.java     |    1 +
 .../apache/flume/source/http/TestHTTPSource.java   |   20 +++++----
 3 files changed, 36 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/26f3bc18/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
index b46dc0e..a96fc0d 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
@@ -19,24 +19,27 @@ package org.apache.flume.source.http;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Throwables;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import org.apache.flume.ChannelException;
 import org.apache.flume.Context;
 import org.apache.flume.Event;
 import org.apache.flume.EventDrivenSource;
 import org.apache.flume.conf.Configurable;
 import org.apache.flume.source.AbstractSource;
+import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
 import org.mortbay.jetty.servlet.ServletHolder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * A source which accepts Flume Events by HTTP POST and GET. GET should be used
  * for experimentation only. HTTP requests are converted into flume events by a
@@ -79,6 +82,7 @@ public class HTTPSource extends AbstractSource implements
   private static final Logger LOG = LoggerFactory.getLogger(HTTPSource.class);
   private volatile Integer port;
   private volatile Server srv;
+  private volatile String host;
   private HTTPSourceHandler handler;
 
   @Override
@@ -86,6 +90,8 @@ public class HTTPSource extends AbstractSource implements
     try {
       port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT);
       checkPort();
+      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_HOST);
+      checkHost();
       String handlerClassName = context.getString(
               HTTPSourceConfigurationConstants.CONFIG_HANDLER,
               HTTPSourceConfigurationConstants.DEFAULT_HANDLER);
@@ -113,14 +119,23 @@ public class HTTPSource extends AbstractSource implements
     }
   }
 
-  @Override
+    private void checkHost() {
+        Preconditions.checkNotNull(host, "HTTPSource requires a hostname to be"
+                + "specified");
+    }
+
+    @Override
   public void start() {
     checkPort();
     Preconditions.checkState(srv == null,
             "Running HTTP Server found in source: " + getName()
             + " before I started one."
             + "Will not attempt to start.");
-    srv = new Server(port);
+    srv = new Server();
+    SocketConnector connector = new SocketConnector();
+    connector.setPort(port);
+    connector.setHost(host);
+    srv.setConnectors(new Connector[] { connector });
     try {
       org.mortbay.jetty.servlet.Context root =
               new org.mortbay.jetty.servlet.Context(

http://git-wip-us.apache.org/repos/asf/flume/blob/26f3bc18/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
index 55800f8..e7b3c7a 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
@@ -27,6 +27,7 @@ public class HTTPSourceConfigurationConstants {
   public static final String CONFIG_HANDLER = "handler";
   public static final String CONFIG_HANDLER_PREFIX =
           CONFIG_HANDLER + ".";
+  public static final String CONFIG_HOST = "host";
 
   public static final String DEFAULT_HANDLER =
           "org.apache.flume.source.http.JSONHandler";

http://git-wip-us.apache.org/repos/asf/flume/blob/26f3bc18/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
index 0a1b07d..59d1cb1 100644
--- a/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
+++ b/flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
@@ -17,19 +17,10 @@
  */
 package org.apache.flume.source.http;
 
-import static org.fest.reflect.core.Reflection.*;
-
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import javax.servlet.http.HttpServletResponse;
 import junit.framework.Assert;
 import org.apache.flume.Channel;
 import org.apache.flume.ChannelSelector;
@@ -50,6 +41,16 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+
+import static org.fest.reflect.core.Reflection.field;
+
 /**
  *
  */
@@ -82,6 +83,7 @@ public class TestHTTPSource {
     Context context = new Context();
 
     context.put("port", String.valueOf(41404));
+    context.put("host", "0.0.0.0");
 
     Configurables.configure(source, context);
     source.start();


Mime
View raw message