123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #!/bin/bash
- # Licensed Materials - Property of IBM
- # IBM Cognos Products: Moser
- # (C) Copyright IBM Corp. 2018
- # US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- # parquetUpgrade - A tool to migrate uploaded files and data sets from the older parquet format to newer
- # Usage:
- # Options:
- # -h : Url pointing to the cognos server
- # -n : Authentication namespace, -u and -p required if specified [optional]
- # -u : Namespace user, -n and -p required if specified [optional]
- # -p : Namespace password, -n and -u required if specified [optional]
- # -d : Display only mode : produces report about parquet files in the CM [optional]
- # -k : ignore the SSL certificate validation [optional]
- # -v : verbose comments output [optional]
- # -t : filter displayed results by task id (only works with -d)
- # -l : apply to only to the number of last used files [optional]
- # -s : store id (will apply the command down to the hierarchy starting with the provided store ID)[optional]
- # -m : smarts upgrade after the parquet conversion [optional]
- # -a : smarts version upgrade only [optional]
- # Example:
- # ./parquetUpgrade.sh -u url -n namespace -u username -p password
- # Notes:
- # - curl utility has to be present on the system
- ignoreSertificate=""
- verbose=""
- taskParam=""
- lines=""
- search=""
- while getopts "h:p:u:n:dkvt:l:s:ma" opt; do
- case $opt in
- h) server="$OPTARG"
- ;;
- p) password="$OPTARG"
- ;;
- u) user="$OPTARG"
- ;;
- n) namespace="$OPTARG"
- ;;
- d) displayonly="true"
- ;;
- k) ignoreSertificate="-k"
- ;;
- v) verbose="-v"
- ;;
- t) taskParam="&taskid=""$OPTARG"
- ;;
- l) lines="&lastNumberUsed=""$OPTARG"
- ;;
- s) search="&searchPath=storeID(%27""$OPTARG""%27)"
- ;;
- m) smartsOn="&smartsUpgrade=true"
- ;;
- a) smartsOnly="true"
- ;;
- \?) echo "Invalid option -$OPTARG" >&2
- ;;
- esac
- done
- if [[ "$server" == "" ]]; then
- echo "Command line arguments :"
- echo "-h : Url pointing to the cognos server"
- echo "-n : Authentication namespace, -u and -p required if specified [optional]"
- echo "-u : Namespace user, -n and -p required if specified [optional]"
- echo "-p : Namespace password, -n and -u required if specified [optional]"
- echo "-d : Display only mode : produces report about parquet files in the CM [optional]"
- echo "-k : ignore the SSL certificate validation [optional]"
- echo "-v : verbose comments output [optional]"
- echo "-t : filter displayed results by task id (only works with -d)"
- echo "-l : apply to only to the number of last used files [optional]"
- echo "-s : store id (will apply the command down to the hierarchy starting with the provided store ID)[optional]"
- echo "-m : smarts upgrade after the parquet conversion [optional]"
- echo "-a : smarts version upgrade only [optional]"
- exit 0
- fi
- curl ${ignoreSertificate} ${verbose} -c cookie.txt -X GET "${server}/bi/v1/login"
- xsrf=`grep XSRF cookie.txt | awk '{print $7}'`
- echo ""
- echo "-----" + ${xsrf}
- echo ""
- if [[ "$user" != "" && "$password" != "" && "$namespace" != "" ]]; then
- echo " "
- curl ${ignoreSertificate} ${verbose} -b cookie.txt -X POST -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" -d '{"parameters": [{"name": "h_CAM_action","value": "logonAs"},{"name": "CAMNamespace","value": "'${namespace}'"}]}' "${server}/bi/v1/login"
- echo " "
- curl ${ignoreSertificate} ${verbose} -b cookie.txt -c cookie.txt -X POST -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" -d '{"parameters": [{"name": "h_CAM_action","value": "logonAs"},{"name": "CAMNamespace","value": "'${namespace}'"},{"name": "CAMUsername","value": "'${user}'"},{"name": "CAMPassword","value": "'${password}'"}]}' "${server}/bi/v1/login"
- fi
- sleep 2
- echo ""
- if [[ "$displayonly" != "" ]]; then
- echo ""
- curl ${ignoreSertificate} ${verbose} -b cookie.txt -X GET -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" "${server}/bi/v1/metadata/parquets??version=${search}${taskParam}${lines}"
- exit
- fi
- taskid=null
- if [[ "$smartsOnly" != "" ]]; then
- echo "smart upgrade only"
- taskid=$(curl ${ignoreSertificate} ${verbose} -b cookie.txt -X PUT -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" "${server}/bi/v1/metadata/parquets/smarts" | sed -e 's/^.*"taskID":"\([^"]*\)".*$/\1/')
- else
- taskid=$(curl ${ignoreSertificate} ${verbose} -b cookie.txt -X PUT -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" "${server}/bi/v1/metadata/parquets?version=VERSION_1${search}${lines}${smartsOn}" | sed -e 's/^.*"taskID":"\([^"]*\)".*$/\1/')
- fi
- check=100
- for (( ; ; ))
- do
- out=$(curl ${ignoreSertificate} ${verbose} -b cookie.txt -X GET -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" "${server}/bi/v1/metadata/tasks/${taskid}");
- echo ${out}
- check=${#out}
- echo $check
- if [ $check -le 26 ]; then break
- fi
- sleep 2
- done
- curl ${ignoreSertificate} ${verbose} -b cookie.txt -X GET -H "Content-Type: application/json" -H "X-XSRF-Token: ${xsrf}" "${server}/bi/v1/metadata/parquets?taskid=${taskid}"
|