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.net.URI;
23import org.apache.hadoop.chukwa.ChukwaArchiveKey;
24import org.apache.hadoop.chukwa.ChunkImpl;
25import org.apache.hadoop.conf.Configuration;
26import org.apache.hadoop.fs.FileSystem;
27import org.apache.hadoop.fs.Path;
28import org.apache.hadoop.io.SequenceFile;
29import org.apache.hadoop.io.Writable;
3031publicclassSinkFileValidator {
3233publicstaticvoid main(String[] args) {
34 String fsURL = "hdfs://localhost:9000";
35 String fname;
36if (args.length < 1) {
37 System.out
38 .println("usage: SinkFileValidator <filename> [filesystem URI] ");
39 System.exit(0);
40 }
41 fname = args[0];
42if (args.length > 1)
43 fsURL = args[1];
4445 Configuration conf = new Configuration();
46try {
47 FileSystem fs;
48if (fsURL.equals("local"))
49 fs = FileSystem.getLocal(conf);
50else51 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());
5556ChukwaArchiveKey key = newChukwaArchiveKey();
57ChunkImpl evt = ChunkImpl.getBlankChunk();
58int events = 0;
59while (r.next(key, evt) && (events < 5)) {
60if (!Writable.class.isAssignableFrom(key.getClass()))
61 System.out.println("warning: keys aren't writable");
6263if (!Writable.class.isAssignableFrom(evt.getClass()))
64 System.out.println("warning: values aren't writable");
6566if (evt.getData().length > 1000) {
67 System.out.println("got event; data: "68 + new String(evt.getData(), 0, 1000));
69 System.out.println("....[truncating]");
70 } else71 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 }
7879 }
8081 }