initial load

parents
passwords
*.properties
This diff is collapsed.
# SLA Core #
##Description##
The SLA Core is an implementation of an SLA module, compliant with WS-Agreement.
It supports:
* one-shot negotiation
* agreement enforcement
* REST API
Read the [documentation][1]
##Technical description##
Read the [Developer Guide][2]
##How to deploy##
Read the [Installation Guide][3]
##In use##
It is currently used in:
* [XIFI][6]
* [MODAClouds][4]
* [SeaClouds][5]
* [Fed4Fire][7]
##License##
Licensed under the [Apache License, Version 2.0][8]
[1]: docs/TOC.md
[2]: docs/developer-guide.md
[3]: docs/installation-guide.md
[4]: http://www.modaclouds.eu
[5]: http://www.seaclouds-project.eu
[6]: http:/fi-xifi.eu/
[7]: http://www.fed4fire.eu/
[8]: http://www.apache.org/licenses/LICENSE-2.0
Some utility scripts. All must be executed from project root (i.e. bin/<script>)
* createDatabaseMvn.sh
(re)creates database using jpa.
hibernate.hbm2dll.auto must be set to "create" or "update" in
sla-repository/src/main/resources/META-INF/persistence.xml
* dropTables.sh
drop tables
* dumpDatabase.sh
dumps database schema to sla-repository/trunk/src/main/resources/sql
* restoreDatabase.sh
drop tables and recreate tables from sla-repository/trunk/src/main/resources/sql
* runserver.sh
starts tomcat server
* copySLACoreToFolder.sh, syncSLACoreToFolder.bat
copy source tree to another directory
* generate-appendix.sh
automatically generates markdown appendix of calls to server.
If a table/column is added/modified, it is recommended the following procedure:
* dropTables.sh
* createDatabaseMvn.sh
* dumpDatabase.sh
#!/usr/bin/env bash
#
# Copy slacore project to another location.
#
# The following tasks are performed:
# copy source tree to $1
# from sla-personalization only pom.xml and src/main/resources/personalization-context.xml
# rename groudId to $2
#
# Usage:
# $0 <dir> <groupId>
# <dir>: destination directory; parent pom.xml will be here
# <groupId>: if specified, change the groupId of slacore projects to this value.
#
if [ "$0" != "bin/copySLACoreToFolder.sh" ]; then
echo "Must be executed from project root"
exit 1
fi
if [ $# -lt 1 ]; then
echo "Usage: $0 <destdir> [<groupId>]"
exit 1
fi
if [ -e "$1" ]; then
echo "$1 exists; exiting"
exit 1
fi
### copy source tree ###
echo -e "Starting copy: \n source=$(pwd)\n dest=$1"
EXCLUDE=$(cat << 'EOF'
target
.*
configuration.properties
sla-personalization
EOF
)
echo "$EXCLUDE" | rsync -a --exclude-from=- ./* "$1"
# sla-personalization is an special case
res="sla-personalization/src/main/resources"
mkdir -p "$1/$res"
cp "sla-personalization/pom.xml" "$1/sla-personalization"
cp "$res/personalization-context.xml" "$1/$res"
### rename groupId ###
if [ -n "$2" ]; then
echo "Renaming groupId to $2"
find "$1" -name pom.xml -exec sed -i -e"s/<groupId>eu.atos.sla<\/groupId>/<groupId>$2<\/groupId>/" {} \;
fi
#!/usr/bin/env bash
mvn compile exec:java -f sla-repository/pom.xml
DROP=$(mysql -p"_atossla_" -u atossla atossla <<< "show tables" | grep -v "Tables" | sed -e's/\(.*\)/drop table \1; /')
SQL=$(echo "SET FOREIGN_KEY_CHECKS=0;" && echo $DROP)
echo "$SQL" | mysql -p -u atossla atossla
#!/usr/bin/env bash
if [ "$0" != "bin/dumpDatabase.sh" ]; then
echo "Must be executed from project root"
exit 1
fi
mysqldump -d -p -u atossla atossla > sla-repository/src/main/resources/sql/atossla.sql
#!/usr/bin/env bash
#
# sla-core MUST be running with env var ENFORCEMENT_TEST=1
#
SLA_MANAGER_URL="http://localhost:8080/sla-service"
XML="application/xml"
JSON="application/json"
in_case=0
#####
#shopt -s expand_aliases
set -o history -o histexpand
#alias curl='/usr/bin/curl --trace-ascii /tmp/curl.out '
if [ "$0" != "bin/generate-appendix.sh" ]; then
echo "Must be executed from project root"
exit 1
fi
>&2 bin/restoreDatabase.sh
debug() {
[[ -n $DEBUG ]] && echo "$*" >&2
}
function curl_cmd() {
in_case=1
CMD="/usr/bin/curl -u user:password ""$@"
[[ -n $DEBUG ]] && set -o xtrace
/usr/bin/curl --trace-ascii /tmp/curl.out -u user:password "$@" > /dev/null 2>&1
local status=$?
[[ -n $DEBUG ]] && set +o xtrace
if [ "$?" != "0" ]; then
return "-1"
fi
debug "$code"
return $status
}
function assert() {
#$1 expected
local actual=$(cat /tmp/curl.out | grep -v "^..... HTTP\/1.1 100" | awk "/^.{5} HTTP\/1.1/ {print \$3;}")
debug "assert(expected:'$1' actual:'$actual')"
if [ -z "$expected" ]; then
exit 0
fi
out=$(echo "$actual" | grep "$1")
if [ "$?" = "0" ]; then
return $code
else
echo "ERROR: Expected: $1. Actual: $actual"
exit $code
fi
}
function curl_post() {
#
# $1: relative url
# $2: file to send
# $3: expected code (optional)
# $4: content type header (optional)
# $5: accept header (optional)
md_text "Content type: $4\n"
local expected=${3:-""}
local type_header=${4:+-H Content-type:$4}
local accept_header=${5:+-H Accept:$5}
local url="$SLA_MANAGER_URL/$1"
curl_cmd "-d@samples/appendix/$2" -X POST $type_header $accept_header "$url"
assert "$expected"
md_rest
return $code
}
function curl_put() {
# $1: relative url
# $2: file to send
# $3: expected code (optional)
# $4: content type header (optional)
md_text "Content type: $4\n"
local expected=${3:-""}
local url="$SLA_MANAGER_URL/$1"
local file_param=${2:+-d@samples/appendix/$2}
local type_header=${4:+-H Content-type:$3}
curl_cmd -X PUT $file_param $type_header "$url"
assert "$expected"
md_rest
return $code
}
function curl_get() {
# $1: relative url
# $2: query string (without ?)
# $3: expected code (optional)
# $4: accept header (optional)
md_text "Accept: $3\n"
local expected=${3:-""}
local url="$SLA_MANAGER_URL/$1?$2"
local accept_header=${4:+-H Accept:$4}
curl_cmd -X GET $accept_header "$url"
assert "$expected"
md_rest
return $code
}
function curl_delete() {
# $1: relative url
# $2: expected code (optional)
md_text "\n"
local expected=${2:-""}
local url="$SLA_MANAGER_URL/$1"
local accept_header="-H Accept:$XML"
curl_cmd -X DELETE $accept_header "$url"
assert "$expected"
md_rest
return $code
}
function md_rest() {
local out=$(grep -e "^[0-9a-f]\{1,4\}:" /tmp/curl.out | sed -e's/^.\{5\} /\t/')
local request=$(
echo "$out" | awk -e'BEGIN{flag=1}/^\tHTTP\/1./{flag=0}{if (flag && ($0 !~ /(^\t?$)|Expect: 100/)) print;}'
)
local response=$(
echo "$out" | awk -e'BEGIN{flag=0}/^\tHTTP\/1\.. [^1]/{flag=1}{if (flag && $0 !~ /^\t?0?$/) print;}'
)
echo -e "\t\$ $CMD"
echo
echo "$request"
echo
echo "$response"
echo
#get_status
}
function md_text() {
[ "$in_case" = "1" ] && md_hr
echo -e "$@"
in_case=0
}
function md_hr() {
echo "---"
echo
}
function md_title() {
# $1: importance
# $2: title
# $3: anchor
in_case=0
local hashes="#"
for (( i = 1; i < $1; i++ )); do
hashes="$hashes#"
done
local anchor=${3:+<a name=\"$3\"></a>}
echo "$hashes$2$anchor$hashes"
echo
}
function get_status() {
filter_status=$(awk "/^.{5} HTTP\/1.1 [^1]/ {print \$3;}" /tmp/curl.out)
echo "$filter_status"
}
md_title 1 "Appendix REST API examples"
md_title 2 "Providers" "providers" ###### PROVIDERS
md_title 3 "Create a provider" ###
curl_post "providers" "provider01.xml" "201" "$XML" "$XML"
curl_post "providers" "provider02.xml" "201" "$XML" "$XML"
curl_post "providers" "provider03.json" "201" "$JSON" "$JSON"
md_text "Provider exists."
curl_post "providers" "provider02.xml" "409" "$XML" "$XML"
md_title 3 "Get a provider" ###
curl_get "providers/provider02" "" "200" "$XML"
curl_get "providers/provider02" "" "200" "$JSON"
md_text "Provider not exists."
curl_get "providers/notexists" "" "404" "$XML"
md_title 3 "Get all the providers" ###
curl_get "providers" "" "200" "$XML"
curl_get "providers" "" "200" "$JSON"
md_title 3 "Delete a provider" ###
curl_delete "providers/provider03" "200"
md_text "Provider not exists"
curl_delete "providers/notexists" "404"
md_title 2 "Templates" "templates" ###### TEMPLATES
md_title 3 "Create a template" ###
curl_post "templates" "template01.xml" "201" "$XML" "$XML"
curl_post "templates" "template02.json" "201" "$JSON" "$JSON"
curl_post "templates" "template02b.xml" "201" "$XML" "$XML"
md_text "Template exists."
curl_post "templates" "template01.xml" "409" "$XML" "$XML"
md_text "Linked provider not exists."
curl_post "templates" "template03.xml" "409" "$XML" "$XML"
md_title 3 "Get a template" ###
curl_get "templates/template02" "" "200" "$XML"
curl_get "templates/template02" "" "200" "$JSON"
md_text "Template not exists."