parquetUpgrade.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # Licensed Materials - Property of IBM
  3. # IBM Cognos Products: Moser
  4. # (C) Copyright IBM Corp. 2018
  5. # US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. # parquetUpgrade - A tool to migrate uploaded files and data sets from the older parquet format to newer
  7. # Usage:
  8. # Options:
  9. # -h : Url pointing to the cognos server
  10. # -n : Authentication namespace, -u and -p required if specified [optional]
  11. # -u : Namespace user, -n and -p required if specified [optional]
  12. # -p : Namespace password, -n and -u required if specified [optional]
  13. # -d : Display only mode : produces report about parquet files in the CM [optional]
  14. # -k : ignore the SSL certificate validation [optional]
  15. # -v : verbose comments output [optional]
  16. # -t : filter displayed results by task id (only works with -d)
  17. # -l : apply to only to the number of last used files [optional]
  18. # -s : store id (will apply the command down to the hierarchy starting with the provided store ID)[optional]
  19. # -m : smarts upgrade after the parquet conversion [optional]
  20. # -a : smarts version upgrade only [optional]
  21. # Example:
  22. # ./parquetUpgrade.sh -u url -n namespace -u username -p password
  23. # Notes:
  24. # - curl utility has to be present on the system
  25. ignoreSertificate=""
  26. verbose=""
  27. taskParam=""
  28. lines=""
  29. search=""
  30. while getopts "h:p:u:n:dkvt:l:s:ma" opt; do
  31. case $opt in
  32. h) server="$OPTARG"
  33. ;;
  34. p) password="$OPTARG"
  35. ;;
  36. u) user="$OPTARG"
  37. ;;
  38. n) namespace="$OPTARG"
  39. ;;
  40. d) displayonly="true"
  41. ;;
  42. k) ignoreSertificate="-k"
  43. ;;
  44. v) verbose="-v"
  45. ;;
  46. t) taskParam="&taskid=""$OPTARG"
  47. ;;
  48. l) lines="&lastNumberUsed=""$OPTARG"
  49. ;;
  50. s) search="&searchPath=storeID(%27""$OPTARG""%27)"
  51. ;;
  52. m) smartsOn="&smartsUpgrade=true"
  53. ;;
  54. a) smartsOnly="true"
  55. ;;
  56. \?) echo "Invalid option -$OPTARG" >&2
  57. ;;
  58. esac
  59. done
  60. if [[ "$server" == "" ]]; then
  61. echo "Command line arguments :"
  62. echo "-h : Url pointing to the cognos server"
  63. echo "-n : Authentication namespace, -u and -p required if specified [optional]"
  64. echo "-u : Namespace user, -n and -p required if specified [optional]"
  65. echo "-p : Namespace password, -n and -u required if specified [optional]"
  66. echo "-d : Display only mode : produces report about parquet files in the CM [optional]"
  67. echo "-k : ignore the SSL certificate validation [optional]"
  68. echo "-v : verbose comments output [optional]"
  69. echo "-t : filter displayed results by task id (only works with -d)"
  70. echo "-l : apply to only to the number of last used files [optional]"
  71. echo "-s : store id (will apply the command down to the hierarchy starting with the provided store ID)[optional]"
  72. echo "-m : smarts upgrade after the parquet conversion [optional]"
  73. echo "-a : smarts version upgrade only [optional]"
  74. exit 0
  75. fi
  76. curl ${ignoreSertificate} ${verbose} -c cookie.txt -X GET "${server}/bi/v1/login"
  77. xsrf=`grep XSRF cookie.txt | awk '{print $7}'`
  78. echo ""
  79. echo "-----" + ${xsrf}
  80. echo ""
  81. if [[ "$user" != "" && "$password" != "" && "$namespace" != "" ]]; then
  82. echo " "
  83. 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"
  84. echo " "
  85. 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"
  86. fi
  87. sleep 2
  88. echo ""
  89. if [[ "$displayonly" != "" ]]; then
  90. echo ""
  91. 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}"
  92. exit
  93. fi
  94. taskid=null
  95. if [[ "$smartsOnly" != "" ]]; then
  96. echo "smart upgrade only"
  97. 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/')
  98. else
  99. 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/')
  100. fi
  101. check=100
  102. for (( ; ; ))
  103. do
  104. 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}");
  105. echo ${out}
  106. check=${#out}
  107. echo $check
  108. if [ $check -le 26 ]; then break
  109. fi
  110. sleep 2
  111. done
  112. 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}"