use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.
the class TitanFactory method getLocalConfiguration.
//###################################
// HELPER METHODS
//###################################
private static ReadConfiguration getLocalConfiguration(String shortcutOrFile) {
File file = new File(shortcutOrFile);
if (file.exists())
return getLocalConfiguration(file);
else {
int pos = shortcutOrFile.indexOf(':');
if (pos < 0)
pos = shortcutOrFile.length();
String backend = shortcutOrFile.substring(0, pos);
Preconditions.checkArgument(StandardStoreManager.getAllManagerClasses().containsKey(backend.toLowerCase()), "Backend shorthand unknown: %s", backend);
String secondArg = null;
if (pos + 1 < shortcutOrFile.length())
secondArg = shortcutOrFile.substring(pos + 1).trim();
BaseConfiguration config = new BaseConfiguration();
ModifiableConfiguration writeConfig = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(config), BasicConfiguration.Restriction.NONE);
writeConfig.set(STORAGE_BACKEND, backend);
ConfigOption option = Backend.getOptionForShorthand(backend);
if (option == null) {
Preconditions.checkArgument(secondArg == null);
} else if (option == STORAGE_DIRECTORY || option == STORAGE_CONF_FILE) {
Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
writeConfig.set(option, getAbsolutePath(secondArg));
} else if (option == STORAGE_HOSTS) {
Preconditions.checkArgument(StringUtils.isNotBlank(secondArg), "Need to provide additional argument to initialize storage backend");
writeConfig.set(option, new String[] { secondArg });
} else
throw new IllegalArgumentException("Invalid configuration option for backend " + option);
return new CommonsConfiguration(config);
}
}
use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.
the class TitanFactory method getLocalConfiguration.
/**
* Load a properties file containing a Titan graph configuration.
* <p/>
* <ol>
* <li>Load the file contents into a {@link org.apache.commons.configuration.PropertiesConfiguration}</li>
* <li>For each key that points to a configuration object that is either a directory
* or local file, check
* whether the associated value is a non-null, non-absolute path. If so,
* then prepend the absolute path of the parent directory of the provided configuration {@code file}.
* This has the effect of making non-absolute backend
* paths relative to the config file's directory rather than the JVM's
* working directory.
* <li>Return the {@link ReadConfiguration} for the prepared configuration file</li>
* </ol>
* <p/>
*
* @param file A properties file to load
* @return A configuration derived from {@code file}
*/
@SuppressWarnings("unchecked")
private static ReadConfiguration getLocalConfiguration(File file) {
Preconditions.checkArgument(file != null && file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
try {
PropertiesConfiguration configuration = new PropertiesConfiguration(file);
final File tmpParent = file.getParentFile();
final File configParent;
if (null == tmpParent) {
/*
* null usually means we were given a Titan config file path
* string like "foo.properties" that refers to the current
* working directory of the process.
*/
configParent = new File(System.getProperty("user.dir"));
} else {
configParent = tmpParent;
}
Preconditions.checkNotNull(configParent);
Preconditions.checkArgument(configParent.isDirectory());
// TODO this mangling logic is a relic from the hardcoded string days; it should be deleted and rewritten as a setting on ConfigOption
final Pattern p = Pattern.compile("(" + Pattern.quote(STORAGE_NS.getName()) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY.getName()) + "|" + Pattern.quote(STORAGE_CONF_FILE.getName()) + ")" + "|" + Pattern.quote(INDEX_NS.getName()) + "\\..*" + "(" + Pattern.quote(INDEX_DIRECTORY.getName()) + "|" + Pattern.quote(INDEX_CONF_FILE.getName()) + ")" + ")");
final Iterator<String> keysToMangle = Iterators.filter(configuration.getKeys(), new Predicate<String>() {
@Override
public boolean apply(String key) {
if (null == key)
return false;
return p.matcher(key).matches();
}
});
while (keysToMangle.hasNext()) {
String k = keysToMangle.next();
Preconditions.checkNotNull(k);
String s = configuration.getString(k);
Preconditions.checkArgument(StringUtils.isNotBlank(s), "Invalid Configuration: key %s has null empty value", k);
configuration.setProperty(k, getAbsolutePath(configParent, s));
}
return new CommonsConfiguration(configuration);
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Could not load configuration at: " + file, e);
}
}
use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testLocalNodeUsingExt.
@Test
public void testLocalNodeUsingExt() throws BackendException, InterruptedException {
String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext");
assertFalse(new File(baseDir + File.separator + "data").exists());
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
assertTrue(new File(baseDir + File.separator + "data").exists());
}
use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration 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);
}
use of com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testNetworkNodeUsingExt.
@Test
public void testNetworkNodeUsingExt() throws BackendException, InterruptedException {
ElasticsearchRunner esr = new ElasticsearchRunner(".", "networkNodeUsingExt.yml");
esr.start();
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "false");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "true");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "networkNodeUsingExt");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.multicast.enabled", "false");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.discovery.zen.ping.unicast.hosts", "10.11.12.13");
config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
config.set(HEALTH_REQUEST_TIMEOUT, "5s", INDEX_NAME);
indexConfig = config.restrictTo(INDEX_NAME);
Throwable failure = null;
try {
idx = new ElasticSearchIndex(indexConfig);
} catch (Throwable t) {
failure = t;
}
// idx.close();
Assert.assertNotNull("ES client failed to throw exception on connection failure", failure);
esr.stop();
}
Aggregations