private HostAndPort getHost() { return this.origin.host(); }
private static String hosts(Iterable<RemoteHost> origins) { return stream(origins.spliterator(), false) .map(host -> host.origin().hostAsString()) .collect(joining(", ")); } }
private static Set<Origin> withAppId(Collection<Origin> origins, String appId) { return origins.stream().map(origin -> newOriginBuilder(origin) .applicationId(appId) .build()) .collect(toSet()); }
/** * Gets a naming scope for metrics pertaining to the given origin. * * @param origin an origin * @return naming scope */ public static String originMetricsScope(Origin origin) { return name(OriginMetrics.PREFIX, origin.applicationId().toString(), originName(origin)); }
private boolean isUnchangedOrigin(Id originId, Origin newOrigin) { MonitoredOrigin oldOrigin = this.origins.get(originId); return (nonNull(oldOrigin) && nonNull(newOrigin)) && oldOrigin.origin.equals(newOrigin); }
@Override public int compareTo(ConnectionPool other) { return this.origin.compareTo(other.getOrigin()); }
/** * Builds a new Origin with the properties set in this builder. * * @return a new Origin */ public Origin build() { return new Origin(this); } }
private BackendService(Builder builder) { this.id = checkNotNull(builder.id, "id"); this.path = checkNotNull(builder.path, "path"); this.connectionPoolSettings = checkNotNull(builder.connectionPoolSettings); this.origins = ImmutableSet.copyOf(builder.origins); this.healthCheckConfig = nullIfDisabled(builder.healthCheckConfig); this.stickySessionConfig = checkNotNull(builder.stickySessionConfig); this.rewrites = checkNotNull(builder.rewrites); this.responseTimeoutMillis = builder.responseTimeoutMillis == 0 ? DEFAULT_RESPONSE_TIMEOUT_MILLIS : builder.responseTimeoutMillis; this.tlsSettings = builder.tlsSettings; checkThatOriginsAreDistinct(origins); checkArgument(responseTimeoutMillis >= 0, "Request timeout must be greater than or equal to zero"); }
private static Origin originFromRequest(HttpRequest request) { String hostAndPort = request.header(HOST) .orElseGet(() -> { checkArgument(request.url().isAbsolute(), "host header is not set for request=%s", request); return request.url().authority().map(Url.Authority::hostAndPort) .orElseThrow(() -> new IllegalArgumentException("Cannot send request " + request + " as URL is not absolute and no HOST header is present")); }); return newOriginBuilder(HostAndPort.fromString(hostAndPort)).build(); }
/** * Construct an instance. * * @param healthCheckUri URI to make health-check requests to * @param client HTTP client to make health-check requests with * @param metricRegistry metric registry */ public UrlRequestHealthCheck(String healthCheckUri, HttpClient client, MetricRegistry metricRegistry) { this.healthCheckUri = uriWithInitialSlash(healthCheckUri); this.client = checkNotNull(client); this.meterCache = new SimpleCache<>(origin -> metricRegistry.meter("origins.healthcheck.failure." + origin.applicationId())); }
private boolean isUpdatedOrigin(Id originId, Origin newOrigin) { MonitoredOrigin oldOrigin = this.origins.get(originId); return (nonNull(oldOrigin) && nonNull(newOrigin)) && !oldOrigin.origin.equals(newOrigin); }
@Override public int compareTo(ConnectionDestination other) { return this.origin.compareTo(other.getOrigin()); }
private void removeMonitoredEndpoint(Id originId) { MonitoredOrigin host = this.origins.get(originId); host.close(); LOG.info("Existing origin has been removed. Origin={}:{}", appId, host.origin.id()); metricRegistry.deregister(host.gaugeName); }
private io.netty.handler.codec.http.HttpRequest makeRequest(HttpRequest request) { DefaultHttpRequest nettyRequest = toNettyRequest(request); Optional<String> host = request.header(HOST); if (!host.isPresent()) { nettyRequest.headers().set(HOST, nettyConnection.getOrigin().hostAsString()); } return nettyRequest; } }
@Override public int compareTo(Origin other) { return this.host.toString().compareTo(other.host().toString()); }
/** * Create a new OriginMetrics. * * @param origin an origin * @param metricRegistry a metrics registry * @return a new OriginMetrics */ public static OriginMetrics create(Origin origin, MetricRegistry metricRegistry) { MetricRegistry originsRootRegistry = metricRegistry.scope(OriginMetrics.PREFIX); ApplicationMetrics appMetrics = new ApplicationMetrics(origin.applicationId(), originsRootRegistry); return new OriginMetrics(appMetrics, origin); }
public Id id() { return origin().id(); };
private HttpRequest newHealthCheckRequestFor(Origin origin) { return get(healthCheckUri) .header(HOST, origin.hostAsString()) .build(); }
private ChannelFuture openConnection(Origin origin, Connection.Settings connectionSettings) { bootstrap(connectionSettings); HostAndPort host = origin.host(); return bootstrap.connect(host.getHostText(), host.getPort()); }