public void initializeGraph(Configuration config) { if (!provided) { this.graph = (StandardTitanGraph) TitanFactory.open((BasicConfiguration) config); } }
public static TitanGraph create(final String directory) { TitanFactory.Builder config = TitanFactory.build(); config.set("storage.backend", "berkeleyje"); config.set("storage.directory", directory); config.set("index." + INDEX_NAME + ".backend", "elasticsearch"); config.set("index." + INDEX_NAME + ".directory", directory + File.separator + "es"); config.set("index." + INDEX_NAME + ".elasticsearch.local-mode", true); config.set("index." + INDEX_NAME + ".elasticsearch.client-only", false); TitanGraph graph = config.open(); GraphOfTheGodsFactory.load(graph); return graph; }
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); } }
/** * Opens a {@link TitanGraph} database. * <p/> * If the argument points to a configuration file, the configuration file is loaded to configure the Titan graph * If the string argument is a configuration short-cut, then the short-cut is parsed and used to configure the returned Titan graph. * <p /> * A configuration short-cut is of the form: * [STORAGE_BACKEND_NAME]:[DIRECTORY_OR_HOST] * * @param shortcutOrFile Configuration file name or configuration short-cut * @return Titan graph database configured according to the provided configuration * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/configuration.html">"Configuration" manual chapter</a> * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/titan-config-ref.html">Configuration Reference</a> */ public static TitanGraph open(String shortcutOrFile) { return open(getLocalConfiguration(shortcutOrFile)); }
private static final String getAbsolutePath(String file) { return getAbsolutePath(new File(System.getProperty("user.dir")), file); }
/** * Opens a {@link TitanGraph} database. * <p/> * If the argument points to a configuration file, the configuration file is loaded to configure the Titan graph * If the string argument is a configuration short-cut, then the short-cut is parsed and used to configure the returned Titan graph. * <p /> * A configuration short-cut is of the form: * [STORAGE_BACKEND_NAME]:[DIRECTORY_OR_HOST] * * @param shortcutOrFile Configuration file name or configuration short-cut * @return Titan graph database configured according to the provided configuration * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/configuration.html">"Configuration" manual chapter</a> * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/titan-config-ref.html">Configuration Reference</a> */ public static TitanGraph open(String shortcutOrFile) { return open(getLocalConfiguration(shortcutOrFile)); }
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));
/** * Opens a {@link TitanGraph} database configured according to the provided configuration. * * @param configuration Configuration for the graph database * @return Titan graph database */ public static TitanGraph open(BasicConfiguration configuration) { return open(configuration.getConfiguration()); }
/** * Opens a {@link TitanGraph} database. * <p/> * If the argument points to a configuration file, the configuration file is loaded to configure the Titan graph * If the string argument is a configuration short-cut, then the short-cut is parsed and used to configure the returned Titan graph. * <p /> * A configuration short-cut is of the form: * [STORAGE_BACKEND_NAME]:[DIRECTORY_OR_HOST] * * @param shortcutOrFile Configuration file name or configuration short-cut * @return Titan graph database configured according to the provided configuration * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/configuration.html">"Configuration" manual chapter</a> * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/titan-config-ref.html">Configuration Reference</a> */ public static TitanGraph open(String shortcutOrFile) { return open(getLocalConfiguration(shortcutOrFile)); }
@Test public void testTitanFactoryBuilder() { String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext"); TitanFactory.Builder builder = TitanFactory.build(); builder.set("storage.backend", "inmemory"); builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work"); builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs"); TitanGraph graph = builder.open(); // Must not throw an exception assertTrue(graph.isOpen()); graph.close(); }
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); } }
private static final String getAbsolutePath(String file) { return getAbsolutePath(new File(System.getProperty("user.dir")), file); }
/** * Opens a {@link TitanGraph} database configured according to the provided configuration. * * @param configuration Configuration for the graph database * @return Titan graph database * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/configuration.html">"Configuration" manual chapter</a> * @see <a href="http://s3.thinkaurelius.com/docs/titan/current/titan-config-ref.html">Configuration Reference</a> */ public static TitanGraph open(Configuration configuration) { return open(new CommonsConfiguration(configuration)); }
private TitanGraph configureGraph(String name, String address, Properties properties, boolean batchLoading){ //Load default properties if none provided if(properties == null){ properties = new Properties(); InputStream in = getClass().getResourceAsStream(DEFAULT_CONFIG); try { properties.load(in); in.close(); } catch (IOException e) { throw new RuntimeException(ErrorMessage.INVALID_PATH_TO_CONFIG.getMessage(DEFAULT_CONFIG), e); } } TitanFactory.Builder builder = TitanFactory.build(). set("storage.hostname", address). set("storage.cassandra.keyspace", name). set("storage.batch-loading", batchLoading); properties.entrySet().forEach(entry-> builder.set(entry.getKey().toString(), entry.getValue())); return builder.open(); }
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); } }
private static final String getAbsolutePath(String file) { return getAbsolutePath(new File(System.getProperty("user.dir")), file); }
public static TitanGraph getInMemoryGraph() { return TitanFactory.open(getInMemoryConfiguration()); }
private TitanGraph configureGraph(String name, String address, String pathToConfig){ ResourceBundle defaultConfig; if(pathToConfig == null) { defaultConfig = ResourceBundle.getBundle(DEFAULT_CONFIG); } else { try { FileInputStream fis = new FileInputStream(pathToConfig); defaultConfig = new PropertyResourceBundle(fis); } catch (IOException e) { LOG.error(ErrorMessage.INVALID_PATH_TO_CONFIG.getMessage(pathToConfig), e); throw new IllegalArgumentException(ErrorMessage.INVALID_PATH_TO_CONFIG.getMessage(pathToConfig)); } } TitanFactory.Builder builder = TitanFactory.build(). set("storage.hostname", address). set("storage.cassandra.keyspace", name); defaultConfig.keySet().forEach(key -> builder.set(key, defaultConfig.getString(key))); return builder.open(); }
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));
/** * Opens a Titan graph with the previously configured options. * * @return */ public TitanGraph open() { ModifiableConfiguration mc = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, writeConfiguration.copy(), BasicConfiguration.Restriction.NONE); return TitanFactory.open(mc); }