You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by jk...@apache.org on 2018/03/21 11:48:53 UTC

thrift git commit: THRIFT-4489: Add unix domain socket support for nodejs Client: nodejs

Repository: thrift
Updated Branches:
  refs/heads/master 9aaf29580 -> e41de0fbc


THRIFT-4489: Add unix domain socket support for nodejs
Client: nodejs

This closes #1491


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

Branch: refs/heads/master
Commit: e41de0fbcb43c51a0f1ede40207c80bd3409f99f
Parents: 9aaf295
Author: Daniel Shih <ho...@gmail.com>
Authored: Wed Mar 21 08:28:38 2018 +0800
Committer: James E. King III <jk...@apache.org>
Committed: Wed Mar 21 07:48:31 2018 -0400

----------------------------------------------------------------------
 LANGUAGES.md                             |  2 +-
 lib/nodejs/lib/thrift/connection.js      | 14 +++++++++++++-
 lib/nodejs/lib/thrift/http_connection.js | 23 +++++++++++++++--------
 lib/nodejs/lib/thrift/index.js           |  2 ++
 lib/nodejs/test/client.js                | 18 ++++++++++++++----
 lib/nodejs/test/server.js                | 18 +++++++++++++-----
 test/known_failures_Linux.json           |  9 +++++++++
 test/tests.json                          |  3 ++-
 8 files changed, 69 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/LANGUAGES.md
----------------------------------------------------------------------
diff --git a/LANGUAGES.md b/LANGUAGES.md
index 10b2e15..779d9b6 100644
--- a/LANGUAGES.md
+++ b/LANGUAGES.md
@@ -234,7 +234,7 @@ The Language/Library Levels indicate the minimum and maximum versions that are u
 <!-- Since -----------------><td>0.6.0</td>
 <!-- Build Systems ---------><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td>
 <!-- Language Levels -------><td>6.x</td><td>8.x</td>
-<!-- Low-Level Transports --><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
+<!-- Low-Level Transports --><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
 <!-- Transport Wrappers ----><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td>
 <!-- Protocols -------------><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td>
 <!-- Servers ---------------><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cgrn.png" alt="Yes"/></td><td><img src="doc/images/cred.png" alt=""/></td><td><img src="doc/images/cred.png" alt=""/></td>

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/lib/nodejs/lib/thrift/connection.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 273339b..b545454 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -232,7 +232,11 @@ Connection.prototype.connection_gone = function () {
        return;
     }
 
-    self.connection.connect(self.port, self.host);
+    if (self.path !== undefined) {
+      self.connection.connect(self.path);
+    } else {
+      self.connection.connect(self.port, self.host);
+    }
     self.retry_timer = null;
   }, this.retry_delay);
 };
@@ -246,6 +250,14 @@ exports.createConnection = function(host, port, options) {
   return connection;
 };
 
+exports.createUDSConnection = function(path, options) {
+  var stream = net.createConnection(path);
+  var connection = new Connection(stream, options);
+  connection.path = path;
+
+  return connection;
+};
+
 exports.createSSLConnection = function(host, port, options) {
   if (!('secureProtocol' in options) && !('secureOptions' in options)) {
     options.secureProtocol = "SSLv23_method";

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/lib/nodejs/lib/thrift/http_connection.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/lib/thrift/http_connection.js b/lib/nodejs/lib/thrift/http_connection.js
index 5085538..4f5378f 100644
--- a/lib/nodejs/lib/thrift/http_connection.js
+++ b/lib/nodejs/lib/thrift/http_connection.js
@@ -59,8 +59,6 @@ var createClient = require('./create_client');
  * Initializes a Thrift HttpConnection instance (use createHttpConnection() rather than
  *    instantiating directly).
  * @constructor
- * @param {string} host - The host name or IP to connect to.
- * @param {number} port - The TCP port to connect to.
  * @param {ConnectOptions} options - The configuration options to use.
  * @throws {error} Exceptions other than InputBufferUnderrunError are rethrown
  * @event {error} The "error" event is fired when a Node.js error event occurs during
@@ -71,15 +69,16 @@ var createClient = require('./create_client');
  *     semantics implemented over the Node.js http.request() method.
  * @see {@link createHttpConnection}
  */
-var HttpConnection = exports.HttpConnection = function(host, port, options) {
+var HttpConnection = exports.HttpConnection = function(options) {
   //Initialize the emitter base object
   EventEmitter.call(this);
 
   //Set configuration
   var self = this;
   this.options = options || {};
-  this.host = host;
-  this.port = port;
+  this.host = this.options.host;
+  this.port = this.options.port;
+  this.socketPath = this.options.socketPath;
   this.https = this.options.https || false;
   this.transport = this.options.transport || TBufferedTransport;
   this.protocol = this.options.protocol || TBinaryProtocol;
@@ -87,7 +86,8 @@ var HttpConnection = exports.HttpConnection = function(host, port, options) {
   //Prepare Node.js options
   this.nodeOptions = {
     host: this.host,
-    port: this.port || 80,
+    port: this.port,
+    socketPath: this.socketPath,
     path: this.options.path || '/',
     method: 'POST',
     headers: this.options.headers || {},
@@ -238,7 +238,14 @@ HttpConnection.prototype.write = function(data) {
  * @see {@link ConnectOptions}
  */
 exports.createHttpConnection = function(host, port, options) {
-  return new HttpConnection(host, port, options);
+  options.host = host;
+  options.port = port || 80;
+  return new HttpConnection(options);
+};
+
+exports.createHttpUDSConnection = function(path, options) {
+  options.socketPath = path;
+  return new HttpConnection(options);
 };
 
 exports.createHttpClient = createClient
@@ -253,4 +260,4 @@ function THTTPException(statusCode, response) {
   this.type = thrift.TApplicationExceptionType.PROTOCOL_ERROR;
   this.message = "Received a response with a bad HTTP status code: " + response.statusCode;
 }
-util.inherits(THTTPException, thrift.TApplicationException);
\ No newline at end of file
+util.inherits(THTTPException, thrift.TApplicationException);

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/lib/nodejs/lib/thrift/index.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/lib/thrift/index.js b/lib/nodejs/lib/thrift/index.js
index 020726d..b09953d 100644
--- a/lib/nodejs/lib/thrift/index.js
+++ b/lib/nodejs/lib/thrift/index.js
@@ -27,6 +27,7 @@ var connection = require('./connection');
 exports.Connection = connection.Connection;
 exports.createClient = connection.createClient;
 exports.createConnection = connection.createConnection;
+exports.createUDSConnection = connection.createUDSConnection;
 exports.createSSLConnection = connection.createSSLConnection;
 exports.createStdIOClient = connection.createStdIOClient;
 exports.createStdIOConnection = connection.createStdIOConnection;
@@ -34,6 +35,7 @@ exports.createStdIOConnection = connection.createStdIOConnection;
 var httpConnection = require('./http_connection');
 exports.HttpConnection = httpConnection.HttpConnection;
 exports.createHttpConnection = httpConnection.createHttpConnection;
+exports.createHttpUDSConnection = httpConnection.createHttpUDSConnection;
 exports.createHttpClient = httpConnection.createHttpClient;
 
 var wsConnection = require('./ws_connection');

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/lib/nodejs/test/client.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/test/client.js b/lib/nodejs/test/client.js
index 006fad2..55839f6 100644
--- a/lib/nodejs/test/client.js
+++ b/lib/nodejs/test/client.js
@@ -36,6 +36,7 @@ program
   .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http) [transport]')
   .option('--port <port>', 'Set thrift server port number to connect', 9090)
   .option('--host <host>', 'Set thrift server host to connect', 'localhost')
+  .option('--domain-socket <path>', 'Set thrift server unix domain socket to connect')
   .option('--ssl', 'use SSL transport')
   .option('--promise', 'test with promise style functions')
   .option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
@@ -43,6 +44,7 @@ program
 
 var host = program.host;
 var port = program.port;
+var domainSocket = program.domainSocket;
 var type = program.type;
 var ssl = program.ssl;
 var promise = program.promise;
@@ -83,11 +85,19 @@ var client;
 var testDriver = promise ? ThriftTestDriverPromise : ThriftTestDriver;
 
 if (type === 'tcp' || type === 'multiplex') {
-  connection = ssl ?
-    thrift.createSSLConnection(host, port, options) :
-    thrift.createConnection(host, port, options);
+  if (domainSocket) {
+    connection = thrift.createUDSConnection(domainSocket, options);
+  } else {
+    connection = ssl ?
+      thrift.createSSLConnection(host, port, options) :
+      thrift.createConnection(host, port, options);
+  }
 } else if (type === 'http') {
-  connection = thrift.createHttpConnection(host, port, options);
+  if (domainSocket) {
+    connection = thrift.createHttpUDSConnection(domainSocket, options);
+  } else {
+    connection = thrift.createHttpConnection(host, port, options);
+  }
 } else if (type === 'websocket') {
   connection = thrift.createWSConnection(host, port, options);
   connection.open();

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/lib/nodejs/test/server.js
----------------------------------------------------------------------
diff --git a/lib/nodejs/test/server.js b/lib/nodejs/test/server.js
index 8f2e06b..030d28b 100644
--- a/lib/nodejs/test/server.js
+++ b/lib/nodejs/test/server.js
@@ -36,11 +36,13 @@ program
   .option('-t, --transport <transport>', 'Set thrift transport (buffered|framed|http)', 'buffered')
   .option('--ssl', 'use ssl transport')
   .option('--port <port>', 'Set thrift server port', 9090)
+  .option('--domain-socket <path>', 'Set thift server unix domain socket')
   .option('--promise', 'test with promise style functions')
   .option('-t, --type <type>', 'Select server type (http|multiplex|tcp|websocket)', 'tcp')
   .parse(process.argv);
 
 var port = program.port;
+var domainSocket = program.domainSocket;
 var type = program.type;
 var ssl = program.ssl;
 var promise = program.promise;
@@ -88,10 +90,12 @@ if (type === 'multiplex') {
 }
 
 if (ssl) {
-  options.tls = {
-    key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
-    cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
-  };
+  if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+    options.tls = {
+      key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
+      cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
+    };
+  }
 }
 
 var server;
@@ -103,4 +107,8 @@ if (type === 'tcp') {
   server = thrift.createWebServer(options);
 }
 
-server.listen(port);
+if (domainSocket) {
+  server.listen(domainSocket);
+} else if (type === 'tcp' || type === 'multiplex' || type === 'http' || type === 'websocket') {
+  server.listen(port);
+}

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/test/known_failures_Linux.json
----------------------------------------------------------------------
diff --git a/test/known_failures_Linux.json b/test/known_failures_Linux.json
index a886098..16a912d 100644
--- a/test/known_failures_Linux.json
+++ b/test/known_failures_Linux.json
@@ -67,16 +67,22 @@
   "cpp-java_multij_http-ip-ssl",
   "cpp-nodejs_binary_http-ip",
   "cpp-nodejs_binary_http-ip-ssl",
+  "cpp-nodejs_binary_http-domain",
   "cpp-nodejs_compact_http-ip",
   "cpp-nodejs_compact_http-ip-ssl",
+  "cpp-nodejs_compact_http-domain",
   "cpp-nodejs_json_http-ip",
   "cpp-nodejs_json_http-ip-ssl",
+  "cpp-nodejs_json_http-domain",
   "cpp-nodejs_multi-binary_http-ip",
   "cpp-nodejs_multi-binary_http-ip-ssl",
+  "cpp-nodejs_multi-binary_http-domain",
   "cpp-nodejs_multic-compact_http-ip",
   "cpp-nodejs_multic-compact_http-ip-ssl",
+  "cpp-nodejs_multic-compact_http-domain",
   "cpp-nodejs_multij-json_http-ip",
   "cpp-nodejs_multij-json_http-ip-ssl",
+  "cpp-nodejs_multij-json_http-domain",
   "cpp-rs_multi_buffered-ip",
   "cpp-rs_multi_framed-ip",
   "cpp-rs_multic_buffered-ip",
@@ -235,10 +241,13 @@
   "netcore-csharp_json_framed-ip-ssl",
   "nodejs-cpp_binary_http-ip",
   "nodejs-cpp_binary_http-ip-ssl",
+  "nodejs-cpp_binary_http-domain",
   "nodejs-cpp_compact_http-ip",
   "nodejs-cpp_compact_http-ip-ssl",
+  "nodejs-cpp_compact_http-domain",
   "nodejs-cpp_json_http-ip",
   "nodejs-cpp_json_http-ip-ssl",
+  "nodejs-cpp_json_http-domain",
   "nodejs-d_binary_http-ip",
   "nodejs-d_binary_http-ip-ssl",
   "nodejs-d_compact_http-ip",

http://git-wip-us.apache.org/repos/asf/thrift/blob/e41de0fb/test/tests.json
----------------------------------------------------------------------
diff --git a/test/tests.json b/test/tests.json
index 99050a1..511be5f 100644
--- a/test/tests.json
+++ b/test/tests.json
@@ -192,7 +192,8 @@
     ],
     "sockets": [
       "ip",
-      "ip-ssl"
+      "ip-ssl",
+      "domain"
     ],
     "protocols": [
       "compact",