From 4340ccd1532b0cc73ce3e6b8b00b755912a5875c Mon Sep 17 00:00:00 2001 From: Tom Klapiscak <7372253+tomklapiscak@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:58:02 +0000 Subject: [PATCH] job implementation --- .../templates/05-postsync-db2-manage.yaml | 62 ++++++++++++++++--- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/instance-applications/510-550-ibm-mas-suite-app-config/templates/05-postsync-db2-manage.yaml b/instance-applications/510-550-ibm-mas-suite-app-config/templates/05-postsync-db2-manage.yaml index 7a089cec..6120b288 100644 --- a/instance-applications/510-550-ibm-mas-suite-app-config/templates/05-postsync-db2-manage.yaml +++ b/instance-applications/510-550-ibm-mas-suite-app-config/templates/05-postsync-db2-manage.yaml @@ -151,7 +151,7 @@ spec: value: "{{ $db2_namespace }}" - name: DB2_DBNAME value: "{{ $db2_dbname }}" - - name: INSTANCE_ID + - name: MAS_INSTANCE_ID value: "{{ .Values.instance_id }}" volumeMounts: [] @@ -159,17 +159,61 @@ spec: - /bin/sh - -c - | - set -e - source /mascli/functions/gitops_utils - oc exec -n ${DB2_NAMESPACE} c-db2wh-${INSTANCE_ID}-manage-db2u-0 -- su -lc 'echo "hello world"' db2inst1 - # su - db2inst1 - # db2 connect to bludb - # db2 "select 'alter sequence maximo.' || sequencename || ' cache 500;' from maximo.maxsequence" | grep "alter sequence" > AlterSEQ.sql - # echo "alter sequence maximo.maxseq cache 2000;" >> AlterSEQ.sql - # db2 -tvf AlterSEQ.sql | tee AlterSEQ.OUT + DB2_POD_NAME="c-db2wh-${INSTANCE_ID}-manage-db2u-0" + + echo "" + echo "================================================================================" + echo "Settings" + echo "================================================================================" + echo "MAS_INSTANCE_ID ..................... ${MAS_INSTANCE_ID}" + echo "DB2_DBNAME .......................... ${DB2_DBNAME}" + echo "AVP_TYPE ............................ ${AVP_TYPE}" + echo "DB2_NAMESPACE ....................... ${DB2_NAMESPACE}" + echo "DB2_POD_NAME ........................ ${DB2_POD_NAME}" + + # Path to the generated script, on both this pod and on the db2u pod + ALTERSEQ_SH_PATH="/tmp/alterseq.sh" + + echo "" + echo "Create ${ALTERSEQ_SH_PATH}" + echo "--------------------------------------------------------------------------------" + + # Generate a script to copy and run on the db2u pod + cat > ${ALTERSEQ_SH_PATH} << EOF + #!/bin/bash + db2 connect to ${DB2_DBNAME} + if [ \$? != 0 ]; then + echo "Failed to connect to database!" + exit 1 + fi + + SQL_PATH="${ALTERSEQ_SH_PATH}.sql" + + db2 "select 'alter sequence maximo.' || sequencename || ' cache 500;' from maximo.maxsequence" | grep "alter sequence" > ${SQL_PATH} + echo "alter sequence maximo.maxseq cache 2000;" >> ${SQL_PATH} + + cat ${SQL_PATH} + + # db2 -tvf ${SQL_PATH} | tee ${SQL_PATH}.log + EOF + # IMPORTANT: Do not make any changes to the "EOF" line above (including its indentation) + + cat ${ALTERSEQ_SH_PATH} + + chmod +x ${ALTERSEQ_SH_PATH} + + echo "" + echo "Copy ${ALTERSEQ_SH_PATH} to ${DB2_NAMESPACE}/${DB2_POD_NAME}" + echo "--------------------------------------------------------------------------------" + oc cp ${ALTERSEQ_SH_PATH} ${DB2_NAMESPACE}/${DB2_POD_NAME}:${ALTERSEQ_SH_PATH} -c db2u || exit $? + + echo "" + echo "Executing ${ALTERSEQ_SH_PATH} file on ${DB2_NAMESPACE}/${DB2_POD_NAME}" + echo "--------------------------------------------------------------------------------" + oc exec -n ${DB2_NAMESPACE} ${DB2_POD_NAME} -- su -lc "${ALTERSEQ_SH_PATH} | tee ${ALTERSEQ_SH_PATH}.log" db2inst1 || exit $? restartPolicy: Never serviceAccountName: "{{ $sa_name }}"