From a8896e640ae3feb1852920c8c93418ecb8b654bc Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Sat, 20 Jan 2024 09:17:07 +0100 Subject: [PATCH 1/7] feat: added view agent --- modules/view | 33 +++++++++++++++++++++++++++++---- tests/unit/viewTest.bats | 7 +++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/modules/view b/modules/view index ba4eec5..9a345a2 100644 --- a/modules/view +++ b/modules/view @@ -68,23 +68,48 @@ sd_view_version() { } +sd_view_agent() { + # parse and validate inputs + local output_format="ntriples" + local OPTIND opt; while getopts ":o:" opt; do + case "${opt}" in + o) output_format="${OPTARG}" ;; + *) sd_log -p ERROR "Invalid option: -$OPTARG ." ; return 1 ;; + esac + done; shift $((OPTIND-1)) + sd_validate output_format "^(rdfxml|ntriples|turtle)$" || return 1 + + + cat <<-EOF | sd_rapper -i turtle -o "$output_format" - "$AGENT_ID" + @prefix foaf: . + @prefix prov: . + @prefix rdfs: . + <$AGENT_ID> a prov:SoftwareAgent, prov:Agent ; + rdfs:label "SDaaS Agent" ; + foaf:name "$SDAAS_SIGNATURE" . +EOF +} + + + sd_view_ontology() { # parse and validate inputs - local OPT_OUTPUT_FORMAT="ntriples" + local output_format="ntriples" local OPTIND opt; while getopts ":o:" opt; do case "${opt}" in - o) OPT_OUTPUT_FORMAT="${OPTARG}" ;; + o) output_format="${OPTARG}" ;; *) sd_log -p ERROR "Invalid option: -$OPTARG ." ; return 1 ;; esac done; shift $((OPTIND-1)) - sd_validate OPT_OUTPUT_FORMAT "^(rdfxml|ntriples|turtle)$" || return 1 + sd_validate output_format "^(rdfxml|ntriples|turtle)$" || return 1 function get_triples { local files_array="$(find $SDAAS_ETC -type f \( -name "*.rdf" -o -name "*.nt" -o -name "*.ttl" \))" for file in "${files_array[@]}"; do sd_rapper -g -I "urn:sdaas:tbox" -o ntriples "$file" || sd_abort "Internal error, invalid tbox $file" done + sd_view_agent } - get_triples | sd_rapper -i ntriples -o "$OPT_OUTPUT_FORMAT" - "urn:sdaas:tbox" + get_triples | sd_rapper -i ntriples -o "$output_format" - "urn:sdaas:tbox" } \ No newline at end of file diff --git a/tests/unit/viewTest.bats b/tests/unit/viewTest.bats index f9a42a7..66536dd 100644 --- a/tests/unit/viewTest.bats +++ b/tests/unit/viewTest.bats @@ -84,3 +84,10 @@ on_script_startup [[ "$status" -eq 0 ]] [[ "${lines[0]}" == "$SDAAS_VERSION" ]] } + + + +@test "view agent" { + run sd_view_agent + [[ "$status" -eq 0 ]] +} \ No newline at end of file From 735ec0f4e3f2cb82d80172980abaa3b82e25654a Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Wed, 24 Jan 2024 19:00:51 +0100 Subject: [PATCH 2/7] feat: added store module --- modules/sparql | 2 +- modules/store | 42 ++++++++++++++++++ tests/functional/storeTest.bats | 26 ++++++++++++ tests/system/gettingStartedCETest.bats | 6 +-- tests/unit/storeTest.bats | 59 ++++++++++++++++++++++++++ 5 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 modules/store create mode 100644 tests/functional/storeTest.bats create mode 100644 tests/unit/storeTest.bats diff --git a/modules/sparql b/modules/sparql index 2cfefe5..fdf180b 100644 --- a/modules/sparql +++ b/modules/sparql @@ -72,7 +72,7 @@ sd_sparql_query() { sd_sparql_graph() { # parse and validate inputs - local sid="STORE" accrual_method="POST" graph="$(sd_uuid)ù" + local sid="STORE" accrual_method="POST" graph="$(sd_uuid)" eval "declare $SD_DEFAULT_CONTEXT" local OPTIND opt; while getopts ":a:s:D:" opt; do case "${opt}" in diff --git a/modules/store b/modules/store new file mode 100644 index 0000000..eea2489 --- /dev/null +++ b/modules/store @@ -0,0 +1,42 @@ +if [[ ! -z ${__module_store+x} ]]; then return ; else __module_store=1 ; fi +# Copyright (C) 2019-2024 LinkedData.Center - All Rights Reserved + +sd_include driver + +################################################################################ +## Core functions definition +################################################################################ + + +sd_store_erase() { + # parse and validate inputs + local sid="STORE" + eval "declare $SD_DEFAULT_CONTEXT" + local OPTIND opt; while getopts ":s:D:" opt; do + case "${opt}" in + s) sid="$OPTARG" ;; + D) eval "declare $OPTARG" ;; + *) sd_log -p ERROR "Invalid option: -$OPTARG ." ; return 1 ;; + esac + done; + + # call driver function + sd_driver_erase "$sid" +} + + +sd_store_size() { + # parse and validate inputs + local sid="STORE" + eval "declare $SD_DEFAULT_CONTEXT" + local OPTIND opt; while getopts ":s:D:" opt; do + case "${opt}" in + s) sid="$OPTARG" ;; + D) eval "declare $OPTARG" ;; + *) sd_log -p ERROR "Invalid option: -$OPTARG ." ; return 1 ;; + esac + done; + + # call driver function + sd_driver_size "$sid" +} diff --git a/tests/functional/storeTest.bats b/tests/functional/storeTest.bats new file mode 100644 index 0000000..171f969 --- /dev/null +++ b/tests/functional/storeTest.bats @@ -0,0 +1,26 @@ +#!/usr/bin/env bats + +function on_script_startup { + source "$SDAAS_INSTALL_DIR/core" NO_SPLASH + STORE="http://kb:8080/sdaas/sparql" + STORE_TYPE=w3c + sd_include store +} + +on_script_startup + + + +@test "sd_store_erase " { + run sd_store_erase + [[ "$status" -eq 0 ]] + [[ "$(sd_driver_size STORE)" -eq 0 ]] +} + + +@test "sd_store_size" { + echo 'INSERT DATA { GRAPH { } }' | sd sparql update + run sd_store_size + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" -eq 1 ]] +} diff --git a/tests/system/gettingStartedCETest.bats b/tests/system/gettingStartedCETest.bats index c9cc38c..fbd57e3 100644 --- a/tests/system/gettingStartedCETest.bats +++ b/tests/system/gettingStartedCETest.bats @@ -31,7 +31,7 @@ on_script_startup run pipe_load [[ "$status" -eq 0 ]] - [[ "$(sd driver size STORE)" -eq 1346 ]] + [[ "$(sd driver size STORE)" -eq 1350 ]] } @@ -43,9 +43,9 @@ on_script_startup run pipe_load [[ "$status" -eq 0 ]] [[ "${lines[0]}" == "g,subjects" ]] - [[ "$(sd driver size STORE)" -eq 1346 ]] + [[ "$(sd driver size STORE)" -eq 1350 ]] [[ "${lines[1]}" == "urn:graph:0,1205" ]] - [[ "${lines[2]}" == "urn:graph:1,141" ]] + [[ "${lines[2]}" == "urn:graph:1,145" ]] } @test "step5: query by streamed command" { diff --git a/tests/unit/storeTest.bats b/tests/unit/storeTest.bats new file mode 100644 index 0000000..9c3cede --- /dev/null +++ b/tests/unit/storeTest.bats @@ -0,0 +1,59 @@ +#!/usr/bin/env bats + +function on_script_startup { + source "$SDAAS_INSTALL_DIR/core" NO_SPLASH + STORE=http://dummy.example.org/sparql + STORE_TYPE=testdriver + sd_include store +} + +on_script_startup + + +function test_sid { + local cmd="$1" + shift 1 + + # Tests setup + local MYSTORE="$STORE" MYSTORE_TYPE="testdriver" + + run "$cmd" "$@" + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" == "STORE" ]] + + run "$cmd" -s MYSTORE "$@" + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" == "MYSTORE" ]] + + run "$cmd" -D "sid=MYSTORE" "$@" + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" == "MYSTORE" ]] + + # test with bad store + run "$cmd" -s NOTEXIST "$@" + [[ "$status" -eq 1 ]] + + run "$cmd" -D "sid=NOTEXIST" "$@" + [[ "$status" -eq 1 ]] + + # test precendences + run "$cmd" -D "sid=NOTEXIST" -s STORE "$@" + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" == "STORE" ]] + + run "$cmd" -s NOTEXIST -D "sid=STORE" "$@" + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" == "STORE" ]] + +} + + +@test "sd_store_erase interface " { + test_sid sd_store_erase +} + + + +@test "sd_store_size interface " { + test_sid sd_store_size +} \ No newline at end of file From cd4d68f8b91083eccd0401d89056467702a01af4 Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Thu, 25 Jan 2024 17:55:43 +0100 Subject: [PATCH 3/7] feat: add integrity test --- modules/core | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/core b/modules/core index 8ec9aa7..7d080f1 100644 --- a/modules/core +++ b/modules/core @@ -236,11 +236,11 @@ sd_uuid() { ################################################################################ ## Ensure mandatory variables are well-defined ################################################################################ -# [[ -d "$SDAAS_INSTALL_DIR" && -r "$SDAAS_INSTALL_DIR/core" ]] || sd_abort "Invalid SDAAS_INSTALL_DIR directory ($SDAAS_INSTALL_DIR)" -# [[ "$SDAAS_VERSION" =~ "^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" ]] || sd_abort "No semver in SDAAS_VERSION ($SDAAS_VERSION)" -# [[ "$SDAAS_REFERENCE_DOC" =~ "^https?://" ]] || sd_abort "Invalid SDAAS_REFERENCE_DOC URL ($SDAAS_REFERENCE_DOC)" -# [[ -d "$SDAAS_ETC" ]] || sd_abort "Invalid SDAAS_ETC directory ($SDAAS_ETC)" -# [[ -z "$SDAAS_APPLICATION_ID" ]] || sd_abort "Empty SDAAS_APPLICATION_ID not allowed" +[[ -d "$SDAAS_INSTALL_DIR" && -r "$SDAAS_INSTALL_DIR/core" ]] || sd_abort "Invalid SDAAS_INSTALL_DIR directory ($SDAAS_INSTALL_DIR)" +[[ -n "$SDAAS_VERSION" ]] || sd_abort "No semver in SDAAS_VERSION ($SDAAS_VERSION)" +[[ "$SDAAS_REFERENCE_DOC" =~ ^https?:// ]] || sd_abort "Invalid SDAAS_REFERENCE_DOC URL ($SDAAS_REFERENCE_DOC)" +[[ -d "$SDAAS_ETC" ]] || sd_abort "Invalid SDAAS_ETC directory ($SDAAS_ETC)" +[[ -n "$SDAAS_APPLICATION_ID" ]] || sd_abort "Empty SDAAS_APPLICATION_ID not allowed" ########################### # Module initialization From 4b7fd5ad427e843a070ba31f8e894a4c4a86eea5 Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Thu, 25 Jan 2024 18:09:33 +0100 Subject: [PATCH 4/7] fix: var names --- modules/core | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/modules/core b/modules/core index 7d080f1..2e4aed0 100644 --- a/modules/core +++ b/modules/core @@ -34,61 +34,59 @@ SDAAS_SIGNATURE=${SDAAS_SIGNATURE:-"SDaaS $SDAAS_APPLICATION_ID $SDAAS_VERSION"} sd_log() { # parse and validate inputs - local OPT_PRIORITY=5 - local OPT_SIZE=1024 - local OPT_FILE="" + local priority=5 size=1024 file="" local OPTIND opt; while getopts ":f:p:S:" opt; do case "${opt}" in - f) OPT_FILE="$(readlink -f "${OPTARG}")" ;; - p) OPT_PRIORITY="${OPTARG}" ;; + f) file="$(readlink -f "${OPTARG}")" ;; + p) priority="${OPTARG}" ;; S) if [[ $(( OPTARG )) -gt 0 ]]; then - OPT_SIZE=$OPTARG; + size=$OPTARG; fi ;; *) sd_log -p ERROR "Invalid option: -$OPTARG ." ; return 1 ;; esac done; shift $((OPTIND-1)) local ARG_MESSAGE="$1" - ARG_MESSAGE="${ARG_MESSAGE:0:$OPT_SIZE}" + ARG_MESSAGE="${ARG_MESSAGE:0:$size}" # normalize priority level - case "${OPT_PRIORITY^^}" in - CRITICAL | 2) OPT_PRIORITY=2 ;; - ERROR | 3) OPT_PRIORITY=3 ;; - WARNING | 4) OPT_PRIORITY=4 ;; - NOTICE | 5) OPT_PRIORITY=5 ;; - INFORMATIONAL | 6) OPT_PRIORITY=6 ;; - DEBUG | 7) OPT_PRIORITY=7 ;; + case "${priority^^}" in + CRITICAL | 2) priority=2 ;; + ERROR | 3) priority=3 ;; + WARNING | 4) priority=4 ;; + NOTICE | 5) priority=5 ;; + INFORMATIONAL | 6) priority=6 ;; + DEBUG | 7) priority=7 ;; * ) - ARG_MESSAGE="invalid log priority $OPT_PRIORITY" - OPT_PRIORITY=3 + ARG_MESSAGE="invalid log priority $priority" + priority=3 ;; esac # normalize priority level mnemonic local mnemonic - case "${OPT_PRIORITY}" in + case "${priority}" in 2) mnemonic=CRITICAL ;; 3) mnemonic=ERROR ;; 4) mnemonic=WARNING ;; 5) mnemonic=NOTICE ;; 6) mnemonic=INFORMATIONAL ;; 7) mnemonic=DEBUG ;; - * ) mnemonic="$OPT_PRIORITY" + * ) mnemonic="$priority" ;; esac # format and print log ARG_MESSAGE - if [[ "$OPT_PRIORITY" -le "$SD_LOG_PRIORITY" ]]; then + if [[ "$priority" -le "$SD_LOG_PRIORITY" ]]; then echo "[$mnemonic] [sdaas-$$ ${FUNCNAME[1]}] "$ARG_MESSAGE"" >&2 - if [[ -r "$OPT_FILE" ]]; then - local file_size=$(stat -c %s "$OPT_FILE") + if [[ -r "$file" ]]; then + local file_size=$(stat -c %s "$file") if [[ "$file_size" -gt 1024 ]]; then - head -c 1024 "$OPT_FILE" >&2 - echo "...see more info at $OPT_FILE (size=$file_size bytes)" >&2 + head -c 1024 "$file" >&2 + echo "...see more info at $file (size=$file_size bytes)" >&2 else - cat "$OPT_FILE" >&2 + cat "$file" >&2 fi fi fi @@ -96,8 +94,7 @@ sd_log() { sd_validate() { - local var="$1" - local regexp="$2" + local var="$1" regexp="$2" if ! [[ "${!var}" =~ $regexp ]]; then sd_log -p ERROR "${FUNCNAME[2]} parameter $var does not match '$regexp'" return 1 @@ -183,8 +180,7 @@ sd_url_encode() { sd() { - local abort_on_fail=${SD_ABORT_ON_FAIL:-false} - local help=false + local abort_on_fail=${SD_ABORT_ON_FAIL:-false} help=false local OPTIND opt; while getopts ":hA" opt; do case "${opt}" in h) help=true ;; From 0df662385a4ac996e67df2ecf7a95e93b5ff03e0 Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Tue, 30 Jan 2024 18:17:07 +0100 Subject: [PATCH 5/7] fix: INSTALL_DIR init --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ab4f821..a2170f1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ RUN apt-get update && \ libxml2-utils ###### Mandatory configuration variables -ENV SDAAS_INSTALL_DIR=/opt/SDAAS_REFERENCE_DOC +ENV SDAAS_INSTALL_DIR=/opt/sdaas ENV SDAAS_ETC="/etc/sdaas" ENV SDAAS_REFERENCE_DOC="https://linkeddata.center/sdaas" ENV SDAAS_VERSION="4.0.0-rc.1" From 80e9e5795be56d600518ad416a13b2d11b094354 Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Tue, 13 Feb 2024 10:28:07 +0100 Subject: [PATCH 6/7] updated --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4c70a9..40fa95d 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A platform to build knowledge graphs. -This is the open source implementation of the [LinkeData.Center SDaaS™ product](https://it.linkeddata.center/p/sdaas). +This is the open source implementation of the [LinkeData.Center SDaaS™ product](https://en.linkeddata.center/p/sdaas). > ## end-of-support approaching for Anassimene releases (SDaaS 3.x) > @@ -28,7 +28,7 @@ docker compose down ## Installation & usage -See the [documentation](https://gitlab.com/linkeddatacenter/sdaas/doc) for more info. +See the [documentation](https:/linkeddata.center/sdaas) for more info. ## Start test environment @@ -102,7 +102,7 @@ docker push linkeddatacenter/sdaas-ce:latest ## Credits and license -The sdaas community edition platform is derived from [LinkedData.Center SDaas Product](https://it.linkeddata.center/p/sdaas) and licensed with MIT by LinkedData.Center +The sdaas community edition platform is derived from [LinkedData.Center SDaas Product](https://en.linkeddata.center/p/sdaas) and licensed with MIT by LinkedData.Center. Copyright (C) 2018-2024 LinkedData.Center SRL - All Rights Reserved From 813e0d2bc9e47ce22d2a2293ec9ff8d1b83ee82c Mon Sep 17 00:00:00 2001 From: Enrico Fagnoni Date: Thu, 15 Feb 2024 14:39:36 +0100 Subject: [PATCH 7/7] ready for merge request --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 40fa95d..883f30a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A platform to build knowledge graphs. -This is the open source implementation of the [LinkeData.Center SDaaS™ product](https://en.linkeddata.center/p/sdaas). +This is the open source implementation of the [LinkeData.Center SDaaS™ product](https://en.linkeddata.center/p/sdaas). > ## end-of-support approaching for Anassimene releases (SDaaS 3.x) >