diff --git a/docker/gaffer-gremlin/README.md b/docker/gaffer-gremlin/README.md index 94ec9dac..74207771 100644 --- a/docker/gaffer-gremlin/README.md +++ b/docker/gaffer-gremlin/README.md @@ -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 diff --git a/docker/gaffer-gremlin/example/compose.yaml b/docker/gaffer-gremlin/example/compose.yaml index 410a2bba..0c80c665 100644 --- a/docker/gaffer-gremlin/example/compose.yaml +++ b/docker/gaffer-gremlin/example/compose.yaml @@ -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: diff --git a/docker/gaffer-gremlin/example/conf/gaffer/data/tinkerpop-modern.json b/docker/gaffer-gremlin/example/conf/gaffer/data/tinkerpop-modern.json new file mode 100644 index 00000000..b541d267 --- /dev/null +++ b/docker/gaffer-gremlin/example/conf/gaffer/data/tinkerpop-modern.json @@ -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 +} \ No newline at end of file diff --git a/docker/gaffer-gremlin/example/conf/gafferpop/gafferpop.properties b/docker/gaffer-gremlin/example/conf/gafferpop/gafferpop.properties index fa08069d..4a4920a2 100644 --- a/docker/gaffer-gremlin/example/conf/gafferpop/gafferpop.properties +++ b/docker/gaffer-gremlin/example/conf/gafferpop/gafferpop.properties @@ -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 diff --git a/docker/gaffer-gremlin/example/create-deployment.sh b/docker/gaffer-gremlin/example/create-deployment.sh new file mode 100755 index 00000000..bf531a09 --- /dev/null +++ b/docker/gaffer-gremlin/example/create-deployment.sh @@ -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} .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!" diff --git a/docker/gaffer-gremlin/example/notebooks/graphnotebook-modern-example.ipynb b/docker/gaffer-gremlin/example/notebooks/graphnotebook-modern-example.ipynb index c6087096..c23f2fb7 100644 --- a/docker/gaffer-gremlin/example/notebooks/graphnotebook-modern-example.ipynb +++ b/docker/gaffer-gremlin/example/notebooks/graphnotebook-modern-example.ipynb @@ -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." ] }, { diff --git a/docker/gaffer-gremlin/example/notebooks/gremlinpython-modern-example.ipynb b/docker/gaffer-gremlin/example/notebooks/gremlinpython-modern-example.ipynb index 92ecb526..88a9913a 100644 --- a/docker/gaffer-gremlin/example/notebooks/gremlinpython-modern-example.ipynb +++ b/docker/gaffer-gremlin/example/notebooks/gremlinpython-modern-example.ipynb @@ -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": {}, @@ -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": {