1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.accumulo.core.conf;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.PrintStream;
22 import java.util.ArrayList;
23 import java.util.Iterator;
24 import java.util.Map.Entry;
25 import java.util.TreeMap;
26
27 import org.apache.log4j.Logger;
28
29 public class DefaultConfiguration extends AccumuloConfiguration {
30 private static DefaultConfiguration instance = null;
31 private static Logger log = Logger.getLogger(DefaultConfiguration.class);
32
33 synchronized public static DefaultConfiguration getInstance() {
34 if (instance == null) {
35 instance = new DefaultConfiguration();
36 ConfigSanityCheck.validate(instance);
37 }
38 return instance;
39 }
40
41 @Override
42 public String get(Property property) {
43 return property.getDefaultValue();
44 }
45
46 @Override
47 public Iterator<Entry<String,String>> iterator() {
48 TreeMap<String,String> entries = new TreeMap<String,String>();
49 for (Property prop : Property.values())
50 if (!prop.isExperimental() && !prop.getType().equals(PropertyType.PREFIX))
51 entries.put(prop.getKey(), prop.getDefaultValue());
52
53 return entries.entrySet().iterator();
54 }
55
56 private static void generateDocumentation(PrintStream doc) {
57
58 InputStream data = DefaultConfiguration.class.getClassLoader().getResourceAsStream("config.html");
59 if (data != null) {
60 byte[] buffer = new byte[1024];
61 int n;
62 try {
63 while ((n = data.read(buffer)) > 0)
64 doc.print(new String(buffer, 0, n));
65 } catch (IOException e) {
66 e.printStackTrace();
67 return;
68 } finally {
69 try {
70 data.close();
71 } catch (IOException ex) {
72 log .error(ex, ex);
73 }
74 }
75 }
76 doc.println();
77
78 ArrayList<Property> prefixes = new ArrayList<Property>();
79 TreeMap<String,Property> sortedProps = new TreeMap<String,Property>();
80 for (Property prop : Property.values()) {
81 if (prop.isExperimental())
82 continue;
83
84 if (prop.getType().equals(PropertyType.PREFIX))
85 prefixes.add(prop);
86 else
87 sortedProps.put(prop.getKey(), prop);
88 }
89
90 doc.println(" <p>Jump to: ");
91 String delimiter = "";
92 for (Property prefix : prefixes) {
93 if (prefix.isExperimental())
94 continue;
95
96 doc.print(delimiter + "<a href='#" + prefix.name() + "'>" + prefix.getKey() + "*</a>");
97 delimiter = " | ";
98 }
99 doc.println(" </p>");
100
101 doc.println(" <table>");
102 for (Property prefix : prefixes) {
103
104 if (prefix.isExperimental())
105 continue;
106
107 doc.println(" <tr><td colspan='5'><a name='" + prefix.name() + "' class='large'>" + prefix.getKey() + "*</a></td></tr>");
108 doc.println(" <tr><td colspan='5'><i>" + prefix.getDescription() + "</i></td></tr>");
109 if (!prefix.equals(Property.TABLE_CONSTRAINT_PREFIX) && !prefix.equals(Property.TABLE_ITERATOR_PREFIX)
110 && !prefix.equals(Property.TABLE_LOCALITY_GROUP_PREFIX))
111 doc.println(" <tr><th>Property</th><th>Type</th><th>Zookeeper Mutable</th><th>Default Value</th><th>Description</th></tr>");
112
113 boolean highlight = true;
114 for (Property prop : sortedProps.values()) {
115 if (prop.isExperimental())
116 continue;
117
118 if (prop.getKey().startsWith(prefix.getKey())) {
119 doc.println(" <tr " + (highlight ? "class='highlight'" : "") + ">");
120 highlight = !highlight;
121 doc.println(" <td>" + prop.getKey() + "</td>");
122 doc.println(" <td><b><a href='#" + prop.getType().name() + "'>" + prop.getType().toString().replaceAll(" ", " ") + "</a></b></td>");
123 String zoo = "no";
124 if (Property.isValidZooPropertyKey(prop.getKey())) {
125 zoo = "yes";
126 if (Property.isFixedZooPropertyKey(prop)) {
127 zoo = "yes but requires restart of the " + prop.getKey().split("[.]")[0];
128 }
129 }
130 doc.println(" <td>" + zoo + "</td>");
131 doc.println(" <td><pre>" + (prop.getDefaultValue().isEmpty() ? " " : prop.getDefaultValue().replaceAll(" ", " ")) + "</pre></td>");
132 doc.println(" <td>" + prop.getDescription() + "</td>");
133 doc.println(" </tr>");
134 }
135 }
136 }
137 doc.println(" </table>");
138
139 doc.println(" <h1>Property Type Descriptions</h1>");
140 doc.println(" <table>");
141 doc.println(" <tr><th>Property Type</th><th>Description</th></tr>");
142 boolean highlight = true;
143 for (PropertyType type : PropertyType.values()) {
144 if (type.equals(PropertyType.PREFIX))
145 continue;
146 doc.println(" <tr " + (highlight ? "class='highlight'" : "") + ">");
147 highlight = !highlight;
148 doc.println(" <td><h3><a name='" + type.name() + "'>" + type + "</a></td>");
149 doc.println(" <td>" + type.getFormatDescription() + "</td>");
150 doc.println(" </tr>");
151 }
152 doc.println(" </table>");
153 doc.println(" </body>");
154 doc.println("</html>");
155 doc.close();
156 }
157
158
159
160
161 public static void main(String[] args) {
162 if (args.length == 1 && args[0].equals("--generate-doc"))
163 generateDocumentation(System.out);
164 }
165 }