From 4443b1f3944c09f699e5d50a79ff8a282a7da354 Mon Sep 17 00:00:00 2001 From: John Myers Date: Sat, 6 Sep 2014 11:26:22 -0700 Subject: [PATCH 1/4] Upgrade to Platform 1.03 --- pom.xml | 6 +++--- src/main/java/com/proofpoint/event/collector/Main.java | 5 +++-- .../java/com/proofpoint/event/collector/MainModule.java | 5 +++-- .../java/com/proofpoint/event/collector/TestServer.java | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index f0d60d4..37fd0e1 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.proofpoint.platform rest-server-base - 1.02 + 1.03 @@ -167,8 +167,8 @@ - com.sun.jersey - jersey-core + javax.ws.rs + javax.ws.rs-api diff --git a/src/main/java/com/proofpoint/event/collector/Main.java b/src/main/java/com/proofpoint/event/collector/Main.java index c33cb07..b4f28e6 100755 --- a/src/main/java/com/proofpoint/event/collector/Main.java +++ b/src/main/java/com/proofpoint/event/collector/Main.java @@ -21,7 +21,6 @@ import com.proofpoint.discovery.client.announce.Announcer; import com.proofpoint.event.client.JsonEventModule; import com.proofpoint.http.server.HttpServerModule; -import com.proofpoint.jaxrs.JaxrsModule; import com.proofpoint.jmx.JmxHttpModule; import com.proofpoint.jmx.JmxModule; import com.proofpoint.json.JsonModule; @@ -31,6 +30,8 @@ import com.proofpoint.reporting.ReportingModule; import org.weakref.jmx.guice.MBeanModule; +import static com.proofpoint.jaxrs.JaxrsModule.explicitJaxrsModule; + public class Main { private final static Logger log = Logger.get(Main.class); @@ -45,7 +46,7 @@ public static void main(String[] args) new DiscoveryModule(), new HttpServerModule(), new JsonModule(), - new JaxrsModule(), + explicitJaxrsModule(), new MBeanModule(), new JmxModule(), new JmxHttpModule(), diff --git a/src/main/java/com/proofpoint/event/collector/MainModule.java b/src/main/java/com/proofpoint/event/collector/MainModule.java index af07313..19e9212 100644 --- a/src/main/java/com/proofpoint/event/collector/MainModule.java +++ b/src/main/java/com/proofpoint/event/collector/MainModule.java @@ -47,6 +47,7 @@ import static com.proofpoint.configuration.ConfigurationModule.bindConfig; import static com.proofpoint.discovery.client.DiscoveryBinder.discoveryBinder; import static com.proofpoint.event.client.EventBinder.eventBinder; +import static com.proofpoint.jaxrs.JaxrsBinder.jaxrsBinder; import static com.proofpoint.reporting.ReportBinder.reportBinder; import static org.weakref.jmx.guice.ExportBinder.newExporter; import static java.util.concurrent.Executors.newScheduledThreadPool; @@ -71,7 +72,7 @@ public void configure(Binder binder) newExporter(binder).export(SpoolingEventWriter.class).withGeneratedName(); newSetBinder(binder, EventWriter.class).addBinding().to(Key.get(SpoolingEventWriter.class)).in(Scopes.SINGLETON); - binder.bind(EventResource.class).in(Scopes.SINGLETON); + jaxrsBinder(binder).bind(EventResource.class); binder.bind(StoredObjectCombiner.class).in(Scopes.SINGLETON); newExporter(binder).export(StoredObjectCombiner.class).withGeneratedName(); @@ -86,7 +87,7 @@ public void configure(Binder binder) eventBinder(binder).bindEventClient(CombineCompleted.class); - binder.bind(EventWriterStatsResource.class).in(Scopes.SINGLETON); + jaxrsBinder(binder).bind(EventWriterStatsResource.class); reportBinder(binder).bindReportCollection(EventCollectorStats.class).as(new ObjectNameBuilder(EventCollectorStats.class.getPackage().getName()).withProperty("type", "EventCollector").build()); diff --git a/src/test/java/com/proofpoint/event/collector/TestServer.java b/src/test/java/com/proofpoint/event/collector/TestServer.java index 523d3dd..6215432 100755 --- a/src/test/java/com/proofpoint/event/collector/TestServer.java +++ b/src/test/java/com/proofpoint/event/collector/TestServer.java @@ -30,7 +30,6 @@ import com.proofpoint.http.client.jetty.JettyHttpClient; import com.proofpoint.http.server.testing.TestingHttpServer; import com.proofpoint.http.server.testing.TestingHttpServerModule; -import com.proofpoint.jaxrs.JaxrsModule; import com.proofpoint.jmx.testing.TestingJmxModule; import com.proofpoint.json.JsonCodec; import com.proofpoint.json.JsonModule; @@ -53,6 +52,7 @@ import static com.proofpoint.http.client.StaticBodyGenerator.createStaticBodyGenerator; import static com.proofpoint.http.client.StatusResponseHandler.createStatusResponseHandler; import static com.proofpoint.http.client.StringResponseHandler.createStringResponseHandler; +import static com.proofpoint.jaxrs.JaxrsModule.explicitJaxrsModule; import static javax.ws.rs.core.HttpHeaders.CONTENT_TYPE; import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.Response.Status; @@ -91,7 +91,7 @@ public void setup() new TestingDiscoveryModule(), new TestingJmxModule(), new JsonModule(), - new JaxrsModule(), + explicitJaxrsModule(), new JsonEventModule(), new EventTapModule(), new ReportingModule(), From a8d4f1d89924dd2467149429c8463836202ccbe5 Mon Sep 17 00:00:00 2001 From: John Myers Date: Sat, 6 Sep 2014 11:29:29 -0700 Subject: [PATCH 2/4] Upgrade to Platform 1.05 and enable RPM packaging --- .build-rpm | 0 pom.xml | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 .build-rpm mode change 100644 => 100755 pom.xml diff --git a/.build-rpm b/.build-rpm new file mode 100644 index 0000000..e69de29 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 37fd0e1..d6e28b2 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.proofpoint.platform rest-server-base - 1.03 + 1.05 @@ -25,6 +25,7 @@ com.proofpoint.event.collector.Main + platform From 4cc4af70208d37a07894b94eadf8aebc3c97f18e Mon Sep 17 00:00:00 2001 From: John Myers Date: Sat, 6 Sep 2014 11:58:55 -0700 Subject: [PATCH 3/4] Support receiving SMILE-encoded events --- .../event/collector/EventResource.java | 20 ++++++ .../event/collector/TestEventResource.java | 36 ++++++++++ .../event/collector/TestServer.java | 72 +++++++++++++++++-- src/test/resources/single.json | 12 ---- 4 files changed, 123 insertions(+), 17 deletions(-) delete mode 100644 src/test/resources/single.json diff --git a/src/main/java/com/proofpoint/event/collector/EventResource.java b/src/main/java/com/proofpoint/event/collector/EventResource.java index 82a71ba..8cca3d6 100644 --- a/src/main/java/com/proofpoint/event/collector/EventResource.java +++ b/src/main/java/com/proofpoint/event/collector/EventResource.java @@ -63,6 +63,15 @@ public Response write(List events) return processEvents(WRITER, events, WRITE); } + // Separate method to permit gathering of statistics + @POST + @Consumes("application/x-jackson-smile") + public Response writeSmile(List events) + throws IOException + { + return write(events); + } + @POST @Path("/distribute") @Consumes(MediaType.APPLICATION_JSON) @@ -72,6 +81,17 @@ public Response distribute(List events) return processEvents(DISTRIBUTOR, events, DISTRIBUTE); } + + // Separate method to permit gathering of statistics + @POST + @Path("/distribute") + @Consumes("application/x-jackson-smile") + public Response distributeSmile(List events) + throws IOException + { + return distribute(events); + } + private Response processEvents(EventProcessor processor, List events, ProcessType processType) throws IOException { diff --git a/src/test/java/com/proofpoint/event/collector/TestEventResource.java b/src/test/java/com/proofpoint/event/collector/TestEventResource.java index d4cdfe5..4079e6f 100644 --- a/src/test/java/com/proofpoint/event/collector/TestEventResource.java +++ b/src/test/java/com/proofpoint/event/collector/TestEventResource.java @@ -79,6 +79,24 @@ public void testWrite() verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1))); } + @Test + public void testWriteSmile() + throws IOException + { + EventResource resource = new EventResource(ImmutableSet.of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats); + + Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA); + + List events = ImmutableList.of(event); + Response response = resource.writeSmile(events); + + verifyAcceptedResponse(response); + + verifyWrittenAndDistributedEvents(events, ImmutableList.of()); + + verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1))); + } + @Test public void testWriteUnsupportedType() throws IOException @@ -140,6 +158,24 @@ public void testDistribute() verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1))); } + @Test + public void testDistributeSmile() + throws IOException + { + EventResource resource = new EventResource(ImmutableSet.of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats); + + Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA); + + List events = ImmutableList.of(event); + Response response = resource.distributeSmile(events); + + verifyAcceptedResponse(response); + + verifyWrittenAndDistributedEvents(ImmutableList.of(), events); + + verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1))); + } + @Test public void testDistributeUnsupportedType() throws IOException diff --git a/src/test/java/com/proofpoint/event/collector/TestServer.java b/src/test/java/com/proofpoint/event/collector/TestServer.java index 6215432..a7b0b8a 100755 --- a/src/test/java/com/proofpoint/event/collector/TestServer.java +++ b/src/test/java/com/proofpoint/event/collector/TestServer.java @@ -15,7 +15,11 @@ */ package com.proofpoint.event.collector; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.google.common.base.Charsets; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.io.Files; import com.google.common.io.Resources; @@ -24,6 +28,7 @@ import com.proofpoint.bootstrap.LifeCycleManager; import com.proofpoint.discovery.client.testing.TestingDiscoveryModule; import com.proofpoint.event.client.JsonEventModule; +import com.proofpoint.http.client.BodyGenerator; import com.proofpoint.http.client.HttpClient; import com.proofpoint.http.client.StatusResponseHandler.StatusResponse; import com.proofpoint.http.client.StringResponseHandler.StringResponse; @@ -43,9 +48,11 @@ import java.io.File; import java.io.IOException; +import java.io.OutputStream; import java.net.URI; import java.util.concurrent.ExecutionException; +import static com.proofpoint.http.client.JsonBodyGenerator.jsonBodyGenerator; import static com.proofpoint.http.client.Request.Builder.prepareDelete; import static com.proofpoint.http.client.Request.Builder.prepareGet; import static com.proofpoint.http.client.Request.Builder.preparePost; @@ -60,7 +67,20 @@ public class TestServer { - private JsonCodec OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); + private static final JsonCodec OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); + private static final ObjectMapper MAPPER = new ObjectMapper(new SmileFactory()).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + private static final Object TESTING_SINGLE_EVENT_STRUCTURE = ImmutableList.of( + ImmutableMap.of( + "type", "Test", + "uuid", "DCD36293-3072-4AFD-B6E3-A9EB9CE1F219", + "host", "test.local", + "timestamp", "2011-03-30T16:10:16.000Z", + "data", ImmutableMap.of( + "foo", "bar", + "hello", "world" + ) + ) + ); private HttpClient client; private TestingHttpServer server; private File tempStageDir; @@ -134,11 +154,32 @@ public void teardown() public void testPostSingle() throws IOException, ExecutionException, InterruptedException { - String json = Resources.toString(Resources.getResource("single.json"), Charsets.UTF_8); StatusResponse response = client.execute(preparePost() .setUri(urlFor("/v2/event")) .setHeader("Content-Type", APPLICATION_JSON) - .setBodyGenerator(createStaticBodyGenerator(json, Charsets.UTF_8)) + .setBodyGenerator(jsonBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) + .build(), + createStatusResponseHandler()); + + assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); + } + + @Test + public void testPostSmile() + throws IOException, ExecutionException, InterruptedException + { + StatusResponse response = client.execute(preparePost() + .setUri(urlFor("/v2/event")) + .setHeader("Content-Type", "application/x-jackson-smile") + .setBodyGenerator(new BodyGenerator() + { + @Override + public void write(OutputStream outputStream) + throws Exception + { + MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); + } + }) .build(), createStatusResponseHandler()); @@ -190,17 +231,38 @@ public void testClearSpoolCounts() public void testDistributeSingle() throws IOException, ExecutionException, InterruptedException { - String json = Resources.toString(Resources.getResource("single.json"), Charsets.UTF_8); StatusResponse response = client.execute(preparePost() .setUri(urlFor("/v2/event/distribute")) .setHeader("Content-Type", APPLICATION_JSON) - .setBodyGenerator(createStaticBodyGenerator(json, Charsets.UTF_8)) + .setBodyGenerator(jsonBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) .build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); } + @Test + public void testDistributeSmile() + throws IOException, ExecutionException, InterruptedException + { + StatusResponse response = client.execute(preparePost() + .setUri(urlFor("/v2/event/distribute")) + .setHeader("Content-Type", "application/x-jackson-smile") + .setBodyGenerator(new BodyGenerator() + { + @Override + public void write(OutputStream outputStream) + throws Exception + { + MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); + } + }) + .build(), + createStatusResponseHandler()); + + assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); + } + private URI urlFor(String path) { return server.getBaseUrl().resolve(path); diff --git a/src/test/resources/single.json b/src/test/resources/single.json deleted file mode 100644 index 648ec20..0000000 --- a/src/test/resources/single.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "type": "Test", - "uuid": "DCD36293-3072-4AFD-B6E3-A9EB9CE1F219", - "host": "test.local", - "timestamp": "2011-03-30T16:10:16.000Z", - "data": { - "foo": "bar", - "hello": "world" - } - } -] From cd3ef30b250c95244edd3470e3af13b68aa2e9ba Mon Sep 17 00:00:00 2001 From: John Myers Date: Wed, 12 Nov 2014 11:27:26 -0800 Subject: [PATCH 4/4] Upgrade to Platform 1.07 --- pom.xml | 2 +- .../event/collector/TestServer.java | 30 ++++--------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index d6e28b2..d662d31 100755 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.proofpoint.platform rest-server-base - 1.05 + 1.07 diff --git a/src/test/java/com/proofpoint/event/collector/TestServer.java b/src/test/java/com/proofpoint/event/collector/TestServer.java index a7b0b8a..6be33f0 100755 --- a/src/test/java/com/proofpoint/event/collector/TestServer.java +++ b/src/test/java/com/proofpoint/event/collector/TestServer.java @@ -28,7 +28,6 @@ import com.proofpoint.bootstrap.LifeCycleManager; import com.proofpoint.discovery.client.testing.TestingDiscoveryModule; import com.proofpoint.event.client.JsonEventModule; -import com.proofpoint.http.client.BodyGenerator; import com.proofpoint.http.client.HttpClient; import com.proofpoint.http.client.StatusResponseHandler.StatusResponse; import com.proofpoint.http.client.StringResponseHandler.StringResponse; @@ -48,7 +47,6 @@ import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.net.URI; import java.util.concurrent.ExecutionException; @@ -56,6 +54,7 @@ import static com.proofpoint.http.client.Request.Builder.prepareDelete; import static com.proofpoint.http.client.Request.Builder.prepareGet; import static com.proofpoint.http.client.Request.Builder.preparePost; +import static com.proofpoint.http.client.SmileBodyGenerator.smileBodyGenerator; import static com.proofpoint.http.client.StaticBodyGenerator.createStaticBodyGenerator; import static com.proofpoint.http.client.StatusResponseHandler.createStatusResponseHandler; import static com.proofpoint.http.client.StringResponseHandler.createStringResponseHandler; @@ -68,7 +67,6 @@ public class TestServer { private static final JsonCodec OBJECT_CODEC = JsonCodec.jsonCodec(Object.class); - private static final ObjectMapper MAPPER = new ObjectMapper(new SmileFactory()).disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); private static final Object TESTING_SINGLE_EVENT_STRUCTURE = ImmutableList.of( ImmutableMap.of( "type", "Test", @@ -169,18 +167,10 @@ public void testPostSmile() throws IOException, ExecutionException, InterruptedException { StatusResponse response = client.execute(preparePost() - .setUri(urlFor("/v2/event")) - .setHeader("Content-Type", "application/x-jackson-smile") - .setBodyGenerator(new BodyGenerator() - { - @Override - public void write(OutputStream outputStream) - throws Exception - { - MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); - } - }) - .build(), + .setUri(urlFor("/v2/event")) + .setHeader("Content-Type", "application/x-jackson-smile") + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) + .build(), createStatusResponseHandler()); assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode()); @@ -248,15 +238,7 @@ public void testDistributeSmile() StatusResponse response = client.execute(preparePost() .setUri(urlFor("/v2/event/distribute")) .setHeader("Content-Type", "application/x-jackson-smile") - .setBodyGenerator(new BodyGenerator() - { - @Override - public void write(OutputStream outputStream) - throws Exception - { - MAPPER.writeValue(outputStream, TESTING_SINGLE_EVENT_STRUCTURE); - } - }) + .setBodyGenerator(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE)) .build(), createStatusResponseHandler());