diff --git a/CHANGES b/CHANGES index fb61cd4e5..1307288ef 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,11 @@ +Platform 2.96 + +* Reporting + + ReportingClientModule no longer uses the Discovery service to find the reporting service. + The URI of the reporting service must now be specified through the "service-client.reporting.uri" + configuration property. + Platform 2.95 * Discovery diff --git a/http-client/src/main/java/com/proofpoint/http/client/HttpClientBinder.java b/http-client/src/main/java/com/proofpoint/http/client/HttpClientBinder.java index 018cd98b6..b1dcb53ea 100644 --- a/http-client/src/main/java/com/proofpoint/http/client/HttpClientBinder.java +++ b/http-client/src/main/java/com/proofpoint/http/client/HttpClientBinder.java @@ -316,6 +316,34 @@ public BalancingHttpClientBindingBuilder bindBalancingHttpClient(String name, An return createBalancingHttpClientBindingBuilder(privateBinder, name, annotation, serviceName); } + /** + * Binds an {@link HttpClient} to an implementation that takes relative + * {@link URI}s. The requests are balanced against the set of prefixes + * specified in configuration. + * + * See the EDSL examples at {@link HttpClientBinder}. + * + * @param name The configuration prefix. Should be lowercase hyphen-separated. + * @param annotation The binding annotation. + * @param serviceName The name of the service being balanced. + * Used in metrics and in the configuration prefix for the service balancer. + * Ordinarily this is the value of the binding annotation. + */ + public BalancingHttpClientBindingBuilder bindBalancingHttpClient(String name, Class annotation, String serviceName) + { + requireNonNull(name, "name is null"); + requireNonNull(annotation, "annotation is null"); + + bindConfig(binder).bind(HttpServiceBalancerConfig.class).annotatedWith(annotation).prefixedWith("service-client." + serviceName); + bindConfig(binder).bind(HttpServiceBalancerUriConfig.class).annotatedWith(annotation).prefixedWith("service-client." + serviceName); + PrivateBinder privateBinder = binder.newPrivateBinder(); + privateBinder.bind(HttpServiceBalancer.class).annotatedWith(ForBalancingHttpClient.class) + .toProvider(new ConfiguredStaticHttpServiceBalancerProvider(serviceName, + Key.get(HttpServiceBalancerConfig.class, annotation), + Key.get(HttpServiceBalancerUriConfig.class, annotation))); + return createBalancingHttpClientBindingBuilder(privateBinder, name, annotation, serviceName); + } + private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilder(PrivateBinder privateBinder, String name, Class annotation) { HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class); @@ -416,6 +444,23 @@ private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilde return new BalancingHttpClientBindingBuilder(binder, annotation, delegateBindingBuilder); } + private BalancingHttpClientBindingBuilder createBalancingHttpClientBindingBuilder(PrivateBinder privateBinder, String name, Class annotation, String serviceName) + { + HttpClientBindingBuilder delegateBindingBuilder = httpClientPrivateBinder(privateBinder, binder).bindHttpClient(name, ForBalancingHttpClient.class); + bindConfig(privateBinder).bind(BalancingHttpClientConfig.class).prefixedWith(name); + privateBinder.bind(HttpClient.class).annotatedWith(annotation).to(BalancingHttpClient.class).in(Scopes.SINGLETON); + privateBinder.expose(HttpClient.class).annotatedWith(annotation); + reportBinder(binder).export(HttpClient.class).annotatedWith(annotation).withNamePrefix("HttpClient." + serviceName); + newExporter(binder).export(HttpClient.class).annotatedWith(annotation).as(new ObjectNameBuilder(HttpClient.class.getPackage().getName()) + .withProperty("type", "HttpClient") + .withProperty("name", serviceName) + .build() + ); + binder.bind(ScheduledExecutorService.class).annotatedWith(ForBalancingHttpClient.class).toProvider(RetryExecutorProvider.class); + + return new BalancingHttpClientBindingBuilder(binder, annotation, delegateBindingBuilder); + } + public static class HttpClientBindingBuilder { private final HttpClientModule module; diff --git a/reporting-client/pom.xml b/reporting-client/pom.xml index 3adc776e3..99cf18450 100644 --- a/reporting-client/pom.xml +++ b/reporting-client/pom.xml @@ -13,7 +13,7 @@ com.proofpoint.platform - discovery + bootstrap diff --git a/reporting-client/src/main/java/com/proofpoint/reporting/ReportingClientModule.java b/reporting-client/src/main/java/com/proofpoint/reporting/ReportingClientModule.java index 387b95a38..52a9ae545 100644 --- a/reporting-client/src/main/java/com/proofpoint/reporting/ReportingClientModule.java +++ b/reporting-client/src/main/java/com/proofpoint/reporting/ReportingClientModule.java @@ -29,7 +29,7 @@ import static com.google.inject.Scopes.SINGLETON; import static com.proofpoint.concurrent.Threads.daemonThreadsNamed; import static com.proofpoint.configuration.ConfigBinder.bindConfig; -import static com.proofpoint.discovery.client.DiscoveryBinder.discoveryBinder; +import static com.proofpoint.http.client.HttpClientBinder.httpClientBinder; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; public class ReportingClientModule @@ -43,7 +43,7 @@ public void configure(Binder binder) binder.bind(ReportSink.class).to(ReportQueue.class).in(SINGLETON); binder.bind(ReportClient.class).in(SINGLETON); - discoveryBinder(binder).bindDiscoveredHttpClient("reporting", ForReportClient.class); + httpClientBinder(binder).bindBalancingHttpClient("reporting", ForReportClient.class, "reporting"); bindConfig(binder).bind(ReportClientConfig.class); binder.install(new ReportingBaseMetricsModule()); diff --git a/reporting-client/src/test/java/com/proofpoint/reporting/TestReportScheduler.java b/reporting-client/src/test/java/com/proofpoint/reporting/TestReportScheduler.java index c6c4cd1bc..4530d674c 100644 --- a/reporting-client/src/test/java/com/proofpoint/reporting/TestReportScheduler.java +++ b/reporting-client/src/test/java/com/proofpoint/reporting/TestReportScheduler.java @@ -22,7 +22,6 @@ import com.google.inject.Injector; import com.proofpoint.configuration.ConfigurationFactory; import com.proofpoint.configuration.ConfigurationModule; -import com.proofpoint.discovery.client.testing.TestingDiscoveryModule; import com.proofpoint.json.JsonModule; import com.proofpoint.node.ApplicationNameModule; import com.proofpoint.node.testing.TestingNodeModule; @@ -76,8 +75,9 @@ public void testReportingModule() Injector injector = Guice.createInjector( new ApplicationNameModule("test-application"), new TestingNodeModule(), - new TestingDiscoveryModule(), - new ConfigurationModule(new ConfigurationFactory(ImmutableMap.of())), + new ConfigurationModule(new ConfigurationFactory(ImmutableMap.of( + "service-client.reporting.uri", "https://reporting.invalid" + ))), new JsonModule(), new ReportingModule(), new ReportingClientModule()); diff --git a/reporting-client/src/test/java/com/proofpoint/reporting/TestReportingClientModule.java b/reporting-client/src/test/java/com/proofpoint/reporting/TestReportingClientModule.java index 82953c875..e9afb6823 100644 --- a/reporting-client/src/test/java/com/proofpoint/reporting/TestReportingClientModule.java +++ b/reporting-client/src/test/java/com/proofpoint/reporting/TestReportingClientModule.java @@ -17,7 +17,6 @@ import com.google.inject.Injector; import com.proofpoint.bootstrap.LifeCycleManager; -import com.proofpoint.discovery.client.testing.TestingDiscoveryModule; import com.proofpoint.json.JsonModule; import com.proofpoint.node.testing.TestingNodeModule; import org.testng.annotations.Test; @@ -35,9 +34,9 @@ public void testCreateInjector() new ReportingModule(), new JsonModule(), new TestingNodeModule(), - new TestingDiscoveryModule(), new ReportingClientModule() ) + .setRequiredConfigurationProperty("service-client.reporting.uri", "https://reporting.invalid") .initialize(); injector.getInstance(LifeCycleManager.class).stop();