1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.datacollection.test;
20
21
22 import java.io.IOException;
23 import java.net.URI;
24 import java.net.URISyntaxException;
25 import java.nio.charset.Charset;
26
27 import org.apache.hadoop.chukwa.ChukwaArchiveKey;
28 import org.apache.hadoop.chukwa.ChunkImpl;
29 import org.apache.hadoop.conf.Configuration;
30 import org.apache.hadoop.fs.FileSystem;
31 import org.apache.hadoop.fs.Path;
32 import org.apache.hadoop.io.SequenceFile;
33 import org.apache.hadoop.io.Writable;
34
35 public class SinkFileValidator {
36
37 public static void main(String[] args) {
38 String fsURL = "hdfs://localhost:9000";
39 String fname;
40 if (args.length < 1) {
41 System.out
42 .println("usage: SinkFileValidator <filename> [filesystem URI] ");
43 return;
44 }
45 fname = args[0];
46 if (args.length > 1)
47 fsURL = args[1];
48
49 Configuration conf = new Configuration();
50 try {
51 FileSystem fs;
52 if (fsURL.equals("local"))
53 fs = FileSystem.getLocal(conf);
54 else
55 fs = FileSystem.get(new URI(fsURL), conf);
56 SequenceFile.Reader r = new SequenceFile.Reader(fs, new Path(fname), conf);
57 System.out.println("key class name is " + r.getKeyClassName());
58 System.out.println("value class name is " + r.getValueClassName());
59
60 ChukwaArchiveKey key = new ChukwaArchiveKey();
61 ChunkImpl evt = ChunkImpl.getBlankChunk();
62 int events = 0;
63 while (r.next(key, evt) && (events < 5)) {
64 if (!Writable.class.isAssignableFrom(key.getClass()))
65 System.out.println("warning: keys aren't writable");
66
67 if (!Writable.class.isAssignableFrom(evt.getClass()))
68 System.out.println("warning: values aren't writable");
69
70 if (evt.getData().length > 1000) {
71 System.out.println("got event; data: "
72 + new String(evt.getData(), 0, 1000, Charset.forName("UTF-8")));
73 System.out.println("....[truncating]");
74 } else
75 System.out.println("got event; data: " + new String(evt.getData(), Charset.forName("UTF-8")));
76 events++;
77 }
78 System.out.println("file looks OK!");
79 } catch (IOException e) {
80 e.printStackTrace();
81 } catch (URISyntaxException e) {
82 e.printStackTrace();
83 }
84
85 }
86
87 }