Skip to content

Commit

Permalink
Merge pull request #145 from DavidVujic/windows_support
Browse files Browse the repository at this point in the history
Windows support
  • Loading branch information
DavidVujic authored Mar 2, 2019
2 parents 2cd19a9 + 3ee5126 commit 15be9ff
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 209 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build
node_modules
npm-debug.log
.idea
*.tgz
deps/zookeeper*
.DS_Store
package-lock.json
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ node_js:
- "10"
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
- "0.10"
os:
- linux
- osx
- windows
before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"; fi
install:
- npm run-script prepublish
- npm install
script: echo "Skipping tests for now"
env:
- CXX=g++-4.8
addons:
apt:
sources:
Expand Down
64 changes: 42 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,41 @@ This module is implemented on top of the ZooKeeper C API; consult the [ZK Refere
# Example

```javascript
var ZooKeeper = require ("zookeeper");
var zk = new ZooKeeper({
connect: "localhost:2181"
,timeout: 200000
,debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN
,host_order_deterministic: false
});
zk.connect(function (err) {
if(err) throw err;
console.log ("zk session established, id=%s", zk.client_id);
zk.a_create ("/node.js1", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, function (rc, error, path) {
if (rc != 0) {
console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
} else {
console.log ("created zk node %s", path);
process.nextTick(function () {
zk.close ();
});
}
});
const ZooKeeper = require('zookeeper');

function onCreate(client, rc, error, path) {
if (rc !== 0) {
console.log(`zk node create result: ${rc}, error: '${error}', path=${path}`);
} else {
console.log(`created zk node ${path}`);

process.nextTick(() => {
client.close();
});
}
}

function onConnect(client, err) {
if (err) {
throw err;
}

console.log(`zk session established, id=${client.client_id}`);
client.a_create('/node.js1', 'some value', ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, onCreate.bind(null, client));
}

const zk = new ZooKeeper({
connect: '127.0.0.1:2181',
timeout: 200000,
debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
host_order_deterministic: false,
});

try {
zk.connect(onConnect.bind(null, zk));
} catch (e) {
console.error(e);
}
```

# API Reference
Expand Down Expand Up @@ -169,6 +183,12 @@ For more details please refer to ZooKeeper docs.
* tests are not standalone, must run a zk server (easiest if you run at localhost:2181, if not you must pass the connect string to the tests)
* only asynchronous ZK methods are implemented. Hey, this is node.js ... no sync calls are allowed

# Windows support
Install `CMake` to build a ZooKeeper client on Windows. `Python 2.7.x` is currently required by the tool `node-gyp` to build the ZooKeeper client as a native Node.js Addon.

Also, run `npm install` in a Powershell window as an __Administrator__.

Windows support has been enabled mainly for supporting development, not for production.
# Implementation Notes

### NOTE on Module Status (DDOPSON-2011-11-30):
Expand Down Expand Up @@ -268,8 +288,8 @@ DDOPSON-2011-11-30 - are these issues still relevant? unknown.

# See Also

- [http://hadoop.apache.org/zookeeper/releases.html](http://hadoop.apache.org/zookeeper/releases.html)
- [http://hadoop.apache.org/zookeeper/docs/r3.3.1/zookeeperProgrammers.html#ZooKeeper+C+client+API](http://hadoop.apache.org/zookeeper/docs/r3.3.1/zookeeperProgrammers.html#ZooKeeper+C+client+API)
- [http://zookeeper.apache.org/releases.html](http://zookeeper.apache.org/releases.html)
- [http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ZooKeeper+C+client+API](http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ZooKeeper+C+client+API)
- [http://github.com/kriszyp/node-promise](http://github.com/kriszyp/node-promise)
- [http://github.com/pgriess/node-webworker](http://github.com/pgriess/node-webworker)

Expand Down
28 changes: 25 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
],
'libraries': ['<(module_root_dir)/deps/zookeeper/src/c/.libs/libzookeeper_st.a'],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'MACOSX_DEPLOYMENT_TARGET': '<!(sw_vers -productVersion)'
}
}],['OS=="linux"',{
'include_dirs': [
Expand All @@ -34,6 +35,27 @@
'<!(node -e "require(\'nan\')")'
],
'libraries': ['<(module_root_dir)/deps/zookeeper/src/c/.libs/libzookeeper_st.a'],
}],['OS=="win"',{
'defines': ['WIN32', 'USE_STATIC_LIB'],
'msvs_settings': {
'VCLinkerTool':{
'IgnoreDefaultLibraryNames': ['msvcrtd.lib', 'msvcmrtd.lib', 'libcmt.lib'],
}
},
'include_dirs': [
'<(module_root_dir)/deps/zookeeper/src/c/include',
'<(module_root_dir)/deps/zookeeper/src/c/generated',
'<!(node -e "require(\'nan\')")'
],
'libraries': [
'<(module_root_dir)/deps/zookeeper/src/c/Debug/zookeeper.lib',
'<(module_root_dir)/deps/zookeeper/src/c/Debug/hashtable.lib',
'msvcrt.lib',
'msvcmrt.lib',
'Ws2_32.lib',
'Mswsock.lib',
'AdvApi32.lib'
],
}]
]},
{
Expand All @@ -43,7 +65,7 @@
'action_name': 'build_zk_client_lib',
'inputs': [''],
'outputs': [''],
'action': ['sh', 'scripts/build.sh']
'action': ['node', 'scripts/build.js']
}]
},
{
Expand All @@ -54,7 +76,7 @@
"action_name": "symlink",
"inputs": ["<@(PRODUCT_DIR)/zookeeper.node"],
"outputs": ["<(module_root_dir)/build/zookeeper.node"],
"action": ["sh", "scripts/symlink.sh", "<@(_inputs)"]
"action": ["node", "scripts/symlink.js", "<@(_inputs)"]
}]
}],
}
57 changes: 36 additions & 21 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
#!/usr/bin/env node
var ZooKeeper = require ("./");
var zk = new ZooKeeper({
connect: "localhost:2181"
,timeout: 200000
,debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARNING
,host_order_deterministic: false
});
zk.connect(function (err) {
if(err) throw err;
console.log ("zk session established, id=%s", zk.client_id);
zk.a_create ("/node.js1", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, function (rc, error, path) {
if (rc != 0) {
console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
} else {
console.log ("created zk node %s", path);
process.nextTick(function () {
zk.close ();
});
}
});
const ZooKeeper = require('./lib/zookeeper');

function onCreate(client, rc, error, path) {
if (rc !== 0) {
console.log(`zk node create result: ${rc}, error: '${error}', path=${path}`);
} else {
console.log(`created zk node ${path}`);

process.nextTick(() => {
client.close();
});
}
}

function onConnect(client, err) {
if (err) {
throw err;
}

console.log(`zk session established, id=${client.client_id}`);
client.a_create('/node.js1', 'some value', ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, onCreate.bind(null, client));
}

const zk = new ZooKeeper({
connect: '127.0.0.1:2181',
timeout: 200000,
debug_level: ZooKeeper.ZOO_LOG_LEVEL_DEBUG,
host_order_deterministic: false,
});

zk.setLogger(console.log);

try {
zk.connect(onConnect.bind(null, zk));
} catch (e) {
console.error(e);
}
80 changes: 45 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
{
"name": "zookeeper"
,"description": "apache zookeeper client (zookeeper async API >= 3.4.0)"
,"version": "3.4.9-4"
,"author": "Yuri Finkelstein <[email protected]>"
,"contributors": [
"Yuri Finkelstein <[email protected]>"
,"Woody Anderson <[email protected]>"
,"Mark Cavage <[email protected]>"
,"Dave Dopson <[email protected]>"
,"David Trejo <[email protected]>"
,"Pooya Karimian <[email protected]>"
,"Jakub Lekstan <[email protected]>"
,"Matt Lavin <[email protected]>"
,"Roy Cheng <[email protected]>"
]
,"repository": {
"type": "git"
,"url": "https://github.com/yfinkelstein/node-zookeeper"
"name": "zookeeper",
"description": "apache zookeeper client (zookeeper async API >= 3.4.0)",
"version": "4.0.0",
"author": "Yuri Finkelstein <[email protected]>",
"contributors": [
"Yuri Finkelstein <[email protected]>",
"Woody Anderson <[email protected]>",
"Mark Cavage <[email protected]>",
"Dave Dopson <[email protected]>",
"David Trejo <[email protected]>",
"Pooya Karimian <[email protected]>",
"Jakub Lekstan <[email protected]>",
"Matt Lavin <[email protected]>",
"Roy Cheng <[email protected]>",
"David Vujic github.com/DavidVujic"
],
"repository": {
"type": "git",
"url": "https://github.com/yfinkelstein/node-zookeeper"
},
"keywords": [
"apache",
"zookeeper",
"client"
],
"dependencies": {
"async": "2.6.x",
"decompress": "4.2.x",
"decompress-targz": "4.1.x",
"lodash": "4.x",
"nan": "2.x",
"shelljs": "0.8.x"
},
"devDependencies": {
"log4js": "4.x",
"webworker": "0.x"
},
"main": "lib/index",
"scripts": {
"build": "node-gyp configure build",
"install": "node ./scripts/prepublish.js && npm run build",
"test": "pushd test; ./test; popd"
},
"engines": {
"node": ">=8.9.4"
}
,"keywords": ["apache", "zookeeper", "client"]
,"dependencies": {
"async": "~2.6.1"
,"nan": "~2.11.0"
,"lodash": "~4.17.11"
}
,"devDependencies": {
"log4js": "~3.0.5"
,"webworker": ">=0.8.4"
}
,"main": "lib/index"
,"scripts" : {
"build" : "node-gyp configure build"
,"test" : "pushd test; ./test; popd"
,"prepublish" : "./scripts/prepublish.sh"
}
,"engines": { "node": ">=0.10" }
}
6 changes: 3 additions & 3 deletions patches/ZOOKEEPER-642.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Index: src/c/src/zookeeper.c
Index: zookeeper/src/c/src/zookeeper.c
===================================================================
--- src/c/src/zookeeper.c (revision 1173876)
+++ src/c/src/zookeeper.c (working copy)
--- zookeeper/src/c/src/zookeeper.c (revision 1173876)
+++ zookeeper/src/c/src/zookeeper.c (working copy)
@@ -1543,7 +1543,9 @@
gettimeofday(&now, 0);
if(zh->next_deadline.tv_sec!=0 || zh->next_deadline.tv_usec!=0){
Expand Down
45 changes: 45 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const shell = require('shelljs');
const env = require('./env.js');
const { exec } = require('./helper.js');

function handleSunOS() {
const uname = shell.exec('uname -v');

if (uname.match('joyent_.*')) {
const res = shell.exec(`pkgin list | grep zookeeper-client-${env.zookeeperVersion}`);

if (res.code !== 0) {
shell.echo('You must install zookeeper before installing this module. Try:');
shell.echo(`pkgin install zookeeper-client-${env.zookeeperVersion}`);
}
}
}

if (env.isSunOs) {
handleSunOS();
return;
}

if (env.isAlreadyBuilt) {
shell.echo('Zookeeper has already been built');
shell.exit(0);
return;
}

shell.config.fatal = true;
shell.config.verbose = true;

shell.cd(`${env.sourceFolder}/src/c`);

if (env.isWindows) {
exec(`cmake -DWANT_SYNCAPI=OFF -DCMAKE_GENERATOR_PLATFORM=${process.arch} .`);
exec('cmake --build .');
} else {
exec('./configure --without-syncapi --disable-shared --with-pic');
exec('make');
}

shell.cd(env.rootFolder);



Loading

0 comments on commit 15be9ff

Please sign in to comment.