I was recently tasked with setting up a local database instance for testing a web application. The application uses a Gremlin graph database hosted on Azure Cosmos DB. The solution we decided on was using the Azure Cosmos DB Emulator with data populated by a script. Due to the low usage of Gremlin, there does not exist much documentation supporting this. Therefore, after finishing the scripts and setup, I decided to share my newfound knowledge with everybody.
First, you need to download and install the Azure Cosmos DB Emulator. Then, download the Gremlin console sdk and place the unzipped folder in C:/sdk.
Then, run this command in your console:
C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /EnableGremlinEndpoint
This will start the emulator. When your browser window opens, create a new container and database. When finished, paste the following in C:\sdk\apache-tinkerpop-gremlin-console-3.4.3\conf\remote-localcompute.yaml:
hosts: [localhost]
port: 8901
username: /dbs/{database}/colls/{collection}
password:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
connectionPool: {
enableSsl: false}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0,
config: { serializeResultToString: true }}
Now, run the following command from C:\sdk\apache-tinkerpop-gremlin-console-3.4.3:
bin\gremlin.bat
This will open the Gremlin console in your console window. To start a data-populating script, run ‘. {location of your script}’ An example script looks like:
:remote connect tinkerpop.server conf/remote-localcompute.yaml
:remote console
g.E().drop()
g.V().drop()
g.addV(‘Location’).property(‘Name’, ‘Atlanta’).property(‘_partitionKey’, ‘v1’)
g.addV(‘Person’).property(‘Name’, ‘Josh Kostal’).property(‘_partitionKey’, ‘v1’)
This will connect to your local database, drop all existing edges and vertices, and add two new vertices. Now, you are able to run your tests. When these are finished, run:
C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /Shutdown
This will spin down the emulator.
Finally, here are working examples of my scripts:
gremlin-connect.bat
start C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /EnableGremlinEndpoint
cd /d C:\sdk\apache-tinkerpop-gremlin-console-3.4.3
start cmd /k call bin\gremlin.bat
ECHO When finished testing, press any key. This will shutdown the local database
PAUSE
C:\”Program Files”\”Azure Cosmos DB Emulator”\CosmosDB.Emulator.exe /Shutdown
load-data.txt
:remote connect tinkerpop.server conf/remote-localcompute.yaml
:remote console
g.E().drop()
g.V().drop()
g.addV(‘Location’).property(‘Name’, ‘Atlanta’).property(‘_partitionKey’, ‘v1’)
g.addV(‘Person’).property(‘Name’, ‘Josh Kostal’).property(‘_partitionKey’, ‘v1’)
I hope this helps, feel free to reach out to me if you have any questions! My email is josh.kostal@perficient.com.