cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: CXF-6360: Integration with Apache HTrace. Evolving sample application with HBase support.
Date Wed, 05 Aug 2015 00:44:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ddc01a185 -> 6f2a98efa


CXF-6360: Integration with Apache HTrace. Evolving sample application with HBase support.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6f2a98ef
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6f2a98ef
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6f2a98ef

Branch: refs/heads/master
Commit: 6f2a98efabe16b6e129ca86b292b74d006093541
Parents: ddc01a1
Author: reta <drreta@gmail.com>
Authored: Tue Aug 4 20:44:25 2015 -0400
Committer: reta <drreta@gmail.com>
Committed: Tue Aug 4 20:44:25 2015 -0400

----------------------------------------------------------------------
 .../samples/jax_rs/tracing_htrace/README.txt    |  6 +--
 .../java/demo/jaxrs/tracing/server/Catalog.java | 39 ++++++++++++++++----
 .../demo/jaxrs/tracing/server/CatalogStore.java |  9 +++++
 3 files changed, 44 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6f2a98ef/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt b/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
index 96adeb3..c246b6d 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/README.txt
@@ -27,9 +27,9 @@ docker run -p 2181:2181 -p 60010:60010 -p 60000:60000 -p 60020:60020 -p
60030:60
 Preparing test dataset
 ---------------------------------------
 create 'catalog', {NAME => 'c', VERSIONS => 5}
-put 'catalog', '1', 'c:title', 'Apache CXF Web Service Development'
-put 'catalog', '2', 'c:title', 'HBase: The Definitive Guide'
-put 'catalog', '3', 'c:title', 'HBase in Action'
+put 'catalog', '7e51155e-70fd-4b2a-b3ae-0b6352945ecf', 'c:title', 'Apache CXF Web Service
Development'
+put 'catalog', 'f948c2ca-9687-4d56-8388-75bfde31fae9', 'c:title', 'HBase: The Definitive
Guide'
+put 'catalog', 'bd80053a-9542-47fa-9a36-25af5521f2fb', 'c:title', 'HBase in Action'
 
 Building and running the demo using Maven
 ---------------------------------------

http://git-wip-us.apache.org/repos/asf/cxf/blob/6f2a98ef/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
index b52cf86..1761bb8 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Catalog.java
@@ -21,9 +21,12 @@ package demo.jaxrs.tracing.server;
 
 
 import java.io.IOException;
+import java.util.UUID;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 
+import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonObject;
 import javax.ws.rs.DELETE;
@@ -34,13 +37,13 @@ import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
-import javax.ws.rs.container.AsyncResponse;
-import javax.ws.rs.container.Suspended;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.cxf.tracing.Traceable;
+import org.apache.cxf.tracing.TracerContext;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.trace.SpanReceiverHost;
@@ -62,12 +65,34 @@ public class Catalog {
     
     @POST
     @Produces(MediaType.APPLICATION_JSON)
-    public void addBook(@Suspended final AsyncResponse response, @Context final UriInfo uri,

+    public Response addBook(@Context final UriInfo uriInfo, @Context final TracerContext
tracing, 
             @FormParam("title") final String title)  {
-        executor.submit(new Runnable() {
-            public void run() {
-            }
-        });
+        try {
+            final String id = UUID.randomUUID().toString();
+        
+            executor.submit(
+                tracing.wrap("Inserting New Book", 
+                    new Traceable<Void>() {
+                        public Void call(final TracerContext context) throws Exception {
+                            store.put(id, title);
+                            return null;
+                        }
+                    }
+                )
+            ).get(10, TimeUnit.SECONDS);
+            
+            return Response
+                .created(uriInfo.getRequestUriBuilder().path(id).build())
+                .build();
+        } catch (final Exception ex) {
+            return Response
+                .serverError()
+                .entity(Json
+                     .createObjectBuilder()
+                     .add("error", ex.getMessage())
+                     .build())
+                .build();
+        }
     }
     
     @GET

http://git-wip-us.apache.org/repos/asf/cxf/blob/6f2a98ef/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
index 0960441..060cbbb 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
@@ -34,6 +34,7 @@ import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.ConnectionFactory;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.client.ResultScanner;
 import org.apache.hadoop.hbase.client.Scan;
@@ -83,6 +84,14 @@ public class CatalogStore {
         return null;
     }
     
+    public void put(final String key, final String title) throws IOException {
+        try (final Table table = connection.getTable(TableName.valueOf(tableName))) {
+            final Put put = new Put(Bytes.toBytes(key));
+            put.addColumn(Bytes.toBytes("c"), Bytes.toBytes("title"), Bytes.toBytes(title));
+            table.put(put);
+        }
+    }
+    
     public JsonArray scan() throws IOException {
         final JsonArrayBuilder builder = Json.createArrayBuilder();
         


Mime
View raw message