Loading data into Titan - titan

I am currently running Titan Server (0.4) [via bin/titan.sh -c cassandra-es start] and load the sample data using rexster-console:
rexster[groovy]> g = rexster.getGraph("graph")
rexster[groovy]> GraphOfTheGodsFactory.load(g)
How can I do the same thing above using a RexsterClient in java? Essentially, Is it possible to get access to graph without me having to embed all this in client.execute()?
Thanks for your help.

Once you've created the graph you can access it with RexsterClient. You shouldn't need to recreate the graph again with it as the data is already in Cassandra. Just specify the graph name when constructing your RexsterClient instance (in the case of Titan Server the graph name is just "graph"):
RexsterClient client = RexsterClientFactory.open("localhost", "graph");
List<Map<String, Object>> results = client.execute("g.v(4).map");
That will initialize "g" and allow you to just issue some Gremlin against the Graph of the Gods sample data set. You can read more about the options for RexsterClient here.

Related

Store Gremlin graph in local DynamoDB

Instead of using AWS, I am using its local available DynamoDB database and creating a graph in the Gremlin console.
My PC is using Gremlin-version=3.0.1.incubating and Titan-version=1.0.0
My question: How to save a graph in my local DynamoDB so that I can retrieve it back whenever I wish? (E.g. after computer restart).
I have tried a lot, using save() or commit() graph. But I always got an error:
g.commit()
No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph
.GraphTraversalSource.commit() is applicable for argument types: () values: []
Possible solutions: wait(), computer(), collect(), wait(long), computer(java.lang.Class), collect(groovy.lang.Closure)
I am using Tinkerpop 3.
Relevant documentation links:
Amazon DynamoDB Storage Backend for Titan
Running DynamoDB on Your Computer
As Filipe mentioned, g.commit() throws an exception because there is no commit() method on g which is a GraphTraversalSource. I suggested that you use graph.tx().commit(), where graph.tx() gets the Transaction from the Graph. In the comments we found out that you were trying to commit() a transaction on a TinkerGraph, which does not support transactions.
You need to instantiate a TitanGraph, not a TinkerGraph. This commonly done with a properties file, and there is a DynamoDB Local example properties file in the dynamodb-titan-storage-backend repository. Make sure to update the storage.dynamodb.client.endpoint to match your configuration. If you are using the Titan Server directions from the DynamoDB-Titan link, the port is 4567. If you are using the directions from the DynamoDB local link above, the default port is 8000.
gremlin> graph = TitanFactory.open('conf/gremlin-server/dynamodb-local.properties')
==>standardtitangraph[com.amazon.titan.diskstorage.dynamodb.DynamoDBStoreManager:[127.0.0.1]]
gremlin> v0 = graph.addVertex('name', 'jason'); v1 = graph.addVertex('name', 'mustaffa'); v0.addEdge('helps', v1)
==>e[175-39k-1lh-374][4232-helps->4144]
gremlin> graph.tx().commit()
==>null
Also note, the DynamoDB-Titan directions end up starting an in-memory DynamoDB Local instance. This behavior can be changed by commenting out the -inMemory argument the pom.xml.
You are attempting to commit your traversal g. You should be attempting to commit your graph like so: graph.commit().
g is the traversal which is initialised as such: g = graph.traversal() and it cannot be committed.

How to create a H2OFrame using H2O REST API

Is it possible to create a H2OFrame using the H2O's REST API and if so how?
My main objective is to utilize models stored inside H2O so as to make predictions on external H2OFrames.
I need to be able to generate those H2OFrames externally from JSON (I suppose by calling an endpoint)
I read the API documentation but couldn't find any clear explanation.
I believe that the closest endpoints are
/3/CreateFrame which creates random data and /3/ParseSetup
but I couldn't find any reliable tutorial.
Currently there is no REST API endpoint to directly convert some JSON record into a Frame object. Thus, the only way forward for you would be to first write the data to a CSV file, then upload it to h2o using POST /3/PostFile, and then parse using POST /3/Parse.
(Note that POST /3/PostFile endpoint is not in the documentation. This is because it is handled separately from the other endpoints. Basically, it's an endpoint that takes an arbitrary file in the body of the post request, and saves it as "raw data file").
The same job is much easier to do in Python or in R: for example in order to upload some dataset into h2o for scoring, you only need to say
df = h2o.H2OFrame(plaindata)
I am already doing something similar in my project. Since, there is no REST API endpoint to directly convert JSON record into a Frame object. So, I am doing the following: -
1- For Model Building:- first transfer and write the data into the CSV file where h2o server or cluster is running.Then import data into the h2o using POST /3/ImportFiles, and then parse and build a model etc. I am using the h2o-bindings APIs (RESTful APIs) for it. Since I have a large data (hundreds MBs to few GBs), so I use /3/ImportFiles instead POST /3/PostFile as latter is slow to upload large data.
2- For Model Scoring or Prediction:- I am using the Model MOJO and POJO. In your case, you use POST /3/PostFile as suggested by #Pasha, if your data is not large. But, as per h2o documentation, it's advisable to use the MOJO or POJO for model scoring or prediction in a production environment and not to call h2o server/cluster directly. MOJO and POJO are thread safe, so you can scale it using multithreading for concurrent requests.

Add metric name in OTSDB via API

I am adding data into OTSDB from different sources. But i give metric name for each data points using XML file. Also i dont have any access to OTSDB to create Metric Name via terminal
I have reffered below links :-
API PUT
GitHub Issue
In gitHub issue, i couldn't understand how to use --auto-metirc .
I know how to create metric using Terminal :-
Here i am creating abxcs metirc using terminal.
./tsdb mkmetric abxcs
But How to create metric using API?
FYI :- Please suggest solution using JAVA
Thanks for help in advance.
In order to have metric names auto created on-the-fly, you'll need to set
tsd.core.auto_create_metrics = true
in the OpenTSDB configuration file. Ref: http://opentsdb.net/docs/build/html/user_guide/configuration.html
Whether or not a data point with a new metric will assign a UID to the metric. When false, a data point with a metric that is not in the database will be rejected and an exception will be thrown.
CLI equivalent of it is to pass --auto-metric switch while starting tsd process.

Create\Add a graph Titan server using default rexster

when i run
rexster.getGraphNames()
my only result is graph, when i ran a gremlin instance directly over titan i had
tmp
and created a graph called
mygraph
i have been loooking around and havent found anything
Titan Server will only host a single instance of a graph. Therefore, rexster.getGraphNames() will always only return one graph and it will always be called graph.
Creating a graph called mygraph with the Gremlin REPL won't connect Titan Server to the graph unless you've configured it to do so and even then, it will still be referred to by Titan Server as just graph.

Is there a way to wipe an entire Neo4j database via the REST API?

I'm using the Neography gem to interact with a Neo4j database through the REST API. I don't see any way in Neography itself (though if it's there, I'd love to use it!), nor have I been able to find by searching on Google whether this is possible directly through the REST API itself. Does anyone out there with Neo4j experience happen to know?
With Neography, you can send this Gremlin script:
#neo = Neography::Rest.new
#neo.execute_script("g.clear()")
to remove all the nodes and relationships.
To clear all nodes and relationships except the root node, use the solution provided in neography wiki
#neo = Neography::Rest.new
#neo.execute_query("START n0=node(0),nx=node(*) MATCH n0-[r0?]-(),nx-[rx?]-() WHERE nx <> n0 DELETE r0,rx,nx")