You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2015/07/06 00:57:43 UTC
cxf git commit: CXF-6360: Integration with Apache HTrace. Evolving
sample application with HBase support.
Repository: cxf
Updated Branches:
refs/heads/master 4306144c1 -> e545379cd
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/e545379c
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e545379c
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e545379c
Branch: refs/heads/master
Commit: e545379cdc71ba79bd6c60b4ee788d11db678d24
Parents: 4306144
Author: reta <dr...@gmail.com>
Authored: Sun Jul 5 18:57:19 2015 -0400
Committer: reta <dr...@gmail.com>
Committed: Sun Jul 5 18:57:19 2015 -0400
----------------------------------------------------------------------
.../samples/jax_rs/tracing_htrace/pom.xml | 6 +-
.../java/demo/jaxrs/tracing/client/Client.java | 29 +++++-
.../java/demo/jaxrs/tracing/server/Catalog.java | 44 ++++----
.../demo/jaxrs/tracing/server/CatalogStore.java | 104 +++++++++++++++++++
.../java/demo/jaxrs/tracing/server/Server.java | 19 ++++
5 files changed, 172 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/e545379c/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
index c84bb96..d7a3936 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/pom.xml
@@ -135,6 +135,10 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hbase</groupId>
+ <artifactId>hbase-client</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/cxf/blob/e545379c/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
index ee2ca0e..9c33696 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/client/Client.java
@@ -1,7 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package demo.jaxrs.tracing.client;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.Map;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -13,9 +33,12 @@ import org.apache.htrace.Trace;
import org.apache.htrace.impl.AlwaysSampler;
import org.apache.htrace.impl.StandardOutSpanReceiver;
-public class Client {
- public static void main( final String[] args ) throws Exception {
- final HashMap<String, String> properties = new HashMap<String, String>();
+public final class Client {
+ private Client() {
+ }
+
+ public static void main(final String[] args) throws Exception {
+ final Map<String, String> properties = new HashMap<String, String>();
final HTraceConfiguration conf = HTraceConfiguration.fromMap(properties);
Trace.addReceiver(new StandardOutSpanReceiver(conf));
http://git-wip-us.apache.org/repos/asf/cxf/blob/e545379c/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 7e7f52d..d2fdc5e 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
@@ -20,15 +20,11 @@
package demo.jaxrs.tracing.server;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
+import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import javax.json.Json;
import javax.json.JsonArray;
-import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
@@ -45,10 +41,18 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+
@Path("/catalog")
public class Catalog {
private final ExecutorService executor = Executors.newFixedThreadPool(2);
- private ConcurrentMap<String, String> books = new ConcurrentHashMap<>();
+ private final CatalogStore store;
+
+ public Catalog() throws IOException {
+ final Configuration configuration = HBaseConfiguration.create();
+ store = new CatalogStore(configuration, "books");
+ }
@POST
@Produces(MediaType.APPLICATION_JSON)
@@ -62,40 +66,28 @@ public class Catalog {
@GET
@Produces(MediaType.APPLICATION_JSON)
- public JsonArray getBooks() {
- final JsonArrayBuilder builder = Json.createArrayBuilder();
-
- for (final Map.Entry<String, String> entry: books.entrySet()) {
- builder.add(Json.createObjectBuilder()
- .add("id", entry.getKey())
- .add("title", entry.getValue())
- );
- }
-
- return builder.build();
+ public JsonArray getBooks() throws IOException {
+ return store.scan();
}
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
- public JsonObject getBook(@PathParam("id") final String id) {
- final String title = books.get(id);
+ public JsonObject getBook(@PathParam("id") final String id) throws IOException {
+ final JsonObject book = store.get(id);
- if (title == null) {
+ if (book == null) {
throw new NotFoundException("Book with does not exists: " + id);
}
- return Json.createObjectBuilder()
- .add("id", id)
- .add("title", title)
- .build();
+ return book;
}
@DELETE
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
- public Response delete(@PathParam("id") final String id) {
- if (books.remove(id) == null) {
+ public Response delete(@PathParam("id") final String id) throws IOException {
+ if (!store.remove(id)) {
throw new NotFoundException("Book with does not exists: " + id);
}
http://git-wip-us.apache.org/repos/asf/cxf/blob/e545379c/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
new file mode 100644
index 0000000..5ab8efa
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/CatalogStore.java
@@ -0,0 +1,104 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.jaxrs.tracing.server;
+
+import java.io.IOException;
+
+import javax.json.Json;
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObject;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.TableName;
+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.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.trace.SpanReceiverHost;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class CatalogStore {
+ @SuppressWarnings("unused")
+ private final SpanReceiverHost spanReceiverHost;
+ private final Connection connection;
+ private final String tableName;
+
+ public CatalogStore(final Configuration configuration, final String tableName) throws IOException {
+ this.connection = ConnectionFactory.createConnection(configuration);
+ this.spanReceiverHost = SpanReceiverHost.getInstance(configuration);
+ this.tableName = tableName;
+ }
+
+ public boolean remove(final String key) throws IOException {
+ try (final Table table = connection.getTable(TableName.valueOf(tableName))) {
+ if (get(key) != null) {
+ final Delete delete = new Delete(Bytes.toBytes(key));
+ table.delete(delete);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public JsonObject get(final String key) throws IOException {
+ try (final Table table = connection.getTable(TableName.valueOf(tableName))) {
+ final Get get = new Get(Bytes.toBytes(key));
+ final Result result = table.get(get);
+
+ if (!result.isEmpty()) {
+ final Cell cell = result.getColumnLatestCell(Bytes.toBytes("c"), Bytes.toBytes("title"));
+
+ return Json.createObjectBuilder()
+ .add("id", Bytes.toString(cell.getRowArray()))
+ .add("title", Bytes.toString(cell.getValueArray()))
+ .build();
+ }
+ }
+
+ return null;
+ }
+
+ public JsonArray scan() throws IOException {
+ final JsonArrayBuilder builder = Json.createArrayBuilder();
+
+ try (final Table table = connection.getTable(TableName.valueOf(tableName))) {
+ final Scan scan = new Scan();
+ final ResultScanner results = table.getScanner(scan);
+ for (final Result result: results) {
+ final Cell cell = result.getColumnLatestCell(Bytes.toBytes("c"), Bytes.toBytes("title"));
+
+ builder.add(Json.createObjectBuilder()
+ .add("id", new String(cell.getRowArray()))
+ .add("title", new String(cell.getValueArray()))
+ );
+ }
+ }
+
+ return builder.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cxf/blob/e545379c/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
index aff8c8b..eda69b6 100644
--- a/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
+++ b/distribution/src/main/release/samples/jax_rs/tracing_htrace/src/main/java/demo/jaxrs/tracing/server/Server.java
@@ -1,3 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package demo.jaxrs.tracing.server;
import org.apache.commons.lang.StringUtils;