4 public class ProcessSanitizedAssignments
{
5 public static void main(String
[] args
) throws IOException
{
7 /* Validate command-line arguments. */
8 if (args
.length
!= 1 || !new File(args
[0]).exists()) {
9 System
.out
.println("Usage: java ProcessSanitizedAssignments <dir>");
13 /* Find all files that we should parse. Somewhat fragile, but should
15 System
.out
.println("Creating list of files we should parse.");
16 SortedMap
<String
, File
> assignments
= new TreeMap
<String
, File
>();
17 Stack
<File
> files
= new Stack
<File
>();
18 files
.add(new File(args
[0]));
19 while (!files
.isEmpty()) {
20 File file
= files
.pop();
21 if (file
.isDirectory()) {
22 files
.addAll(Arrays
.asList(file
.listFiles()));
24 assignments
.put(file
.getName(), file
);
27 System
.out
.println("We found " + assignments
.size() + " bridge pool "
28 + "assignment files.");
30 /* Parse assignments. */
31 if (!assignments
.isEmpty()) {
32 System
.out
.println("Parsing bridge pool assignment files.");
33 BufferedWriter bw
= new BufferedWriter(new FileWriter(
35 bw
.write("assignment,fingerprint,type,ring,port,flag,bucket\n");
36 int parsedAssignments
= 0, totalAssignments
= assignments
.size(),
37 writtenOutputLines
= 1;
38 long started
= System
.currentTimeMillis();
39 for (File file
: assignments
.values()) {
40 BufferedReader br
= new BufferedReader(new FileReader(file
));
41 String line
, assignmentTime
= null;
42 while ((line
= br
.readLine()) != null) {
43 if (line
.startsWith("bridge-pool-assignment ")) {
44 assignmentTime
= line
.substring("bridge-pool-assignment ".
47 String
[] parts
= line
.split(" ");
48 String fingerprint
= parts
[0];
49 String type
= parts
[1];
50 String ring
= null, port
= null, flag
= null, bucket
= null;
51 for (int i
= 2; i
< parts
.length
; i
++) {
52 String
[] parts2
= parts
[i
].split("=");
53 String key
= parts2
[0];
54 String value
= parts2
[1];
55 if (key
.equals("ring")) {
56 } else if (key
.equals("ring")) {
58 } else if (key
.equals("port")) {
60 } else if (key
.equals("flag")) {
62 } else if (key
.equals("bucket")) {
65 System
.out
.println("Unknown keyword in line '" + line
66 + "'. Please check. Exiting.");
70 bw
.write(assignmentTime
+ "," + fingerprint
+ "," + type
+ ","
71 + (ring
!= null ? ring
: "NA") + ","
72 + (port
!= null ? port
: "NA") + ","
73 + (flag
!= null ? flag
: "NA") + ","
74 + (bucket
!= null ? bucket
: "NA") + "\n");
80 if (parsedAssignments
% (totalAssignments
/ 10) == 0) {
81 double fractionDone
= (double) (parsedAssignments
) /
82 (double) totalAssignments
;
83 double fractionLeft
= 1.0D
- fractionDone
;
84 long now
= System
.currentTimeMillis();
85 double millisLeft
= ((double) (now
- started
)) * fractionLeft
/
87 long secondsLeft
= (long) millisLeft
/ 1000L;
88 System
.out
.println(" " + (parsedAssignments
/ (totalAssignments
89 / 10)) + "0% done, " + secondsLeft
+ " seconds left.");
93 System
.out
.println("Parsed " + parsedAssignments
+ " bridge pool "
94 + "assignment files and wrote " + writtenOutputLines
+ " lines "
95 + "to assignments.csv.");
99 System
.out
.println("Terminating.");