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.extraction.demux.processor.mapper;
202122import java.io.IOException;
23import java.text.ParseException;
24import java.text.SimpleDateFormat;
25import java.util.Calendar;
26import java.util.Date;
2728import org.apache.hadoop.chukwa.datacollection.writer.hbase.Annotation.Table;
29import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
30import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
31import org.apache.hadoop.mapred.OutputCollector;
32import org.apache.hadoop.mapred.Reporter;
33import org.apache.log4j.Logger;
3435 @Table(name="SystemMetrics",columnFamily="SysLog")
36publicclassSysLogextendsAbstractProcessor {
3738static Logger log = Logger.getLogger(SysLog.class);
39privatestaticfinal String reduceType = "SysLog";
40private SimpleDateFormat sdf = null;
4142publicSysLog() {
43 sdf = new SimpleDateFormat("MMM d HH:mm:ss");
44 }
4546 @Override
47protectedvoid parse(String recordEntry,
48 OutputCollector<ChukwaRecordKey, ChukwaRecord> output, Reporter reporter)
49throws Throwable {
50try {
51 String dStr = recordEntry.substring(0, 15);
52int start = 15;
53int idx = recordEntry.indexOf(' ', start);
54 start = idx + 1;
55 idx = recordEntry.indexOf(' ', start);
56 String body = recordEntry.substring(idx + 1);
57 body = body.replaceAll("\n", "");
5859 Calendar convertDate = Calendar.getInstance();
60 Date d = sdf.parse(dStr);
61int year = convertDate.get(Calendar.YEAR);
62 convertDate.setTime(d);
63 convertDate.set(Calendar.YEAR, year);
64if(convertDate.getTimeInMillis() > Calendar.getInstance().getTimeInMillis()) {
65 convertDate.set(Calendar.YEAR, year - 1);
66 }
6768ChukwaRecord record = newChukwaRecord();
69 buildGenericRecord(record, recordEntry, convertDate.getTime().getTime(),
70 reduceType);
71 output.collect(key, record);
72 } catch (ParseException e) {
73 e.printStackTrace();
74 log.warn("Wrong format in SysLog [" + recordEntry + "]", e);
75throw e;
76 } catch (IOException e) {
77 e.printStackTrace();
78 log.warn("Unable to collect output in SysLog [" + recordEntry + "]", e);
79throw e;
80 }
8182 }
8384public String getDataType() {
85return SysLog.class.getName();
86 }
8788 }