chukwa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ey...@apache.org
Subject [01/19] chukwa git commit: CHUKWA-747. Change widget to be stored in HBase. (Eric Yang)
Date Tue, 26 May 2015 00:12:36 GMT
Repository: chukwa
Updated Branches:
  refs/heads/master a6e0cbad7 -> dfe84a2c3


CHUKWA-747. Change widget to be stored in HBase.  (Eric Yang)


Project: http://git-wip-us.apache.org/repos/asf/chukwa/repo
Commit: http://git-wip-us.apache.org/repos/asf/chukwa/commit/1c4ed7bc
Tree: http://git-wip-us.apache.org/repos/asf/chukwa/tree/1c4ed7bc
Diff: http://git-wip-us.apache.org/repos/asf/chukwa/diff/1c4ed7bc

Branch: refs/heads/master
Commit: 1c4ed7bcc043e6b391ca5a74edb224a6cdabc1cb
Parents: a6e0cba
Author: Eric Yang <eyang@apache.org>
Authored: Sun May 10 16:26:50 2015 -0700
Committer: Eric Yang <eyang@apache.org>
Committed: Sun May 10 16:26:50 2015 -0700

----------------------------------------------------------------------
 .../apache/hadoop/chukwa/hicc/bean/Widget.java  |  63 ++++++++++
 .../chukwa/hicc/rest/WidgetController.java      | 123 +++++++++++++++++++
 .../chukwa/rest/resource/WidgetResource.java    |   2 +-
 3 files changed, 187 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/chukwa/blob/1c4ed7bc/src/main/java/org/apache/hadoop/chukwa/hicc/bean/Widget.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/chukwa/hicc/bean/Widget.java b/src/main/java/org/apache/hadoop/chukwa/hicc/bean/Widget.java
new file mode 100644
index 0000000..987f525
--- /dev/null
+++ b/src/main/java/org/apache/hadoop/chukwa/hicc/bean/Widget.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.hadoop.chukwa.hicc.bean;
+
+import java.net.URI;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class Widget {
+  @XmlElement
+  public String title;
+  @XmlElement
+  public URI url;
+  @XmlElement
+  public String[] tokens;
+
+  public String getTitle() {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+
+  public URI getUrl() {
+    return url;
+  }
+  
+  public void setUrl(URI url) {
+    this.url = url;
+  }
+
+  public String[] getTokens() {
+    return tokens;
+  }
+
+  public void setTokens(String[] tokens) {
+    this.tokens = tokens;
+  }
+
+  public void tokenize() {
+    String[] tokens = title.split(" ");
+    this.tokens = tokens;    
+  }
+}

http://git-wip-us.apache.org/repos/asf/chukwa/blob/1c4ed7bc/src/main/java/org/apache/hadoop/chukwa/hicc/rest/WidgetController.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/chukwa/hicc/rest/WidgetController.java b/src/main/java/org/apache/hadoop/chukwa/hicc/rest/WidgetController.java
new file mode 100644
index 0000000..1df8efb
--- /dev/null
+++ b/src/main/java/org/apache/hadoop/chukwa/hicc/rest/WidgetController.java
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.hadoop.chukwa.hicc.rest;
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Scope;
+import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.hadoop.chukwa.datastore.ChukwaHBaseStore;
+import org.apache.hadoop.chukwa.hicc.bean.Widget;
+import org.apache.log4j.Logger;
+
+import com.google.gson.Gson;
+
+@Path("widget")
+public class WidgetController {
+
+  static Logger LOG = Logger.getLogger(WidgetController.class);
+
+  @Context
+  private ServletContext context;
+
+  @PostConstruct
+  @Singleton
+  public void init() {
+    ChukwaHBaseStore.populateDefaults();
+  }
+
+  @GET
+  @Path("list")
+  public String listWidget(@DefaultValue("1000") @QueryParam("limit") int limit, 
+      @DefaultValue("0") @QueryParam("offset") int offset) {
+    List<Widget> widgets = ChukwaHBaseStore.listWidget(limit, offset);
+    Gson gson = new Gson();
+    String json = gson.toJson(widgets);
+    return json;
+  }
+
+  @GET
+  @Path("search/{query}")
+  public String searchWidget(@PathParam("query") String query) {
+    List<Widget> widgets = ChukwaHBaseStore.searchWidget(query);
+    Gson gson = new Gson();
+    String json = gson.toJson(widgets);
+    return json;
+  }
+
+  @GET
+  @Path("view/{title}")
+  public String viewWidget(@PathParam("title") String title) {
+    Widget w = ChukwaHBaseStore.viewWidget(title);
+    Gson gson = new Gson();
+    String json = gson.toJson(w);
+    return json;
+  }
+
+  @POST
+  @Path("create")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response createWidget(String buffer) {
+    Gson gson = new Gson();
+    Widget widget = gson.fromJson(buffer, Widget.class);
+    boolean result = ChukwaHBaseStore.createWidget(widget);
+    if(!result) {
+      return Response.status(Status.BAD_REQUEST).build();
+    }
+    return Response.ok().build();
+  }
+
+  @PUT
+  @Path("update/{title}")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response updateWidget(@PathParam("title") String title, String buffer){
+    Gson gson = new Gson();
+    Widget widget = gson.fromJson(buffer, Widget.class);
+    boolean result = ChukwaHBaseStore.updateWidget(title, widget);
+    if(!result) {
+      return Response.status(Status.BAD_REQUEST).build();
+    }
+    return Response.ok().build();
+  }
+
+  @DELETE
+  @Path("delete/{title}")
+  public Response deleteWidget(@PathParam("title") String title) {
+    boolean result = ChukwaHBaseStore.deleteWidget(title);
+    if(!result) {
+      return Response.status(Status.BAD_REQUEST).build();
+    }
+    return Response.ok().build();
+  }
+}

http://git-wip-us.apache.org/repos/asf/chukwa/blob/1c4ed7bc/src/main/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java b/src/main/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java
index b4be659..5c0bf37 100755
--- a/src/main/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java
+++ b/src/main/java/org/apache/hadoop/chukwa/rest/resource/WidgetResource.java
@@ -36,7 +36,7 @@ import javax.ws.rs.PathParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Response;
 
-@Path ("/widget")
+@Path ("/widget1")
 public class WidgetResource {
   private static Log log = LogFactory.getLog(WidgetResource.class);
   


Mime
View raw message