Skip to content

Commit f357c30

Browse files
authored
Only check for the server when necessary (#25)
* Only test if we can connect to the server when running a command that requires a server connection.
1 parent 29425ef commit f357c30

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

cromshell

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ function checkPrerequisites
190190
return 0
191191
}
192192

193+
194+
function assertCanCommunicateWithServer
195+
{
196+
# Make sure we can talk to the cromwell server:
197+
serverName=$( echo ${1}| sed 's#.*://##g' )
198+
$PING_CMD $serverName &> /dev/null
199+
r=$?
200+
[[ $r -ne 0 ]] && error "Error: Cannot communicate with Cromwell server: $serverName" && exit 4
201+
}
202+
193203
function assertHavePreviouslySubmittedAJob()
194204
{
195205
local nLines=$( wc -l ${CROMWELL_SUBMISSIONS_FILE} | awk '{print $1}' )
@@ -241,8 +251,9 @@ function populateWorkflowIdAndServerUrl()
241251

242252
# Submit a workflow and arguments to the Cromwell Server
243253

244-
function submit()
245-
{
254+
function submit()
255+
{
256+
assertCanCommunicateWithServer $CROMWELL_URL
246257

247258
local response=$(curl --connect-timeout $CURL_CONNECT_TIMEOUT -s -F workflowSource=@${1} ${2:+ -F workflowInputs=@${2}} ${3:+ -F workflowOptions=@${3}} ${4:+ -F workflowDependencies=@${4}} ${CROMWELL_URL}/api/workflows/v1)
248259
local r=$?
@@ -267,6 +278,7 @@ function status()
267278
{
268279
local retVal=0
269280

281+
assertCanCommunicateWithServer $2
270282
local f=$( makeTemp )
271283
curl --connect-timeout $CURL_CONNECT_TIMEOUT -s ${2}/api/workflows/v1/${1}/status > $f
272284
[[ $? -ne 0 ]] && error "Could not connect to Cromwell server." && return 2
@@ -286,32 +298,36 @@ function status()
286298
}
287299

288300
# Get the logs of a Cromwell job UUID
289-
function logs()
301+
function logs()
290302
{
303+
assertCanCommunicateWithServer $2
291304
curl --connect-timeout $CURL_CONNECT_TIMEOUT -s ${2}/api/workflows/v1/${1}/logs | jq .
292305
checkPipeStatus "Could not connect to Cromwell server." "Could not parse JSON output from cromwell server."
293306
return $?
294307
}
295308

296309
# Get the metadata for a Cromwell job UUID
297-
function metadata()
310+
function metadata()
298311
{
312+
assertCanCommunicateWithServer $2
299313
curl --connect-timeout $CURL_CONNECT_TIMEOUT --compressed -s ${2}/api/workflows/v1/${1}/metadata?${CROMWELL_METADATA_PARAMETERS} | jq .
300314
checkPipeStatus "Could not connect to Cromwell server." "Could not parse JSON output from cromwell server."
301315
return $?
302316
}
303317

304318
# Get the metadata in condensed form for a Cromwell job UUID
305-
function slim-metadata()
319+
function slim-metadata()
306320
{
321+
assertCanCommunicateWithServer $2
307322
curl --connect-timeout $CURL_CONNECT_TIMEOUT --compressed -s "${2}/api/workflows/v1/$1/metadata?includeKey=executionStatus&includeKey=backendStatus" | jq .
308323
checkPipeStatus "Could not connect to Cromwell server." "Could not parse JSON output from cromwell server."
309324
return $?
310325
}
311326

312327
# Get the status of the given job and how many times it was run
313-
function execution-status-count()
328+
function execution-status-count()
314329
{
330+
assertCanCommunicateWithServer $2
315331
f=$( makeTemp )
316332
curl --connect-timeout $CURL_CONNECT_TIMEOUT --compressed -s ${2}/api/workflows/v1/$1/metadata?${CROMWELL_METADATA_PARAMETERS} > $f
317333
[[ $? -ne 0 ]] && error "Could not connect to Cromwell server." && return 9
@@ -330,16 +346,17 @@ function execution-status-count()
330346
}
331347

332348
# Bring up a browser window to view timing information on the job.
333-
function timing()
349+
function timing()
334350
{
335-
echo "Opeining timing information in a web browser for job ID: ${1}"
351+
echo "Opening timing information in a web browser for job ID: ${1}"
336352
open ${2}/api/workflows/v1/${1}/timing
337353
return $?
338354
}
339355

340356
# Cancel a running job.
341-
function abort()
357+
function abort()
342358
{
359+
assertCanCommunicateWithServer $2
343360
response=$(curl --connect-timeout $CURL_CONNECT_TIMEOUT -X POST --header "Content-Type: application/json" --header "Accept: application/json" "${2}/api/workflows/v1/${1}/abort")
344361
local r=$?
345362
echo $response
@@ -430,8 +447,9 @@ function list()
430447
# stderr
431448
# script
432449
# output
433-
function list-outputs()
450+
function list-outputs()
434451
{
452+
assertCanCommunicateWithServer $2
435453
local id=$1
436454
local cromwellServer=$2
437455

@@ -456,8 +474,9 @@ function list-outputs()
456474

457475

458476
# Get the root log folder from the cloud and put it in the metadata folder for this run
459-
function fetch-logs()
477+
function fetch-logs()
460478
{
479+
assertCanCommunicateWithServer $2
461480
local id=$1
462481
local cromwellServer=$2
463482

@@ -490,8 +509,9 @@ function fetch-logs()
490509

491510
# Get the root log folder from the cloud and put it in the metadata folder for this run
492511
# Includes all logs and output files
493-
function fetch-all()
512+
function fetch-all()
494513
{
514+
assertCanCommunicateWithServer $2
495515
local id=$1
496516
local cromwellServer=$2
497517

@@ -523,7 +543,8 @@ function notify()
523543
local id=$1
524544
local email=$2
525545
local cromwellServer=$3
526-
546+
547+
assertCanCommunicateWithServer ${cromwellServer}
527548
local separator="=================================================="
528549

529550
while true ; do
@@ -602,12 +623,6 @@ if ${ISCALLEDBYUSER} ; then
602623
r=$?
603624
[[ $r -ne 0 ]] && exit 6
604625

605-
# Make sure we can talk to the cromwell server:
606-
serverName=$( echo ${CROMWELL_URL} | sed 's#.*://##g' )
607-
$PING_CMD $serverName &> /dev/null
608-
r=$?
609-
[[ $r -ne 0 ]] && error "Error: Cannot communicate with Cromwell server: $serverName" && exit 4
610-
611626
# Special case: submitting a job:
612627
if [[ "${SUB_COMMAND}" == "submit" ]] ; then
613628
${SUB_COMMAND} $1 $2 $3 $4

0 commit comments

Comments
 (0)