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.nio.charset.Charset;
24 import java.util.*;
25
26 public class ClusterConfig {
27 private HashMap<String, String> clusterMap = new HashMap<String, String>();
28 private String path = System.getenv("CHUKWA_CONF_DIR") + File.separator;
29
30 static public String getContents(File aFile) {
31
32 StringBuffer contents = new StringBuffer();
33
34 try {
35 BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(aFile.getAbsolutePath()), Charset.forName("UTF-8")));
36 try {
37 String line = null;
38
39
40
41
42
43 while ((line = input.readLine()) != null) {
44 contents.append(line);
45 contents.append(System.getProperty("line.separator"));
46 }
47 } finally {
48 input.close();
49 }
50 } catch (IOException ex) {
51 ex.printStackTrace();
52 }
53
54 return contents.toString();
55 }
56
57 public ClusterConfig() {
58 File cc = new File(path + "jdbc.conf");
59 String buffer = getContents(cc);
60 String[] lines = buffer.split("\n");
61 for (String line : lines) {
62 String[] data = line.split("=", 2);
63 clusterMap.put(data[0], data[1]);
64 }
65 }
66
67 public String getURL(String cluster) {
68 String url = clusterMap.get(cluster);
69 return url;
70 }
71
72 public Iterator<String> getClusters() {
73 Set<String> keys = clusterMap.keySet();
74 Iterator<String> i = keys.iterator();
75 return i;
76 }
77 }