Skip to content

Commit

Permalink
move to a unified start script and readonly example
Browse files Browse the repository at this point in the history
  • Loading branch information
tb06904 committed May 23, 2024
1 parent 414645e commit acbae4e
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 42 deletions.
7 changes: 3 additions & 4 deletions docker/gaffer-gremlin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ to deploy the containers then, the provided jupiter notebooks demonstrate how to
connect and some basic queries on the data using `gremlinpython` or via
`graph-notebook` (note this requires the [graph-notebook extension](https://github.com/aws/graph-notebook)).

To run the example first source the environment file for the image versions
e.g. `accumulo2.env` then use docker compose to start up the containers:
To run the example please use the provided start script with an environment file
to specify the image versions e.g. `accumulo2.env`:

```bash
source ../accumulo2.env
docker compose up -d
./example/create-deployment.sh ../accumulo2.env
```

With the demo deployment both a standard Gaffer REST API and Gaffer Gremlin
Expand Down
3 changes: 0 additions & 3 deletions docker/gaffer-gremlin/example/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

version: "3.7"

services:

zookeeper:
Expand Down
121 changes: 121 additions & 0 deletions docker/gaffer-gremlin/example/conf/gaffer/data/tinkerpop-modern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"class": "AddElements",
"input": [
{
"class": "Entity",
"group": "person",
"vertex": "1",
"properties": {
"name": "marko",
"age": 29
}
},
{
"class": "Entity",
"group": "person",
"vertex": "2",
"properties": {
"name": "vadas",
"age": 27
}
},
{
"class": "Entity",
"group": "person",
"vertex": "4",
"properties": {
"name": "josh",
"age": 32
}
},
{
"class": "Entity",
"group": "person",
"vertex": "6",
"properties": {
"name": "peter",
"age": 35
}
},
{
"class": "Entity",
"group": "software",
"vertex": "3",
"properties": {
"name": "lop",
"lang": "java"
}
},
{
"class": "Entity",
"group": "software",
"vertex": "5",
"properties": {
"name": "ripple",
"lang": "java"
}
},
{
"class": "Edge",
"group": "knows",
"source": "1",
"destination": "2",
"directed": true,
"properties": {
"weight": 0.5
}
},
{
"class": "Edge",
"group": "created",
"source": "1",
"destination": "3",
"directed": true,
"properties": {
"weight": 0.4
}
},
{
"class": "Edge",
"group": "knows",
"source": "1",
"destination": "4",
"directed": true,
"properties": {
"weight": 1.0
}
},
{
"class": "Edge",
"group": "created",
"source": "4",
"destination": "3",
"directed": true,
"properties": {
"weight": 0.4
}
},
{
"class": "Edge",
"group": "created",
"source": "4",
"destination": "5",
"directed": true,
"properties": {
"weight": 1.0
}
},
{
"class": "Edge",
"group": "created",
"source": "6",
"destination": "3",
"directed": true,
"properties": {
"weight": 0.2
}
}
],
"skipInvalidElements": false,
"validate": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
# limitations under the License.
#
gremlin.graph=uk.gov.gchq.gaffer.tinkerpop.GafferPopGraph
gaffer.graphId=graph1
gaffer.graphId=superGraph
gaffer.storeproperties=conf/gaffer/store.properties
gaffer.schemas=conf/gaffer/schema/
gaffer.userId=user01
# This is required to load data via gremlin queries
gaffer.elements.notreadonly=true
59 changes: 59 additions & 0 deletions docker/gaffer-gremlin/example/create-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/sh
# Copyright 2024 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

CURRENT_DIR="$(dirname "$(readlink -f "${0}")")"
TINKERPOP_MODERN_JSON="${CURRENT_DIR}/conf/gaffer/data/tinkerpop-modern.json"
GAFFER_REST_URL="http://localhost:8080"

# Make sure we have an evironment file for the image versions
if [ ! -f "${1}" ]; then
echo "Error - Environment file not set"
echo "Example: ${0} <envfile>.env"
exit 1
fi

# Remove any existing containers
docker compose --env-file "${1}" -f "${CURRENT_DIR}/compose.yaml" down

# Start new deployment
echo "-----------------------------------"
echo "Starting new deployment..."
docker compose --env-file "${1}" -f "${CURRENT_DIR}/compose.yaml" up --detach

# Check can connect to instance
echo "-----------------------------------"
echo "Attempting to connect to Gaffer instance..."
if ! docker run --rm --network=host curlimages/curl:latest \
curl --retry 20 \
--retry-delay 5 \
--retry-all-errors "${GAFFER_REST_URL}"/rest/graph/status
then
echo "Failed to connect to Gaffer instance"
exit 1
fi

# Load dataset
echo "-----------------------------------"
echo "Loading data into Gaffer instance..."
if ! docker run --rm --network=host curlimages/curl:latest \
curl -H "Content-Type: application/json" \
--data "$(cat "${TINKERPOP_MODERN_JSON}")" "${GAFFER_REST_URL}"/rest/graph/operations/execute
then
echo "Failed to load tinkerpop modern JSON: ${TINKERPOP_MODERN_JSON}"
exit 1
fi

echo "-----------------------------------"
echo "Deployment started!"
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,12 @@
"along with extended tooling."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Load the modern Graph via the gremlinpython client\n",
"from gremlin_python.driver.client import Client\n",
"\n",
"Client('ws://localhost:8182/gremlin', 'g').submit(\"graph.io(graphml()).readGraph('data/tinkerpop-modern.xml')\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These cells configure the connection to the gremlin server and reloading the extension,\n",
"need to ensure the gaffer-gremlin container is running before connecting."
"need to ensure the `gaffer-gremlin` example deployment is running before connecting."
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@
"nest_asyncio.apply()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load the 'modern' tinkerpop dataset"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create gremlin client to run gremlin scripts directly\n",
"client = Client('ws://localhost:8182/gremlin', 'g')\n",
"# Import graphml data with script\n",
"client.submit(\"graph.io(graphml()).readGraph('data/tinkerpop-modern.xml')\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -114,6 +95,15 @@
"source": [
"g.V('1').repeat(__.both().simplePath()).until(__.has('name', 'lop')).limit(3).path().by(__.valueMap()).to_list()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"g.V('1').outE().as_(\"a\").V('1').values(\"name\").to_list()"
]
}
],
"metadata": {
Expand Down

0 comments on commit acbae4e

Please sign in to comment.