diff --git a/scripts/wa_restart.sh b/scripts/wa_restart.sh index bd2e189..c4bf758 100644 --- a/scripts/wa_restart.sh +++ b/scripts/wa_restart.sh @@ -1,12 +1,12 @@ -# Restart WA pods. Run script after changing project to where WA is installed. -# Author - Manu Thapar +# Restart WA pods. Run this script after changing to the project where WA is installed. +# Author - Manu Thapar # Copyright 2021 IBM Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http:#www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -14,24 +14,97 @@ # See the License for the specific language governing permissions and # limitations under the License. -INSTANCE="wa" # Replace Watson Assistant instance name if different -for DEPLOYMENT in ed dragonfly-clu-mm tfmm clu-serving master nlu dialog store -do -echo "#Starting rolling restart of $INSTANCE-$DEPLOYMENT." -oc rollout restart deployment $INSTANCE-$DEPLOYMENT -oc rollout status deployment/$INSTANCE-$DEPLOYMENT --watch=true -echo "#Rolling restart of $INSTANCE-$DEPLOYMENT completed successfully." -done +INSTANCE="$(oc get wa -o jsonpath='{.items[0].metadata.name}' 2>/dev/null)" + +if [ -z "$INSTANCE" ]; then + echo "# Unable to determine Watson Assistant instance name from 'oc get wa'." + exit 1 +fi + +echo "# Detected Watson Assistant instance name: $INSTANCE" + +restart_and_wait() { + DEPLOYMENT_NAME="$1" + + echo "# Starting rolling restart of ${DEPLOYMENT_NAME}." + if oc rollout restart "deployment/${DEPLOYMENT_NAME}" 2>/dev/null; then + if oc rollout status "deployment/${DEPLOYMENT_NAME}" --watch=true; then + echo "# Rolling restart of ${DEPLOYMENT_NAME} completed successfully." + else + echo "# Rolling restart of ${DEPLOYMENT_NAME} started, but rollout status check failed." + fi + else + echo "# Deployment ${DEPLOYMENT_NAME} not found, skipping." + fi +} + +restart_only() { + DEPLOYMENT_NAME="$1" -for DEPLOYMENT in analytics clu-embedding incoming-webhooks integrations recommends spellchecker-mm store-sync system-entities ui webhooks-connector gw-instance store-admin + echo "# Starting rolling restart of ${DEPLOYMENT_NAME}." + if oc rollout restart "deployment/${DEPLOYMENT_NAME}" 2>/dev/null; then + return 0 + fi + + echo "# Deployment ${DEPLOYMENT_NAME} not found, skipping." + return 1 +} + +wait_for_rollout() { + DEPLOYMENT_NAME="$1" + + if oc rollout status "deployment/${DEPLOYMENT_NAME}" --watch=true 2>/dev/null; then + echo "# Rolling restart of ${DEPLOYMENT_NAME} completed successfully." + else + echo "# Rolling restart of ${DEPLOYMENT_NAME} started, but rollout status check failed." + fi +} + +restart_and_wait "${INSTANCE}-ed" +restart_and_wait "${INSTANCE}-dragonfly-clu-mm" +restart_and_wait "${INSTANCE}-tfmm" +restart_and_wait "tf" +restart_and_wait "${INSTANCE}-clu-serving" +restart_and_wait "${INSTANCE}-master" +restart_and_wait "${INSTANCE}-nlu" +restart_and_wait "${INSTANCE}-dialog" +restart_and_wait "${INSTANCE}-store" + +STARTED_DEPLOYMENTS="" + +for DEPLOYMENT in \ + dragonfly-clu-dms \ + ed-dms \ + clu-serving-dms \ + clu-training \ + clu-triton-serving \ + analytics \ + clu-embedding \ + incoming-webhooks \ + integrations \ + recommends \ + spellchecker-mm \ + spellchecker \ + store-sync \ + system-entities \ + ui \ + webhooks-connector \ + gw-instance \ + gw-provisioner \ + store-admin \ + dms-controller \ + redis-clu-haproxy \ + redis-haproxy \ + knative-wa-clu-dlq do -echo "#Starting rolling restart of $INSTANCE-$DEPLOYMENT" -oc rollout restart deployment $INSTANCE-$DEPLOYMENT + if restart_only "${INSTANCE}-${DEPLOYMENT}"; then + STARTED_DEPLOYMENTS="${STARTED_DEPLOYMENTS} ${INSTANCE}-${DEPLOYMENT}" + fi done -for DEPLOYMENT in analytics clu-embedding incoming-webhooks integrations recommends spellchecker-mm store-sync system-entities ui webhooks-connector gw-instance store-admin +for DEPLOYMENT_NAME in $STARTED_DEPLOYMENTS do -oc rollout status deployment/$INSTANCE-$DEPLOYMENT --watch=true -echo "#Rolling restart of $INSTANCE-$DEPLOYMENT completed successfully." + wait_for_rollout "${DEPLOYMENT_NAME}" done -echo "#All Watson Assistant deployments restarted successfully." + +echo "# Watson Assistant deployment restart flow completed."