diff --git a/pswi/01_smpe.sh b/pswi/01_smpe.sh index 42d9f89aff..38a40b11c3 100644 --- a/pswi/01_smpe.sh +++ b/pswi/01_smpe.sh @@ -18,7 +18,7 @@ echo "SMPE workflow name :" $SMPE_WF_NAME CREATE_SMPE_WF_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows" SMPE_WF_LIST_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows?owner=${ZOSMF_USER}&workflowName=${SMPE_WF_NAME}" -# JSONs +# JSONs ADD_WORKFLOW_JSON='{"workflowName":"'$SMPE_WF_NAME'", "workflowDefinitionFile":"'${DIR}'/SMPE20", @@ -43,7 +43,7 @@ echo "Uploading workflow SMPE into ${DIR} directory thru SSH" cd workflows -sshpass -p${ZOSMF_PASS} sftp -o HostKeyAlgorithms=+ssh-rsa -o BatchMode=no -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -b - -P ${ZZOW_SSH_PORT} ${ZOSMF_USER}@${HOST} << EOF +sshpass -p${ZOSMF_PASS} sftp -o HostKeyAlgorithms=+ssh-rsa -o BatchMode=no -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -b - -P ${ZZOW_SSH_PORT} ${ZOSMF_USER}@${HOST} <> report.txt - echo $RESP >> report.txt - exit -1 -elif [ "$STATUS_NAME" = "complete" ] -then - echo "Workflow finished successfully." - STATUS="FINISHED" -fi +until [ "$STATUS" = "FINISHED" ]; do + sleep 20 + + # Get the result of the workflow + RESP=$(curl -s ${WORKFLOW_URL} -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) + if [ $? -gt 0 ]; then exit -1; fi + STATUS_NAME=$(echo $RESP | grep -o '"statusName":".*"' | cut -f4 -d\") + + if [ "$STATUS_NAME" = "in-progress" ]; then + echo "Workflow with SMP/E ended with an error." >>$LOG_DIR/report.txt + echo $RESP >>$LOG_DIR/report.txt + exit -1 + elif [ "$STATUS_NAME" = "complete" ]; then + echo "Workflow finished successfully." + STATUS="FINISHED" + fi done - diff --git a/pswi/02_ptf.sh b/pswi/02_ptf.sh index e5174333d7..c6f189e43a 100644 --- a/pswi/02_ptf.sh +++ b/pswi/02_ptf.sh @@ -22,7 +22,7 @@ echo "PTF workflow name :" $PTF_WF_NAME CREATE_PTF_WF_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows" PTF_WF_LIST_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows?owner=${ZOSMF_USER}&workflowName=${PTF_WF_NAME}" -# JSONs +# JSONs ADD_WORKFLOW_JSON='{"workflowName":"'$PTF_WF_NAME'", "workflowDefinitionFile":"'${DIR}'/WFPTF", "system":"'$ZOSMF_SYSTEM'", @@ -38,7 +38,7 @@ ADD_WORKFLOW_JSON='{"workflowName":"'$PTF_WF_NAME'", cd workflows -sshpass -p${ZOSMF_PASS} sftp -o HostKeyAlgorithms=+ssh-rsa -o BatchMode=no -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -b - -P ${ZZOW_SSH_PORT} ${ZOSMF_USER}@${HOST} << EOF +sshpass -p${ZOSMF_PASS} sftp -o HostKeyAlgorithms=+ssh-rsa -o BatchMode=no -o StrictHostKeyChecking=no -o PubkeyAuthentication=no -b - -P ${ZZOW_SSH_PORT} ${ZOSMF_USER}@${HOST} <> report.txt - echo $RESP >> report.txt - exit -1 -elif [ "$STATUS_NAME" = "complete" ] -then - echo "Workflow finished successfully." - STATUS="FINISHED" -fi +until [ "$STATUS" = "FINISHED" ]; do + sleep 20 + + # Get the result of the workflow + RESP=$(curl -s ${WORKFLOW_URL} -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) + if [ $? -gt 0 ]; then exit -1; fi + + STATUS_NAME=$(echo $RESP | grep -o '"statusName":".*"' | cut -f4 -d\") + + if [ "$STATUS_NAME" = "in-progress" ]; then + echo "Workflow with PTFs ended with an error." >>$LOG_DIR/report.txt + echo $RESP >>$LOG_DIR/report.txt + exit -1 + elif [ "$STATUS_NAME" = "complete" ]; then + echo "Workflow finished successfully." + STATUS="FINISHED" + fi done diff --git a/pswi/03_create.sh b/pswi/03_create.sh index 23d19d57bd..3f0727843c 100644 --- a/pswi/03_create.sh +++ b/pswi/03_create.sh @@ -72,8 +72,8 @@ if [ -n "$MOUNTZ" ]; then if [ "$MOUNTZ/" = "$ZOWE_MOUNT" ]; then echo "${ZOWE_MOUNT} with zFS ${ZOWE_ZFS} mounted will be used." else - echo "The file system ${ZOWE_ZFS} exists but is mounted to different mount point ${MOUNTZ}." >>report.txt - echo "It is required to have the file system ${ZOWE_ZFS} mounted to the exact mount point (${ZOWE_MOUNT}) to successfully export Zowe PSWI." >>report.txt + echo "The file system ${ZOWE_ZFS} exists but is mounted to different mount point ${MOUNTZ}." >>$LOG_DIR/report.txt + echo "It is required to have the file system ${ZOWE_ZFS} mounted to the exact mount point (${ZOWE_MOUNT}) to successfully export Zowe PSWI." >>$LOG_DIR/report.txt exit -1 fi else @@ -82,7 +82,7 @@ else MOUNTZFS=$(echo $RESP | grep -o "name":".*" | cut -f4 -d\") if [ -n "$MOUNTZFS" ]; then # If ZFS is not mounted to the mountpoint then this ZOWE mountpoint has different zFS - echo "The mountpoint ${ZOWE_MOUNT} has different zFS ${MOUNTZFS}." >>report.txt + echo "The mountpoint ${ZOWE_MOUNT} has different zFS ${MOUNTZFS}." >>$LOG_DIR/report.txt exit -1 else # Mount zFS to Zowe mountpoint @@ -99,13 +99,13 @@ echo "Checking if WORKFLOW data set already exists." RESP=$(curl -s $CHECK_WORKFLOW_DSN_URL -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) DS_COUNT=$(echo $RESP | grep -o '"returnedRows":[0-9]*' | cut -f2 -d:) if [ $DS_COUNT -ne 0 ]; then - echo "The ${WORKFLOW_DSN} already exist. Because there is a possibility that it contains something unwanted the script does not continue." >>report.txt + echo "The ${WORKFLOW_DSN} already exist. Because there is a possibility that it contains something unwanted the script does not continue." >>$LOG_DIR/report.txt exit -1 else echo "Creating a data set where the post-Deployment workflow will be stored." RESP=$(curl -s $WORKFLOW_DSN_URL -k -X "POST" -d "$ADD_WORKFLOW_DSN_JSON" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) if [ -n "$RESP" ]; then - echo "The creation of the ${WORKFLOW_DSN} was not successful. Error message: ${RESP}" >>report.txt + echo "The creation of the ${WORKFLOW_DSN} was not successful. Error message: ${RESP}" >>$LOG_DIR/report.txt exit -1 fi fi @@ -162,7 +162,7 @@ echo "Checking if the data set for export jobs already exists." RESP=$(curl -s $CHECK_EXPORT_DSN_URL -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) DSN_COUNT=$(echo $RESP | grep -o '"returnedRows":[0-9]*' | cut -f2 -d:) if [ $DSN_COUNT -ne 0 ]; then - echo "The ${EXPORT_DSN} already exist. Because there is a possibility that it contains something unwanted the script does not continue." >>report.txt + echo "The ${EXPORT_DSN} already exist. Because there is a possibility that it contains something unwanted the script does not continue." >>$LOG_DIR/report.txt exit -1 else echo "Creating a data set where the export jobs will be stored." @@ -196,7 +196,7 @@ if [ $? -gt 0 ]; then exit -1; fi LOAD_STATUS_URL=$(echo $RESP | grep -o '"statusurl":".*"' | cut -f4 -d\" | tr -d '\' 2>/dev/null) if [ -z "$LOAD_STATUS_URL" ]; then - echo "No response from the load product REST API call." >>report.txt + echo "No response from the load product REST API call." >>$LOG_DIR/report.txt exit -1 fi @@ -223,7 +223,7 @@ sh scripts/check_response.sh "${RESP}" $? if [ $? -gt 0 ]; then exit -1; fi EXPORT_STATUS_URL=$(echo $RESP | grep -o '"statusurl":".*"' | cut -f4 -d\" | tr -d '\' 2>/dev/null) if [ -z "$EXPORT_STATUS_URL" ]; then - echo "No response from the export REST API call." >>report.txt + echo "No response from the export REST API call." >>$LOG_DIR/report.txt exit -1 fi @@ -247,7 +247,7 @@ until [ "$STATUS" = "complete" ]; do echo "The status is: "$STATUS # Can be 100% but still running if [ "$STATUS" != "complete" ] && [ "$STATUS" != "running" ]; then - echo "Status of generation of Export JCL failed." >>report.txt + echo "Status of generation of Export JCL failed." >>$LOG_DIR/report.txt exit -1 fi fi @@ -255,7 +255,7 @@ until [ "$STATUS" = "complete" ]; do done if [ -z "$DSN" ]; then - echo "The creation of export JCL failed" >>report.txt + echo "The creation of export JCL failed" >>$LOG_DIR/report.txt exit -1 fi diff --git a/pswi/06_test_cleanup.sh b/pswi/06_test_cleanup.sh index efecd53df5..a45144a454 100644 --- a/pswi/06_test_cleanup.sh +++ b/pswi/06_test_cleanup.sh @@ -2,7 +2,7 @@ #version=1.0 export BASE_URL="${ZOSMF_URL}:${ZOSMF_PORT}" -LOG_FILE=$$LOG_DIR/log_test_cleanup.txt +LOG_FILE=$LOG_DIR/log_test_cleanup.txt echo "" echo "" diff --git a/pswi/scripts/check_response.sh b/pswi/scripts/check_response.sh index b589cf88d2..2a2deb11cd 100644 --- a/pswi/scripts/check_response.sh +++ b/pswi/scripts/check_response.sh @@ -1,17 +1,15 @@ RESP=$1 RESPCODE=$2 - -REASON=`echo $RESP | grep -o '"reason":'` -MSG=`echo $RESP | grep -o '"messageText":'` -if [ -n "$REASON" ] || [ -n "$MSG" ] -then - echo $RESP >> report.txt + +REASON=$(echo $RESP | grep -o '"reason":') +MSG=$(echo $RESP | grep -o '"messageText":') +if [ -n "$REASON" ] || [ -n "$MSG" ]; then + echo $RESP >>$LOG_DIR/report.txt exit -1 -fi -if [ $RESPCODE -ne 0 ] -then - echo "REST API call failed." >> report.txt - echo $RESP >> report.txt +fi +if [ $RESPCODE -ne 0 ]; then + echo "REST API call failed." >>$LOG_DIR/report.txt + echo $RESP >>$LOG_DIR/report.txt exit -1 else echo "REST API call was successful." diff --git a/pswi/scripts/tmp_mounts.sh b/pswi/scripts/tmp_mounts.sh index eb44340d58..9f8d55e724 100644 --- a/pswi/scripts/tmp_mounts.sh +++ b/pswi/scripts/tmp_mounts.sh @@ -6,57 +6,50 @@ MOUNT=${2} MOUNTED=false echo "Checking if file system ${ZFS} is mounted." -RESP=`curl -s "${BASE_URL}/zosmf/restfiles/mfs?fsname=${ZFS}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` -MOUNTP=`echo $RESP | grep -o '"mountpoint":".*"' | cut -f4 -d\"` +RESP=$(curl -s "${BASE_URL}/zosmf/restfiles/mfs?fsname=${ZFS}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) +MOUNTP=$(echo $RESP | grep -o '"mountpoint":".*"' | cut -f4 -d\") NEW_ZFS_JSON='{"cylsPri":2000,"cylsSec": 140,"volumes":[ "'${VOLUME}'" ]}' - - -if [ -n "$MOUNTP" ] -then + +if [ -n "$MOUNTP" ]; then # Check if temp zFS is mounted to given mount point - if [ "$MOUNTP" = "$MOUNT" ] - then + if [ "$MOUNTP" = "$MOUNT" ]; then echo "${MOUNT} with zFS ${ZFS} mounted will be used as is." MOUNTED=true else - echo "The file system ${ZFS} exists but is mounted to different mount point(${MOUNTP})." >> report.txt - echo "Use different name of zFS or ${MOUNTP} for mount point." >> report.txt + echo "The file system ${ZFS} exists but is mounted to different mount point(${MOUNTP})." >>$LOG_DIR/report.txt + echo "Use different name of zFS or ${MOUNTP} for mount point." >>$LOG_DIR/report.txt exit -1 fi else echo "Temporary zFS isn't mounted. Now checking if mount point has any other zFS mounted." - RESP=`curl -s "${BASE_URL}/zosmf/restfiles/mfs?path=${MOUNT}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` + RESP=$(curl -s "${BASE_URL}/zosmf/restfiles/mfs?path=${MOUNT}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) sh scripts/check_response.sh "${RESP}" $? - if [ $? -gt 0 ];then exit -1;fi - MOUNTZFS=`echo $RESP | grep -o "name":".*" | cut -f4 -d\"` - if [ -n "$MOUNTZFS" ] - then + if [ $? -gt 0 ]; then exit -1; fi + MOUNTZFS=$(echo $RESP | grep -o "name":".*" | cut -f4 -d\") + if [ -n "$MOUNTZFS" ]; then # If zFS is not mounted to the mount point then this mount point has different zFS - echo "The mount point ${MOUNT} has different zFS (${MOUNTZFS}) mounted." >> report.txt - echo "Use different mount point (not ${MOUNT})." >> report.txt - echo "Or use ${MOUNTZFS} for zFS." >> report.txt + echo "The mount point ${MOUNT} has different zFS (${MOUNTZFS}) mounted." >>$LOG_DIR/report.txt + echo "Use different mount point (not ${MOUNT})." >>$LOG_DIR/report.txt + echo "Or use ${MOUNTZFS} for zFS." >>$LOG_DIR/report.txt exit -1 fi fi - -if [ "$MOUNTED" = false ] -then +if [ "$MOUNTED" = false ]; then # Check if data set exists echo "Checking if temporary zFS ${ZFS} exists." - RESP=`curl -s "${BASE_URL}/zosmf/restfiles/ds?dslevel=${ZFS}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` + RESP=$(curl -s "${BASE_URL}/zosmf/restfiles/ds?dslevel=${ZFS}" -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) sh scripts/check_response.sh "${RESP}" $? - if [ $? -gt 0 ];then exit -1;fi - ZFS_COUNT=`echo $RESP | grep -o '"returnedRows":[0-9]*' | cut -f2 -d:` - if [ "$ZFS_COUNT" = "0" ] - then + if [ $? -gt 0 ]; then exit -1; fi + ZFS_COUNT=$(echo $RESP | grep -o '"returnedRows":[0-9]*' | cut -f2 -d:) + if [ "$ZFS_COUNT" = "0" ]; then # Create new zFS if not echo "${ZFS} does not exists." echo "Creating new zFS ${ZFS}." - RESP=`curl -s "${BASE_URL}/zosmf/restfiles/mfs/zfs/${ZFS}" -k -X "POST" -d "$NEW_ZFS_JSON" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` + RESP=$(curl -s "${BASE_URL}/zosmf/restfiles/mfs/zfs/${ZFS}" -k -X "POST" -d "$NEW_ZFS_JSON" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) sh scripts/check_response.sh "${RESP}" $? - if [ $? -gt 0 ];then exit -1;fi + if [ $? -gt 0 ]; then exit -1; fi else #TODO: also check the first dsname because it can be something that just has tmp_zfs as HLQ echo @@ -64,25 +57,25 @@ then # Mount zFS to MOUNT echo "Mounting zFS ${ZFS} to ${MOUNT} mount point with JCL because REST API doesn't allow AGGRGROW parm." -echo ${JOBST1} > JCL -echo ${JOBST2} >> JCL -echo "//MKDIR EXEC PGM=BPXBATCH" >> JCL -echo "//STDOUT DD SYSOUT=*" >> JCL -echo "//STDERR DD SYSOUT=*" >> JCL -echo "//STDPARM DD *" >> JCL -echo "SH mkdir -p ${MOUNT}" >> JCL -echo "/*" >> JCL -echo "//MNT1ZFS1 EXEC PGM=IKJEFT01,REGION=4096K,DYNAMNBR=50" >> JCL -echo "//SYSTSPRT DD SYSOUT=*" >> JCL -echo "//SYSTSOUT DD SYSOUT=*" >> JCL -echo "//SYSTSIN DD * " >> JCL -echo "MOUNT FILESYSTEM('${ZFS}') + " >> JCL -echo "TYPE(ZFS) MODE(RDWR) + " >> JCL -echo "PARM('AGGRGROW') + " >> JCL -echo "MOUNTPOINT('${MOUNT}') " >> JCL -echo "/*" >> JCL + echo ${JOBST1} >JCL + echo ${JOBST2} >>JCL + echo "//MKDIR EXEC PGM=BPXBATCH" >>JCL + echo "//STDOUT DD SYSOUT=*" >>JCL + echo "//STDERR DD SYSOUT=*" >>JCL + echo "//STDPARM DD *" >>JCL + echo "SH mkdir -p ${MOUNT}" >>JCL + echo "/*" >>JCL + echo "//MNT1ZFS1 EXEC PGM=IKJEFT01,REGION=4096K,DYNAMNBR=50" >>JCL + echo "//SYSTSPRT DD SYSOUT=*" >>JCL + echo "//SYSTSOUT DD SYSOUT=*" >>JCL + echo "//SYSTSIN DD * " >>JCL + echo "MOUNT FILESYSTEM('${ZFS}') + " >>JCL + echo "TYPE(ZFS) MODE(RDWR) + " >>JCL + echo "PARM('AGGRGROW') + " >>JCL + echo "MOUNTPOINT('${MOUNT}') " >>JCL + echo "/*" >>JCL - sh scripts/submit_jcl.sh "`cat JCL`" - if [ $? -gt 0 ];then exit -1;fi + sh scripts/submit_jcl.sh "$(cat JCL)" + if [ $? -gt 0 ]; then exit -1; fi rm JCL fi diff --git a/pswi/scripts/wf_run_test.sh b/pswi/scripts/wf_run_test.sh index e31a8e3c19..7429c91a9a 100755 --- a/pswi/scripts/wf_run_test.sh +++ b/pswi/scripts/wf_run_test.sh @@ -21,17 +21,16 @@ WF_NAME="Testing_workflows" CREATE_WF_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows" WF_LIST_URL="${BASE_URL}/zosmf/workflow/rest/1.0/workflows?owner=${ZOSMF_USER}&workflowName=${WF_NAME}" -# JSONs -if [ -n "$INPUT_FILE" ] -then -ADD_WORKFLOW_JSON='{"workflowName":"'$WF_NAME'", +# JSONs +if [ -n "$INPUT_FILE" ]; then + ADD_WORKFLOW_JSON='{"workflowName":"'$WF_NAME'", "workflowDefinitionFile":"'${WF_DEF_FILE}'", "variableInputFile":"'${INPUT_FILE}'", "system":"'$ZOSMF_SYSTEM'", "owner":"'$ZOSMF_USER'", "assignToOwner" :true}' else -ADD_WORKFLOW_JSON='{"workflowName":"'$WF_NAME'", + ADD_WORKFLOW_JSON='{"workflowName":"'$WF_NAME'", "workflowDefinitionFile":"'${WF_DEF_FILE}'", "system":"'$ZOSMF_SYSTEM'", "owner":"'$ZOSMF_USER'", @@ -42,75 +41,67 @@ set -x # Get workflowKey for the workflow owned by user echo "Get workflowKey for the workflow if it exists." -RESP=`curl -s $WF_LIST_URL -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` -WFKEY=`echo $RESP | grep -o '"workflowKey":".*"' | cut -f4 -d\"` +RESP=$(curl -s $WF_LIST_URL -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) +WFKEY=$(echo $RESP | grep -o '"workflowKey":".*"' | cut -f4 -d\") -if [ -n "$WFKEY" ] -then -WORKFLOW_URL="${CREATE_WF_URL}/${WFKEY}" +if [ -n "$WFKEY" ]; then + WORKFLOW_URL="${CREATE_WF_URL}/${WFKEY}" -echo "Deleting the workflow." -RESP=`curl -s $WORKFLOW_URL -k -X "DELETE" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` -sh scripts/check_response.sh "${RESP}" $? + echo "Deleting the workflow." + RESP=$(curl -s $WORKFLOW_URL -k -X "DELETE" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) + sh scripts/check_response.sh "${RESP}" $? fi # Create workflow with REST API echo 'Invoking REST API to create the workflow.' -RESP=`curl -s $CREATE_WF_URL -k -X "POST" -d "$ADD_WORKFLOW_JSON" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` +RESP=$(curl -s $CREATE_WF_URL -k -X "POST" -d "$ADD_WORKFLOW_JSON" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) sh scripts/check_response.sh "${RESP}" $? -if [ $? -gt 0 ];then exit -1;fi -WFKEY=`echo $RESP | grep -o '"workflowKey":".*"' | cut -f4 -d\"` +if [ $? -gt 0 ]; then exit -1; fi +WFKEY=$(echo $RESP | grep -o '"workflowKey":".*"' | cut -f4 -d\") WORKFLOW_URL="${CREATE_WF_URL}/${WFKEY}" -if [ "$run" = "run" ] -then -# Run workflow -echo "Invoking REST API to start the workflow." - -RESP=`curl -s ${WORKFLOW_URL}/operations/start -k -X "PUT" -d "{}" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` -sh scripts/check_response.sh "${RESP}" $? -if [ $? -gt 0 ];then exit -1;fi -STATUS="" -until [ "$STATUS" = "FINISHED" ] -do -sleep 20 - - -# Get the result of the workflow -RESP=`curl -s ${WORKFLOW_URL} -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` -if [ $? -gt 0 ];then exit -1;fi -STATUS_NAME=`echo $RESP | grep -o '"statusName":".*"' | cut -f4 -d\"` - -if [ "$STATUS_NAME" = "in-progress" ] -then - echo "Workflow ended with an error." >> report.txt - echo $RESP >> report.txt - echo "Checking if the workflow is ZWECONF" >> report.txt - if [ "$ZWECONF" = "ZWECONF" ] - then - STEP_NAME=`echo $RESP | grep -o '"currentStepName":".*"' | cut -f4 -d\"` - if [ "$STEP_NAME" = "init_zowe" ] - then - echo "The workflow is ZWECONF and should end in step 'init_zowe'" +if [ "$run" = "run" ]; then + # Run workflow + echo "Invoking REST API to start the workflow." + + RESP=$(curl -s ${WORKFLOW_URL}/operations/start -k -X "PUT" -d "{}" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) + sh scripts/check_response.sh "${RESP}" $? + if [ $? -gt 0 ]; then exit -1; fi + STATUS="" + until [ "$STATUS" = "FINISHED" ]; do + sleep 20 + + # Get the result of the workflow + RESP=$(curl -s ${WORKFLOW_URL} -k -X "GET" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) + if [ $? -gt 0 ]; then exit -1; fi + STATUS_NAME=$(echo $RESP | grep -o '"statusName":".*"' | cut -f4 -d\") + + if [ "$STATUS_NAME" = "in-progress" ]; then + echo "Workflow ended with an error." >>$LOG_DIR/report.txt + echo $RESP >>$LOG_DIR/report.txt + echo "Checking if the workflow is ZWECONF" >>$LOG_DIR/report.txt + if [ "$ZWECONF" = "ZWECONF" ]; then + STEP_NAME=$(echo $RESP | grep -o '"currentStepName":".*"' | cut -f4 -d\") + if [ "$STEP_NAME" = "init_zowe" ]; then + echo "The workflow is ZWECONF and should end in step 'init_zowe'" + STATUS="FINISHED" + else + echo "The workflow is ZWECONF but ended in different step: '$STEP_NAME'" >>$LOG_DIR/report.txt + exit -1 + fi + else + echo "Workflow ended with an error and it is not ZWECONF." >>$LOG_DIR/report.txt + echo $RESP >>$LOG_DIR/report.txt + exit -1 + fi + elif [ "$STATUS_NAME" = "complete" ]; then + echo "Workflow finished successfully." STATUS="FINISHED" - else - echo "The workflow is ZWECONF but ended in different step: '$STEP_NAME'" >> report.txt - exit -1 fi - else - echo "Workflow ended with an error and it is not ZWECONF." >> report.txt - echo $RESP >> report.txt - exit -1 - fi -elif [ "$STATUS_NAME" = "complete" ] -then - echo "Workflow finished successfully." - STATUS="FINISHED" -fi -done + done fi echo "Deleting the workflow." -RESP=`curl -s $WORKFLOW_URL -k -X "DELETE" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS` +RESP=$(curl -s $WORKFLOW_URL -k -X "DELETE" -H "Content-Type: application/json" -H "X-CSRF-ZOSMF-HEADER: A" --user $ZOSMF_USER:$ZOSMF_PASS) sh scripts/check_response.sh "${RESP}" $?