Revised URL for websockets in 3.2.2

466 views
Skip to first unread message

Stephen Mallette

unread,
Sep 29, 2016, 7:36:20 PM9/29/16
to Gremlin-users
I just wanted to make it clear that 3.2.2 introduced a breaking change that went undocumented in the upgrade notes. When I bumped to the latest version of netty in Gremlin Server, it fixed a bug that forced a change to the websocket URL that Gremlin Server responds to. It used to be:

ws://localhost:8182

but is now:

ws://localhost:8182/gremlin

That's an important piece of information for third-party drivers (and the developers of those drivers).  If you encounter problems on 3.2.2 with getting responses from Gremlin Server using those drivers, this is likely the problem. Anyway, I think most of the driver repo owners know about this issue at this point, but I thought I just send this email in case there were those who were unaware or for users so that they could attempt to fix the problem themselves.

Thanks,

Stephen

Ambarish Jadhav

unread,
Oct 22, 2016, 6:31:05 AM10/22/16
to Gremlin-users
Hi Stephen,

I have installed titan-1.0.0-hadoop1 on an instance of Ubuntu 14.0 on Soft Layer. The titan and gremlin servers are up as I have tested it through gremlin shell (created/read few vertices). Now, I want to test the websocket connection to this gremlin server from my local machine (internet) [I can connect to this VM through putty].

I have written a java class that implements okhttp3.ws.WebSocketListener and in the run method I try to create the websocket connection using url as 'ws://<vmurl>/gremlin' but I get error in onFailure method as,

java.net.ProtocolException: Expected HTTP 101 response but was '502 Connection refused'

When I tried with ws://<vmurl>:8182/gremlin, ws://<vmurl>:8182 it gave 'java.net.ConnectException: Failed to connect to the given url'

Gremlin-server is using the default WebSocketChannelizer. Can you please let me know if I am missing anything in the titan/gremlin server configuration or the websocket client call?

Thanks,
Ambarish

Stephen Mallette

unread,
Oct 22, 2016, 6:36:02 AM10/22/16
to Gremlin-users
Any reason why you are writing a custom WebSocketListener? Why not just connect with a compliant driver like gremlin-driver:



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/342600a6-b0bb-43ce-9c00-8caae2993854%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ambarish Jadhav

unread,
Oct 22, 2016, 7:44:45 AM10/22/16
to Gremlin-users
Hi Stephen,

It's just a project specific requirement to use WebSocket which will enable a faster streaming. Does the gremlin-driver option also use WebSocket or we need to  configure some other channelizer in gremlin-server?
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.

Jason Plurad

unread,
Oct 22, 2016, 12:20:48 PM10/22/16
to Gremlin-users
Hi Ambarish,

Welcome to the Gremlin mailing list.

Be aware of the versions that you're using. Titan 1.0 uses TinkerPop 3.0.1, so the original topic of this thread does not apply at all to what you're asking about. Relevant docs for your version are here.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#gremlin-server

The most obvious thing to check is the gremlin-server.yaml and make sure that the host (default is localhost) is set to something that is accessible from a remote machine, like its public IP address.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#_configuring_2

After that, you can test whether the Gremlin Server is accessible by using a Gremlin Console on the remote machine. Again, check the configuration on the remote.yaml and make sure the host (default is localhost) points to the public IP address of the remote server.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#connecting-via-console

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Connected - localhost/127.0.0.1:8182

Alternatively, you could use a websocket client plugin on your web browser and send a request message like the one described in the docs.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#_developing_a_driver

{ "requestId":"1d6d02bd-8e56-421d-9438-3bd6d0079ff1",
 
"op":"eval",
 
"processor":"",
 
"args":{"gremlin":"g.traversal().V(x).out()",
         
"bindings":{"x":1},
         
"language":"gremlin-groovy"}}

As Stephen mentioned before, you could use the gremlin-driver to write a Java program. Yes, it uses websockets. I'd suggest trying one of the other approaches first if you're just debugging connectivity.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#_connecting_via_java

I created an example of using the Gremlin Driver with Titan here.
https://github.com/pluradj/titan-tp3-driver-example


-- Jason

Ambarish Jadhav

unread,
Nov 7, 2016, 10:30:52 PM11/7/16
to Gremlin-users
Hi Jason, Stephen,

Sorry for late reply.

Like I said before, I am able to create vertices and retrieve them using the gremlin on the Softlayer Ubuntu VM where Gremlin server is running.

gremlin> :remote connect tinkerpop.server conf/remote.yaml
==>Connected - localhost/127.0.0.1:8182
gremlin> :> graph.addVertex("name", "stephen")
==>v[256]
gremlin> :> g.V().values('name')
==>stephen2
==>stephen28
==>stephen
==>stephen

Now, I am trying to execute the same query using the gremlin-driver for java from my local m/c. For this, I referred your code on Github (where you create a graph using groovy and then query it) and only used the code to create the web-socket connection and submitting a task. The Code is as follows:

----------------------------------
import org.apache.tinkerpop.gremlin.driver.Client;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.ResultSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.stream.Collectors.toList;

public class TitanConnector {

    private static final Logger logger = LoggerFactory.getLogger(TitanConnector.class);
   
    public static void main(String[] args) {
       
        Cluster cluster;
        Client client;
       
        try {
            cluster = Cluster.build(new File("conf/driver-settings.yaml")).channelizer("WebSocketChannelizer").create();
            client = cluster.connect();
//            System.out.println("Connected"+client.getSettings().toString());
            logger.info("Connected"+client.getSettings().toString());
        ResultSet results = client.submit("g.V().values('name')");
        logger.info("Connected"+client.getSettings().toString());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
----------------------------------

And the contents of the driver-settings.yaml file are as follows:
----------------------------------
hosts: [public ip of the vm]
port: 8182
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0, config: { serializeResultToString: true }}
----------------------------------

When I run this code I get the following exception while submitting the query on this line client.submit("g.V().values('name')");

java.lang.RuntimeException: java.util.concurrent.TimeoutException: Timed out while waiting for an available host - check the client configuration and connectivity to the server if this message persists

The yaml file used by the running Gremlin server, conf/gremlin-server/gremlin-server.yaml has all the default settings I haven't changed them.

Is there anything I am missing in the client configuration (change the serializer) in the java code? or which server configuration should I change (increase the timeout value) to get the response from Gremlin?

Regards,
Ambarish

Jason Plurad

unread,
Nov 8, 2016, 8:04:23 AM11/8/16
to Gremlin-users
Hi Ambarish,

Please review my previous response, in particular:


> The most obvious thing to check is the gremlin-server.yaml and make sure that the host (default is localhost) is set to something that is accessible from a remote machine, like its public IP address.
http://tinkerpop.apache.org/docs/3.0.1-incubating/#_configuring_2

You need to make changes at least in the gremlin-server.yaml to ensure it is listening on a port bound to a public IP address. After you restart the server, verify the Gremlin Server process is listening on the IP address and port you're expecting with `ss` or `netstat`.


> gremlin> :remote connect tinkerpop.server conf/remote.yaml
> ==>Connected - localhost/127.0.0.1:8182

This shows that you ran the Gremlin Console on the same machine (localhost/127.0.0.1) as the Gremlin Server, so the default value (localhost) value for host in the gremlin-server.yaml and remote.yaml would appear to work just fine. Try running the Gremlin Console on a remote machine.

-- Jason

Ambarish Jadhav

unread,
Nov 9, 2016, 11:46:10 PM11/9/16
to Gremlin-users
Hi Jason,

Thanks for the correction. Somehow, I missed considering it earlier.

I was able to establish WebSocket connection using gremlin-driver for java after doing some client as well as server side configuration changes.
I could create/retrieve a vertices on Gremlin server by submitting some basic gremlin commands through client in java.

I had to make changes in two files on Gremlin-server for this to work:
1. add the public ip address in gremlin-server.yaml
2. add the public ip address in : ${ELASTICSEARCH_IP:=<public ip>}, : ${GSRV_IP:=<public ip>} fields in titan.sh file before starting titan/gremlin servers.

However, now there is one issue after this change. I am not able to create/retrieve vertices using Gremlin shell after connecting to the Gremlin server and getting
the RemoteException as "Host did not respond in a timely fashion - check the server status and submit again". The same was working without error when I had gremlin-server running on localhost.

gremlin> :> g.V().values('name')
Host did not respond in a timely fashion - check the server status and submit again.
Display stack trace? [yN] n

However, the same query if I submit through Java code I am getting correct response. I saw Stephen's comment on this issue on SO, http://stackoverflow.com/questions/36832957/gremlin-remote-command-fails-with-timeout-error-host-did-not-respond-in-a-timel and verified that both the yamls have same ip:port and server is up,
<titan_home># bin/titan.sh status
Gremlin-Server (org.apache.tinkerpop.gremlin.server.GremlinServer) is running with pid 15362
Cassandra (org.apache.cassandra.service.CassandraDaemon) is running with pid 15584
Elasticsearch (org.elasticsearch.bootstrap.Elasticsearch) is running with pid 15822
 
Though it's not a blocker now as WebSocket is working but will be helpful for further testing through gremlin-shell.

Thanks,
Ambarish

Jason Plurad

unread,
Nov 10, 2016, 8:31:36 AM11/10/16
to Gremlin-users
Hi Ambarish,

It doesn't make much sense why you'd be able to connect with a Java program and not with Gremlin Console. They can use the same remote connection settings file.

https://github.com/pluradj/titan-tp3-driver-example/blob/master/conf/driver-settings.yaml

https://github.com/thinkaurelius/titan/blob/titan11/titan-dist/src/assembly/static/conf/remote.yaml

-- Jason
Reply all
Reply to author
Forward
0 new messages