Skip to content

Commit

Permalink
job implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomklapiscak committed Nov 13, 2024
1 parent 7129134 commit 4340ccd
Showing 1 changed file with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,69 @@ spec:
value: "{{ $db2_namespace }}"
- name: DB2_DBNAME
value: "{{ $db2_dbname }}"
- name: INSTANCE_ID
- name: MAS_INSTANCE_ID
value: "{{ .Values.instance_id }}"

volumeMounts: []
command:
- /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 }}"
Expand Down

0 comments on commit 4340ccd

Please sign in to comment.