Adding the Cognos PowerCubes PVC to the Cognos Analytics instance
Use the add_powercube.sh script add the Cognos PowerCubes PVC to the Cognos Analytics service instance.
Synopsis
./add_powercube.sh -t tethered_namespace -p persistent_volume_name [-v] [-h]Options
- -v
- Enables verbose mode.
- -p persistent_volume_name
- Name of the persistent volume.
- -t tethered_namespace
- Namespace in which Cognos Analytics is provisioned.
- -h
- Prints help to the console and exits.
Example
The following example adds the powercube1-pvc PVC to the Cognos Analytics service instance:
./add_powercube.sh -t cat -p powercube1-pvc
Script file
The add_powercube.sh script is a file with the following contents:
#!/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
function usage {
echo $0: usage: $0 [-h] -t tethered_namespace -p persistentvolume [-v]
}
function help {
usage
echo "-h Prints help to the console and exits."
echo "-t Required. Namespace in which Cognos
Analytics is provisioned."
echo "-p Name of the persistent volume."
echo "-v Enables verbose mode."
echo ""
exit 0
}
while getopts ":ht:p:v" opt; do
case ${opt} in
h)
help
;;
t)
tethered_namespace=$OPTARG
;;
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
if [[ -z ${pvc_name} ]]; then
echo "A pvc name must be provided"
help
fi
echo "Checking of the PVC: $pvc_name is in a Bound State..."
check_status="Bound"
# Checking status of pvc
for i in {1..12};do
pvcStatus=$(oc get pvc ${pvc_name} -o jsonpath="{.status.phase}" -n ${tethered_namespace})
if [[ ${pvcStatus} == ${check_status} ]];then
echo "pvc status:${pvcStatus} "
break
elif [[ ${pvcStatus} == "Pending" ]];then
echo "PVC status: ${pvcStatus}! Please check the PVC: $pvc_name Events..."
EVENTS=$(oc describe pvc $pvc_name -n ${tethered_namespace} | grep 'Events')
echo "$EVENTS"
echo "Deleting PVC $pvc_name..."
oc delete pvc $pvc_name -n $tethered_namespace
exit 1
fi
sleep 30
done
echo "Patching the CR to update the powercubes pvc...."
cr_name=$(oc -n ${tethered_namespace} get caserviceinstance --no-headers -o custom-columns=NAME:.metadata.name)
if [[ -z ${cr_name} ]]; then
echo "Unable to find CAServiceInstance CR for namespace: ${tethered_namespace}"
help
fi
echo "Checking duplicate powercube pvc names 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 already exists in the CA Service Instance Custom Resource. Please use a new pvc name or remove the duplicate pvc and try again"
echo "Delete PVC COMMAND : oc delete pvc ${pvc_name} -n ${tethered_namespace}"
exit 1
fi
echo "Adding powercube pvc name: ${pvc_name} to the Custom Resource ${cr_name}..."
if [[ -z ${getPc} || ${getPc} == null || ${getPc} == "" ]];then
oc patch caserviceinstance ${cr_name} --type merge -p "{\"spec\":{\"powerCube\":[\"${pvc_name}\"]}}" -n ${tethered_namespace}
else
oc patch caserviceinstance ${cr_name} -n ${tethered_namespace} --type=json --patch "[{"op": "add", "path": "/spec/powerCube/-", "value": \"${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}!"
echo "Deleting the powercube pvc value from custom resource to revert changes done..."
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 ':')
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}"}]"
exit 1
fi
echo "ca Status: ${caStatus}"
sleep 30
done