Skip to content

Commit 15be9ff

Browse files
authored
Merge pull request #145 from DavidVujic/windows_support
Windows support
2 parents 2cd19a9 + 3ee5126 commit 15be9ff

17 files changed

+478
-209
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
build
22
node_modules
33
npm-debug.log
4+
.idea
45
*.tgz
56
deps/zookeeper*
7+
.DS_Store
8+
package-lock.json

.travis.yml

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ node_js:
33
- "10"
44
- "9"
55
- "8"
6-
- "7"
7-
- "6"
8-
- "5"
9-
- "4"
10-
- "0.10"
6+
os:
7+
- linux
8+
- osx
9+
- windows
10+
before_install:
11+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export CXX=g++-4.8; fi
12+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"; fi
1113
install:
12-
- npm run-script prepublish
1314
- npm install
1415
script: echo "Skipping tests for now"
15-
env:
16-
- CXX=g++-4.8
1716
addons:
1817
apt:
1918
sources:

README.md

+42-22
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,41 @@ This module is implemented on top of the ZooKeeper C API; consult the [ZK Refere
77
# Example
88

99
```javascript
10-
var ZooKeeper = require ("zookeeper");
11-
var zk = new ZooKeeper({
12-
connect: "localhost:2181"
13-
,timeout: 200000
14-
,debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN
15-
,host_order_deterministic: false
16-
});
17-
zk.connect(function (err) {
18-
if(err) throw err;
19-
console.log ("zk session established, id=%s", zk.client_id);
20-
zk.a_create ("/node.js1", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, function (rc, error, path) {
21-
if (rc != 0) {
22-
console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
23-
} else {
24-
console.log ("created zk node %s", path);
25-
process.nextTick(function () {
26-
zk.close ();
27-
});
28-
}
29-
});
10+
const ZooKeeper = require('zookeeper');
11+
12+
function onCreate(client, rc, error, path) {
13+
if (rc !== 0) {
14+
console.log(`zk node create result: ${rc}, error: '${error}', path=${path}`);
15+
} else {
16+
console.log(`created zk node ${path}`);
17+
18+
process.nextTick(() => {
19+
client.close();
20+
});
21+
}
22+
}
23+
24+
function onConnect(client, err) {
25+
if (err) {
26+
throw err;
27+
}
28+
29+
console.log(`zk session established, id=${client.client_id}`);
30+
client.a_create('/node.js1', 'some value', ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, onCreate.bind(null, client));
31+
}
32+
33+
const zk = new ZooKeeper({
34+
connect: '127.0.0.1:2181',
35+
timeout: 200000,
36+
debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARN,
37+
host_order_deterministic: false,
3038
});
39+
40+
try {
41+
zk.connect(onConnect.bind(null, zk));
42+
} catch (e) {
43+
console.error(e);
44+
}
3145
```
3246

3347
# API Reference
@@ -169,6 +183,12 @@ For more details please refer to ZooKeeper docs.
169183
* 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)
170184
* only asynchronous ZK methods are implemented. Hey, this is node.js ... no sync calls are allowed
171185

186+
# Windows support
187+
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.
188+
189+
Also, run `npm install` in a Powershell window as an __Administrator__.
190+
191+
Windows support has been enabled mainly for supporting development, not for production.
172192
# Implementation Notes
173193

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

269289
# See Also
270290

271-
- [http://hadoop.apache.org/zookeeper/releases.html](http://hadoop.apache.org/zookeeper/releases.html)
272-
- [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)
291+
- [http://zookeeper.apache.org/releases.html](http://zookeeper.apache.org/releases.html)
292+
- [http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ZooKeeper+C+client+API](http://zookeeper.apache.org/doc/current/zookeeperProgrammers.html#ZooKeeper+C+client+API)
273293
- [http://github.com/kriszyp/node-promise](http://github.com/kriszyp/node-promise)
274294
- [http://github.com/pgriess/node-webworker](http://github.com/pgriess/node-webworker)
275295

binding.gyp

+25-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
],
2626
'libraries': ['<(module_root_dir)/deps/zookeeper/src/c/.libs/libzookeeper_st.a'],
2727
'xcode_settings': {
28-
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES'
28+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
29+
'MACOSX_DEPLOYMENT_TARGET': '<!(sw_vers -productVersion)'
2930
}
3031
}],['OS=="linux"',{
3132
'include_dirs': [
@@ -34,6 +35,27 @@
3435
'<!(node -e "require(\'nan\')")'
3536
],
3637
'libraries': ['<(module_root_dir)/deps/zookeeper/src/c/.libs/libzookeeper_st.a'],
38+
}],['OS=="win"',{
39+
'defines': ['WIN32', 'USE_STATIC_LIB'],
40+
'msvs_settings': {
41+
'VCLinkerTool':{
42+
'IgnoreDefaultLibraryNames': ['msvcrtd.lib', 'msvcmrtd.lib', 'libcmt.lib'],
43+
}
44+
},
45+
'include_dirs': [
46+
'<(module_root_dir)/deps/zookeeper/src/c/include',
47+
'<(module_root_dir)/deps/zookeeper/src/c/generated',
48+
'<!(node -e "require(\'nan\')")'
49+
],
50+
'libraries': [
51+
'<(module_root_dir)/deps/zookeeper/src/c/Debug/zookeeper.lib',
52+
'<(module_root_dir)/deps/zookeeper/src/c/Debug/hashtable.lib',
53+
'msvcrt.lib',
54+
'msvcmrt.lib',
55+
'Ws2_32.lib',
56+
'Mswsock.lib',
57+
'AdvApi32.lib'
58+
],
3759
}]
3860
]},
3961
{
@@ -43,7 +65,7 @@
4365
'action_name': 'build_zk_client_lib',
4466
'inputs': [''],
4567
'outputs': [''],
46-
'action': ['sh', 'scripts/build.sh']
68+
'action': ['node', 'scripts/build.js']
4769
}]
4870
},
4971
{
@@ -54,7 +76,7 @@
5476
"action_name": "symlink",
5577
"inputs": ["<@(PRODUCT_DIR)/zookeeper.node"],
5678
"outputs": ["<(module_root_dir)/build/zookeeper.node"],
57-
"action": ["sh", "scripts/symlink.sh", "<@(_inputs)"]
79+
"action": ["node", "scripts/symlink.js", "<@(_inputs)"]
5880
}]
5981
}],
6082
}

example.js

+36-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
#!/usr/bin/env node
2-
var ZooKeeper = require ("./");
3-
var zk = new ZooKeeper({
4-
connect: "localhost:2181"
5-
,timeout: 200000
6-
,debug_level: ZooKeeper.ZOO_LOG_LEVEL_WARNING
7-
,host_order_deterministic: false
8-
});
9-
zk.connect(function (err) {
10-
if(err) throw err;
11-
console.log ("zk session established, id=%s", zk.client_id);
12-
zk.a_create ("/node.js1", "some value", ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, function (rc, error, path) {
13-
if (rc != 0) {
14-
console.log ("zk node create result: %d, error: '%s', path=%s", rc, error, path);
15-
} else {
16-
console.log ("created zk node %s", path);
17-
process.nextTick(function () {
18-
zk.close ();
19-
});
20-
}
21-
});
1+
const ZooKeeper = require('./lib/zookeeper');
2+
3+
function onCreate(client, rc, error, path) {
4+
if (rc !== 0) {
5+
console.log(`zk node create result: ${rc}, error: '${error}', path=${path}`);
6+
} else {
7+
console.log(`created zk node ${path}`);
8+
9+
process.nextTick(() => {
10+
client.close();
11+
});
12+
}
13+
}
14+
15+
function onConnect(client, err) {
16+
if (err) {
17+
throw err;
18+
}
19+
20+
console.log(`zk session established, id=${client.client_id}`);
21+
client.a_create('/node.js1', 'some value', ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, onCreate.bind(null, client));
22+
}
23+
24+
const zk = new ZooKeeper({
25+
connect: '127.0.0.1:2181',
26+
timeout: 200000,
27+
debug_level: ZooKeeper.ZOO_LOG_LEVEL_DEBUG,
28+
host_order_deterministic: false,
2229
});
30+
31+
zk.setLogger(console.log);
32+
33+
try {
34+
zk.connect(onConnect.bind(null, zk));
35+
} catch (e) {
36+
console.error(e);
37+
}

package.json

+45-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
{
2-
"name": "zookeeper"
3-
,"description": "apache zookeeper client (zookeeper async API >= 3.4.0)"
4-
,"version": "3.4.9-4"
5-
,"author": "Yuri Finkelstein <[email protected]>"
6-
,"contributors": [
7-
"Yuri Finkelstein <[email protected]>"
8-
,"Woody Anderson <[email protected]>"
9-
,"Mark Cavage <[email protected]>"
10-
,"Dave Dopson <[email protected]>"
11-
,"David Trejo <[email protected]>"
12-
,"Pooya Karimian <[email protected]>"
13-
,"Jakub Lekstan <[email protected]>"
14-
,"Matt Lavin <[email protected]>"
15-
,"Roy Cheng <[email protected]>"
16-
]
17-
,"repository": {
18-
"type": "git"
19-
,"url": "https://github.com/yfinkelstein/node-zookeeper"
2+
"name": "zookeeper",
3+
"description": "apache zookeeper client (zookeeper async API >= 3.4.0)",
4+
"version": "4.0.0",
5+
"author": "Yuri Finkelstein <[email protected]>",
6+
"contributors": [
7+
"Yuri Finkelstein <[email protected]>",
8+
"Woody Anderson <[email protected]>",
9+
"Mark Cavage <[email protected]>",
10+
"Dave Dopson <[email protected]>",
11+
"David Trejo <[email protected]>",
12+
"Pooya Karimian <[email protected]>",
13+
"Jakub Lekstan <[email protected]>",
14+
"Matt Lavin <[email protected]>",
15+
"Roy Cheng <[email protected]>",
16+
"David Vujic github.com/DavidVujic"
17+
],
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/yfinkelstein/node-zookeeper"
21+
},
22+
"keywords": [
23+
"apache",
24+
"zookeeper",
25+
"client"
26+
],
27+
"dependencies": {
28+
"async": "2.6.x",
29+
"decompress": "4.2.x",
30+
"decompress-targz": "4.1.x",
31+
"lodash": "4.x",
32+
"nan": "2.x",
33+
"shelljs": "0.8.x"
34+
},
35+
"devDependencies": {
36+
"log4js": "4.x",
37+
"webworker": "0.x"
38+
},
39+
"main": "lib/index",
40+
"scripts": {
41+
"build": "node-gyp configure build",
42+
"install": "node ./scripts/prepublish.js && npm run build",
43+
"test": "pushd test; ./test; popd"
44+
},
45+
"engines": {
46+
"node": ">=8.9.4"
2047
}
21-
,"keywords": ["apache", "zookeeper", "client"]
22-
,"dependencies": {
23-
"async": "~2.6.1"
24-
,"nan": "~2.11.0"
25-
,"lodash": "~4.17.11"
26-
}
27-
,"devDependencies": {
28-
"log4js": "~3.0.5"
29-
,"webworker": ">=0.8.4"
30-
}
31-
,"main": "lib/index"
32-
,"scripts" : {
33-
"build" : "node-gyp configure build"
34-
,"test" : "pushd test; ./test; popd"
35-
,"prepublish" : "./scripts/prepublish.sh"
36-
}
37-
,"engines": { "node": ">=0.10" }
3848
}

patches/ZOOKEEPER-642.patch

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Index: src/c/src/zookeeper.c
1+
Index: zookeeper/src/c/src/zookeeper.c
22
===================================================================
3-
--- src/c/src/zookeeper.c (revision 1173876)
4-
+++ src/c/src/zookeeper.c (working copy)
3+
--- zookeeper/src/c/src/zookeeper.c (revision 1173876)
4+
+++ zookeeper/src/c/src/zookeeper.c (working copy)
55
@@ -1543,7 +1543,9 @@
66
gettimeofday(&now, 0);
77
if(zh->next_deadline.tv_sec!=0 || zh->next_deadline.tv_usec!=0){

scripts/build.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const shell = require('shelljs');
2+
const env = require('./env.js');
3+
const { exec } = require('./helper.js');
4+
5+
function handleSunOS() {
6+
const uname = shell.exec('uname -v');
7+
8+
if (uname.match('joyent_.*')) {
9+
const res = shell.exec(`pkgin list | grep zookeeper-client-${env.zookeeperVersion}`);
10+
11+
if (res.code !== 0) {
12+
shell.echo('You must install zookeeper before installing this module. Try:');
13+
shell.echo(`pkgin install zookeeper-client-${env.zookeeperVersion}`);
14+
}
15+
}
16+
}
17+
18+
if (env.isSunOs) {
19+
handleSunOS();
20+
return;
21+
}
22+
23+
if (env.isAlreadyBuilt) {
24+
shell.echo('Zookeeper has already been built');
25+
shell.exit(0);
26+
return;
27+
}
28+
29+
shell.config.fatal = true;
30+
shell.config.verbose = true;
31+
32+
shell.cd(`${env.sourceFolder}/src/c`);
33+
34+
if (env.isWindows) {
35+
exec(`cmake -DWANT_SYNCAPI=OFF -DCMAKE_GENERATOR_PLATFORM=${process.arch} .`);
36+
exec('cmake --build .');
37+
} else {
38+
exec('./configure --without-syncapi --disable-shared --with-pic');
39+
exec('make');
40+
}
41+
42+
shell.cd(env.rootFolder);
43+
44+
45+

0 commit comments

Comments
 (0)