Consistent roles handling
This commit is contained in:
3
lib/Connection.d.ts
vendored
3
lib/Connection.d.ts
vendored
@ -34,8 +34,7 @@ export default class Connection {
|
|||||||
MASTER: string;
|
MASTER: string;
|
||||||
DATA: string;
|
DATA: string;
|
||||||
INGEST: string;
|
INGEST: string;
|
||||||
COORDINATING: string;
|
ML: string;
|
||||||
MACHINE_LEARNING: string;
|
|
||||||
};
|
};
|
||||||
url: URL;
|
url: URL;
|
||||||
ssl: SecureContextOptions | null;
|
ssl: SecureContextOptions | null;
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class Connection {
|
|||||||
|
|
||||||
this._openRequests = 0
|
this._openRequests = 0
|
||||||
this._status = opts.status || Connection.statuses.ALIVE
|
this._status = opts.status || Connection.statuses.ALIVE
|
||||||
this.roles = opts.roles || defaultRoles
|
this.roles = Object.assign({}, defaultRoles, opts.roles) || Object.assign({}, defaultRoles)
|
||||||
|
|
||||||
if (!['http:', 'https:'].includes(this.url.protocol)) {
|
if (!['http:', 'https:'].includes(this.url.protocol)) {
|
||||||
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
throw new ConfigurationError(`Invalid protocol: '${this.url.protocol}'`)
|
||||||
@ -199,16 +199,14 @@ Connection.roles = {
|
|||||||
MASTER: 'master',
|
MASTER: 'master',
|
||||||
DATA: 'data',
|
DATA: 'data',
|
||||||
INGEST: 'ingest',
|
INGEST: 'ingest',
|
||||||
COORDINATING: 'coordinating',
|
ML: 'ml'
|
||||||
MACHINE_LEARNING: 'machine_learning'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultRoles = {
|
const defaultRoles = {
|
||||||
[Connection.roles.MASTER]: true,
|
[Connection.roles.MASTER]: true,
|
||||||
[Connection.roles.DATA]: true,
|
[Connection.roles.DATA]: true,
|
||||||
[Connection.roles.INGEST]: true,
|
[Connection.roles.INGEST]: true,
|
||||||
[Connection.roles.COORDINATING]: true,
|
[Connection.roles.ML]: false
|
||||||
[Connection.roles.MACHINE_LEARNING]: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const validStatuses = Object.keys(Connection.statuses)
|
const validStatuses = Object.keys(Connection.statuses)
|
||||||
|
|||||||
@ -314,7 +314,6 @@ class ConnectionPool {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the nodes objects to a host object.
|
* Transforms the nodes objects to a host object.
|
||||||
* TODO: handle ssl and agent options
|
|
||||||
*
|
*
|
||||||
* @param {object} nodes
|
* @param {object} nodes
|
||||||
* @returns {array} hosts
|
* @returns {array} hosts
|
||||||
@ -331,13 +330,20 @@ class ConnectionPool {
|
|||||||
address = address.slice(0, 4) === 'http'
|
address = address.slice(0, 4) === 'http'
|
||||||
? address
|
? address
|
||||||
: 'http://' + address
|
: 'http://' + address
|
||||||
|
const roles = node.roles.reduce((acc, role) => {
|
||||||
|
acc[role] = true
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
|
||||||
hosts.push({
|
hosts.push({
|
||||||
url: new URL(address),
|
url: new URL(address),
|
||||||
id: ids[i],
|
id: ids[i],
|
||||||
roles: node.roles.reduce((acc, role) => {
|
roles: Object.assign({
|
||||||
acc[role] = true
|
[Connection.roles.MASTER]: true,
|
||||||
return acc
|
[Connection.roles.DATA]: true,
|
||||||
}, {})
|
[Connection.roles.INGEST]: true,
|
||||||
|
[Connection.roles.ML]: false
|
||||||
|
}, roles)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,9 +377,9 @@ ConnectionPool.resurrectStrategies = {
|
|||||||
|
|
||||||
function defaultNodeFilter (node) {
|
function defaultNodeFilter (node) {
|
||||||
// avoid master only nodes
|
// avoid master only nodes
|
||||||
if (!!node.roles.master === true &&
|
if (node.roles.master === true &&
|
||||||
!!node.roles.data === false &&
|
node.roles.data === false &&
|
||||||
!!node.roles.ingest === false) {
|
node.roles.ingest === false) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user