5 public class BridgeDBLogConverter
{
6 public static void main(String
[] args
) throws Exception
{
7 if (args
.length
!= 3) {
8 System
.out
.println("Usage: java BridgeDBLogConverter logfile year "
12 File logfile
= new File(args
[0]), outfile
= new File(args
[2]);
13 String year
= args
[1];
14 SimpleDateFormat logFormat
= new SimpleDateFormat(
15 "yyyy MMM dd HH:mm:ss");
16 SimpleDateFormat isoFormat
= new SimpleDateFormat(
17 "yyyy-MM-dd HH:mm:ss");
18 SimpleDateFormat fileFormat
= new SimpleDateFormat(
19 "yyyy/MM/dd/yyyy-MM-dd-HH-mm-ss");
20 logFormat
.setTimeZone(TimeZone
.getTimeZone("UTC"));
21 isoFormat
.setTimeZone(TimeZone
.getTimeZone("UTC"));
22 fileFormat
.setTimeZone(TimeZone
.getTimeZone("UTC"));
23 BufferedReader br
= new BufferedReader(new FileReader(logfile
));
24 BufferedWriter bw
= new BufferedWriter(new FileWriter(outfile
));
26 SortedMap
<String
, String
> entries
= new TreeMap
<String
, String
>();
27 long lastTimestamp
= -1L;
28 String fingerprint
= null, lastFingerprint
= null, type
= null,
30 while ((line
= br
.readLine()) != null) {
31 long timestamp
= logFormat
.parse(year
+ " "
32 + line
.substring(0, 15)).getTime();
33 if (timestamp
> lastTimestamp
+ 10L * 60L * 1000L) {
34 if (lastTimestamp
> 0L) {
35 bw
.write("bridge-pool-assignment "
36 + isoFormat
.format(lastTimestamp
) + "\n");
37 for (String entry
: entries
.values()) {
38 bw
.write(entry
+ "\n");
43 lastTimestamp
= timestamp
;
44 String
[] parts
= line
.split(" ");
45 fingerprint
= parts
[7];
46 String assignment
= line
.substring(line
.indexOf(parts
[7]) + 41);
47 if (!fingerprint
.equals(lastFingerprint
)) {
48 if (lastFingerprint
!= null) {
49 entries
.put(lastFingerprint
, lastFingerprint
+ " " + type
56 if (assignment
.startsWith("to IP ")) {
58 if (assignment
.startsWith("to IP category ring")) {
59 ring
= 4; // TODO This is fragile!
61 ring
= Integer
.parseInt(assignment
.split(" ")[3]) - 1;
63 String newType
= "https ring=" + ring
;
64 if (type
!= null && !type
.equals(newType
)) {
65 System
.out
.println("type inconsistency in line '" + line
+ "'");
69 if (assignment
.endsWith(" (port-443 subring)")) {
70 String newPort
= " port=443";
71 if (port
.length() > 0 && !port
.equals(newPort
)) {
72 System
.out
.println("port inconsistency in line '" + line
77 } else if (assignment
.endsWith(" (stable subring)")) {
78 String newFlag
= " flag=stable";
79 if (flag
.length() > 0 && !flag
.equals(newFlag
)) {
80 System
.out
.println("flag inconsistency in line '" + line
86 } else if (assignment
.equals("to email ring")) {
87 String newType
= "email";
88 if (type
!= null && !type
.equals(newType
)) {
89 System
.out
.println("type inconsistency in line '" + line
+ "'");
93 } else if (assignment
.startsWith("to Ring ")) {
94 String newType
= "email";
95 if (type
!= null && !type
.equals(newType
)) {
96 System
.out
.println("type inconsistency in line '" + line
+ "'");
100 if (assignment
.equals("to Ring (port-443 subring)")) {
101 String newPort
= " port=443";
102 if (port
.length() > 0 && !port
.equals(newPort
)) {
103 System
.out
.println("port inconsistency in line '" + line
108 } else if (assignment
.equals("to Ring (stable subring)")) {
109 String newFlag
= " flag=stable";
110 if (flag
.length() > 0 && !flag
.equals(newFlag
)) {
111 System
.out
.println("flag inconsistency in line '" + line
117 System
.out
.println("type inconsistency in line '" + line
122 type
= "unallocated";
124 lastFingerprint
= fingerprint
;
126 if (lastTimestamp
> 0L) {
127 bw
.write("bridge-pool-assignment "
128 + isoFormat
.format(lastTimestamp
) + "\n");
129 for (String entry
: entries
.values()) {
130 bw
.write(entry
+ "\n");