This project has retired. For details please refer to its
Attic page.
DataConfig xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.chukwa.inputtools.mdl;
20
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.Path;
26 import java.util.Iterator;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.io.File;
30 import java.io.FilenameFilter;
31
32 public class DataConfig {
33 private static Configuration config;
34 final static String MDL_XML = "mdl.xml";
35 private Log log = LogFactory.getLog(DataConfig.class);
36
37 public DataConfig(String path) {
38 Path fileResource = new Path(path);
39 config = new Configuration();
40 config.addResource(fileResource);
41 }
42
43 public DataConfig() {
44 String dataConfig = System.getenv("CHUKWA_CONF_DIR");
45 if (dataConfig == null) {
46 dataConfig = MDL_XML;
47 } else {
48 dataConfig += File.separator + MDL_XML;
49 }
50 log.debug("DATACONFIG=" + dataConfig);
51 if (config == null) {
52 try {
53 Path fileResource = new Path(dataConfig);
54 config = new Configuration();
55 config.addResource(fileResource);
56 } catch (Exception e) {
57 log.debug("Error reading configuration file:" + dataConfig);
58 }
59 }
60
61 if (System.getenv("CHUKWA_CONF_DIR") != null) {
62
63
64 File confDir = new File(System.getenv("CHUKWA_CONF_DIR"));
65 File[] confFiles = confDir.listFiles(new FilenameFilter() {
66
67 @Override
68 public boolean accept(File dir, String name) {
69
70
71 return name.endsWith(MDL_XML) && !name.equals(MDL_XML);
72 }
73
74 });
75
76 if (confFiles != null) {
77 for (File confFile : confFiles)
78 config.addResource(new Path(confFile.getAbsolutePath()));
79 }
80 }
81 }
82
83 public String get(String key) {
84 return config.get(key);
85 }
86
87 public void put(String key, String value) {
88 config.set(key, value);
89 }
90
91 public Iterator<Map.Entry<String, String>> iterator() {
92 return config.iterator();
93 }
94
95 public HashMap<String, String> startWith(String key) {
96 HashMap<String, String> transformer = new HashMap<String, String>();
97 Iterator<Map.Entry<String, String>> entries = config.iterator();
98 while (entries.hasNext()) {
99 String entry = entries.next().toString();
100 if (entry.startsWith(key)) {
101 String[] metrics = entry.split("=");
102 transformer.put(metrics[0], metrics[1]);
103 }
104 }
105 return transformer;
106 }
107 }