Skip to content

Commit

Permalink
[ZEPPELIN-38] Add config setting for listen address
Browse files Browse the repository at this point in the history
This is useful when running in a Multi-host environment

Author: Sebastian YEPES <[email protected]>

Closes apache#32 from syepes/add_cfg_listen_addr and squashes the following commits:

6df7373 [Sebastian YEPES] Add config setting for listen address
  • Loading branch information
syepes authored and Leemoonsoo committed Apr 11, 2015
1 parent 84839c7 commit c0a7d08
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
12 changes: 12 additions & 0 deletions conf/zeppelin-site.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@

<configuration>

<property>
<name>zeppelin.server.addr</name>
<value>0.0.0.0</value>
<description>Server address</description>
</property>

<property>
<name>zeppelin.server.port</name>
<value>8080</value>
<description>Server port. port+1 is used for web socket.</description>
</property>

<property>
<name>zeppelin.websocket.addr</name>
<value>0.0.0.0</value>
<description>Testing websocket address</description>
</property>

<!-- If the port value is negative, then it'll default to the server
port + 1.
-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private static Server setupJettyServer(ZeppelinConfiguration conf)
int timeout = 1000 * 30;
connector.setMaxIdleTime(timeout);
connector.setSoLingerTime(-1);
connector.setHost(conf.getServerAddress());
connector.setPort(conf.getServerPort());

final Server server = new Server();
Expand All @@ -156,7 +157,7 @@ private static Server setupJettyServer(ZeppelinConfiguration conf)
private static NotebookServer setupNotebookServer(ZeppelinConfiguration conf)
throws Exception {

NotebookServer server = new NotebookServer(conf.getWebSocketPort());
NotebookServer server = new NotebookServer(conf.getWebSocketAddress(), conf.getWebSocketPort());

// Default WebSocketServer uses unencrypted connector, so only need to
// change the connector if SSL should be used.
Expand Down Expand Up @@ -233,7 +234,7 @@ private static ServletContextHandler setupSwaggerContextHandler(
swaggerServlet.setInitParameter("api.version", "1.0.0");
swaggerServlet.setInitParameter(
"swagger.api.basepath",
"http://localhost:" + conf.getServerPort() + "/api");
"http://" + conf.getServerAddress() + ":" + conf.getServerPort() + "/api");
swaggerServlet.setInitOrder(2);

// Setup the handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,25 @@
public class NotebookServer extends WebSocketServer implements JobListenerFactory {

private static final Logger LOG = LoggerFactory.getLogger(NotebookServer.class);
private static final String DEFAULT_ADDR = "0.0.0.0";
private static final int DEFAULT_PORT = 8282;

private static void creatingwebSocketServerLog(int port) {
LOG.info("Create zeppelin websocket on port {}", port);
private static void creatingwebSocketServerLog(String address, int port) {
LOG.info("Create zeppelin websocket on {}:{}", address, port);
}

Gson gson = new Gson();
Map<String, List<WebSocket>> noteSocketMap = new HashMap<String, List<WebSocket>>();
List<WebSocket> connectedSockets = new LinkedList<WebSocket>();

public NotebookServer() {
super(new InetSocketAddress(DEFAULT_PORT));
creatingwebSocketServerLog(DEFAULT_PORT);
super(new InetSocketAddress(DEFAULT_ADDR, DEFAULT_PORT));
creatingwebSocketServerLog(DEFAULT_ADDR, DEFAULT_PORT);
}

public NotebookServer(int port) {
super(new InetSocketAddress(port));
creatingwebSocketServerLog(port);
public NotebookServer(String address, int port) {
super(new InetSocketAddress(address, port));
creatingwebSocketServerLog(address, port);
}

private Notebook notebook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,18 @@ public boolean useClientAuth() {
return getBoolean(ConfVars.ZEPPELIN_SSL_CLIENT_AUTH);
}

public String getServerAddress() {
return getString(ConfVars.ZEPPELIN_ADDR);
}

public int getServerPort() {
return getInt(ConfVars.ZEPPELIN_PORT);
}

public String getWebSocketAddress() {
return getString(ConfVars.ZEPPELIN_WEBSOCKET_ADDR);
}

public int getWebSocketPort() {
int port = getInt(ConfVars.ZEPPELIN_WEBSOCKET_PORT);
if (port < 0) {
Expand Down Expand Up @@ -356,8 +364,10 @@ public String getRelativeDir(String path) {
*/
public static enum ConfVars {
ZEPPELIN_HOME("zeppelin.home", "../"),
ZEPPELIN_ADDR("zeppelin.server.addr", "0.0.0.0"),
ZEPPELIN_PORT("zeppelin.server.port", 8080),
// negative websocket port denotes that server port + 1 should be used
ZEPPELIN_WEBSOCKET_ADDR("zeppelin.websocket.addr", "0.0.0.0"),
ZEPPELIN_WEBSOCKET_PORT("zeppelin.websocket.port", -1),
ZEPPELIN_SSL("zeppelin.ssl", false),
ZEPPELIN_SSL_CLIENT_AUTH("zeppelin.ssl.client.auth", false),
Expand Down

0 comments on commit c0a7d08

Please sign in to comment.