public void initializeGraph(Configuration config) { if (!provided) { this.graph = (StandardTitanGraph) TitanFactory.open((BasicConfiguration) config); } }
/** * 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 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)); }
public static TitanGraph getInMemoryGraph() { return TitanFactory.open(getInMemoryConfiguration()); }
/** * 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)); }
/** * 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); }
/** * Calls {@link TitanFactory#open(String)}, passing the Titan configuration file path * which must be the sole element in the {@code args} array, then calls * {@link #load(com.thinkaurelius.titan.core.TitanGraph)} on the opened graph, * then calls {@link com.thinkaurelius.titan.core.TitanGraph#close()} * and returns. * <p/> * This method may call {@link System#exit(int)} if it encounters an error, such as * failure to parse its arguments. Only use this method when executing main from * a command line. Use one of the other methods on this class ({@link #create(String)} * or {@link #load(com.thinkaurelius.titan.core.TitanGraph)}) when calling from * an enclosing application. * * @param args a singleton array containing a path to a Titan config properties file */ public static void main(String args[]) { if (null == args || 1 != args.length) { System.err.println("Usage: GraphOfTheGodsFactory <titan-config-file>"); System.exit(1); } TitanGraph g = TitanFactory.open(args[0]); load(g); g.close(); } }
@Override public RecordWriter<NullWritable, VertexWritable> getRecordWriter(TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException { synchronized (this) { if (null == graph) { Configuration hadoopConf = taskAttemptContext.getConfiguration(); ModifiableHadoopConfiguration mhc = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf); graph = (StandardTitanGraph) TitanFactory.open(mhc.getTitanGraphConf()); } } // Special case for a TP3 vertex program: persist only those properties whose keys are // returned by VertexProgram.getComputeKeys() if (null == persistableKeys) { try { persistableKeys = VertexProgram.createVertexProgram(graph, ConfUtil.makeApacheConfiguration(taskAttemptContext.getConfiguration())).getElementComputeKeys(); log.debug("Set persistableKeys={}", Joiner.on(",").join(persistableKeys)); } catch (Exception e) { log.debug("Unable to detect or instantiate vertex program", e); persistableKeys = ImmutableSet.of(); } } StandardTitanTx tx = transactions.computeIfAbsent(taskAttemptContext.getTaskAttemptID(), id -> (StandardTitanTx)graph.newTransaction()); return new TitanH1RecordWriter(taskAttemptContext, tx, persistableKeys); }
public void open(WriteConfiguration config) { graph = (StandardTitanGraph) TitanFactory.open(config); features = graph.getConfiguration().getStoreFeatures(); tx = graph.newTransaction(); mgmt = graph.openManagement(); }
public TitanHadoopSetupImpl(final Configuration config) { scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, config); BasicConfiguration bc = scanConf.getTitanGraphConf(); graph = (StandardTitanGraph) TitanFactory.open(bc); tx = (StandardTitanTx)graph.buildTransaction().readOnly().vertexCacheSize(200).start(); }
@Override protected StandardTitanGraph getGraph() throws BackendException { if (null == graph) { GraphDatabaseConfiguration graphconfig = new GraphDatabaseConfiguration(conf); graphconfig.getBackend().clearStorage(); log.debug("Cleared backend storage"); graph = (StandardTitanGraph)TitanFactory.open(conf); initializeGraph(graph); } return graph; }
@Override protected void setup(Context context) throws IOException, InterruptedException { /* Don't call super implementation super.setup(context); */ org.apache.hadoop.conf.Configuration hadoopConf = DEFAULT_COMPAT.getContextConfiguration(context); ModifiableHadoopConfiguration scanConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf); VertexScanJob vertexScan = getVertexScanJob(scanConf); ModifiableConfiguration graphConf = getTitanConfiguration(context); TitanGraph graph = TitanFactory.open(graphConf); job = VertexJobConverter.convert(graph, vertexScan); metrics = new HadoopContextScanMetrics(context); finishSetup(scanConf, graphConf); }
TitanGraph g2 = TitanFactory.open(config); TitanManagement m2 = g2.openManagement(); assertEquals(secondValue.toString(), m2.get(path));
wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); try { graph = (StandardTitanGraph) TitanFactory.open(wc); fail("Masking managed config options should be disabled in this configuration"); } catch (TitanConfigurationException e) { wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); graph = (StandardTitanGraph) TitanFactory.open(wc); graph = (StandardTitanGraph) TitanFactory.open(wc); close(); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); try { graph = (StandardTitanGraph) TitanFactory.open(wc); fail("Masking managed config options should be disabled in this configuration"); } catch (TitanConfigurationException e) { wc.set(ConfigElement.getPath(ALLOW_STALE_CONFIG), true); wc.set(ConfigElement.getPath(MAX_COMMIT_TIME), customCommitTime); graph = (StandardTitanGraph) TitanFactory.open(wc);
); StandardTitanGraph graph2 = (StandardTitanGraph) TitanFactory.open(config); TitanTransaction tx2;
@Test public void testGraphConfigUsedByThreadBoundTx() { close(); WriteConfiguration wc = getConfiguration(); wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL"); wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM"); graph = (StandardTitanGraph) TitanFactory.open(wc); StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx(); assertEquals("ALL", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY)); assertEquals("LOCAL_QUORUM", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY)); }
@Test public void testGraphConfigUsedByTx() { close(); WriteConfiguration wc = getConfiguration(); wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO"); wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE"); graph = (StandardTitanGraph) TitanFactory.open(wc); StandardTitanTx tx = (StandardTitanTx)graph.newTransaction(); assertEquals("TWO", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY)); assertEquals("THREE", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY)); tx.rollback(); }
@Test public void testCustomConfigUsedByTx() { close(); WriteConfiguration wc = getConfiguration(); wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL"); wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL"); graph = (StandardTitanGraph) TitanFactory.open(wc); StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction() .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE") .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start(); assertEquals("ONE", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY)); assertEquals("TWO", tx.getTxHandle().getBaseTransactionConfig().getCustomOptions() .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY)); tx.rollback(); } }
/** * 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()); }
public static TitanGraph getInMemoryGraph() { BaseConfiguration config = new BaseConfiguration(); config.subset(GraphDatabaseConfiguration.STORAGE_NAMESPACE).addProperty(GraphDatabaseConfiguration.STORAGE_BACKEND_KEY, "inmemory"); return TitanFactory.open(config); }