From ba0b4c051f72328aef429c8f26d35fd14c227d12 Mon Sep 17 00:00:00 2001 From: codependent Date: Sat, 28 Nov 2015 00:02:36 +0100 Subject: [PATCH 1/2] Support for same host different ports apps --- .../java/com/netflix/turbine/discovery/Instance.java | 9 +++++++++ .../netflix/turbine/monitor/cluster/ClusterMonitor.java | 7 +++++-- .../turbine/monitor/instance/InstanceMonitor.java | 6 +++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java b/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java index 8d2d661..7582ad9 100644 --- a/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java +++ b/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java @@ -74,6 +74,12 @@ public boolean equals(Object obj) { equals &= (this.hostname != null) ? (this.hostname.equals(other.hostname)) : (other.hostname == null); equals &= (this.cluster != null) ? (this.cluster.equals(other.cluster)) : (other.cluster == null); equals &= (this.isUp == other.isUp); + if(attributes != null && attributes.get("port") != null){ + String port = attributes.get("port"); + if(other.getAttributes() != null && other.getAttributes().get("port") != null){ + equals &= (port == other.getAttributes().get("port")); + } + } return equals; } @@ -85,6 +91,9 @@ public int hashCode() { result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); result = prime * result + ((cluster == null) ? 0 : cluster.hashCode()); result = prime * result + (isUp ? 1 : 0); + if(attributes != null && attributes.get("port") != null){ + result = prime * result + (attributes.get("port").hashCode()); + } return result; } diff --git a/turbine-core/src/main/java/com/netflix/turbine/monitor/cluster/ClusterMonitor.java b/turbine-core/src/main/java/com/netflix/turbine/monitor/cluster/ClusterMonitor.java index 41d7fce..45c48a2 100644 --- a/turbine-core/src/main/java/com/netflix/turbine/monitor/cluster/ClusterMonitor.java +++ b/turbine-core/src/main/java/com/netflix/turbine/monitor/cluster/ClusterMonitor.java @@ -294,8 +294,11 @@ public void hostDown(Instance host) { } private TurbineDataMonitor getMonitor(Instance host) { - - TurbineDataMonitor monitor = hostConsole.findMonitor(host.getHostname()); + String hostName = host.getHostname(); + if(host.getAttributes() != null && host.getAttributes().get("port") != null){ + hostName += ":" + host.getAttributes().get("port"); + } + TurbineDataMonitor monitor = hostConsole.findMonitor(hostName); if (monitor == null) { monitor = new InstanceMonitor(host, urlClosure, hostDispatcher, hostConsole); hostCount.incrementAndGet(); diff --git a/turbine-core/src/main/java/com/netflix/turbine/monitor/instance/InstanceMonitor.java b/turbine-core/src/main/java/com/netflix/turbine/monitor/instance/InstanceMonitor.java index b7145be..c7bf466 100644 --- a/turbine-core/src/main/java/com/netflix/turbine/monitor/instance/InstanceMonitor.java +++ b/turbine-core/src/main/java/com/netflix/turbine/monitor/instance/InstanceMonitor.java @@ -198,7 +198,11 @@ private InstanceMonitor(Instance host, */ @Override public String getName() { - return host.getHostname(); + String hostName = host.getHostname(); + if(this.host.getAttributes() != null && this.host.getAttributes().get("port") != null){ + hostName += ":" + this.host.getAttributes().get("port"); + } + return hostName; } /** From 13f315320b124374ae613740a5fcacaeeb9ce3ba Mon Sep 17 00:00:00 2001 From: codependent Date: Wed, 20 Jan 2016 09:26:29 +0100 Subject: [PATCH 2/2] Instance equals fixed --- .../src/main/java/com/netflix/turbine/discovery/Instance.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java b/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java index 7582ad9..3b41dfa 100644 --- a/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java +++ b/turbine-core/src/main/java/com/netflix/turbine/discovery/Instance.java @@ -77,7 +77,7 @@ public boolean equals(Object obj) { if(attributes != null && attributes.get("port") != null){ String port = attributes.get("port"); if(other.getAttributes() != null && other.getAttributes().get("port") != null){ - equals &= (port == other.getAttributes().get("port")); + equals &= (port.equals(other.getAttributes().get("port"))); } }