Skip to content
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
59 changes: 48 additions & 11 deletions ada/ada
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ usage() {
--unstage --from-file <file-list>
Release files in the list.

--stat-request <request-id>
Show status of bulk request for given request-id

--events <channel-name> <path-to-follow> [--resume] [--force] [--recursive] [--timeout s]
Subscribe to changes in the given direcory,
using server-sent events (SSE).
Expand Down Expand Up @@ -295,11 +298,13 @@ get_permissions () {
# Set default values and initialize variables
#
set_defaults() {
args=
api=
debug=false
dry_run=false
channel_timeout=3600
auth_method=
auth_file=
certdir=${X509_CERT_DIR:-/etc/grid-security/certificates}
igtf=true
lifetime=7
Expand Down Expand Up @@ -368,7 +373,7 @@ set_defaults() {
fi
if [ -n "$ada_tokenfile" ] ; then
tokenfile="$ada_tokenfile"
auth_method=token
auth_method=tokenfile
token_debug_info="Token source: \$ada_tokenfile=$ada_tokenfile"
fi
if [ -n "$BEARER_TOKEN" ] ; then
Expand All @@ -387,6 +392,7 @@ get_args() {
if [ -z "$1" ] ; then
usage
fi
args=("$@")
while [ $# -gt 0 ] ; do
case "$1" in
--help | -help | -h )
Expand All @@ -399,8 +405,10 @@ get_args() {
exit 1
;;
--tokenfile )
auth_method=token
auth_method=tokenfile
tokenfile="$2"
#Check if authentication file is passed as argument
auth_file="$2"
token_debug_info="Token source: --tokenfile $tokenfile"
shift ; shift
;;
Expand All @@ -414,6 +422,8 @@ get_args() {
* )
# This must be a file name
netrcfile="$2"
#Check if authentication file is passed as argument
auth_file="$2"
shift
;;
esac
Expand All @@ -429,6 +439,8 @@ get_args() {
* )
# This must be a file name
proxyfile="$2"
#Check if authentication file is passed as argument
auth_file="$2"
shift
;;
esac
Expand Down Expand Up @@ -613,7 +625,12 @@ get_args() {
--request-id )
request_id="$2"
shift ; shift
;;
;;
--stat-request )
command='stat-request'
request_id="$2"
shift ; shift
;;
--events )
command='events'
channel_name="$2"
Expand Down Expand Up @@ -975,7 +992,7 @@ check_authentication() {
proxy )
echo "Proxy file: $proxyfile"
;;
token )
token | tokenfile )
view_token "$token" "$token_debug_info"
;;
* )
Expand Down Expand Up @@ -1448,7 +1465,7 @@ get_status_requestid () {
if [[ $valid == 'true' ]] ; then
echo "$result"
else
echo "Error: the request ID '$request_id' is not valid"
echo 1>&2 "Error: the request ID '$request_id' is not valid"
return 1
fi
fi
Expand Down Expand Up @@ -1514,7 +1531,6 @@ bulk_request() {
done <<<"$pathlist"
target=${target%?}]
data="{\"activity\": \"${activity}\", \"arguments\": ${arguments}, \"target\": ${target}, \"expand_directories\": \"${expand}\"}"
$debug || echo "$target "
# Elsewhere, we do 'set -x' in a subshell, but here we need to catch the return headers.
$debug && set -x # If --debug is specified, show curl command
response=$(curl "${curl_authorization[@]}" \
Expand Down Expand Up @@ -1562,8 +1578,21 @@ bulk_request() {
exit 1
;;
HTTP_CODE_2* )
echo "$response" | grep -e request-url -e Date | tee -a "${requests_log}"
# ToDo: explain to user what to do with the request-url, see issue #86
echo "$response" | grep -e request-url -e Date >> "${requests_log}"
request_url=$(echo "$response" | grep -e request-url)
request_id=$(basename "${request_url}")
echo "Information about bulk request is logged in $requests_log"
echo "To check status of request, paste request URL in browser:"
echo " ${request_url}"
echo "Or use command:"
cmd_args=""
if [[ "${args[@]}" =~ "api" ]]; then
cmd_args="--api $api"
fi
if [[ "${args[@]}" =~ "netrc" || "${args[@]}" =~ "proxy" || "${args[@]}" =~ "tokenfile" ]]; then
cmd_args="$cmd_args --$auth_method $auth_file"
fi
echo " $0 --stat-request $request_id $cmd_args" | tr -d '\r'
;;
* )
# Something else went wrong; could be
Expand All @@ -1575,7 +1604,6 @@ bulk_request() {
exit 1
;;
esac
$debug && echo "Information about bulk request is logged in $requests_log."
{
echo "activity: $activity"
echo "target: $target" | sed 's/,/,\n /g'
Expand Down Expand Up @@ -2134,7 +2162,7 @@ validate_input() {
fi

case $auth_method in
token )
token | tokenfile )
if [ -n "$tokenfile" ] ; then
if ! [ -f "$tokenfile" ] ; then
echo 1>&2 "ERROR: specified tokenfile does not exist."
Expand Down Expand Up @@ -2294,6 +2322,12 @@ validate_input() {
exit 1
fi
;;
stat-request )
if [[ -z $request_id || $request_id =~ ^-- ]] ; then
echo 1>&2 "ERROR: command $command requires a request-id."
exit 1
fi
;;
viewtoken )
if [ -z "$token" ] ; then
echo 1>&2 "ERROR: command --viewtoken requires a token, but no token was found."
Expand Down Expand Up @@ -2338,7 +2372,7 @@ validate_input() {
#
construct_auth() {
case $auth_method in
token )
token | tokenfile )
# We can't specify the token as a command line argument,
# because others could read that with the ps command.
# So we have to put the authorization header in a temporary file.
Expand Down Expand Up @@ -2793,6 +2827,9 @@ api_call () {
esac
bulk_request "$activity" "$pathlist" "$recursive" "$request_id"
;;
stat-request )
get_status_requestid "$request_id"
;;
events | report-staged )
if [ "${BASH_VERSINFO[0]}" -lt 4 ] ; then
echo 1>&2 "ERROR: your bash version is too old: $BASH_VERSION." \
Expand Down
14 changes: 13 additions & 1 deletion tests/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,10 @@ test_ada_stage_dir() {
}

# Unstage a directory based on request_id
# And get status of request_id
# Note: this function uses ${stdoutF} from previous function
# So do not overwrite in between
test_ada_unstage_dir_request_id() {
test_ada_request_id() {
request_url=`grep "request-url" "${stdoutF}" | awk '{print $2}' | tr -d '\r'`
request_id=$(basename "$request_url")
command="ada/ada --tokenfile ${token_file} --unstage /${tape_path}/${dirname}/${dirfile} --request-id ${request_id} --api ${api}"
Expand All @@ -410,6 +411,17 @@ test_ada_unstage_dir_request_id() {
# file should COMPLETED
state=`curl -X GET "${request_url}" -H "accept: application/json" -H "Authorization: Bearer $token" | jq -r '.targets[1].state'`
assertEquals "State of target:" "COMPLETED" $state

# Test status of request id, we do this in same test function because we need same request-id
command="ada/ada --tokenfile ${token_file} --stat-request ${request_id} --api ${api}"
echo "Running command:"
echo $command
eval $command >${stdoutF} 2>${stderrF}
result=$?
assertEquals "ada returned error code ${result}" 0 ${result} || return
uid=`cat "${stdoutF}" | jq -r '.uid'`
echo $uid
assertEquals ${uid} ${request_id}
}

# Stages files in file_list
Expand Down