- Timestamp:
- Jul 25, 2008, 6:26:50 PM (16 years ago)
- Location:
- sample/hadoop-0.16
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sample/hadoop-0.16/test.java
r45 r46 7 7 import java.io.IOException; 8 8 import java.io.RandomAccessFile; 9 import java.text.ParsePosition; 9 10 import java.text.SimpleDateFormat; 10 11 import java.util.Date; … … 252 253 } 253 254 254 void Date()throws Exception{ 255 String da = "20/Jul/2008:08:26:55"; 256 SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss",Locale.US); 255 void Date() throws Exception { 256 String da = "10/Jul/2008:08:26:55"; 257 SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss", 258 Locale.US); 257 259 Date timestamp = sdf.parse(da); 260 long timeint = timestamp.getTime(); 258 261 System.out.println(timestamp.toString()); 262 System.out.println(timeint); 263 } 264 265 void getNowTime() { 266 SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); 267 Date date = new Date(); 268 String strDate = sdFormat.format(date); 269 System.out.println(strDate); 270 System.out.println(date.getTime()); 271 } 272 273 void setTime() { 274 String str = "07/08:01:01:01"; 275 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss", 276 Locale.TAIWAN); 277 Date tim = sdf.parse(str, new ParsePosition(0)); 278 System.out.println(tim); 279 Long timestamp = tim.getTime(); 280 System.out.println(timestamp); 281 259 282 } 260 283 … … 278 301 // 測試 enum 列舉 279 302 // t.enumTest(); 280 t.Date(); 303 // 測試設定 304 // t.Date(); 305 // 測試取得現在時間 306 // t.getNowTime(); 307 t.setTime(); 281 308 } 282 309 -
sample/hadoop-0.16/tw/org/nchc/code/SnortBase.java
r45 r46 50 50 import java.io.FileWriter; 51 51 import java.io.IOException; 52 import java.text.ParseException; 53 import java.text.ParsePosition; 52 54 import java.text.SimpleDateFormat; 55 import java.util.Date; 53 56 import java.util.Locale; 54 57 … … 72 75 import org.apache.hadoop.mapred.Reporter; 73 76 77 74 78 class Log { 75 79 76 public Log(String data) throws Exception{80 public Log(String data) { 77 81 78 82 String[] arr = data.split(";"); … … 84 88 this.class_type = arr[4]; 85 89 this.priority = arr[5]; 86 // this.timestamp = "2008" + arr[6] + arr[7] + arr[8] + arr[9] + 87 // arr[10]; 88 this.timestamp = getTime(arr[7] + "/" + arr[6] + "/2008:" + arr[8] 90 this.timestamp = getTime(arr[7] + "/" + arr[6] + ":" + arr[8] 89 91 + ":" + arr[9] + ":" + arr[10]); 92 // this.timestamp = now.getTime(); 90 93 this.source = arr[11]; 91 94 this.destination = arr[12]; … … 98 101 99 102 } 100 103 Date now = new Date(); 101 104 long timestamp; 102 105 … … 107 110 String source, destination, type, ttl, tos, id, iplen, dgmlen; 108 111 109 long getTime(String str) throws Exception{110 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM M/yyyy:HH:mm:ss",112 long getTime(String str) { 113 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM:HH:mm:ss", 111 114 Locale.TAIWAN); 112 Long timestamp = sdf.parse(str ).getTime();115 Long timestamp = sdf.parse(str,new ParsePosition(0)).getTime(); 113 116 return timestamp; 114 117 } … … 121 124 public static final String TABLE = "table.name"; 122 125 123 static String tableName = " mySnort";126 static String tableName = "SnortBase"; 124 127 125 128 static HTable table = null; … … 140 143 public void map(WritableComparable key, Text value, 141 144 OutputCollector<Text, Writable> output, Reporter reporter) 142 throws IOException 143 144 try {145 throws IOException{ 146 147 // try { 145 148 146 149 Log log = new Log(value.toString()); … … 181 184 table.commit(lockId, log.timestamp); 182 185 183 } catch (Exception e) {184 e.printStackTrace();185 }186 // } catch (Exception e) { 187 // e.printStackTrace(); 188 // } 186 189 187 190 } … … 200 203 } 201 204 202 public static void runMapReduce(String table , String inpath)205 public static void runMapReduce(String tableName, String inpath) 203 206 throws IOException { 204 207 Path tempDir = new Path("/tmp/Mylog/"); … … 207 210 JobConf jobConf = new JobConf(conf, SnortBase.class); 208 211 jobConf.setJobName("Snort Parse"); 209 jobConf.set(TABLE, table );212 jobConf.set(TABLE, tableName); 210 213 // 先省略 自動搜尋目錄的功能 211 214 /* … … 224 227 jobConf.setNumMapTasks(cluster.getMapTasks()); 225 228 jobConf.setNumReduceTasks(0); 229 fs.delete(tempDir); 226 230 JobClient.runJob(jobConf); 227 231 fs.delete(tempDir); … … 248 252 249 253 public static void main(String[] args) throws IOException, Exception { 250 String table_name = "snort"; 254 251 255 String path = "/user/waue/alert_meta"; 252 256 … … 256 260 * SnortParser("/tmp/alert","/tmp/alert_SnortBase"); sp.parseToLine(); 257 261 */ 258 creatTable(table _name);259 260 runMapReduce(table _name, path);262 creatTable(tableName); 263 264 runMapReduce(tableName, path); 261 265 262 266 }
Note: See TracChangeset
for help on using the changeset viewer.