List of usage examples for org.apache.commons.configuration Configuration setProperty
void setProperty(String key, Object value);
From source file:org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram.java
@Override public void storeState(final Configuration configuration) { VertexProgram.super.storeState(configuration); configuration.setProperty(VERTEX_COUNT, this.vertexCountAsDouble); configuration.setProperty(ALPHA, this.alpha); configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations); configuration.setProperty(PROPERTY, this.property); if (null != this.edgeTraversal) this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL); if (null != this.initialRankTraversal) this.initialRankTraversal.storeState(configuration, INITIAL_RANK_TRAVERSAL); }
From source file:org.apache.tinkerpop.gremlin.process.computer.util.ConfigurationTraversal.java
public void storeState(final Configuration configuration) { try {/*w w w .j a va 2s .c o m*/ VertexProgramHelper.serialize(this.traversalFunction, configuration, this.configKey); // the traversal can not be serialized (probably because of lambdas). As such, try direct reference. } catch (final IllegalArgumentException e) { configuration.setProperty(this.configKey, this.traversalFunction); } }
From source file:org.apache.tinkerpop.gremlin.process.computer.util.LambdaHolder.java
public void storeState(final Configuration configuration) { configuration.setProperty(this.configKeyPrefix.concat(DOT_TYPE), this.type.name()); if (this.type.equals(Type.OBJECT)) configuration.setProperty(this.configKeyPrefix.concat(DOT_OBJECT), this.configObject); else if (this.type.equals(Type.SERIALIZED_OBJECT)) VertexProgramHelper.serialize(this.configObject, configuration, this.configKeyPrefix.concat(DOT_OBJECT)); else if (this.type.equals(Type.CLASS)) configuration.setProperty(this.configKeyPrefix.concat(DOT_OBJECT), ((Class) this.configObject).getCanonicalName()); else // SCRIPT VertexProgramHelper.serialize(this.configObject, configuration, this.configKeyPrefix.concat(DOT_OBJECT)); }
From source file:org.apache.tinkerpop.gremlin.process.computer.util.VertexProgramHelper.java
public static void serialize(final Object object, final Configuration configuration, final String key) { if (configuration instanceof AbstractConfiguration) ((AbstractConfiguration) configuration).setDelimiterParsingDisabled(true); try {//from www . ja v a 2 s .co m final String byteString = Arrays.toString(Serializer.serializeObject(object)); configuration.setProperty(key, byteString.substring(1, byteString.length() - 1)); } catch (final IOException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:org.apache.tinkerpop.gremlin.process.computer.VertexProgram.java
/** * When it is necessary to store the state of the VertexProgram, this method is called. * This is typically required when the VertexProgram needs to be serialized to another machine. * Note that what is stored is simply the instance/configuration state, not any processed data. * The default implementation provided simply stores the VertexProgram class name for reflective reconstruction. * It is typically a good idea to VertexProgram.super.storeState(). * * @param configuration the configuration to store the state of the VertexProgram in. *//*from w ww. j a va 2 s. c o m*/ public default void storeState(final Configuration configuration) { configuration.setProperty(VERTEX_PROGRAM, this.getClass().getName()); }
From source file:org.apache.tinkerpop.gremlin.process.traversal.util.PureTraversal.java
public void storeState(final Configuration configuration, final String configurationKey) { try {//from www .j av a2s . co m VertexProgramHelper.serialize(this, configuration, configurationKey); // the traversal can not be serialized (probably because of lambdas). As such, try direct reference. } catch (final IllegalArgumentException e) { configuration.setProperty(configurationKey, this); } }
From source file:org.apache.tinkerpop.gremlin.spark.process.computer.groovy.plugin.SparkGremlinPluginTest.java
@Test public void shouldSupportBasicRDDOperations() throws Exception { final String root = TestHelper.makeTestDataDirectory(SparkGremlinPluginTest.class, "shouldSupportBasicRDDOperations"); final String rddName1 = TestHelper.makeTestDataDirectory(SparkGremlinPluginTest.class, "shouldSupportBasicRDDOperations", "graph-1"); final Configuration configuration = new BaseConfiguration(); configuration.setProperty("spark.master", "local[4]"); configuration.setProperty("spark.serializer", GryoSerializer.class.getCanonicalName()); configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName()); configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern.kryo")); configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT, GryoInputFormat.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD, PersistedOutputRDD.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false); configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, rddName1); configuration.setProperty(Constants.GREMLIN_SPARK_PERSIST_CONTEXT, true); Graph graph = GraphFactory.open(configuration); Spark.create("local[4]"); assertEquals(0, ((List<String>) this.console.eval("spark.ls()")).size()); this.console.addBinding("graph", graph); this.console.eval( "graph.compute(SparkGraphComputer).program(PageRankVertexProgram.build().iterations(1).create()).submit().get()"); assertEquals(1, ((List<String>) this.console.eval("spark.ls()")).size()); assertEquals(rddName1 + " [Memory Deserialized 1x Replicated]", ((List<String>) this.console.eval("spark.ls()")).get(0)); final String rddName2 = TestHelper.makeTestDataDirectory(SparkGremlinPluginTest.class, "shouldSupportBasicRDDOperations", "graph-2"); this.console.eval("graph.configuration().setProperty('" + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + "','" + rddName2 + "')"); this.console.eval( "graph.compute(SparkGraphComputer).program(PageRankVertexProgram.build().iterations(1).create()).submit().get()"); assertEquals(2, ((List<String>) this.console.eval("spark.ls()")).size()); assertTrue(((List<String>) this.console.eval("spark.ls()")) .contains(rddName2 + " [Memory Deserialized 1x Replicated]")); this.console.eval("spark.rm('" + rddName2 + "')"); assertEquals(1, ((List<String>) this.console.eval("spark.ls()")).size()); assertTrue(((List<String>) this.console.eval("spark.ls()")) .contains(rddName1 + " [Memory Deserialized 1x Replicated]")); assertEquals(6, ((List<Object>) this.console.eval("spark.head('" + rddName1 + "')")).size()); this.console.eval("spark.rm('" + root + "graph-*')"); assertEquals(0, ((List<String>) this.console.eval("spark.ls()")).size()); ///////*from w w w .j av a2 s . com*/ this.console.eval("graph.configuration().setProperty('" + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + "','" + rddName1 + "')"); this.console.eval( "graph.compute(SparkGraphComputer).program(PageRankVertexProgram.build().iterations(1).create()).submit().get()"); this.console.eval("graph.configuration().setProperty('" + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + "','" + rddName2 + "')"); this.console.eval( "graph.compute(SparkGraphComputer).program(PageRankVertexProgram.build().iterations(1).create()).submit().get()"); final String rddName3 = TestHelper.makeTestDataDirectory(SparkGremlinPluginTest.class, "shouldSupportBasicRDDOperations", "x"); this.console.eval("graph.configuration().setProperty('" + Constants.GREMLIN_HADOOP_OUTPUT_LOCATION + "','" + rddName3 + "')"); this.console.eval( "graph.compute(SparkGraphComputer).program(PageRankVertexProgram.build().iterations(1).create()).submit().get()"); assertEquals(3, ((List<String>) this.console.eval("spark.ls()")).size()); this.console.eval("spark.rm('" + root + "graph-*')"); assertEquals(1, ((List<String>) this.console.eval("spark.ls()")).size()); this.console.eval("spark.rm('*')"); assertEquals(0, ((List<String>) this.console.eval("spark.ls()")).size()); // }
From source file:org.apache.tinkerpop.gremlin.spark.process.computer.io.InputOutputRDDTest.java
@Test public void shouldReadFromWriteToArbitraryRDD() throws Exception { final Configuration configuration = new BaseConfiguration(); configuration.setProperty("spark.master", "local[4]"); configuration.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName()); configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_INPUT_RDD, ExampleInputRDD.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD, ExampleOutputRDD.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "target/test-output"); configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false); /////////*from ww w . j a va 2 s .c o m*/ Graph graph = GraphFactory.open(configuration); graph.compute(SparkGraphComputer.class).result(GraphComputer.ResultGraph.NEW) .persist( GraphComputer.Persist.EDGES) .program(TraversalVertexProgram.build() .traversal( GraphTraversalSource.build() .engine(ComputerTraversalEngine.build().computer(SparkGraphComputer.class)), "gremlin-groovy", "g.V()") .create(graph)) .submit().get(); }
From source file:org.apache.tinkerpop.gremlin.spark.process.computer.io.InputRDDTest.java
@Test public void shouldReadFromArbitraryRDD() { final Configuration configuration = new BaseConfiguration(); configuration.setProperty("spark.master", "local[4]"); configuration.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName()); configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_INPUT_RDD, ExampleInputRDD.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_OUTPUT_FORMAT, GryoOutputFormat.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "target/test-output"); configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false); /////////*from w w w. ja va 2 s . c o m*/ Graph graph = GraphFactory.open(configuration); assertEquals(Double.valueOf(123.0d), graph .traversal(GraphTraversalSource.computer(SparkGraphComputer.class)).V().values("age").sum().next()); assertEquals(Long.valueOf(4l), graph.traversal(GraphTraversalSource.computer(SparkGraphComputer.class)).V().count().next()); }
From source file:org.apache.tinkerpop.gremlin.spark.process.computer.io.OutputRDDTest.java
@Test public void shouldWriteToArbitraryRDD() throws Exception { final Configuration configuration = new BaseConfiguration(); configuration.setProperty("spark.master", "local[4]"); configuration.setProperty("spark.serializer", "org.apache.spark.serializer.KryoSerializer"); configuration.setProperty(Graph.GRAPH, HadoopGraph.class.getName()); configuration.setProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION, SparkHadoopGraphProvider.PATHS.get("tinkerpop-modern.kryo")); configuration.setProperty(Constants.GREMLIN_HADOOP_GRAPH_INPUT_FORMAT, GryoInputFormat.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_SPARK_GRAPH_OUTPUT_RDD, ExampleOutputRDD.class.getCanonicalName()); configuration.setProperty(Constants.GREMLIN_HADOOP_OUTPUT_LOCATION, "target/test-output"); configuration.setProperty(Constants.GREMLIN_HADOOP_JARS_IN_DISTRIBUTED_CACHE, false); /////////*from w w w .j a v a 2 s. c om*/ Graph graph = GraphFactory.open(configuration); graph.compute(SparkGraphComputer.class).result(GraphComputer.ResultGraph.NEW) .persist( GraphComputer.Persist.EDGES) .program(TraversalVertexProgram.build() .traversal( GraphTraversalSource.build() .engine(ComputerTraversalEngine.build().computer(SparkGraphComputer.class)), "gremlin-groovy", "g.V()") .create(graph)) .submit().get(); }