From 8cd062bb2d58d467a0ba7eea6e9e01c5d1c0a455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Robotka?= <robotka.adrian@gmail.com> Date: Sun, 28 Feb 2021 18:20:58 +0100 Subject: [PATCH] simple schema --- grakn/.gitignore | 2 +- grakn/big-bang.sh | 24 ++++++++++++++ grakn/console.sh | 8 +++-- grakn/data/data.gql | 0 grakn/data/schema.gql | 67 ++++++++++++++++++++++++++++++++++++++++ grakn/docker-compose.yml | 5 +-- 6 files changed, 101 insertions(+), 5 deletions(-) create mode 100755 grakn/big-bang.sh create mode 100644 grakn/data/data.gql create mode 100644 grakn/data/schema.gql diff --git a/grakn/.gitignore b/grakn/.gitignore index 8fce603..19e0180 100644 --- a/grakn/.gitignore +++ b/grakn/.gitignore @@ -1 +1 @@ -data/ +db/ diff --git a/grakn/big-bang.sh b/grakn/big-bang.sh new file mode 100755 index 0000000..ea51cf0 --- /dev/null +++ b/grakn/big-bang.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +docker_cmd=docker +# use podman if possible +command -v podman >/dev/null 2>&1 && docker_cmd=podman + +console() { + $docker_cmd exec -i grakn-srv \ + /grakn-core-all-linux/grakn console $* +} + +db() { + console --keyspace sch $* +} + +wipe() { + echo 'keyspace delete sch' | console +} + +### + +wipe +db --file /data/schema.gql +#db --file /data/data.gql diff --git a/grakn/console.sh b/grakn/console.sh index e6788f2..c72c4c7 100755 --- a/grakn/console.sh +++ b/grakn/console.sh @@ -1,4 +1,8 @@ #!/bin/sh -docker exec -it grakn-srv \ - /grakn-core-all-linux/grakn console +docker_cmd=docker +# use podman if possible +command -v podman >/dev/null 2>&1 && docker_cmd=podman + +$docker_cmd exec -it grakn-srv \ + /grakn-core-all-linux/grakn console $* diff --git a/grakn/data/data.gql b/grakn/data/data.gql new file mode 100644 index 0000000..e69de29 diff --git a/grakn/data/schema.gql b/grakn/data/schema.gql new file mode 100644 index 0000000..f1aaf39 --- /dev/null +++ b/grakn/data/schema.gql @@ -0,0 +1,67 @@ +define + +################ +## Attributes ## +################ + label sub attribute, + value string; + + annotation sub attribute, + value string; + + identifier sub label; + name sub label; + nick sub label; + + #fqdn sub label; + #ip sub label; + + operating-system sub annotation, + regex "^(linux|ios|windows)$"; + number sub annotation; + color sub annotation; + cableLabel sub annotation; + +################ +## Entities ## +################ + + abstractInfraItem sub entity, abstract, + key identifier, + has name, + plays container, + plays containee; + + node sub abstractInfraItem, + has nick, + has operating-system; + + port sub abstractInfraItem, + has number; + + # TODO check out https://docs.grakn.ai/docs/schema/concepts#define-a-relation-to-play-a-role + cable sub abstractInfraItem, + has color, + has cableLabel; + +################ +## Realtions ## +################ + + containment sub relation, + relates container, + relates containee; + + hasPort sub containment; + +################ +## Rules ## +################ + +nodes-has-ports sub rule, +when { + $a isa node; + $b isa port; +}, then { + (container: $a, containee: $b) isa hasPort; +}; diff --git a/grakn/docker-compose.yml b/grakn/docker-compose.yml index e3a3c58..e9dc5a4 100644 --- a/grakn/docker-compose.yml +++ b/grakn/docker-compose.yml @@ -5,7 +5,8 @@ services: container_name: grakn-srv image: graknlabs/grakn:1.8.4 volumes: - - ./data:/grakn-core-all-linux/server/db/ + - ./:/app + - ./data:/data + - ./db:/grakn-core-all-linux/server/db/ ports: - 127.0.0.1:48555:48555 - - 127.0.0.1:1729:1729 -- GitLab