From 6edf1bcb5469d8fa7c944a06117ef80b24c3bcc6 Mon Sep 17 00:00:00 2001 From: "Wolden, Alexander" Date: Thu, 15 Dec 2016 13:52:31 -0800 Subject: [PATCH 1/2] added support for comma delimited vip addresses --- .gitignore | 2 ++ src/EurekaClient.js | 23 ++++++++++++++++++----- test/EurekaClient.test.js | 18 ++++++++++++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1a68402..096bec9 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ build/Release node_modules lib/ + +.DS_Store diff --git a/src/EurekaClient.js b/src/EurekaClient.js index 34f6ec6..c5dfbe0 100644 --- a/src/EurekaClient.js +++ b/src/EurekaClient.js @@ -372,14 +372,20 @@ export default class Eureka extends EventEmitter { const instances = app.instance.filter((instance) => (this.validateInstance(instance))); cache.app[app.name.toUpperCase()] = instances; instances.forEach((inst) => { - if (!cache.vip[inst.vipAddress]) { - cache.vip[inst.vipAddress] = []; - } - cache.vip[inst.vipAddress].push(inst); + const vipAddresses = this.splitVipAddress(inst.vipAddress); + vipAddresses.forEach((vipAddress) => { + if (!cache.vip[vipAddress]) { + cache.vip[vipAddress] = []; + } + cache.vip[vipAddress].push(inst); + }); }); } else if (this.validateInstance(app.instance)) { const instances = [app.instance]; - cache.vip[app.instance.vipAddress] = instances; + const vipAddresses = this.splitVipAddress(app.instance.vipAddress); + vipAddresses.forEach((vipAddress) => { + cache.vip[vipAddress] = instances; + }); cache.app[app.name.toUpperCase()] = instances; } } @@ -391,6 +397,13 @@ export default class Eureka extends EventEmitter { return (!this.config.eureka.filterUpInstances || instance.status === 'UP'); } + /* + Returns an array of vipAddresses from string vipAddress given by eureka + */ + splitVipAddress(vipAddress) { // eslint-disable-line + return vipAddress.split(','); + } + /* Fetches the metadata using the built-in client and updates the instance configuration with the hostname and IP address. If the value of the config diff --git a/test/EurekaClient.test.js b/test/EurekaClient.test.js index f52600c..0cab708 100644 --- a/test/EurekaClient.test.js +++ b/test/EurekaClient.test.js @@ -746,8 +746,10 @@ describe('Eureka client', () => { let app; let instance1; let instance2; + let instance3; let downInstance; let theVip; + let multiVip; let cache; beforeEach(() => { config = makeConfig({ @@ -755,8 +757,10 @@ describe('Eureka client', () => { }); client = new Eureka(config); theVip = 'theVip'; + multiVip = 'fooVip,barVip'; instance1 = { host: '127.0.0.1', port: 1000, vipAddress: theVip, status: 'UP' }; instance2 = { host: '127.0.0.2', port: 2000, vipAddress: theVip, status: 'UP' }; + instance3 = { host: '127.0.0.2', port: 2000, vipAddress: multiVip, status: 'UP' }; downInstance = { host: '127.0.0.2', port: 2000, vipAddress: theVip, status: 'DOWN' }; app = { name: 'theapp' }; cache = { app: {}, vip: {} }; @@ -769,11 +773,21 @@ describe('Eureka client', () => { expect(cache.vip[theVip].length).to.equal(1); }); + it('should transform an app with one instance that has a comma separated vipAddress', () => { + app.instance = instance3; + client.transformApp(app, cache); + expect(cache.app[app.name.toUpperCase()].length).to.equal(1); + expect(cache.vip[multiVip.split(',')[0]].length).to.equal(1); + expect(cache.vip[multiVip.split(',')[1]].length).to.equal(1); + }); + it('should transform an app with two or more instances', () => { - app.instance = [instance1, instance2]; + app.instance = [instance1, instance2, instance3]; client.transformApp(app, cache); - expect(cache.app[app.name.toUpperCase()].length).to.equal(2); + expect(cache.app[app.name.toUpperCase()].length).to.equal(3); expect(cache.vip[theVip].length).to.equal(2); + expect(cache.vip[multiVip.split(',')[0]].length).to.equal(1); + expect(cache.vip[multiVip.split(',')[1]].length).to.equal(1); }); it('should filter UP instances by default', () => { From 6bb4ba1554b4448e5bf6c7cf275758f45e60a29c Mon Sep 17 00:00:00 2001 From: "Wolden, Alexander" Date: Thu, 15 Dec 2016 14:07:52 -0800 Subject: [PATCH 2/2] incremented patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bf8c4af..175d677 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eureka-js-client", - "version": "4.1.2", + "version": "4.1.3", "description": "A JavaScript implementation the Netflix OSS service registry, Eureka.", "main": "lib/index.js", "scripts": {