etcd mesh force is
etcd v2 client for monitoring changes to the force - useful for networks that are changing dynamically.
Yoda gives you 2 things:
If you want to speak like yoda - check out yoda-said
Somewhere on a small lonely planet - a plucky little node script wants to connect to some Mongo databases (or ZeroMQ sockets or any TCP thing).
We know we have an etcd server running on 127.0.0.1:4001 and so we tell Yoda to connect to it to get updates about Mongos.
var Yoda = ;// hostname + port of the etcd servervar yoda = '127.0.0.1' 4001;// location will emit events for anything below /mongovar location = yoda;// listen for servers arrivinglocation
Meanwhile - in amoungst the alliance fleet - we have a Mongo spawning bash script that knows the IP of the server it is running a Mongo database on.
# the IP address of the mongo server we are bootingMONGO_IP='192.168.1.120'# first run a mongo container using dockerMONGO_CONTAINER=$(docker run -p 27017 -t quarry/mongo)# now get the port it is listeningMONGO_PORT=$(docker port $MONGO_CONTAINER 27017)# now lets tell yoda about the serveryoda set /mongo/$MONGO_CONTAINER $MONGO_IP:$MONGO_PORT
A command to boot 2 servers and register them under '/servers' with yoda:
$ node server.js 5678 &$ node server.js 5679 &$ yoda set /servers/1 tcp://127.0.0.1:5678$ yoda set /servers/2 tcp://127.0.0.1:5679
A brokerless ZeroMQ REQ/REP network where multiple clients connect to multiple servers - a feel-the-force mesh!
#!/usr/bin/env nodevar zmq =sock = zmq;var port = processargv2 || 8791;socksock;
A ZeroMQ REQ client that connects to servers registered under '/servers' with yoda:
var zmq =server_socket = zmqYoda = ;var yoda = '127.0.0.1' 4001;var server_pool = yoda;server_pool
The node.js part is so your app can listen to changes in the network and connect/disconnect to endpoints as they come and go.
$ npm install yoda --save
The bash part is so your orchestration script can write changes to the network as you are spawning/killing processes.
$ wget -qO- https://raw.github.com/binocarlos/yoda/master/bootstrap.sh | sudo bash
You need an etcd server running in order for yoda to speak to the force.
2 environment variables are used by yoda to speak to the etcd server:
You can use the Makefile to run an etcd server in a docker container.
First install docker.
Then, to run etcd on the default port:
$ make etcd
There is an example setup so you can see the rough idea
In the first shell:
$ node examples/app.js
And then in the second shell:
You should see servers arriving in the first shell.
var Yoda = ;
Create a new yoda object connected to the given etcd_host & etcd_port.
Returns a location object that will update when anything under '/my/location' changes.
Called when a new item has been added to the locations path.
The route is the full key to the new item and data is the new value.
Called when an item has been deleted from the locations path.
Called when an item has been added or removed from the locations path.
Set the value of $PATH to $DATA.
Get the JSON packet of $PATH.
Get the value of $PATH.
Print all keys beneath $PATH one per line
Remove $PATH and everything beneath.