use of com.thinkaurelius.titan.diskstorage.configuration.ConfigOption in project titan by thinkaurelius.
the class ConfigurationFileFilter method processFile.
private static int processFile(File inputFile, File outputFile) throws IOException {
BufferedReader in = null;
PrintStream out = null;
int inputLines = 0;
int replacements = 0;
int parseErrors = 0;
try {
in = new BufferedReader(new FileReader(inputFile));
out = new PrintStream(outputFile);
String line;
while (null != (line = in.readLine())) {
inputLines++;
Matcher m = REPLACEMENT_PATTERN.matcher(line);
if (m.matches()) {
String cfgKey = m.group(2).trim();
String cfgVal = m.group(3);
try {
ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, cfgKey);
ConfigOption<?> opt = (ConfigOption<?>) pid.element;
//opt.verify(cfgVal);
String kvPair = m.group(1);
String descr = "# " + WordUtils.wrap(opt.getDescription(), WRAP_COLUMNS, "\n# ", false);
String dt = "# Data Type: ";
if (opt.getDatatype().isArray()) {
dt += opt.getDatatype().getComponentType().toString() + "[]";
} else if (opt.getDatatype().isEnum()) {
Enum[] enums = (Enum[]) opt.getDatatype().getEnumConstants();
String[] names = new String[enums.length];
for (int i = 0; i < names.length; i++) names[i] = enums[i].name();
dt += opt.getDatatype().getSimpleName() + " enum:";
String s = "\n# " + "{ " + Joiner.on(", ").join(names) + " }";
dt += WordUtils.wrap(s, WRAP_COLUMNS, "\n# ", false);
} else {
dt += opt.getDatatype().getSimpleName();
}
String defval = "# Default: ";
if (null == opt.getDefaultValue()) {
defval += "(no default value)";
} else if (opt.getDatatype().isArray()) {
defval += Joiner.on(", ").join((Object[]) opt.getDefaultValue());
} else if (opt.getDatatype().isEnum()) {
defval += ((Enum) opt.getDefaultValue()).name();
} else {
defval += opt.getDefaultValue();
}
String mut = "# Mutability: " + opt.getType();
if (opt.isManaged()) {
mut += "\n#\n# ";
if (opt.getType().equals(ConfigOption.Type.FIXED)) {
mut += "This setting is " + opt.getType() + " and cannot be changed after bootstrapping Titan.";
} else {
final String warning = "Settings with mutability " + opt.getType() + " are centrally managed in " + "Titan's storage backend. After starting the database for the first time, " + "this file's copy of this setting is ignored. Use Titan's Management " + "System to read or modify this value after bootstrapping.";
mut += WordUtils.wrap(warning, WRAP_COLUMNS, "\n# ", false);
}
}
String umbrella = null;
// This background info on umbrellas isn't critical when getting started with an Titan config
// if (pid.hasUmbrellaElements() && 1 == pid.umbrellaElements.length) {
// String s = "# " +
// "This setting is under an umbrella namespace. " +
// "The string \"" + pid.umbrellaElements[0] + "\" in this setting groups " +
// "it with other elements under the same umbrella. " +
// "See the Configuration Reference in the manual for more info.";
// umbrella = WordUtils.wrap(s, WRAP_COLUMNS, "\n# ", false);
// }
out.println(descr);
out.println("#");
out.println(defval);
out.println(dt);
out.println(mut);
if (null != umbrella)
out.println(umbrella);
out.println(kvPair);
replacements++;
} catch (RuntimeException e) {
out.println(line);
log.warn("Exception on {}:{}", inputFile, line, e);
parseErrors++;
}
} else {
out.println(line);
}
}
log.info("Read {}: {} lines, {} macro substitutions", inputFile, inputLines, replacements);
} finally {
IOUtils.closeQuietly(out);
IOUtils.closeQuietly(in);
}
// Read what we just wrote. Make sure it validates as a Titan config.
ConfigurationLint.Status stat = ConfigurationLint.validate(outputFile.getAbsolutePath());
if (0 != stat.getErrorSettingCount())
log.error("Output file {} failed to validate", outputFile);
parseErrors += stat.getErrorSettingCount();
return parseErrors;
}
Aggregations