private static Set<Origin> withAppId(Collection<Origin> origins, String appId) { return origins.stream().map(origin -> newOriginBuilder(origin) .applicationId(appId) .build()) .collect(toSet()); }
/** * Creates a new {@link Origin} porting to a specified host and port. * * @param host host * @param port port * @return origin */ public static Origin origin(String host, int port) { return newOriginBuilder(host, port) .applicationId(randomUUID().toString()) .id(randomUUID().toString()) .build(); } }
private static Iterable<Origin> originsWithApplicationId(BackendService backendService) { return backendService.origins().stream().map(origin -> newOriginBuilder(origin) .applicationId(backendService.id()) .build()) .collect(toList()); }
com.hotels.styx.api.extension.service.BackendService createBackendService(String path) { requireNonNull(path, "path must not be null"); checkArgument(!origins.isEmpty(), "A backend service must have at least one origin"); String appId = newId(); Set<Origin> adaptedOrigins = this.origins.stream() .map(origin -> origin.newBuilder() .applicationId(appId) .id(newId()) .build()) .collect(toSet()); com.hotels.styx.api.extension.service.BackendService.Builder builder = newBackendServiceBuilder() .id(appId) .responseTimeoutMillis(responseTimeoutMillis) .origins(adaptedOrigins) .path(path); if (ssl) { builder = builder.https(new TlsSettings.Builder() .trustAllCerts(true) .build()); } return builder .build(); }
private Origin newOrigin(int port) { return newOriginBuilder("localhost", port).build(); }
private static Origin originFromRequest(LiveHttpRequest request, Boolean isHttps) { 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")); }); HostAndPort host = HostAndPort.fromString(hostAndPort); if (host.getPortOrDefault(-1) < 0) { host = host.withDefaultPort(isHttps ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT); } return newOriginBuilder(host.getHostText(), host.getPort()).build(); }
public static ConnectionPool create(String hostname, int port, ConnectionPoolSettings poolSettings) { return new SimpleConnectionPoolFactory.Builder() .connectionPoolSettings(poolSettings) .connectionFactory(new NettyConnectionFactory.Builder().build()) .metricRegistry(new CodaHaleMetricRegistry()) .build() .create(Origin.newOriginBuilder(hostname, port) .applicationId(format("%s:%d", hostname, port)) .id(format("%s:%d-01", hostname, port)) .build()); }