1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.hadoop.chukwa.datacollection.test;
202122import java.io.IOException;
23import java.net.URI;
24import java.net.URISyntaxException;
25import java.nio.charset.Charset;
2627import org.apache.hadoop.chukwa.ChukwaArchiveKey;
28import org.apache.hadoop.chukwa.ChunkImpl;
29import org.apache.hadoop.conf.Configuration;
30import org.apache.hadoop.fs.FileSystem;
31import org.apache.hadoop.fs.Path;
32import org.apache.hadoop.io.SequenceFile;
33import org.apache.hadoop.io.Writable;
3435publicclassSinkFileValidator {
3637publicstaticvoid main(String[] args) {
38 String fsURL = "hdfs://localhost:9000";
39 String fname;
40if (args.length < 1) {
41 System.out
42 .println("usage: SinkFileValidator <filename> [filesystem URI] ");
43return;
44 }
45 fname = args[0];
46if (args.length > 1)
47 fsURL = args[1];
4849 Configuration conf = new Configuration();
50try {
51 FileSystem fs;
52if (fsURL.equals("local"))
53 fs = FileSystem.getLocal(conf);
54else55 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());
5960ChukwaArchiveKey key = newChukwaArchiveKey();
61ChunkImpl evt = ChunkImpl.getBlankChunk();
62int events = 0;
63while (r.next(key, evt) && (events < 5)) {
64if (!Writable.class.isAssignableFrom(key.getClass()))
65 System.out.println("warning: keys aren't writable");
6667if (!Writable.class.isAssignableFrom(evt.getClass()))
68 System.out.println("warning: values aren't writable");
6970if (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 } else75 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 }
8485 }
8687 }