Cognos PowerCubes aus der Cognos Analytics -Serviceinstanz entfernen
Mit dem Script remove_powercube.sh können Sie Cognos PowerCubes -PVCs aus der Cognos Analytics -Serviceinstanz entfernen. Dieses Script löscht auch die Cognos PowerCubes -Dateien und -Verzeichnisse aus dem Cognos Analytics -Pod.
Übersicht
./remove_powercubes.sh -t tethered_namespace [-p persistenter_Datenträgername] [-d] [-v] [-h]Optionen
- -d
- Löscht alle PowerCubes aus der Cognos Analytics -Serviceinstanz
- -v
- Aktiviert den ausführlichen Modus.
- -p persistenter_Datenträgername
- Der Name des persistenten Datenträgers.
- -t. Namensbereich 'tethered_namespace'
- Namensbereich, in dem Cognos Analytics bereitgestellt wird.
- -h
- Gibt die Hilfe an die Konsole aus und wird beendet.
Beispiel
Im folgenden Beispiel wird ein einzelner PVC mit dem Namen powercube1-pvc aus der Cognos Analytics -Serviceinstanz entfernt.
./remove_powercube.sh -t cat -p powercube1-pvc
Im folgenden Beispiel werden alle Cognos PowerCubes -PVCs aus der Cognos Analytics -Serviceinstanz entfernt.
./remove_powercubes.sh -t cat -d
Scriptdatei
Das Script remove_powercubes.sh ist eine Datei mit dem folgenden Inhalt:
#!/usr/bin/env bash
#
# -----------------------------------------------------------------------------
# Licensed Materials - Property of IBM
#
# IBM Cognos Products: ca
#
# (C) Copyright IBM Corp. 2023
#
# US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule
# -----------------------------------------------------------------------------
#
#
set -e
#set -x
delete_full=false
function usage {
echo $0: usage: $0 [-h] -t tethered_namespace [-p powercube to be deleted] [-d] [-v]
}
function help {
usage
echo "-h Prints help to the console and exits."
echo "-t Required. Namespace in which Cognos
Analytics is provisioned."
echo "-d Deletes all the PowerCubes from the Cognos
Analytics service instance."
echo "-p Name of the persistent volume."
echo "-v Enables verbose mode."
echo ""
exit 0
}
while getopts ":ht:p:dv" opt; do
case ${opt} in
h)
help
;;
t)
tethered_namespace=$OPTARG
;;
d)
delete_full=true
;;
p)
pvc_name=$OPTARG
;;
v)
verbose_flag="true"
;;
\?)
usage
exit 0
;;
esac
done
if [[ -z ${tethered_namespace} ]]; then
echo "A tethered namespace must be provided"
help
fi
REPORTING_POD=$(oc -n ${tethered_namespace} get pods | grep -e "^ca.*-ca-cpd-reporting-.*" | awk '{print $1}')
powercube_home=/opt/ibm/cognos/powercube
cr_name=$(oc -n ${tethered_namespace} get caserviceinstance --no-headers -o custom-columns=NAME:.metadata.name)
echo "List of existing powercube pvc added to the custom resource definition $cr_name..."
oc get caserviceinstance ${cr_name} -n ${tethered_namespace} -o jsonpath='{.spec.powerCube}'
if [ $delete_full == true ];then
echo "Deleting powercube from CR: $cr_name"
oc patch caserviceinstance ${cr_name} -n ${tethered_namespace} --type=json --patch "[{"op": "remove", "path": "/spec/powerCube"}]"
#oc exec $REPORTING_POD -c ca-cpd-reporting -- rm -r $powercube_home
else
echo ""
echo "Checking if powercube pvc exists in CA Service Instance Custom Resource ..."
getPc=$(oc get caserviceinstance ${cr_name} -o jsonpath='{.spec.powerCube}' -n ${tethered_namespace})
if [[ "${getPc[*]}" =~ $pvc_name ]]; then
echo "The pvc name to be deleted found in the CA Service Instance Custom Resource..."
else
echo "PVC to be deleted does not exist in the Custom Resource..."
exit 1
fi
oc get caserviceinstance ${cr_name} -n ${tethered_namespace} -o yaml > "$cr_name"-cr.yaml
pcBase=$(grep -n "^\s*powerCube:" "$cr_name"-cr.yaml | sed 's/:.*//')
pcValue=$(grep -n "^\s*powerCube:" "$cr_name"-cr.yaml | sed 's/:.*//' | xargs -I{} grep -n "^\s*- \s*$pvc_name$" "$cr_name"-cr.yaml | cut -d ' ' -f 1| tr -d ':')
rm "$cr_name"-cr.yaml
index=$((pcValue-pcBase-1))
if [[ -z ${index} ]]; then
echo "A powercube pvc index to be deleted not found. Please try with a valid pvc name to be removed from the customresource"
exit 1
fi
echo "Index to be deleted is $index for $pvc_name"
oc patch caserviceinstance ${cr_name} -n ${tethered_namespace} --type=json --patch "[{"op": "remove", "path": "/spec/powerCube/${index}"}]"
#oc exec $REPORTING_POD -c ca-cpd-reporting -- rm -r $powercube_home/${pvc_name}
fi
sleep 20
check_status="Completed"
# Checking status of ca reconcile action
for i in {1..240};do
caStatus=$(oc get caserviceinstance ${cr_name} -o jsonpath="{.status.caStatus}" -n ${tethered_namespace})
if [[ ${caStatus} == ${check_status} ]];then
echo "ca ${check_status} Successfully"
break
elif [[ ${caStatus} == "Failed" ]];then
echo "ca ${caStatus}!"
exit 1
fi
echo "ca Status: ${caStatus}"
sleep 30
done
echo "Delete the PVC if the project needs to be deleted"
echo "Delete PVC COMMAND : oc delete pvc ${pvc_name} -n ${tethered_namespace}"