Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

smile #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .build-rpm
Empty file.
7 changes: 4 additions & 3 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<parent>
<groupId>com.proofpoint.platform</groupId>
<artifactId>rest-server-base</artifactId>
<version>1.02</version>
<version>1.07</version>
</parent>

<licenses>
Expand All @@ -25,6 +25,7 @@

<properties>
<main-class>com.proofpoint.event.collector.Main</main-class>
<project.rpm.username>platform</project.rpm.username>
</properties>

<scm>
Expand Down Expand Up @@ -167,8 +168,8 @@
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>

<dependency>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/proofpoint/event/collector/EventResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ public Response write(List<Event> events)
return processEvents(WRITER, events, WRITE);
}

// Separate method to permit gathering of statistics
@POST
@Consumes("application/x-jackson-smile")
public Response writeSmile(List<Event> events)
throws IOException
{
return write(events);
}

@POST
@Path("/distribute")
@Consumes(MediaType.APPLICATION_JSON)
Expand All @@ -72,6 +81,17 @@ public Response distribute(List<Event> 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<Event> events)
throws IOException
{
return distribute(events);
}

private Response processEvents(EventProcessor processor, List<Event> events, ProcessType processType)
throws IOException
{
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/proofpoint/event/collector/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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(),
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/proofpoint/event/collector/MainModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<EventWriter>of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats);

Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA);

List<Event> events = ImmutableList.of(event);
Response response = resource.writeSmile(events);

verifyAcceptedResponse(response);

verifyWrittenAndDistributedEvents(events, ImmutableList.<Event>of());

verifyMetrics(WRITE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
}

@Test
public void testWriteUnsupportedType()
throws IOException
Expand Down Expand Up @@ -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.<EventWriter>of(writer), new ServerConfig().setAcceptedEventTypes("Test"), eventCollectorStats);

Event event = new Event("Test", UUID.randomUUID().toString(), "test.local", new DateTime(), ARBITRARY_DATA);

List<Event> events = ImmutableList.of(event);
Response response = resource.distributeSmile(events);

verifyAcceptedResponse(response);

verifyWrittenAndDistributedEvents(ImmutableList.<Event>of(), events);

verifyMetrics(DISTRIBUTE, ImmutableList.of(new EventMetric("Test", VALID, 1)));
}

@Test
public void testDistributeUnsupportedType()
throws IOException
Expand Down
58 changes: 51 additions & 7 deletions src/test/java/com/proofpoint/event/collector/TestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +34,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;
Expand All @@ -47,20 +50,35 @@
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;
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;
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;
import static org.testng.Assert.assertEquals;

public class TestServer
{
private JsonCodec<Object> OBJECT_CODEC = JsonCodec.jsonCodec(Object.class);
private static final JsonCodec<Object> OBJECT_CODEC = JsonCodec.jsonCodec(Object.class);
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;
Expand Down Expand Up @@ -91,7 +109,7 @@ public void setup()
new TestingDiscoveryModule(),
new TestingJmxModule(),
new JsonModule(),
new JaxrsModule(),
explicitJaxrsModule(),
new JsonEventModule(),
new EventTapModule(),
new ReportingModule(),
Expand Down Expand Up @@ -134,17 +152,30 @@ 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(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE))
.build(),
createStatusResponseHandler());

assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode());
}

@Test
public void testPostMultiple()
throws IOException, ExecutionException, InterruptedException
Expand Down Expand Up @@ -190,17 +221,30 @@ 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(smileBodyGenerator(OBJECT_CODEC, TESTING_SINGLE_EVENT_STRUCTURE))
.build(),
createStatusResponseHandler());

assertEquals(response.getStatusCode(), Status.ACCEPTED.getStatusCode());
}

private URI urlFor(String path)
{
return server.getBaseUrl().resolve(path);
Expand Down
12 changes: 0 additions & 12 deletions src/test/resources/single.json

This file was deleted.