So I added a first pass at auto-discovery in a branch conveniently called "auto-discover". Please have a look at the code, and be gentle as it is just a rough pass at the general idea. The general idea is that you will first add to the connection options "autoDiscover: true" Then you can either add a "whitelist" or "blacklist" set of rules. Please note that you still need to add "hosts" as these are going to be the seed nodes. If no rules are added then the driver will connect to all available hosts. Whitelist and blacklist rules are specified as an array of objects. Each object int he array specifies a datacenter, a list of racks and/or a list of hosts. If a list of hosts is specified, datacenter and rack are ignored. If a rack is specified a datacenter must be specified as well. If a datacenter is specified without racks or hosts, then the entire datacenter will match.
Here is an example of blacklisting a datacenter:
{
hosts:['10.10.10.10'],
keyspace:'test',
autoDiscover:true,
blacklist:[{'datacenter':'Analytics' } ]
}
Here is an example of whitelisting specific racks:
{
hosts:['10.10.10.10'],
keyspace:'test',
autoDiscover:true,
whitelist:[{'datacenter':'Cassandra', 'racks':['rack1', 'rack2']} ]
}
Here is an example ofwhitelisting specific hosts:
{
hosts:['10.10.10.10'],
keyspace:'test',
autoDiscover:true,
whitelist:[{'hosts':['10.10.10.1', '10.10.10.2']} ]
}
This seemed to me to be the simplest way to specify rules. Other options could include token ranges, but I'm not sure how helpful that would actually be. The discovery takes place in the "monitorConnections" method so that it periodically will pull host information and add/remove connections where applicable.
Let me know what you think.
-Russ