Skip to content

Commit 69ae84c

Browse files
authored
Fixed error in execution-status-count with relative IDs. (#80)
* Fixed error in execution-status-count with relative IDs. fixed non-pretty output for lists of workflow IDs fixed issue with parsing the relative workflow IDs. Fixes #79
1 parent e190f40 commit 69ae84c

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

cromshell

+23-27
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ function extract_workflow_ids_from_args()
336336
else
337337
while [ $# -gt 0 ] ; do
338338
populateWorkflowIdAndServerUrl ${1}
339-
WORKFLOW_ID_LIST="${WORKFLOW_ID_LIST} ${1}"
339+
WORKFLOW_ID_LIST="${WORKFLOW_ID_LIST} ${WORKFLOW_ID}"
340340

341341
#Get next argument in $1:
342342
shift
@@ -434,8 +434,8 @@ function populateWorkflowIdAndServerUrl()
434434
{
435435
local userSpecifiedId=$1
436436

437-
# If the user specified a negative number, get the nth last workflow:
438-
if [[ $userSpecifiedId =~ ^-[[:digit:]]+$ ]]; then
437+
# If the user specified relative workflow ID:
438+
if [[ $(matchRelativeWorkflowId ${userSpecifiedId}) -eq 0 ]] ; then
439439
local row=${userSpecifiedId#-}
440440
assertHavePreviouslySubmittedAJob
441441
WORKFLOW_ID=$(tail -n $row $CROMWELL_SUBMISSIONS_FILE | head -n 1 | awk '{print $3}' )
@@ -781,50 +781,48 @@ function slim-metadata()
781781
function execution-status-count()
782782
{
783783
# Handle Arguments:
784-
local OPTIND
785784
local doPretty=false
786785
local doExpandSubWorkflows=false
787786

788787
local workflowIDs=""
789788

790-
while getopts ":px" opt ; do
791-
case ${opt} in
792-
p)
789+
# Handling args this way to properly be able to detect negative workflow IDs and
790+
# workflow IDs themselves.
791+
# (getopt gets confused when you mix positional and flag args)
792+
for arg in ${@} ; do
793+
case ${arg} in
794+
-p)
793795
doPretty=true
794796
;;
795-
x)
797+
-x)
796798
doExpandSubWorkflows=true
797799
;;
798-
\?)
799-
# This is an unexpected argument.
800-
if [[ $(matchWorkflowId ${OPTARG}) -eq 0 ]] ; then
800+
-[0-9]*)
801801
# This is a workflow ID!
802802
# Add it to the list:
803-
workflowIDs="${workflowIDs} ${OPTARG}"
804-
elif [[ $( matchRelativeWorkflowId "-${OPTARG}" ) -eq 0 ]] ; then
803+
workflowIDs="${workflowIDs} ${arg}"
804+
;;
805+
*)
806+
if [[ $(matchWorkflowId ${arg}) -eq 0 ]] ; then
805807
# This is a workflow ID!
806808
# Add it to the list:
807-
# NOTE: for the relative match we need to add back in the leading `-`
808-
workflowIDs="${workflowIDs} -${OPTARG}"
809+
workflowIDs="${workflowIDs} ${arg}"
809810
else
810-
# This is not a workflow ID!
811-
# Throw an error!
812-
invalidSubCommand execution-status-count flag ${opt}
811+
# This is a flag missing an argument!
812+
invalidSubCommand execution-status-count "missing flag for argument" ${arg}
813813
fi
814814
;;
815-
:)
816-
# This is a flag missing an argument!
817-
invalidSubCommand execution-status-count "missing flag for argument" ${OPTARG}
818-
;;
819815
esac
820816
done
821817
shift $((OPTIND-1))
822818

819+
823820
# Get our workflow IDs in shape:
824821
extract_workflow_ids_from_args ${workflowIDs}
825822

826-
# Go through each workflow ID and get the info we want:
827-
for wfid in ${WORKFLOW_ID_LIST} ; do
823+
# Go through each workflow ID and get the info we want:
824+
for wfid in $WORKFLOW_ID_LIST ; do
825+
828826

829827
populateWorkflowIdAndServerUrl ${wfid}
830828
error "Using workflow-id == $WORKFLOW_ID"
@@ -833,14 +831,13 @@ function execution-status-count()
833831
assertCanCommunicateWithServer "${WORKFLOW_SERVER_URL}"
834832
local tempFile=$( makeTemp )
835833
if ! curl --connect-timeout "$CURL_CONNECT_TIMEOUT" --max-time "$CURL_MAX_TIMEOUT" --compressed -s "${WORKFLOW_SERVER_URL}/api/workflows/v1/${WORKFLOW_ID}/metadata?$CROMWELL_SLIM_METADATA_PARAMETERS" > "${tempFile}" ; then
836-
error "Could not connect to Cromwell server." && return 9
834+
error "Error: Could not connect to Cromwell server."
837835
fi
838836

839837
# Make sure the query succeeded:
840838
if [[ "$( < "${tempFile}" jq '.status' | sed -e 's#^"##g' -e 's#"$##g' )" == 'fail' ]] ; then
841839
reason=$( < "${tempFile}" jq '.message' | sed -e 's#^"##g' -e 's#"$##g' )
842840
error "Error: Query to cromwell server failed: ${reason}"
843-
return 11
844841
fi
845842

846843
if ${doPretty}; then
@@ -851,7 +848,6 @@ function execution-status-count()
851848
# {tasks:{status: count}}
852849
jq '.calls | map_values(group_by(.executionStatus) | map({(.[0].executionStatus): . | length}) | add)' "${tempFile}"
853850
checkPipeStatus "Could not read tmp file JSON data." "Could not parse JSON output from cromwell server."
854-
return $?
855851
fi
856852
done
857853
}

0 commit comments

Comments
 (0)