Skip to content

Commit

Permalink
LoadBalancingGroup: Tidy up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokar committed Jun 11, 2019
1 parent b7ceded commit 0dfd928
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.hotels.styx.routing.handlers;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.hotels.styx.api.Eventual;
import com.hotels.styx.api.HttpInterceptor;
Expand All @@ -30,7 +31,6 @@
import com.hotels.styx.client.StyxBackendServiceClient;
import com.hotels.styx.client.loadbalancing.strategies.PowerOfTwoStrategy;
import com.hotels.styx.client.stickysession.StickySessionLoadBalancingStrategy;
import com.hotels.styx.common.Pair;
import com.hotels.styx.config.schema.Schema;
import com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig;
import com.hotels.styx.routing.RoutingObject;
Expand Down Expand Up @@ -71,7 +71,6 @@
public class LoadBalancingGroup implements RoutingObject {
public static final Schema.FieldType SCHEMA = object(
field("origins", string()),
optional("strategy", string()),
optional("originsRestrictionCookie", string()),
optional("stickySession", object(
field("enabled", bool()),
Expand All @@ -81,12 +80,12 @@ public class LoadBalancingGroup implements RoutingObject {

private static final Logger LOGGER = LoggerFactory.getLogger(LoadBalancingGroup.class);

private StyxObjectStore<RoutingObjectRecord> routeDatabase;
private StyxBackendServiceClient client;
private Disposable changeWatcher;
private final StyxBackendServiceClient client;
private final Disposable changeWatcher;


public LoadBalancingGroup(StyxBackendServiceClient client, Disposable changeWatcher) {
@VisibleForTesting
LoadBalancingGroup(StyxBackendServiceClient client, Disposable changeWatcher) {
this.client = requireNonNull(client);
this.changeWatcher = requireNonNull(changeWatcher);
}
Expand Down Expand Up @@ -141,7 +140,7 @@ public RoutingObject build(List<String> parents, Context context, RoutingObjectD
return new LoadBalancingGroup(client, watch);
}

private LoadBalancer loadBalancer(StickySessionConfig stickySessionConfig, String originsRestrictionCookie, ActiveOrigins activeOrigins) {
private static LoadBalancer loadBalancer(StickySessionConfig stickySessionConfig, String originsRestrictionCookie, ActiveOrigins activeOrigins) {
LoadBalancer loadBalancer = new PowerOfTwoStrategy(activeOrigins);
if (stickySessionConfig.stickySessionEnabled()) {
return new StickySessionLoadBalancingStrategy(activeOrigins, loadBalancer);
Expand Down Expand Up @@ -170,10 +169,10 @@ private static RemoteHost toRemoteHost(String appId, Map.Entry<String, RoutingOb
RoutingObjectAdapter routingObject = record.getValue().getRoutingObject();
String originName = record.getKey();

Pair<String, Integer> hostAndPort = Pair.pair("na", 0);

return remoteHost(
newOriginBuilder(hostAndPort.key(), hostAndPort.value())
// The origin is used to determine remote host hostname or port
// therefore we'll just pass NA:0
newOriginBuilder("na", 0)
.applicationId(appId)
.id(originName)
.build(),
Expand Down

0 comments on commit 0dfd928

Please sign in to comment.