From a1fb05ec4bbdc762649158a1efa9e989f116669d Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Mon, 6 Oct 2025 16:51:26 +0200 Subject: [PATCH 1/6] Added option stat-request to get status of bulk request for given request-id --- ada/ada | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ada/ada b/ada/ada index 83ba47d..c5b325c 100755 --- a/ada/ada +++ b/ada/ada @@ -183,6 +183,9 @@ usage() { --unstage --from-file Release files in the list. + --stat-request + Show status of bulk request for given request-id + --events [--resume] [--force] [--recursive] [--timeout s] Subscribe to changes in the given direcory, using server-sent events (SSE). @@ -613,7 +616,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" @@ -2294,6 +2302,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." @@ -2793,6 +2807,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." \ From 42a2089caeca76c8e80b20220c4cf322d24d3c6a Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Mon, 6 Oct 2025 17:19:04 +0200 Subject: [PATCH 2/6] Added inetrgration test for stat-request --- tests/integration_test.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/integration_test.sh b/tests/integration_test.sh index 192f4d8..2b562d3 100755 --- a/tests/integration_test.sh +++ b/tests/integration_test.sh @@ -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}" @@ -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 From 70e16ece565fa66c7b46040a205c127cc40ab19c Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Tue, 7 Oct 2025 15:15:51 +0200 Subject: [PATCH 3/6] After submitting bulk request, give output to help user follow progress --- ada/ada | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ada/ada b/ada/ada index c5b325c..223fc12 100755 --- a/ada/ada +++ b/ada/ada @@ -1522,7 +1522,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[@]}" \ @@ -1570,7 +1569,14 @@ bulk_request() { exit 1 ;; HTTP_CODE_2* ) - echo "$response" | grep -e request-url -e Date | tee -a "${requests_log}" + 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:" + echo " ada --stat-request ${request_id}" # ToDo: explain to user what to do with the request-url, see issue #86 ;; * ) @@ -1583,7 +1589,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' From 0735b76cd5ff8c7407b4de5adfc9e778d897c0d8 Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Mon, 13 Oct 2025 16:11:08 +0200 Subject: [PATCH 4/6] Return output with arguments api and authentication --- ada/ada | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/ada/ada b/ada/ada index 223fc12..c042a72 100755 --- a/ada/ada +++ b/ada/ada @@ -303,6 +303,7 @@ set_defaults() { dry_run=false channel_timeout=3600 auth_method= + auth_file= certdir=${X509_CERT_DIR:-/etc/grid-security/certificates} igtf=true lifetime=7 @@ -371,7 +372,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 @@ -402,8 +403,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 ;; @@ -417,6 +420,8 @@ get_args() { * ) # This must be a file name netrcfile="$2" + #Check if authentication file is passed as argument + auth_file="$2" shift ;; esac @@ -432,6 +437,8 @@ get_args() { * ) # This must be a file name proxyfile="$2" + #Check if authentication file is passed as argument + auth_file="$2" shift ;; esac @@ -983,7 +990,7 @@ check_authentication() { proxy ) echo "Proxy file: $proxyfile" ;; - token ) + token | tokenfile ) view_token "$token" "$token_debug_info" ;; * ) @@ -1576,8 +1583,12 @@ bulk_request() { echo "To check status of request, paste request URL in browser:" echo " ${request_url}" echo "Or use command:" - echo " ada --stat-request ${request_id}" - # ToDo: explain to user what to do with the request-url, see issue #86 + if [ -n "$auth_file" ] ; then + echo " $0 --stat-request $request_id --api $api --$auth_method $auth_file" | tr -d '\r' + + else + echo " $0 --stat-request $request_id --api $api" | tr -d '\r' + fi ;; * ) # Something else went wrong; could be @@ -2147,7 +2158,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." @@ -2357,7 +2368,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. From 639d9a69ba8df8b0170a68ab7a018e3db44e7291 Mon Sep 17 00:00:00 2001 From: Onno Zweers Date: Tue, 14 Oct 2025 12:08:29 +0200 Subject: [PATCH 5/6] Send "request ID not valid" error to stderr instead of stdin --- ada/ada | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ada/ada b/ada/ada index c042a72..cb0c6a6 100755 --- a/ada/ada +++ b/ada/ada @@ -1463,7 +1463,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 From bcc245cff6c4cd37f7fcdcdf95d24a84618b9b09 Mon Sep 17 00:00:00 2001 From: Haili Hu Date: Wed, 15 Oct 2025 14:00:23 +0200 Subject: [PATCH 6/6] Fix commandline arguments for stat-request --- ada/ada | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ada/ada b/ada/ada index cb0c6a6..4b7c13a 100755 --- a/ada/ada +++ b/ada/ada @@ -298,6 +298,7 @@ get_permissions () { # Set default values and initialize variables # set_defaults() { + args= api= debug=false dry_run=false @@ -391,6 +392,7 @@ get_args() { if [ -z "$1" ] ; then usage fi + args=("$@") while [ $# -gt 0 ] ; do case "$1" in --help | -help | -h ) @@ -1583,12 +1585,14 @@ bulk_request() { echo "To check status of request, paste request URL in browser:" echo " ${request_url}" echo "Or use command:" - if [ -n "$auth_file" ] ; then - echo " $0 --stat-request $request_id --api $api --$auth_method $auth_file" | tr -d '\r' - - else - echo " $0 --stat-request $request_id --api $api" | tr -d '\r' + 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