我们已经看到了如何配置小精灵服务器,从而连接到远程的杰森图和Cassandra 部署。有时设置小精灵服务器只是连接一个基本的廷克图
内存模式的廷克图做为后端是非常有用的。它是一种非常便捷的方式的:如果您正在开发代码,它将最后使用在一个远端支持TinkerPop的图数据库上,但是需要在本地做一些测试和开发。小精灵服务器当然可以配置成远程的终端,或许运行在一台云主机上,但是它也可以配置成运行在您本地电脑上。笔者就是用这样方式,在自己的电脑上进行实验的。在本节笔者将进行一些配置服务器需要的步骤,让它运行在本地,航线图的数据集存储在主机的廷克图中。您可以找到本节中讨论的配置文件,在这个位置的样例代码文件夹中。
We have already seen how a Gremlin Server can be configured as a way to provide remote access
to a JanusGraph and Cassandra deployment. Sometimes it can be useful to setup a Gremlin Server
with just a basic TinkerGraph, in-memory graph, as the backend. This is often a handy way to work
if you are developing code that will ultimately work with a remote TinkerPop enabled graph
database but want to do some testing and development locally. A Gremlin Server can of course be
configured as a genuinely remote endpoint, perhaps running on a cloud hosted machine, but it can
also be configured to run on your local computer. I often set it up this way on my laptop while
experimenting. In this section I am going to walk through the steps required to configure a Gremlin
Server running locally that hosts the air-routes dataset in a TinkerGraph.
You will find the configuration files discussed in this section in the sample-data
folder at this location https://github.com/krlawrence/graph/tree/master/sample
data.
7.6.1. 创建配置文件Creating the configuration files
为了让我们远程的廷克图启动并运行,我们需要做的是配置一些文件,启动小精灵服务器。我们需要创建的第一个文件是YAML文件。在小精灵服务器启动时会读取它的内容。笔者创建了一个名为gremlin-server-air-routes.yaml 的文件。默认文件是做为小精灵服务器下载的一部分被包括到下载中的,与默认的 gremlin-server.yaml 文件相比,这个文件事实上只包含一点点修改。修改的关键是文件包含了对于在/scripts文件夹中名为air-routes.groovy. 的脚本的引用。这个脚本将加载航线图数据到刚创建的廷克图实例中。
To get our remote TinkerGraph up and running, all we have to do is to configure a few settings files
and start the Gremlin Server. The first file we need to create is the YAML file that will be read by
the Gremlin Server as it starts. I created a file called gremlin-server-air-routes.yaml for this
purpose. The file actually only contains minor changes from the default gremlin-server.yaml file
that comes included as part of the Gremlin Server download. The key change is that the file
includes a reference to a script in the /scripts folder called air-routes.groovy. The script will load
the air-routes data set into a TinkerGraph instance once it has been created.
本节中引用的所有的文件,如/data 和 /script,它们都是相对于小精灵的服务器安装位置而言的。gremlin-server-air-routes.yaml这个文件应当放在/conf文件夹中。
All folders referenced in this section, such as /data and /script are relative to the
location where the Gremlin Server is installed.
The gremlin-server-air-routes.yaml file should be placed in the /conf folder.
 

 注意笔者配置了YAML文件,这样当JSON返回时它的格式是最开始的 V1 GraphSON格式。这个可以通过指定GraphSONMessageSerializerV1d0 消息串型器来说明。V1格式和V3格式最大的不同就是V1格式中没有类型信息返回。笔者发现用户在学习小精灵查询语言时觉得这种格式更易读。

Note that I configured the YAML file so that when JSON is returned it is in the original V1 GraphSON
format. This is done by specifying that the GraphSONMessageSerializerV1d0 message serializer be
used. The main difference between the V1 format and the newer V3 format is that no type
information will be returned as part of the V1 format. I find that users find this format much easier
to read while learning Gremlin.在YAML文件中引用的属性文件没有修改来自小精灵服务器中的默认的值。这会创建一个空的内存模式的廷克图。 tinkergraph-empty.properties文件应当只放在/conf文件夹中。
The properties file that is referenced in the YAML file is unchanged from the default one that comes
with Gremlin Server. It creates an empty in-memory TinkerGraph.
The tinkergraph-empty.properties file should also be placed in the /conf folder.

 air-routes.groovy这个文件调用了必要的方法来从/data文件夹中加载航线图文件。这个文件应当放在/script文件夹

The file air-routes.groovy invokes the necessary method to load the air-routes.graphml file from
the /data folder. The file should be placed in the /scripts folder.

 

7.6.2. 启动服务器 Starting the Server
在"配置小精灵服务器"一节中讨论过,您可以在前台或后台启动服务器。我们的初始测试,让服务器就运行在前端。
As discussed in the "Configuring Gremlin Server" section, you can start the Gremlin Server in the
foreground or in the background. For our initial test let’s just start the server running in the
foregorund.

 

7.6.3. 测试服务器Testing the Server
小精灵服务器已经启动并运行,您可以访问它,使用localhost做为主机名,端口号8182,就像我们前边在配置小精灵服务器和杰森图时做的一样。使用简单的curl命令来确保一切正常,这总是一个不错的主意。
Now that the Gremlin Server is up and running you can access it using localhost as the host name
and a port of 8182 just as we did earlier while setting up a Gremlin Server and JanusGraph. It’s
always a good idea to try a simple curl command to make sure that things are working.

 这是返回的输出。注意它是我们前边配置的GraphSON V1 格式的。

Here is the output returned. Note that it is in the GraphSON V1 format that we configured for
earlier.

 我们前边看到的相同的小精灵控制台连接配置可以被重复使用。您可以使用localhost主机名和端口8182来连接您的小精灵服务器。下面这个例子假设您已经启动了小精灵控制台。

The same Gremlin Console remote connections configuration we looked at earlier can also be
reused. Likewise, you can connect to your Gremlin Server using the host name localhost and port
8182. The example below assumes that you have already started the Gremlin Console.

 希望读完这节,您已经理解了如何启动小精灵服务器,这台服务器是一个包含了航线图数据的内存模式廷克图的主机。这是非常有用的环境,当您想要在本地测试一些查询和代码时,这些查询和代码最终将需要用到远程支持Tinkerpop的图数据库上。

Hopefully having read this section you now have an understanding of how to setup a Gremlin
Server that hosts an in-memory TinkerGraph containing the air-routes data set. This can be a useful
environment when you want to test queries and code locally that will ultimately need to work with
a remote TinkerPop enabled graph database.
在下一节我们将看到一些方式可以让返回的JSON更易处理,也增加了Ruby程序来处理JSON。
In the next section we will look at ways to make the JSON returned easier to work with and also add
to our Ruby program to work with the JSON.
posted on 2022-05-05 10:33  bokeyuannicheng0000  阅读(106)  评论(0)    收藏  举报