Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 4.0.0 rc.1 #23

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
>
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
62 changes: 29 additions & 33 deletions modules/core
Original file line number Diff line number Diff line change
Expand Up @@ -34,70 +34,67 @@ 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
}


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
Expand Down Expand Up @@ -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 ;;
Expand Down Expand Up @@ -236,11 +232,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
Expand Down
2 changes: 1 addition & 1 deletion modules/sparql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions modules/store
Original file line number Diff line number Diff line change
@@ -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"
}
33 changes: 29 additions & 4 deletions modules/view
Original file line number Diff line number Diff line change
Expand Up @@ -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: <http://xmlns.com/foaf/0.1/> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<$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"
}
26 changes: 26 additions & 0 deletions tests/functional/storeTest.bats
Original file line number Diff line number Diff line change
@@ -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 <urn:graph:g> { <urn:uri:s> <urn:uri:p> <urn:uri:o>} }' | sd sparql update
run sd_store_size
[[ "$status" -eq 0 ]]
[[ "${lines[0]}" -eq 1 ]]
}
6 changes: 3 additions & 3 deletions tests/system/gettingStartedCETest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]]
}


Expand All @@ -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" {
Expand Down
59 changes: 59 additions & 0 deletions tests/unit/storeTest.bats
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions tests/unit/viewTest.bats
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ on_script_startup
[[ "$status" -eq 0 ]]
[[ "${lines[0]}" == "$SDAAS_VERSION" ]]
}



@test "view agent" {
run sd_view_agent
[[ "$status" -eq 0 ]]
}