|
15 | 15 |
|
16 | 16 | import com.google.inject.Binder; |
17 | 17 | import com.google.inject.Scopes; |
18 | | -import com.google.inject.multibindings.Multibinder; |
19 | 18 | import io.airlift.configuration.AbstractConfigurationAwareModule; |
20 | 19 | import io.airlift.discovery.client.DiscoveryModule; |
21 | | -import io.airlift.discovery.client.ForDiscoveryClient; |
22 | 20 | import io.airlift.discovery.server.DynamicAnnouncementResource; |
23 | 21 | import io.airlift.discovery.server.EmbeddedDiscoveryModule; |
24 | 22 | import io.airlift.discovery.server.ServiceResource; |
25 | 23 | import io.airlift.discovery.store.StoreResource; |
26 | | -import io.airlift.http.client.HttpClientConfig; |
27 | | -import io.airlift.http.client.HttpRequestFilter; |
28 | | -import io.airlift.http.client.Request; |
29 | 24 | import io.trino.failuredetector.FailureDetectorModule; |
30 | | -import io.trino.server.InternalAuthenticationManager; |
31 | | -import io.trino.server.InternalCommunicationConfig; |
32 | 25 | import io.trino.server.NodeResource; |
33 | 26 | import io.trino.server.ServerConfig; |
34 | 27 |
|
35 | | -import java.io.UncheckedIOException; |
36 | | -import java.net.InetAddress; |
37 | | -import java.net.URI; |
38 | | -import java.net.URISyntaxException; |
39 | | -import java.net.UnknownHostException; |
40 | | - |
41 | | -import static com.google.inject.multibindings.Multibinder.newSetBinder; |
42 | | -import static io.airlift.configuration.ConfigBinder.configBinder; |
43 | 28 | import static io.airlift.discovery.client.DiscoveryBinder.discoveryBinder; |
44 | 29 | import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder; |
45 | | -import static io.airlift.node.AddressToHostname.encodeAddressAsHostname; |
46 | | -import static io.trino.server.InternalCommunicationHttpClientModule.configureClient; |
47 | 30 | import static io.trino.server.security.ResourceSecurityBinder.resourceSecurityBinder; |
48 | 31 |
|
49 | 32 | public class AirliftNodeInventoryModule |
@@ -92,43 +75,6 @@ protected void setup(Binder binder) |
92 | 75 | .addProperty("coordinator", String.valueOf(coordinator)); |
93 | 76 |
|
94 | 77 | // internal communication setup for discovery http client |
95 | | - InternalCommunicationConfig internalCommunicationConfig = buildConfigObject(InternalCommunicationConfig.class); |
96 | | - Multibinder<HttpRequestFilter> discoveryFilterBinder = newSetBinder(binder, HttpRequestFilter.class, ForDiscoveryClient.class); |
97 | | - if (internalCommunicationConfig.isHttpsRequired() && internalCommunicationConfig.getKeyStorePath() == null && internalCommunicationConfig.getTrustStorePath() == null) { |
98 | | - discoveryFilterBinder.addBinding().to(DiscoveryEncodeAddressAsHostname.class); |
99 | | - } |
100 | | - configBinder(binder).bindConfigDefaults(HttpClientConfig.class, ForDiscoveryClient.class, config -> configureClient(config, internalCommunicationConfig)); |
101 | | - discoveryFilterBinder.addBinding().to(InternalAuthenticationManager.class); |
102 | | - } |
103 | | - |
104 | | - private static class DiscoveryEncodeAddressAsHostname |
105 | | - implements HttpRequestFilter |
106 | | - { |
107 | | - @Override |
108 | | - public Request filterRequest(Request request) |
109 | | - { |
110 | | - return Request.Builder.fromRequest(request) |
111 | | - .setUri(toIpEncodedAsHostnameUri(request.getUri())) |
112 | | - .build(); |
113 | | - } |
114 | | - |
115 | | - private static URI toIpEncodedAsHostnameUri(URI uri) |
116 | | - { |
117 | | - if (!uri.getScheme().equals("https")) { |
118 | | - return uri; |
119 | | - } |
120 | | - try { |
121 | | - String host = uri.getHost(); |
122 | | - InetAddress inetAddress = InetAddress.getByName(host); |
123 | | - String addressAsHostname = encodeAddressAsHostname(inetAddress); |
124 | | - return new URI(uri.getScheme(), uri.getUserInfo(), addressAsHostname, uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); |
125 | | - } |
126 | | - catch (UnknownHostException e) { |
127 | | - throw new UncheckedIOException(e); |
128 | | - } |
129 | | - catch (URISyntaxException e) { |
130 | | - throw new RuntimeException(e); |
131 | | - } |
132 | | - } |
| 78 | + install(new InternalCommunicationForDiscoveryModule()); |
133 | 79 | } |
134 | 80 | } |
0 commit comments