| | 34 | }}} |
| | 35 | |
| | 36 | = LogParserGo.java = |
| | 37 | |
| | 38 | {{{ |
| | 39 | public static class MapClass extends MapReduceBase implements |
| | 40 | Mapper<WritableComparable, Text, Text, Writable> { |
| | 41 | @Override |
| | 42 | // MapReduceBase.configure(JobConf job) |
| | 43 | // Default implementation that does nothing. |
| | 44 | public void configure(JobConf job) { |
| | 45 | // String get(String name,String defaultValue) |
| | 46 | // Get the value of the name property. If no such property exists,\ |
| | 47 | // then defaultValue is returned. |
| | 48 | tableName = job.get(TABLE, ""); |
| | 49 | } |
| | 50 | |
| | 51 | public void map(WritableComparable key, Text value, |
| | 52 | OutputCollector<Text, Writable> output, Reporter reporter) |
| | 53 | throws IOException { |
| | 54 | |
| | 55 | try { |
| | 56 | /* |
| | 57 | print(value.toString()); |
| | 58 | FileWriter out = new FileWriter(new File( |
| | 59 | "/home/waue/mr-result.txt")); |
| | 60 | out.write(value.toString()); |
| | 61 | out.flush(); |
| | 62 | out.close(); |
| | 63 | */ |
| | 64 | LogParser log = new LogParser(value.toString()); |
| | 65 | |
| | 66 | if (table == null) |
| | 67 | table = new HTable(conf, new Text(tableName)); |
| | 68 | long lockId = table.startUpdate(new Text(log.getIp())); |
| | 69 | table.put(lockId, new Text("http:protocol"), log.getProtocol() |
| | 70 | .getBytes()); |
| | 71 | table.put(lockId, new Text("http:method"), log.getMethod() |
| | 72 | .getBytes()); |
| | 73 | table.put(lockId, new Text("http:code"), log.getCode() |
| | 74 | .getBytes()); |
| | 75 | table.put(lockId, new Text("http:bytesize"), log.getByteSize() |
| | 76 | .getBytes()); |
| | 77 | table.put(lockId, new Text("http:agent"), log.getAgent() |
| | 78 | .getBytes()); |
| | 79 | table.put(lockId, new Text("url:" + log.getUrl()), log |
| | 80 | .getReferrer().getBytes()); |
| | 81 | table.put(lockId, new Text("referrer:" + log.getReferrer()), |
| | 82 | log.getUrl().getBytes()); |
| | 83 | table.commit(lockId, log.getTimestamp()); |
| | 84 | |
| | 85 | } catch (Exception e) { |
| | 86 | e.printStackTrace(); |
| | 87 | } |
| | 88 | |
| | 89 | } |
| | 90 | } |