'JanusGraph Load an existing graph with Gremlin.Net and Docker-Compose
I'm currently working with janusgraph and gremlin via a docker-compose:
version: "3.9"
services:
janusgraph:
image: docker.io/janusgraph/janusgraph:latest
container_name: jce-janusgraph
environment:
JANUS_PROPS_TEMPLATE: cql-es
janusgraph.storage.hostname: jce-cassandra
janusgraph.index.search.hostname: jce-elastic
ports:
- "8182:8182"
networks:
- jce-network
volumes:
- ./mydata:/opt/janusgraph/mydata
healthcheck:
test: ["CMD", "bin/gremlin.sh", "-e", "scripts/remote-connect.groovy"]
interval: 10s
timeout: 30s
retries: 3
cassandra:
image: cassandra:3
container_name: jce-cassandra
ports:
- "9042:9042"
- "9160:9160"
networks:
- jce-network
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.6.0
container_name: jce-elastic
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- "http.host=0.0.0.0"
- "network.host=0.0.0.0"
- "transport.host=127.0.0.1"
- "cluster.name=docker-cluster"
- "xpack.security.enabled=false"
- "discovery.zen.minimum_master_nodes=1"
ports:
- "9200:9200"
networks:
- jce-network
networks:
jce-network:
volumes:
janusgraph-default-data:
Inside /mydata I have a graphml that I'd like to load in order to using it in my .net 6 web api. In gremlin console I'm able to load that graph. I searched online but I have not found anything on how to load a graph with Gremlin.Net.
I was thinking to create a Seed class with a static method that load the graph and then call in Program
Edit
I create Seed.cs:
public static class Seed
{
public static void LoadGraph(GraphTraversalSource g)
{
//g.Io<Graph>("C:\\Users\\ext-azanetti\\Desktop\\janusgraph\\mydata\\air-routes.graphml");
g.Io<Graph>("http://jce-janusgraph:8182/opt/janusgraph/mydata/air-routes.graphml");
}
}
Then i call seed in my Program.cs:
...
builder.Services.AddSingleton<GremlinClient>((serviceProvider) =>
{
var gremlinServer = new GremlinServer(
hostname: "localhost",
port: 8182,
enableSsl: false,
username: null,
password: null
);
var connectionPoolSettings = new ConnectionPoolSettings
{
MaxInProcessPerConnection = 32,
PoolSize = 4,
ReconnectionAttempts = 4,
ReconnectionBaseDelay = TimeSpan.FromSeconds(1),
};
return new GremlinClient(
gremlinServer: gremlinServer,
messageSerializer: new GraphSON3MessageSerializer(new GraphSON3Reader(), new GraphSON3Writer()),
connectionPoolSettings: connectionPoolSettings
);
});
builder.Services.AddSingleton<GraphTraversalSource>((serviceProvider) =>
{
GremlinClient gremlinClient = serviceProvider.GetService<GremlinClient>();
var driverRemoteConnection = new DriverRemoteConnection(gremlinClient, "g");
return AnonymousTraversalSource.Traversal().WithRemote(driverRemoteConnection);
});
...
try
{
var g = app.Services.GetService<GraphTraversalSource>();
if (g != null) Seed.LoadGraph(g);
else throw new Exception("Cannot get service GraphTraversalSource to load data");
}
catch (Exception ex)
{
throw new Exception("Fail to load the graph", ex);
}
...
It doesn't work. And it doesn't throw any execption.
Update
I delete the Seed.cs and in put all inside Program.cs:
builder.Services.AddSingleton<GremlinClient>((serviceProvider) =>
{
var gremlinServer = new GremlinServer(
hostname: "localhost",
port: 8182,
enableSsl: false,
username: null,
password: null
);
var connectionPoolSettings = new ConnectionPoolSettings
{
MaxInProcessPerConnection = 32,
PoolSize = 4,
ReconnectionAttempts = 4,
ReconnectionBaseDelay = TimeSpan.FromSeconds(1),
};
return new GremlinClient(
gremlinServer: gremlinServer,
messageSerializer: new GraphSON3MessageSerializer(new GraphSON3Reader(), new GraphSON3Writer()),
connectionPoolSettings: connectionPoolSettings
);
});
builder.Services.AddSingleton<GraphTraversalSource>((serviceProvider) =>
{
GremlinClient gremlinClient = serviceProvider.GetService<GremlinClient>();
var driverRemoteConnection = new DriverRemoteConnection(gremlinClient, "g");
var g = AnonymousTraversalSource
.Traversal()
.WithRemote(driverRemoteConnection);
// ##### CODE ADDED IN UPDATE ######
g.Io<Graph>("/opt/janusgraph/mydata/air-routes.graphml")
.With(IO.reader, IO.graphml);
return g;
});
Now it's throw InvalidRequestArguments: The traversal source [g] for alias [g] is not configured on the server. Now I'm trying to figure out how to solve this exception.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
