List of usage examples for org.apache.commons.configuration Configuration containsKey
boolean containsKey(String key);
From source file:org.apache.tinkerpop.gremlin.process.traversal.TraversalSource.java
/** * Configures the {@code TraversalSource} as a "remote" to issue the {@link Traversal} for execution elsewhere. * Expects key for {@link #GREMLIN_REMOTE_CONNECTION_CLASS} as well as any configuration required by * the underlying {@link RemoteConnection} which will be instantiated. Note that the {@code Configuration} object * is passed down without change to the creation of the {@link RemoteConnection} instance. *//*from w w w.j a v a2 s .co m*/ public default TraversalSource withRemote(final Configuration conf) { if (!conf.containsKey(GREMLIN_REMOTE_CONNECTION_CLASS)) throw new IllegalArgumentException( "Configuration must contain the '" + GREMLIN_REMOTE_CONNECTION_CLASS + "' key"); final RemoteConnection remoteConnection; try { final Class<? extends RemoteConnection> clazz = Class .forName(conf.getString(GREMLIN_REMOTE_CONNECTION_CLASS)).asSubclass(RemoteConnection.class); final Constructor<? extends RemoteConnection> ctor = clazz.getConstructor(Configuration.class); remoteConnection = ctor.newInstance(conf); } catch (Exception ex) { throw new IllegalStateException(ex); } return withRemote(remoteConnection); }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.PersistedInputRDD.java
@Override public JavaPairRDD<Object, VertexWritable> readGraphRDD(final Configuration configuration, final JavaSparkContext sparkContext) { if (!configuration.containsKey(Constants.GREMLIN_HADOOP_INPUT_LOCATION)) throw new IllegalArgumentException("There is no provided " + Constants.GREMLIN_HADOOP_INPUT_LOCATION + " to read the persisted RDD from"); Spark.create(sparkContext.sc());/*from w w w . ja v a2 s .c om*/ return JavaPairRDD.fromJavaRDD((JavaRDD) Spark.getRDD( Constants.getSearchGraphLocation(configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION), SparkContextStorage.open(sparkContext.sc())).get()) .toJavaRDD()); }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.PersistedInputRDD.java
@Override public <K, V> JavaPairRDD<K, V> readMemoryRDD(final Configuration configuration, final String memoryKey, final JavaSparkContext sparkContext) { if (!configuration.containsKey(Constants.GREMLIN_HADOOP_INPUT_LOCATION)) throw new IllegalArgumentException("There is no provided " + Constants.GREMLIN_HADOOP_INPUT_LOCATION + " to read the persisted RDD from"); return JavaPairRDD .fromJavaRDD((JavaRDD) Spark .getRDD(Constants.getMemoryLocation( configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION), memoryKey)) .toJavaRDD());/*w ww . ja v a 2s . c o m*/ }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.PersistedOutputRDD.java
@Override public void writeGraphRDD(final Configuration configuration, final JavaPairRDD<Object, VertexWritable> graphRDD) { if (!configuration.getBoolean(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, false)) LOGGER.warn(//from ww w . j av a 2s . com "The SparkContext should be persisted in order for the RDD to persist across jobs. To do so, set " + Constants.GREMLIN_SPARK_PERSIST_CONTEXT + " to true"); if (!configuration.containsKey(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION)) throw new IllegalArgumentException("There is no provided " + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + " to write the persisted RDD to"); SparkContextStorage.open(configuration) .rm(configuration.getString(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION)); // this might be bad cause it unpersists the job RDD // determine which storage level to persist the RDD as with MEMORY_ONLY being the default cache() final StorageLevel storageLevel = StorageLevel .fromString(configuration.getString(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, "MEMORY_ONLY")); if (!configuration.getBoolean(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT_HAS_EDGES, true)) graphRDD.mapValues(vertex -> { vertex.get().dropEdges(Direction.BOTH); return vertex; }).setName( Constants.getGraphLocation(configuration.getString(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION))) .persist(storageLevel); else graphRDD.setName( Constants.getGraphLocation(configuration.getString(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION))) .persist(storageLevel); Spark.refresh(); // necessary to do really fast so the Spark GC doesn't clear out the RDD }
From source file:org.apache.tinkerpop.gremlin.spark.structure.io.PersistedOutputRDD.java
@Override public <K, V> Iterator<KeyValue<K, V>> writeMemoryRDD(final Configuration configuration, final String memoryKey, final JavaPairRDD<K, V> memoryRDD) { if (!configuration.getBoolean(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, false)) LOGGER.warn(//from www . j av a2s . co m "The SparkContext should be persisted in order for the RDD to persist across jobs. To do so, set " + Constants.GREMLIN_SPARK_PERSIST_CONTEXT + " to true"); if (!configuration.containsKey(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION)) throw new IllegalArgumentException("There is no provided " + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + " to write the persisted RDD to"); final String memoryRDDName = Constants .getMemoryLocation(configuration.getString(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION), memoryKey); Spark.removeRDD(memoryRDDName); memoryRDD.setName(memoryRDDName).persist(StorageLevel .fromString(configuration.getString(Constants.GREMLIN_SPARK_PERSIST_STORAGE_LEVEL, "MEMORY_ONLY"))); Spark.refresh(); // necessary to do really fast so the Spark GC doesn't clear out the RDD return IteratorUtils.map(memoryRDD.collect().iterator(), tuple -> new KeyValue<>(tuple._1(), tuple._2())); }
From source file:org.apache.tinkerpop.gremlin.structure.GraphConstructionTest.java
/** * A {@link Graph} should maintain the original {@code Configuration} object passed to it via {@link GraphFactory}. *///from ww w. java 2s . c o m @Test public void shouldMaintainOriginalConfigurationObjectGivenToFactory() throws Exception { final Configuration originalConfig = graphProvider.newGraphConfiguration("temp2", this.getClass(), name.getMethodName(), null); final Graph createdGraph = GraphFactory.open(originalConfig); final Configuration configInGraph = createdGraph.configuration(); final AtomicInteger keyCount = new AtomicInteger(0); originalConfig.getKeys().forEachRemaining(k -> { assertTrue(configInGraph.containsKey(k)); keyCount.incrementAndGet(); }); // need some keys in the originalConfig for this test to be meaningful assertTrue(keyCount.get() > 0); assertEquals(keyCount.get(), IteratorUtils.count(configInGraph.getKeys())); graphProvider.clear(createdGraph, originalConfig); }
From source file:org.apache.tinkerpop.gremlin.structure.io.util.IoRegistryHelper.java
public static List<IoRegistry> createRegistries(final Configuration configuration) { if (configuration.containsKey(IoRegistry.IO_REGISTRY)) { final Object property = configuration.getProperty(IoRegistry.IO_REGISTRY); if (property instanceof IoRegistry) return Collections.singletonList((IoRegistry) property); else if (property instanceof List) return createRegistries((List) property); else if (property instanceof String) return createRegistries(Arrays.asList(((String) property).split(","))); else//from ww w. j a v a 2 s. co m throw new IllegalArgumentException( "The provided registry object can not be resolved to an instance: " + property); } else return Collections.emptyList(); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldLoadSystemProperties() { System.setProperty("blah.aa", "1"); System.setProperty("blah.b", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", false); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("blah.aa")); assertTrue(configuration.getBoolean("blah.b")); assertEquals("three", configuration.getProperty("blah.c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.aa"); System.clearProperty("blah.b"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixes() { System.setProperty("blah.a", "1"); System.setProperty("blah.bbb", "true"); System.setProperty("blah.c", "three"); System.setProperty("bleep.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a")); assertTrue(configuration.getBoolean("bbb")); assertEquals("three", configuration.getProperty("c")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); System.clearProperty("blah.a"); System.clearProperty("blah.bbb"); System.clearProperty("blah.c"); System.clearProperty("bleep.d"); }
From source file:org.apache.tinkerpop.gremlin.util.SystemUtilTest.java
@Test public void shouldTrimSystemPropertyPrefixesAndNoMore() { System.setProperty("blah.a.x", "1"); System.setProperty("blah.b.y", "true"); System.setProperty("blah.cc.zzz", "three"); System.setProperty("bleep.d.d", "false"); Configuration configuration = SystemUtil.getSystemPropertiesConfiguration("blah", true); assertEquals(3, IteratorUtils.count(configuration.getKeys())); assertEquals(1, configuration.getInt("a.x")); assertTrue(configuration.getBoolean("b.y")); assertEquals("three", configuration.getProperty("cc.zzz")); assertFalse(configuration.containsKey("d") || configuration.containsKey("bleep.d")); assertFalse(configuration.containsKey("d.d") || configuration.containsKey("bleep.d.d")); System.clearProperty("blah.a.x"); System.clearProperty("blah.b.y"); System.clearProperty("blah.cc.zzz"); System.clearProperty("bleep.d.d"); }