add hive metastore http javascript client

This commit is contained in:
Shirong-Liang 2019-11-07 17:00:10 -08:00
Родитель 6d097e53ee
Коммит 3010186f2c
10 изменённых файлов: 51626 добавлений и 0 удалений

7
Makefile Normal file
Просмотреть файл

@ -0,0 +1,7 @@
genthrift:
rm -rf ./src/gen-nodejs/*
mkdir -p ./src/gen-nodejs
thrift -r --gen js:node -out ./src/gen-nodejs ./thrift/hive_metastore.thrift
npm install -g dts-gen
npm install -g ./src/
dts-gen -m hive-metastore-http-client -f src/hive-metastore-http-client.d.ts

Просмотреть файл

@ -0,0 +1,83 @@
var thrift = require("thrift");
var ThriftHiveMetastore = require("./gen-nodejs/ThriftHiveMetastore.js");
var kerberos = require('kerberos');
const mechOID = kerberos.GSS_MECH_OID_KRB5;
var HiveMetaStoreClient = function (host, port, options) {
var connection = thrift.createHttpConnection(host, port, options);
this.client = thrift.createHttpClient(ThriftHiveMetastore, connection);
}
HiveMetaStoreClient.prototype.get_all_databases = function (callback) {
return this.client.get_all_databases(callback);
}
HiveMetaStoreClient.prototype.get_databases = function (pattern, callback) {
return this.client.get_databases(pattern, callback);
}
HiveMetaStoreClient.prototype.get_database = function (dbName, callback) {
return this.client.get_database(dbName, callback);
}
HiveMetaStoreClient.prototype.get_all_tables = function (dbName, callback) {
return this.client.get_all_tables(dbName, callback);
}
HiveMetaStoreClient.prototype.get_tables_by_type = function (dbName, pattern, tblType, callback) {
return this.client.get_tables_by_type(dbName, pattern, tblType, callback);
}
HiveMetaStoreClient.prototype.get_table = function (dbName, tblName, callback) {
return this.client.get_table(dbName, tblName, callback);
}
HiveMetaStoreClient.prototype.get_partition_names = function (dbName, tblName, max_parts, callback) {
return this.client.get_partition_names(dbName, tblName, max_parts, callback);
}
HiveMetaStoreClient.prototype.get_partitions = function (dbName, tblName, max_parts, callback) {
return this.client.get_partitions(dbName, tblName, max_parts, callback);
}
async function getKerberosToken(hostname) {
let service = 'HTTP/' + hostname;
if(process.platform == 'linux'){
service = 'HTTP@' + hostname;
}
let kerberosClient = await kerberos.initializeClient(service, { mechOID });
let kerberosToken = await kerberosClient.step('');
return kerberosToken;
}
module.exports.DefaultOptions = {
transport: thrift.TBufferedTransport,
protocol: thrift.TJSONProtocol,
path: "/gateway/default/hmshttpthrift/api/hms",
headers: { "Connection": "close" },
https: true
};
module.exports.CreateClient = async function (host, port, authType, params, callback) {
if (!host || !port || !authType){
throw new Error('Input required for fields: {host, port, authType}');
}
let options = params.options || this.DefaultOptions;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
if (authType == 'basic'){
if (!params.username || !params.password){
throw new Error('Input required for fields:{username, password} for HiveMetaStore API when using basic authTpye');
}
let auth = 'Basic ' + Buffer.from(params.username + ':' + params.password).toString('base64');
options.headers.Authorization = auth;
} else if(authType == 'kerberos'){
let kerberosToken = await getKerberosToken(host);
options.headers.Authorization = `Negotiate ${kerberosToken}`;
}
let client = new HiveMetaStoreClient(host, port, options);
if (typeof callback === 'function'){
callback(client)
}else{
return client
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,16 @@
//
// Autogenerated by Thrift Compiler (0.9.1)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
var Thrift = require('thrift').Thrift;
var ttypes = module.exports = {};
ttypes.fb_status = {
'DEAD' : 0,
'STARTING' : 1,
'ALIVE' : 2,
'STOPPING' : 3,
'STOPPED' : 4,
'WARNING' : 5
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

1309
src/hive-metastore-http-client.d.ts поставляемый Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу

16
src/package.json Normal file
Просмотреть файл

@ -0,0 +1,16 @@
{
"name": "hive-metastore-http-client",
"version": "1.0.0",
"description": "Hive MetaStore Thrift client library for HTTP Server",
"main": "HiveMetaStoreClientFactory.js",
"scripts": {
"build": "thrift thrift/hive_metastore.thrift",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Microsoft Corporation",
"license": "MIT",
"dependencies": {
"kerberos": "^1.1.3",
"thrift": "^0.12.0"
}
}

113
thrift/fb303.thrift Normal file
Просмотреть файл

@ -0,0 +1,113 @@
/*
* 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.
*/
/**
* fb303.thrift
*/
namespace java com.facebook.fb303
namespace cpp facebook.fb303
namespace perl Facebook.FB303
namespace netcore Facebook.FB303.Test
/**
* Common status reporting mechanism across all services
*/
enum fb_status {
DEAD = 0,
STARTING = 1,
ALIVE = 2,
STOPPING = 3,
STOPPED = 4,
WARNING = 5,
}
/**
* Standard base service
*/
service FacebookService {
/**
* Returns a descriptive name of the service
*/
string getName(),
/**
* Returns the version of the service
*/
string getVersion(),
/**
* Gets the status of this service
*/
fb_status getStatus(),
/**
* User friendly description of status, such as why the service is in
* the dead or warning state, or what is being started or stopped.
*/
string getStatusDetails(),
/**
* Gets the counters for this service
*/
map<string, i64> getCounters(),
/**
* Gets the value of a single counter
*/
i64 getCounter(1: string key),
/**
* Sets an option
*/
void setOption(1: string key, 2: string value),
/**
* Gets an option
*/
string getOption(1: string key),
/**
* Gets all options
*/
map<string, string> getOptions(),
/**
* Returns a CPU profile over the given time interval (client and server
* must agree on the profile format).
*/
string getCpuProfile(1: i32 profileDurationInSec),
/**
* Returns the unix time that the server has been running since
*/
i64 aliveSince(),
/**
* Tell the server to reload its configuration, reopen log files, etc
*/
oneway void reinitialize(),
/**
* Suggest a shutdown to the server
*/
oneway void shutdown(),
}

1529
thrift/hive_metastore.thrift Normal file

Разница между файлами не показана из-за своего большого размера Загрузить разницу