Skip to content

Commit

Permalink
correct more logs
Browse files Browse the repository at this point in the history
Signed-off-by: MarkAckert <[email protected]>
  • Loading branch information
MarkAckert committed Oct 31, 2024
1 parent 2b322e1 commit a278f0b
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 201 deletions.
66 changes: 30 additions & 36 deletions pswi/01_smpe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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} <<EOF
cd ${DIR}
put SMPE20
EOF
Expand All @@ -52,52 +52,46 @@ cd ..
# Get workflowKey for SMPE workflow owned by user
echo "Get workflowKey for SMPE workflow if it exists."

RESP=`curl -s $SMPE_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
SMPE_WORKFLOW_URL="${CREATE_SMPE_WF_URL}/${WFKEY}"
RESP=$(curl -s $SMPE_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
SMPE_WORKFLOW_URL="${CREATE_SMPE_WF_URL}/${WFKEY}"

echo "Deleting an SMPE workflow."
RESP=`curl -s $SMPE_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 an SMPE workflow."
RESP=$(curl -s $SMPE_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 SMPE workflow.'

RESP=`curl -s $CREATE_SMPE_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_SMPE_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_SMPE_WF_URL}/${WFKEY}"

# Run workflow
echo "Invoking REST API to start a SMPE 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`
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
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 with SMP/E ended with an error." >> 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

66 changes: 31 additions & 35 deletions pswi/02_ptf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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} <<EOF
cd ${DIR}
put WFPTF
EOF
Expand All @@ -47,52 +47,48 @@ cd ..
# Get workflowKey for PTF workflow owned by user
echo "Get workflowKey for PTF workflow if it exists."

RESP=`curl -s $PTF_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 $PTF_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
PTF_WORKFLOW_URL="${CREATE_PTF_WF_URL}/${WFKEY}"
if [ -n "$WFKEY" ]; then
PTF_WORKFLOW_URL="${CREATE_PTF_WF_URL}/${WFKEY}"

echo "Deleting a PTF workflow."
RESP=`curl -s $PTF_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 a PTF workflow."
RESP=$(curl -s $PTF_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 ptf workflow.'

RESP=`curl -s $CREATE_PTF_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_PTF_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_PTF_WF_URL}/${WFKEY}"

# Run workflow
echo "Invoking REST API to start a PTF apply 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`
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
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 with PTFs ended with an error." >> 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
20 changes: 10 additions & 10 deletions pswi/03_create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -247,15 +247,15 @@ 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
sleep 3
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

Expand Down
2 changes: 1 addition & 1 deletion pswi/06_test_cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
20 changes: 9 additions & 11 deletions pswi/scripts/check_response.sh
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
Loading

0 comments on commit a278f0b

Please sign in to comment.