implement config.sniffedNodesProtocol

If you use https to protect traffic between esjs client and the nodes in your cluster then you also can't use sniffing. This is because we use the /_nodes/_all/clear output to populate the connection pool and that API does not know that the nodes speak HTTPS at all. This change implements the config.sniffedNodesProtocol to fix this.

As it is implemented here, the sniffedNodesProtocol can be set to a string which will be used as the protocol configuration for each Host object created durring sniffing, plain and simple. The default value for this configuration depends on the hosts initially passed to the client, if all of the nodes have the same protocol that protocol is used. If your nodes list is empty or there is a mixture of protocols in this list then "http" is used, as it is the default protocol for each host.
This commit is contained in:
spalger
2015-09-10 18:45:37 -07:00
parent 0ddcb057b4
commit 04583c2f96
4 changed files with 108 additions and 3 deletions

View File

@ -24,6 +24,9 @@ function getConnection(transport, status) {
return transport.connectionPool.getConnections(status || 'alive', 1).pop();
}
function CustomConnectionPool() {}
CustomConnectionPool.prototype = Object.create(Transport.connectionPools.main.prototype);
describe('Transport Class', function () {
describe('Constructor', function () {
@ -37,7 +40,6 @@ describe('Transport Class', function () {
});
it('Accepts a connection pool class and intanciates it at this.connectionPool', function () {
function CustomConnectionPool() {}
var trans = new Transport({
connectionPool: CustomConnectionPool
});
@ -46,7 +48,7 @@ describe('Transport Class', function () {
});
it('Accepts the name of a connectionPool class that is defined on Transport.connectionPools', function () {
Transport.connectionPools.custom = function () {};
Transport.connectionPools.custom = CustomConnectionPool;
var trans = new Transport({
connectionPool: 'custom'
@ -91,6 +93,77 @@ describe('Transport Class', function () {
});
describe('config.sniffedNodesProtocol', function () {
it('Assigns to itself', function () {
var football = {};
var trans = new Transport({
sniffedNodesProtocol: football
});
expect(trans).to.have.property('sniffedNodesProtocol', football);
});
it('Defaults to null when no hosts given', function () {
var trans = new Transport({
hosts: []
});
expect(trans).to.have.property('sniffedNodesProtocol', null);
});
it('Defaults to "http" when a single http host given', function () {
var trans = new Transport({
hosts: [
new Host({
protocol: 'http'
})
]
});
expect(trans).to.have.property('sniffedNodesProtocol', 'http');
});
it('Defaults to "http" when multiple http host given', function () {
var trans = new Transport({
hosts: [
new Host(),
'http://google.com',
{
host: 'foo',
path: 'bar'
}
]
});
expect(trans).to.have.property('sniffedNodesProtocol', 'http');
});
it('Defaults to "https" when a single https host given', function () {
var trans = new Transport({
host: {
protocol: 'https'
}
});
expect(trans).to.have.property('sniffedNodesProtocol', 'https');
});
it('Defaults to "https" when every seed host uses https', function () {
var trans = new Transport({
hosts: [
'https://localhost:9200',
new Host({
protocol: 'https'
}),
{
protocol: 'https'
}
]
});
expect(trans).to.have.property('sniffedNodesProtocol', 'https');
});
})
describe('host config', function () {
it('rejects non-strings/objects', function () {
expect(function () {