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.net.URI;
23 import org.apache.hadoop.chukwa.ChukwaArchiveKey;
24 import org.apache.hadoop.chukwa.ChunkImpl;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.fs.FileSystem;
27 import org.apache.hadoop.fs.Path;
28 import org.apache.hadoop.io.SequenceFile;
29 import org.apache.hadoop.io.Writable;
30
31 public class SinkFileValidator {
32
33 public static void main(String[] args) {
34 String fsURL = "hdfs://localhost:9000";
35 String fname;
36 if (args.length < 1) {
37 System.out
38 .println("usage: SinkFileValidator <filename> [filesystem URI] ");
39 System.exit(0);
40 }
41 fname = args[0];
42 if (args.length > 1)
43 fsURL = args[1];
44
45 Configuration conf = new Configuration();
46 try {
47 FileSystem fs;
48 if (fsURL.equals("local"))
49 fs = FileSystem.getLocal(conf);
50 else
51 fs = FileSystem.get(new URI(fsURL), conf);
52 SequenceFile.Reader r = new SequenceFile.Reader(fs, new Path(fname), conf);
53 System.out.println("key class name is " + r.getKeyClassName());
54 System.out.println("value class name is " + r.getValueClassName());
55
56 ChukwaArchiveKey key = new ChukwaArchiveKey();
57 ChunkImpl evt = ChunkImpl.getBlankChunk();
58 int events = 0;
59 while (r.next(key, evt) && (events < 5)) {
60 if (!Writable.class.isAssignableFrom(key.getClass()))
61 System.out.println("warning: keys aren't writable");
62
63 if (!Writable.class.isAssignableFrom(evt.getClass()))
64 System.out.println("warning: values aren't writable");
65
66 if (evt.getData().length > 1000) {
67 System.out.println("got event; data: "
68 + new String(evt.getData(), 0, 1000));
69 System.out.println("....[truncating]");
70 } else
71 System.out.println("got event; data: " + new String(evt.getData()));
72 events++;
73 }
74 System.out.println("file looks OK!");
75 } catch (Exception e) {
76 e.printStackTrace();
77 }
78
79 }
80
81 }