1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.util;
20
21
22 import java.io.*;
23 import java.util.*;
24
25 public class ClusterConfig {
26 public static final HashMap<String, String> clusterMap = new HashMap<String, String>();
27 private String path = System.getenv("CHUKWA_CONF_DIR") + File.separator;
28
29 static public String getContents(File aFile) {
30
31 StringBuffer contents = new StringBuffer();
32
33 try {
34
35
36 BufferedReader input = new BufferedReader(new FileReader(aFile));
37 try {
38 String line = null;
39
40
41
42
43
44 while ((line = input.readLine()) != null) {
45 contents.append(line);
46 contents.append(System.getProperty("line.separator"));
47 }
48 } finally {
49 input.close();
50 }
51 } catch (IOException ex) {
52 ex.printStackTrace();
53 }
54
55 return contents.toString();
56 }
57
58 public ClusterConfig() {
59 File cc = new File(path + "jdbc.conf");
60 String buffer = getContents(cc);
61 String[] lines = buffer.split("\n");
62 for (String line : lines) {
63 String[] data = line.split("=", 2);
64 clusterMap.put(data[0], data[1]);
65 }
66 }
67
68 public String getURL(String cluster) {
69 String url = clusterMap.get(cluster);
70 return url;
71 }
72
73 public Iterator<String> getClusters() {
74 Set<String> keys = clusterMap.keySet();
75 Iterator<String> i = keys.iterator();
76 return i;
77 }
78 }