Skip to content

Commit

Permalink
update proxy example
Browse files Browse the repository at this point in the history
  • Loading branch information
tb06904 committed Aug 19, 2024
1 parent 3551d4e commit 2c34291
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Run a seeded cypher query via Gremlin"
"Run a seeded cypher query via Gremlin. Submitted as a script rather than via gremlin-python bindings"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.
#
# Default operation config
gaffer.elements.getalllimit=5000
gaffer.elements.hasstepfilterstage=PRE_AGGREGATION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"entities": {
"vertex": {
"id": {
"vertex": "string.id"
},
"person": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

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

# Make sure we have an evironment file for the image versions
Expand Down Expand Up @@ -56,4 +56,4 @@ then
fi

echo "-----------------------------------"
echo "Deployment started!"
echo "Deployment started! REST API: ${GAFFER_REST_URL}"
23 changes: 12 additions & 11 deletions docker/example-deployments/proxy-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@

## Running

To run it from the `proxy-example` directory you'll need to specify the
environment file path:
This is an example deployment of Gaffer using a Proxy store. This uses two REST
APIs on a Map store with data in and another as a proxy pointing to the other.

```bash
docker compose --env-file ../.env up
```
The example uses the
[Tinkerpop Modern Graph](https://tinkerpop.apache.org/docs/current/tutorials/the-gremlin-console/#toy-graphs)
as its data set to demonstrate basic querying of data.

## Running the Example

Or to run it from this directory, the compose file path and environment file
path:
To run the example please use the provided start script with an environment file
to specify the image versions e.g. `accumulo2.env`:

```bash
docker compose -f proxy-example/compose.yaml --env-file .env up
./create-deployment.sh ../../accumulo2.env
```

With this deployment both a standard Gaffer REST API and a Gaffer REST API using
the Proxy Store will be started. Only the port for the Proxy REST endpoint is
exposed, this will forward operations to the standard Gaffer REST Endpoint.
With the demo deployment the Proxy backed Gaffer REST API will be started on port 8080
and the Map store backed instance on 8081.
14 changes: 10 additions & 4 deletions docker/example-deployments/proxy-example/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ services:
healthcheck:
test: sleep 15
timeout: 20s
ports:
- 8081:8080
restart: always
volumes:
- ./conf/map/store.properties:/gaffer/store/store.properties:ro
- ./conf/schema:/gaffer/schema:ro

gaffer-rest-proxy:
image: gchq/gaffer-rest:${GAFFER_VERSION}-accumulo-${ACCUMULO_VERSION}
depends_on:
gaffer-rest:
condition: service_healthy
restart: always
ports:
- 8080:8080
network_mode: "host"
volumes:
- ./config/store.properties:/gaffer/store/store.properties:ro
- ./config/operationsDeclarations.json:/gaffer/store/operationsDeclarations.json:ro
- ./conf/proxy/store.properties:/gaffer/store/store.properties:ro
- ./conf/proxy/operationsDeclarations.json:/gaffer/store/operationsDeclarations.json:ro
- ./conf/proxy/gafferpop.properties:/gaffer/gafferpop.properties:ro
- ./conf/schema:/gaffer/schema:ro
19 changes: 19 additions & 0 deletions docker/example-deployments/proxy-example/conf/map/store.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.
gaffer.store.class=uk.gov.gchq.gaffer.mapstore.MapStore
gaffer.store.properties.class=uk.gov.gchq.gaffer.mapstore.MapStoreProperties

# General store config
gaffer.cache.service.class=uk.gov.gchq.gaffer.cache.impl.HashMapCacheService
gaffer.store.job.tracker.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.
#
# Default operation config
gaffer.elements.getalllimit=5000
gaffer.elements.hasstepfilterstage=PRE_AGGREGATION
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ gaffer.store.class=uk.gov.gchq.gaffer.proxystore.ProxyStore
gaffer.store.operation.declarations=/gaffer/store/operationsDeclarations.json

# Proxy config
gaffer.host=gaffer-rest
gaffer.port=8080
gaffer.host=localhost
gaffer.port=8081
gaffer.context-root=/rest
49 changes: 49 additions & 0 deletions docker/example-deployments/proxy-example/conf/schema/elements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"entities": {
"vertex": {
"vertex": "string.id"
},
"person": {
"vertex": "string.id",
"properties": {
"name": "property.string",
"age": "property.integer"
}
},
"software": {
"vertex": "string.id",
"properties": {
"name": "property.string",
"lang": "property.string"
}
}
},
"edges": {
"knows": {
"source": "string.id",
"destination": "string.id",
"directed": "true",
"properties": {
"weight": "property.double"
}
},
"created": {
"source": "string.id",
"destination": "string.id",
"directed": "true",
"properties": {
"weight": "property.double"
}
},
"dependsOn": {
"source": "string.id",
"destination": "string.id",
"directed": "true"
},
"encapsulates": {
"source": "string.id",
"destination": "string.id",
"directed": "true"
}
}
}
43 changes: 43 additions & 0 deletions docker/example-deployments/proxy-example/conf/schema/types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"types": {
"int.id": {
"class": "java.lang.Integer"
},
"long.id": {
"class": "java.lang.Long"
},
"string.id": {
"class": "java.lang.String"
},
"uuid.id": {
"class": "java.util.UUID"
},
"true": {
"class": "java.lang.Boolean"
},
"property.string": {
"class": "java.lang.String",
"aggregateFunction": {
"class": "uk.gov.gchq.koryphe.impl.binaryoperator.First"
}
},
"property.integer": {
"class": "java.lang.Integer",
"aggregateFunction": {
"class": "uk.gov.gchq.koryphe.impl.binaryoperator.First"
}
},
"property.double": {
"class": "java.lang.Double",
"aggregateFunction": {
"class": "uk.gov.gchq.koryphe.impl.binaryoperator.First"
}
},
"property.float": {
"class": "java.lang.Float",
"aggregateFunction": {
"class": "uk.gov.gchq.koryphe.impl.binaryoperator.First"
}
}
}
}
59 changes: 59 additions & 0 deletions docker/example-deployments/proxy-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}/operations/add-tinkerpop-modern.json"
GAFFER_REST_URL="http://localhost:8081"

# 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!"
Loading

0 comments on commit 2c34291

Please sign in to comment.