This project has retired. For details please refer to its Attic page.
SinkFileValidator xref
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  
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  }