1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.rest.resource;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.apache.hadoop.chukwa.Chunk;
24 import org.apache.hadoop.chukwa.ChunkImpl;
25 import org.apache.hadoop.chukwa.datacollection.writer.PipelineStageWriter;
26 import org.apache.hadoop.chukwa.datacollection.writer.SocketTeeWriter;
27 import org.apache.hadoop.chukwa.datacollection.writer.WriterException;
28 import org.apache.hadoop.chukwa.rest.bean.ClientTraceBean;
29 import org.apache.hadoop.chukwa.rest.bean.UserBean;
30 import org.apache.hadoop.chukwa.rest.bean.WidgetBean;
31 import org.apache.hadoop.chukwa.util.ExceptionUtil;
32 import org.apache.hadoop.conf.Configuration;
33
34 import com.sun.jersey.api.client.Client;
35 import com.sun.jersey.api.client.GenericType;
36
37 public class TestClientTrace extends SetupTestEnv {
38 public void testClientTrace() {
39
40 Configuration conf = new Configuration();
41 conf.set("chukwaCollector.pipeline",
42 SocketTeeWriter.class.getCanonicalName());
43 conf.set("chukwaCollector.writerClass",
44 PipelineStageWriter.class.getCanonicalName());
45 PipelineStageWriter psw = new PipelineStageWriter();
46 try {
47 psw.init(conf);
48
49 ArrayList<Chunk> l = new ArrayList<Chunk>();
50 String line = "2009-12-29 22:32:27,047 INFO org.apache.hadoop.hdfs.server.datanode.DataNode.clienttrace: src: /10.10.100.60:43707, dest: /10.10.100.60:50010, bytes: 7003141, op: HDFS_WRITE, cliID: DFSClient_-8389654, offset: 0, srvID: DS-2032680158-98.137.100.60-50010-1259976007324, blockid: blk_-2723720761101769540_705411, duration: 289013780000";
51 l.add(new ChunkImpl("ClientTrace", "name", 1, line.getBytes(), null));
52 assertTrue(l.size()==1);
53 psw.add(l);
54 assertTrue(true);
55 } catch (WriterException e) {
56 fail(ExceptionUtil.getStackTrace(e));
57 }
58
59 try {
60
61 client = Client.create();
62 resource = client.resource("http://localhost:"+restPort);
63 List<ClientTraceBean> list = resource.path("/hicc/v1/clienttrace").header("Authorization", authorization).get(new GenericType<List<ClientTraceBean>>(){});
64 for(ClientTraceBean ctb : list) {
65 assertEquals("HDFS_WRITE", ctb.getAction());
66 }
67 } catch (Exception e) {
68 fail(ExceptionUtil.getStackTrace(e));
69 }
70 }
71 }