View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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      // Setup Collector
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        // Send a client trace chunk
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        // Locate the client trace object
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  }