This project has retired. For details please refer to its Attic page.
SysLog 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.extraction.demux.processor.mapper;
20  
21  
22  import java.io.IOException;
23  import java.text.ParseException;
24  import java.text.SimpleDateFormat;
25  import java.util.Calendar;
26  import java.util.Date;
27  
28  import org.apache.hadoop.chukwa.datacollection.writer.hbase.Annotation.Table;
29  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
30  import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
31  import org.apache.hadoop.mapred.OutputCollector;
32  import org.apache.hadoop.mapred.Reporter;
33  import org.apache.log4j.Logger;
34  
35  @Table(name="SystemMetrics",columnFamily="SysLog")
36  public class SysLog extends AbstractProcessor {
37  
38    static Logger log = Logger.getLogger(SysLog.class);
39    private static final String reduceType = "SysLog";  
40    private SimpleDateFormat sdf = null;
41  
42    public SysLog() {
43      sdf = new SimpleDateFormat("MMM d HH:mm:ss");
44    }
45  
46    @Override
47    protected void parse(String recordEntry,
48        OutputCollector<ChukwaRecordKey, ChukwaRecord> output, Reporter reporter)
49        throws Throwable {
50      try {
51        String dStr = recordEntry.substring(0, 15);
52        int start = 15;
53        int 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", "");
58  
59        Calendar convertDate = Calendar.getInstance();
60        Date d = sdf.parse(dStr);
61        int year = convertDate.get(Calendar.YEAR);
62        convertDate.setTime(d);
63        convertDate.set(Calendar.YEAR, year);
64        if(convertDate.getTimeInMillis() > Calendar.getInstance().getTimeInMillis()) {
65          convertDate.set(Calendar.YEAR, year - 1);
66        }
67  
68        ChukwaRecord record = new ChukwaRecord();
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);
75        throw e;
76      } catch (IOException e) {
77        e.printStackTrace();
78        log.warn("Unable to collect output in SysLog [" + recordEntry + "]", e);
79        throw e;
80      }
81  
82    }
83  
84    public String getDataType() {
85      return SysLog.class.getName();
86    }
87  
88  }