use of com.thinkaurelius.titan.diskstorage.configuration.ConfigElement in project titan by thinkaurelius.
the class ConfigurationPrinter method getSortedChildren.
@SuppressWarnings("unchecked")
private <E> List<E> getSortedChildren(ConfigNamespace n, Function<ConfigElement, Boolean> predicate) {
List<ConfigElement> sortedElements = new ArrayList<ConfigElement>();
for (ConfigElement e : n.getChildren()) {
if (predicate.apply(e)) {
sortedElements.add(e);
}
}
Collections.sort(sortedElements, new Comparator<ConfigElement>() {
@Override
public int compare(ConfigElement o1, ConfigElement o2) {
return o1.getName().compareTo(o2.getName());
}
});
return (List<E>) sortedElements;
}
use of com.thinkaurelius.titan.diskstorage.configuration.ConfigElement in project titan by thinkaurelius.
the class ConfigurationLint method validate.
public static Status validate(String filename) throws IOException {
Properties p = new Properties();
FileInputStream fis = new FileInputStream(filename);
p.load(fis);
fis.close();
final PropertiesConfiguration apc;
try {
apc = new PropertiesConfiguration(filename);
} catch (ConfigurationException e) {
throw new IOException(e);
}
// new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
// , BasicConfiguration.Restriction.NONE);
Iterator<String> iter = apc.getKeys();
int totalKeys = 0;
int keysVerified = 0;
while (iter.hasNext()) {
totalKeys++;
String key = iter.next();
String value = apc.getString(key);
try {
ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, key);
// ConfigElement shouldn't return null; failure here probably relates to titan-core, not the file
Preconditions.checkState(null != pid);
Preconditions.checkState(null != pid.element);
if (!pid.element.isOption()) {
log.warn("Config key {} is a namespace (only options can be keys)", key);
continue;
}
final ConfigOption<?> opt;
try {
opt = (ConfigOption<?>) pid.element;
} catch (RuntimeException re) {
// This shouldn't happen given the preceding check, but catch it anyway
log.warn("Config key {} maps to the element {}, but it could not be cast to an option", key, pid.element, re);
continue;
}
try {
Object o = new CommonsConfiguration(apc).get(key, opt.getDatatype());
opt.verify(o);
keysVerified++;
} catch (RuntimeException re) {
log.warn("Config key {} is recognized, but its value {} could not be validated", key, value);
log.debug("Validation exception on {}={} follows", key, value, re);
}
} catch (RuntimeException re) {
log.warn("Unknown config key {}", key);
}
}
return new Status(totalKeys, totalKeys - keysVerified);
}
Aggregations