I am currently trying to connect to a preexisting Cosmos DB using Gremlin and Mavin for Java. My database requires a username and password to connect. I currently pass in the code with endpoint, username, password, and port to create a cluster. I then use the cluster to start a client and use the client to create a root traversal which I can use to query the DB. My queries return network errors, but I suspect the problem might be in the creation of a cluster since when searching for hosts on the cluster, I get a result of 0 hosts.
I have already tried using a connection string instead of the separated username, password, etc. but that hasn’t worked either. I also tried a Python script which failed.
Here is the connection code:
private static GraphTraversalSource connect(String endpoint, String username, String password, int port) {
System.out.println("STARTING");
System.out.println("creating cluster");
Cluster cluster = Cluster.build()
.addContactPoint(endpoint)
.port(port)
.credentials(username, password)
.enableSsl(true)
.maxWaitForConnection(100000) // Increase connection timeout
.maxContentLength(65536)
.create();
int numHosts = cluster.availableHosts().size();
System.out.println("Cluster created successfully with the following hosts:");
System.out.println(numHosts);
System.out.println("Connecting");
Client client = cluster.connect();
System.out.println("Determining traversal source");
// Define the source and target graph traversal sources
final GraphTraversalSource G = AnonymousTraversalSource.traversal().withRemote(DriverRemoteConnection.using(client));
System.out.println("Finding count");
try {
long vertexCount = G.V().count().next();
System.out.println("Source count: " + vertexCount);
}
catch(Exception e) {
System.out.println("FAILED TO QUERY");
System.exit(1);
}
return G;
}
The output is as follows (I replaced the actual address and hostUri with endpoint for the address):
STARTING
creating cluster
Cluster created successfully with the following hosts:
0
Connecting
Determining traversal source
Finding count
09:28:44.187 [gremlin-driver-loop-1] ERROR o.a.t.g.d.Connection - Server closed the Connection on channel 2017caf4 - scheduling removal from ConnectionPool (Host{address=endpoint/internalIP, hostUri=wss://endpoint:port/gremlin})
Connection Pool Status (size=2 max=8 min=2 toCreate=0 bin=0)
==> Connection{channel=2017caf4 isDead=true borrowed=1 pending=1 markedReplaced=false closing=false created=2024-07-23T16:28:43.549866Z thread=gremlin-driver-conn-scheduler-1}
> Connection{channel=83a2625b isDead=false borrowed=0 pending=0 markedReplaced=false closing=false created=2024-07-23T16:28:43.549858Z thread=gremlin-driver-conn-scheduler-2}
-- bin --
FAILED TO QUERY
Process finished with exit code 1
Nikhil Menon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.