From 457092e5b80ac830d1ce3b7bcb6891c16e9954c4 Mon Sep 17 00:00:00 2001 From: tpetr Date: Wed, 4 May 2016 16:21:00 -0400 Subject: [PATCH 1/6] add support for upstream groups --- .../baragon/models/ServiceContext.java | 26 +++++++++++++-- .../hubspot/baragon/models/UpstreamInfo.java | 33 ++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java index 1909ed9aa..3450213e2 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java @@ -1,17 +1,23 @@ package com.hubspot.baragon.models; -import java.util.Collection; -import java.util.Collections; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.common.base.Objects; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceContext { + public static final String DEFAULT_UPSTREAM_GROUP = "default"; + private final BaragonService service; private final Collection upstreams; + private final Map> upstreamGroups; private final Long timestamp; private final boolean present; private final boolean rootPath; @@ -26,6 +32,16 @@ public ServiceContext(@JsonProperty("service") BaragonService service, this.upstreams = Objects.firstNonNull(upstreams, Collections.emptyList()); this.present = present; this.rootPath = service.getServiceBasePath().equals("/"); + + if (!this.upstreams.isEmpty()) { + final Multimap upstreamGroupsMultimap = ArrayListMultimap.create(); + for (UpstreamInfo upstream : this.upstreams) { + upstreamGroupsMultimap.put(upstream.getGroup().or(DEFAULT_UPSTREAM_GROUP), upstream); + } + this.upstreamGroups = upstreamGroupsMultimap.asMap(); + } else { + this.upstreamGroups = Collections.emptyMap(); + } } public BaragonService getService() { @@ -36,6 +52,10 @@ public Collection getUpstreams() { return upstreams; } + public Map> getUpstreamGroups() { + return upstreamGroups; + } + public Long getTimestamp() { return timestamp; } diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java index 148818226..37e06b548 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java @@ -1,8 +1,5 @@ package com.hubspot.baragon.models; -import javax.validation.constraints.Pattern; -import javax.validation.constraints.Size; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -12,6 +9,9 @@ import com.google.common.base.Strings; import com.google.common.io.BaseEncoding; +import javax.validation.constraints.Pattern; +import javax.validation.constraints.Size; + @JsonIgnoreProperties( ignoreUnknown = true ) public class UpstreamInfo { private final String upstream; @@ -25,6 +25,10 @@ public class UpstreamInfo { private final String rackId; private final Optional originalPath; + @Size(max=100) + @Pattern(regexp = "^$|[^\\s|]+", message = "cannot contain whitespace, '/', or '|'") + private final Optional group; + @JsonCreator public static UpstreamInfo fromString(String value) { String[] split = value.split("\\|", -1); @@ -34,27 +38,30 @@ public static UpstreamInfo fromString(String value) { String upstream = new String(BaseEncoding.base64Url().decode(split[0]), Charsets.UTF_8); Optional requestId = split.length > 1 && !split[1].equals("") ? Optional.of(split[1]) : Optional.absent(); Optional rackId = split.length > 2 && !split[2].equals("") ? Optional.of(split[2]) : Optional.absent(); - return new UpstreamInfo(upstream, requestId, rackId, Optional.of(value)); + Optional group = split.length > 3 && !split[3].equals("") ? Optional.of(split[3]) : Optional.absent(); + return new UpstreamInfo(upstream, requestId, rackId, Optional.of(value), group); } } public static UpstreamInfo fromUnEncodedString(String upstream) { - return new UpstreamInfo(upstream, Optional.absent(), Optional.absent(), Optional.of(upstream)); + return new UpstreamInfo(upstream, Optional.absent(), Optional.absent(), Optional.of(upstream), Optional.absent()); } public UpstreamInfo (String upstream, Optional requestId, Optional rackId) { - this(upstream, requestId, rackId, Optional.absent()); + this(upstream, requestId, rackId, Optional.absent(), Optional.absent()); } @JsonCreator public UpstreamInfo(@JsonProperty("upstream") String upstream, @JsonProperty("requestId") Optional requestId, @JsonProperty("rackId") Optional rackId, - @JsonProperty("originalPath") Optional originalPath) { + @JsonProperty("originalPath") Optional originalPath, + @JsonProperty("group") Optional group) { this.upstream = upstream; this.requestId = requestId.or(""); this.rackId = rackId.or(""); this.originalPath = originalPath; + this.group = group; } public String getUpstream() { @@ -74,13 +81,17 @@ public Optional getOriginalPath() { return originalPath; } + public Optional getGroup() { + return group; + } + @Override public String toString() { return upstream; } public String toPath() { - return String.format("%s|%s|%s", sanitizeUpstream(upstream), requestId, rackId); + return String.format("%s|%s|%s|%s", sanitizeUpstream(upstream), requestId, rackId, group); } protected String sanitizeUpstream(String name) { @@ -110,6 +121,9 @@ public boolean equals(Object o) { if (!originalPath.equals(that.originalPath)) { return false; } + if (!group.equals(that.group)) { + return false; + } return true; } @@ -119,7 +133,8 @@ public int hashCode() { int result = upstream.hashCode(); result = 31 * result + requestId.hashCode(); result = 31 * result + rackId.hashCode(); - result = 31 *result + originalPath.hashCode(); + result = 31 * result + originalPath.hashCode(); + result = 31 * result + group.hashCode(); return result; } } From af62d4676332a569430122fe154196153f3b5506 Mon Sep 17 00:00:00 2001 From: tpetr Date: Wed, 4 May 2016 17:21:26 -0400 Subject: [PATCH 2/6] fix --- .../java/com/hubspot/baragon/models/UpstreamInfo.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java index 37e06b548..3f7de4e03 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java @@ -24,9 +24,6 @@ public class UpstreamInfo { @Pattern(regexp = "^$|[^\\s|]+", message = "cannot contain whitespace, '/', or '|'") private final String rackId; private final Optional originalPath; - - @Size(max=100) - @Pattern(regexp = "^$|[^\\s|]+", message = "cannot contain whitespace, '/', or '|'") private final Optional group; @JsonCreator @@ -47,10 +44,14 @@ public static UpstreamInfo fromUnEncodedString(String upstream) { return new UpstreamInfo(upstream, Optional.absent(), Optional.absent(), Optional.of(upstream), Optional.absent()); } - public UpstreamInfo (String upstream, Optional requestId, Optional rackId) { + public UpstreamInfo(String upstream, Optional requestId, Optional rackId) { this(upstream, requestId, rackId, Optional.absent(), Optional.absent()); } + public UpstreamInfo(String upstream, Optional requestId, Optional rackId, Optional group) { + this(upstream, requestId, rackId, Optional.absent(), group); + } + @JsonCreator public UpstreamInfo(@JsonProperty("upstream") String upstream, @JsonProperty("requestId") Optional requestId, From c42c868013ef845357ae27c9c506a5f24bfbc452 Mon Sep 17 00:00:00 2001 From: tpetr Date: Thu, 5 May 2016 11:48:15 -0400 Subject: [PATCH 3/6] move default group logic + bring back group validation --- .../com/hubspot/baragon/models/ServiceContext.java | 4 +--- .../java/com/hubspot/baragon/models/UpstreamInfo.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java index 3450213e2..b784e12a4 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/ServiceContext.java @@ -13,8 +13,6 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceContext { - public static final String DEFAULT_UPSTREAM_GROUP = "default"; - private final BaragonService service; private final Collection upstreams; private final Map> upstreamGroups; @@ -36,7 +34,7 @@ public ServiceContext(@JsonProperty("service") BaragonService service, if (!this.upstreams.isEmpty()) { final Multimap upstreamGroupsMultimap = ArrayListMultimap.create(); for (UpstreamInfo upstream : this.upstreams) { - upstreamGroupsMultimap.put(upstream.getGroup().or(DEFAULT_UPSTREAM_GROUP), upstream); + upstreamGroupsMultimap.put(upstream.getGroup(), upstream); } this.upstreamGroups = upstreamGroupsMultimap.asMap(); } else { diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java index 3f7de4e03..e56139734 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java @@ -14,6 +14,8 @@ @JsonIgnoreProperties( ignoreUnknown = true ) public class UpstreamInfo { + public static final String DEFAULT_GROUP = "default"; + private final String upstream; @Size(max=250) @@ -24,7 +26,10 @@ public class UpstreamInfo { @Pattern(regexp = "^$|[^\\s|]+", message = "cannot contain whitespace, '/', or '|'") private final String rackId; private final Optional originalPath; - private final Optional group; + + @Size(max=100) + @Pattern(regexp = "^$|[^\\s|]+", message = "cannot contain whitespace, '/', or '|'") + private final String group; @JsonCreator public static UpstreamInfo fromString(String value) { @@ -62,7 +67,7 @@ public UpstreamInfo(@JsonProperty("upstream") String upstream, this.requestId = requestId.or(""); this.rackId = rackId.or(""); this.originalPath = originalPath; - this.group = group; + this.group = group.or(DEFAULT_GROUP); } public String getUpstream() { @@ -82,7 +87,7 @@ public Optional getOriginalPath() { return originalPath; } - public Optional getGroup() { + public String getGroup() { return group; } From 71d0660303f95ce1f5c693e56e5cf59d60526057 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Thu, 5 May 2016 15:37:16 -0400 Subject: [PATCH 4/6] update upstream checks to also match based on group --- .../agent/managers/AgentRequestManager.java | 27 ++++++++++++------- .../baragon/models/BaragonRequest.java | 2 +- .../hubspot/baragon/models/UpstreamInfo.java | 4 +++ .../baragon/data/BaragonStateDatastore.java | 19 ++++--------- BaragonUI/app/templates/serviceDetail.hbs | 2 +- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java b/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java index 68603ca67..d3a583082 100644 --- a/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java +++ b/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java @@ -159,20 +159,27 @@ private ServiceContext getApplyContext(BaragonRequest request) throws Exception return new ServiceContext(request.getLoadBalancerService(), request.getReplaceUpstreams(), System.currentTimeMillis(), true); } else { List upstreams = new ArrayList<>(); - upstreams.addAll(stateDatastore.getUpstreams(request.getLoadBalancerService().getServiceId())); - - List toRemove = new ArrayList<>(); - for (UpstreamInfo removeUpstreamInfo : request.getRemoveUpstreams()) { - for (UpstreamInfo upstreamInfo : upstreams) { - if (upstreamInfo.getUpstream().equals(removeUpstreamInfo.getUpstream())) { - toRemove.add(upstreamInfo); + upstreams.addAll(request.getAddUpstreams()); + for (UpstreamInfo existingUpstream : stateDatastore.getUpstreams(request.getLoadBalancerService().getServiceId())) { + boolean present = false; + boolean toRemove = false; + for (UpstreamInfo currentUpstream : upstreams) { + if (currentUpstream.sameAs(existingUpstream)) { + present = true; + break; + } + } + for (UpstreamInfo upstreamToRemove : request.getRemoveUpstreams()) { + if (upstreamToRemove.sameAs(existingUpstream)) { + toRemove = true; + break; } } + if (!present && !toRemove) { + upstreams.add(existingUpstream); + } } - upstreams.removeAll(toRemove); - upstreams.addAll(request.getAddUpstreams()); - return new ServiceContext(request.getLoadBalancerService(), upstreams, System.currentTimeMillis(), true); } } diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/BaragonRequest.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/BaragonRequest.java index ce3039a0c..65dc860ce 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/BaragonRequest.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/BaragonRequest.java @@ -122,7 +122,7 @@ private List addRequestId(List upstreams, String req private UpstreamInfo addRequestId(UpstreamInfo upstream, String requestId) { if (!upstream.getRequestId().isPresent()) { - return new UpstreamInfo(upstream.getUpstream(), Optional.of(requestId), upstream.getRackId()); + return new UpstreamInfo(upstream.getUpstream(), Optional.of(requestId), upstream.getRackId(), Optional.of(upstream.getGroup())); } else { return upstream; } diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java index e56139734..12989116b 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java @@ -134,6 +134,10 @@ public boolean equals(Object o) { return true; } + public boolean sameAs(UpstreamInfo that) { + return upstream.equals(that.upstream) && group.equals(that.group); + } + @Override public int hashCode() { int result = upstream.hashCode(); diff --git a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java index aefee1493..8696f0c25 100644 --- a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java +++ b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java @@ -97,9 +97,8 @@ public void updateService(BaragonRequest request) throws Exception { createNode(SERVICES_FORMAT); } - Collection currentUpstreams = getUpstreams(request.getLoadBalancerService().getServiceId()); - String serviceId = request.getLoadBalancerService().getServiceId(); + Collection currentUpstreams = getUpstreams(serviceId); String servicePath = String.format(SERVICE_FORMAT, serviceId); CuratorTransactionFinal transaction; if (nodeExists(servicePath)) { @@ -110,7 +109,7 @@ public void updateService(BaragonRequest request) throws Exception { List pathsToDelete = new ArrayList<>(); if (!request.getReplaceUpstreams().isEmpty()) { - for (UpstreamInfo upstreamInfo : getUpstreams(serviceId)) { + for (UpstreamInfo upstreamInfo : currentUpstreams) { String removePath = String.format(UPSTREAM_FORMAT, serviceId, getRemovePath(currentUpstreams, upstreamInfo)); if (nodeExists(removePath)) { pathsToDelete.add(removePath); @@ -119,15 +118,7 @@ public void updateService(BaragonRequest request) throws Exception { } for (UpstreamInfo upstreamInfo : request.getReplaceUpstreams()) { String addPath = String.format(UPSTREAM_FORMAT, serviceId, upstreamInfo.toPath()); - List matchingUpstreamPaths = matchingUpstreamPaths(currentUpstreams, upstreamInfo); - for (String matchingPath : matchingUpstreamPaths) { - String fullPath = String.format(UPSTREAM_FORMAT, serviceId, matchingPath); - if (nodeExists(fullPath) && !pathsToDelete.contains(fullPath)) { - pathsToDelete.add(fullPath); - transaction.delete().forPath(fullPath); - } - } - if (!nodeExists(addPath)) { + if (!nodeExists(addPath) || pathsToDelete.contains(addPath)) { transaction.create().forPath(addPath).and(); } } @@ -161,7 +152,7 @@ public void updateService(BaragonRequest request) throws Exception { private List matchingUpstreamPaths(Collection currentUpstreams, UpstreamInfo toAdd) { List matchingPaths = new ArrayList<>(); for (UpstreamInfo upstreamInfo : currentUpstreams) { - if (upstreamInfo.getUpstream().equals(toAdd.getUpstream())) { + if (upstreamInfo.sameAs(toAdd)) { matchingPaths.add(upstreamInfo.getOriginalPath().or(upstreamInfo.getUpstream())); } } @@ -170,7 +161,7 @@ private List matchingUpstreamPaths(Collection currentUpstr private String getRemovePath(Collection currentUpstreams, UpstreamInfo toRemove) { for (UpstreamInfo upstreamInfo : currentUpstreams) { - if (upstreamInfo.getUpstream().equals(toRemove.getUpstream())) { + if (upstreamInfo.sameAs(toRemove)) { return upstreamInfo.getOriginalPath().or(upstreamInfo.toPath()); } } diff --git a/BaragonUI/app/templates/serviceDetail.hbs b/BaragonUI/app/templates/serviceDetail.hbs index ac113dcc9..529b1f882 100644 --- a/BaragonUI/app/templates/serviceDetail.hbs +++ b/BaragonUI/app/templates/serviceDetail.hbs @@ -124,7 +124,7 @@ {{#each service.splitUpstreams}}
{{#each this}} -

{{upstream}} {{#if rackId}}({{ rackId }}){{/if}}{{#if ../../config.allowEdit}}{{/if}}

+

{{upstream}} {{#if rackId}}({{ rackId }}){{/if}}{{#if group}}({{{ group }}}){{/if}}{{#if ../../config.allowEdit}}{{/if}}

{{/each}}
{{/each}} From 485764c3b0deff1371f0a185b3cbf15779beaf44 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Thu, 5 May 2016 15:45:26 -0400 Subject: [PATCH 5/6] missing a .and() --- .../java/com/hubspot/baragon/data/BaragonStateDatastore.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java index 8696f0c25..0c1930a0a 100644 --- a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java +++ b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java @@ -138,7 +138,7 @@ public void updateService(BaragonRequest request) throws Exception { if (nodeExists(fullPath) && !pathsToDelete.contains(fullPath) && !fullPath.equals(addPath)) { LOG.info(String.format("Deleting %s", fullPath)); pathsToDelete.add(fullPath); - transaction.delete().forPath(fullPath); + transaction.delete().forPath(fullPath).and(); } } if (!nodeExists(addPath) || pathsToDelete.contains(addPath)) { From 42ac7b4e5865078fbc22555adec21b4682ea9dc6 Mon Sep 17 00:00:00 2001 From: tpetr Date: Fri, 6 May 2016 10:15:15 -0400 Subject: [PATCH 6/6] use static method to compare upstream info objects --- .../agent/managers/AgentRequestManager.java | 20 +++++------ .../hubspot/baragon/models/UpstreamInfo.java | 8 ++--- .../baragon/data/BaragonStateDatastore.java | 35 +++++++++---------- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java b/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java index d3a583082..6a864c08a 100644 --- a/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java +++ b/BaragonAgentService/src/main/java/com/hubspot/baragon/agent/managers/AgentRequestManager.java @@ -1,14 +1,5 @@ package com.hubspot.baragon.agent.managers; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Random; -import java.util.concurrent.atomic.AtomicReference; - -import javax.ws.rs.core.Response; - import com.google.common.base.Optional; import com.google.inject.Inject; import com.google.inject.Singleton; @@ -30,6 +21,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.concurrent.atomic.AtomicReference; +import javax.ws.rs.core.Response; + @Singleton public class AgentRequestManager { private static final Logger LOG = LoggerFactory.getLogger(AgentRequestManager.class); @@ -164,13 +162,13 @@ private ServiceContext getApplyContext(BaragonRequest request) throws Exception boolean present = false; boolean toRemove = false; for (UpstreamInfo currentUpstream : upstreams) { - if (currentUpstream.sameAs(existingUpstream)) { + if (UpstreamInfo.upstreamAndGroupMatches(currentUpstream, existingUpstream)) { present = true; break; } } for (UpstreamInfo upstreamToRemove : request.getRemoveUpstreams()) { - if (upstreamToRemove.sameAs(existingUpstream)) { + if (UpstreamInfo.upstreamAndGroupMatches(upstreamToRemove, existingUpstream)) { toRemove = true; break; } diff --git a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java index 12989116b..19e9afe3a 100644 --- a/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java +++ b/BaragonCore/src/main/java/com/hubspot/baragon/models/UpstreamInfo.java @@ -16,6 +16,10 @@ public class UpstreamInfo { public static final String DEFAULT_GROUP = "default"; + public static boolean upstreamAndGroupMatches(UpstreamInfo a, UpstreamInfo b) { + return a.getUpstream().equals(b.getUpstream()) && a.getGroup().equals(b.getGroup()); + } + private final String upstream; @Size(max=250) @@ -134,10 +138,6 @@ public boolean equals(Object o) { return true; } - public boolean sameAs(UpstreamInfo that) { - return upstream.equals(that.upstream) && group.equals(that.group); - } - @Override public int hashCode() { int result = upstream.hashCode(); diff --git a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java index 0c1930a0a..327bf9d98 100644 --- a/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java +++ b/BaragonData/src/main/java/com/hubspot/baragon/data/BaragonStateDatastore.java @@ -1,21 +1,5 @@ package com.hubspot.baragon.data; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.api.transaction.CuratorTransactionFinal; -import org.apache.curator.utils.ZKPaths; -import org.apache.zookeeper.data.Stat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.codahale.metrics.annotation.Timed; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Function; @@ -31,6 +15,21 @@ import com.hubspot.baragon.models.BaragonServiceState; import com.hubspot.baragon.models.UpstreamInfo; import com.hubspot.baragon.utils.ZkParallelFetcher; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.api.transaction.CuratorTransactionFinal; +import org.apache.curator.utils.ZKPaths; +import org.apache.zookeeper.data.Stat; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; @Singleton public class BaragonStateDatastore extends AbstractDataStore { @@ -152,7 +151,7 @@ public void updateService(BaragonRequest request) throws Exception { private List matchingUpstreamPaths(Collection currentUpstreams, UpstreamInfo toAdd) { List matchingPaths = new ArrayList<>(); for (UpstreamInfo upstreamInfo : currentUpstreams) { - if (upstreamInfo.sameAs(toAdd)) { + if (UpstreamInfo.upstreamAndGroupMatches(upstreamInfo, toAdd)) { matchingPaths.add(upstreamInfo.getOriginalPath().or(upstreamInfo.getUpstream())); } } @@ -161,7 +160,7 @@ private List matchingUpstreamPaths(Collection currentUpstr private String getRemovePath(Collection currentUpstreams, UpstreamInfo toRemove) { for (UpstreamInfo upstreamInfo : currentUpstreams) { - if (upstreamInfo.sameAs(toRemove)) { + if (UpstreamInfo.upstreamAndGroupMatches(upstreamInfo, toRemove)) { return upstreamInfo.getOriginalPath().or(upstreamInfo.toPath()); } }