This project has retired. For details please refer to its
Attic page.
WidgetController xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.hicc.rest;
19
20 import java.util.List;
21
22 import javax.annotation.PostConstruct;
23 import javax.inject.Singleton;
24 import javax.servlet.ServletContext;
25 import javax.ws.rs.Consumes;
26 import javax.ws.rs.DELETE;
27 import javax.ws.rs.DefaultValue;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.PUT;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.QueryParam;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
37 import javax.ws.rs.core.Response;
38 import javax.ws.rs.core.Response.Status;
39
40 import org.apache.hadoop.chukwa.datastore.ChukwaHBaseStore;
41 import org.apache.hadoop.chukwa.hicc.bean.Widget;
42 import org.apache.log4j.Logger;
43
44 import com.google.gson.Gson;
45
46 @Path("widget")
47 public class WidgetController {
48
49 static Logger LOG = Logger.getLogger(WidgetController.class);
50
51 @Context
52 private ServletContext context;
53
54 @PostConstruct
55 @Singleton
56 public void init() {
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70 @GET
71 @Path("list")
72 @Produces(MediaType.APPLICATION_JSON)
73 public String listWidget(@DefaultValue("1000") @QueryParam("limit") int limit,
74 @DefaultValue("0") @QueryParam("offset") int offset) {
75 List<Widget> widgets = ChukwaHBaseStore.listWidget(limit, offset);
76 Gson gson = new Gson();
77 String json = gson.toJson(widgets);
78 return json;
79 }
80
81
82
83
84
85
86
87
88
89
90 @GET
91 @Path("search/{query}")
92 public String searchWidget(@PathParam("query") String query) {
93 List<Widget> widgets = ChukwaHBaseStore.searchWidget(query);
94 Gson gson = new Gson();
95 String json = gson.toJson(widgets);
96 return json;
97 }
98
99
100
101
102
103
104
105
106
107
108 @GET
109 @Path("view/{title}")
110 public String viewWidget(@PathParam("title") String title) {
111 Widget w = ChukwaHBaseStore.viewWidget(title);
112 Gson gson = new Gson();
113 String json = gson.toJson(w);
114 return json;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 @POST
131 @Path("create")
132 @Consumes(MediaType.APPLICATION_JSON)
133 public Response createWidget(String buffer) {
134 Gson gson = new Gson();
135 Widget widget = gson.fromJson(buffer, Widget.class);
136 boolean result = ChukwaHBaseStore.createWidget(widget);
137 if(!result) {
138 return Response.status(Status.BAD_REQUEST).build();
139 }
140 return Response.ok().build();
141 }
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 @PUT
158 @Path("update/{title}")
159 @Consumes(MediaType.APPLICATION_JSON)
160 public Response updateWidget(@PathParam("title") String title, String buffer){
161 Gson gson = new Gson();
162 Widget widget = gson.fromJson(buffer, Widget.class);
163 boolean result = ChukwaHBaseStore.updateWidget(title, widget);
164 if(!result) {
165 return Response.status(Status.BAD_REQUEST).build();
166 }
167 return Response.ok().build();
168 }
169
170
171
172
173
174
175
176
177
178
179
180
181
182 @DELETE
183 @Path("delete/{title}")
184 public Response deleteWidget(@PathParam("title") String title) {
185 boolean result = ChukwaHBaseStore.deleteWidget(title);
186 if(!result) {
187 return Response.status(Status.BAD_REQUEST).build();
188 }
189 return Response.ok().build();
190 }
191 }