configsupport.sh 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. FILE=$1
  18. OUTPUT_FILE=""
  19. # ------------------------------------------------------------------------------
  20. # Initialization and Dependency Checks
  21. # ------------------------------------------------------------------------------
  22. checkDependency() {
  23. if ! command -v xmlstarlet &> /dev/null; then
  24. echo "ERROR: 'xmlstarlet' is not installed. Please install it to run this script."
  25. echo "Exiting..."
  26. exit 1
  27. fi
  28. }
  29. validateInputFile() {
  30. if [ ! -f "$FILE" ]; then
  31. echo "Error: File '$FILE' not found. Exiting...."
  32. exit 1
  33. fi
  34. if [[ "$FILE" != *.xml ]]; then
  35. echo "The file provided is not an XML file. Exiting...."
  36. exit 1
  37. fi
  38. }
  39. init() {
  40. checkDependency
  41. validateInputFile
  42. OUTPUT_FILE="abfs-converted-config.xml"
  43. cp "$FILE" "$OUTPUT_FILE"
  44. }
  45. # ------------------------------------------------------------------------------
  46. # Global Variables & Config Mappings
  47. # ------------------------------------------------------------------------------
  48. contactTeamMsg="For any queries or support, kindly reach out to us at 'askabfs@microsoft.com'."
  49. endpoint=".dfs."
  50. # Mapping for renaming configurations
  51. declare -A renameConfigsMap=(
  52. ["autothrottling.enable"]="enable.autothrottling" #fs.azure.autothrottling.enable to fs.azure.enable.autothrottling
  53. ["rename.dir"]="rename.key" # fs.azure.atomic.rename.dir to fs.azure.atomic.rename.key
  54. ["block.blob.buffered.pread.disable"]="buffered.pread.disable" #fs.azure.block.blob.buffered.pread.disable to fs.azure.buffered.pread.disable
  55. ["fs.azure.sas"]="fs.azure.sas.fixed.token." #fs.azure.sas.CONTAINER_NAME.ACCOUNT_NAME to fs.azure.sas.fixed.token.CONTAINER_NAME.ACCOUNT_NAME
  56. ["check.block.md5"]="enable.checksum.validation" #fs.azure.check.block.md5 to fs.azure.enable.checksum.validation
  57. )
  58. # Configs not supported in ABFS
  59. unsupportedConfigsList=(
  60. "fs.azure.page.blob.dir"
  61. "fs.azure.block.blob.with.compaction.dir"
  62. "fs.azure.store.blob.md5"
  63. )
  64. # Configurations not required in ABFS Driver and can be removed
  65. obsoleteConfigsList=(
  66. "azure.authorization" #fs.azure.authorization, fs.azure.authorization.caching.enable , fs.azure.authorization.caching.maxentries, fs.azure.authorization.cacheentry.expiry.period, fs.azure.authorization.remote.service.urls
  67. "azure.selfthrottling" #fs.azure.selfthrottling.enable, fs.azure.selfthrottling.read.factor, fs.azure.selfthrottling.write.factor
  68. "azure.saskey" #fs.azure.saskey.cacheentry.expiry.period , fs.azure.saskey.usecontainersaskeyforallaccess
  69. "copyblob.retry" #fs.azure.io.copyblob.retry.min.backoff.interval, fs.azure.io.copyblob.retry.max.backoff.interval, fs.azure.io.copyblob.retry.backoff.interval, fs.azure.io.copyblob.retry.max.retries
  70. "service.urls" #fs.azure.cred.service.urls , fs.azure.delegation.token.service.urls, fs.azure.authorization.remote.service.urls
  71. "blob.metadata.key.case.sensitive" #fs.azure.blob.metadata.key.case.sensitive
  72. "cacheentry.expiry.period" #fs.azure.cacheentry.expiry.period
  73. "chmod.allowed.userlist" #fs.azure.chmod.allowed.userlist
  74. "chown.allowed.userlist" #fs.azure.chown.allowed.userlist
  75. "daemon.userlist" #fs.azure.daemon.userlist
  76. "delete.threads" #fs.azure.delete.threads
  77. "enable.kerberos.support" #fs.azure.enable.kerberos.support
  78. "flatlist.enable" #fs.azure.flatlist.enable
  79. "fsck.temp.expiry.seconds" #fs.azure.fsck.temp.expiry.seconds
  80. "local.sas.key.mode" #fs.azure.local.sas.key.mode
  81. "override.canonical.service.name" #fs.azure.override.canonical.service.name
  82. "permissions.supergroup" #fs.azure.permissions.supergroup
  83. "rename.threads" #fs.azure.rename.threads
  84. "secure.mode" #fs.azure.secure.mode
  85. "skip.metrics" #fs.azure.skip.metrics
  86. "storage.client.logging" #fs.azure.storage.client.logging
  87. "storage.emulator.account.name" #fs.azure.storage.emulator.account.name
  88. "storage.timeout" #fs.azure.storage.timeout
  89. "enable.append.support" #fs.azure.enable.append.support
  90. )
  91. # ------------------------------------------------------------------------------
  92. # User Interaction
  93. # ------------------------------------------------------------------------------
  94. promptNamespaceType() {
  95. printf "Select 'HNS' if you're migrating to ABFS driver for Hierarchical Namespace enabled account,
  96. or 'Non-HNS' if you're migrating to ABFS driver for Non-Hierarchical Namespace (FNS) account. \n"
  97. printf "WARNING: Please ensure the correct option is chosen as it will affect the configuration changes made to the file. \n"
  98. printf "If you are unsure, follow the instructions below to check from Azure Portal: \n"
  99. printf "* Go to the Azure Portal and navigate to your storage account. \n"
  100. printf "* In the left-hand menu, select 'Overview' section and look for 'Properties'. \n"
  101. printf "* Under 'Blob service', check if 'Hierarchical namespace' is enabled or disabled. \n"
  102. echo "$contactTeamMsg"
  103. select namespaceType in "HNS" "NonHNS"
  104. do
  105. case $namespaceType in
  106. HNS)
  107. xmlstarlet ed -L -i '//configuration/property[1]' -t elem -n property -v '' \
  108. -s '//configuration/property[1]' -t elem -n name -v 'fs.azure.account.hns.enabled' \
  109. -s '//configuration/property[1]' -t elem -n value -v 'true' "$OUTPUT_FILE"
  110. break
  111. ;;
  112. NonHNS)
  113. endpoint=".blob."
  114. break
  115. ;;
  116. *)
  117. echo "Invalid selection. Please try again. Exiting..."
  118. exit 1
  119. ;;
  120. esac
  121. done
  122. }
  123. # ------------------------------------------------------------------------------
  124. # Config File Transformations
  125. # ------------------------------------------------------------------------------
  126. # Stop the script if any unsupported config is found
  127. unsupportedConfigCheck() {
  128. for key in "${unsupportedConfigsList[@]}"; do
  129. if grep -q "$key" "$OUTPUT_FILE"; then
  130. echo "Remove the following configuration from file and rerun: '$key'"
  131. failure=true
  132. fi
  133. done
  134. if [ "$failure" = true ]; then
  135. echo "FAILURE: Unsupported Config Found"
  136. echo "$contactTeamMsg"
  137. echo "Exiting..."
  138. exit 1
  139. fi
  140. }
  141. # Renaming the configs
  142. renameConfigs() {
  143. for old in "${!renameConfigsMap[@]}"; do
  144. new="${renameConfigsMap[$old]}"
  145. xmlstarlet ed -L -u "//property/name[contains(., '$old')]" -x "concat(substring-before(., '$old'),
  146. '$new', substring-after(., '$old'))" "$OUTPUT_FILE"
  147. done
  148. }
  149. # Remove the obsolete configs
  150. removeObsoleteConfigs() {
  151. for key in "${obsoleteConfigsList[@]}"; do
  152. xmlstarlet ed -L -d "//property[name[contains(text(), '$key')]]" "$OUTPUT_FILE"
  153. done
  154. }
  155. # Change the endpoints to DFS if migrating to HNS
  156. changeEndpointForHNS() {
  157. if [ "$endpoint" = ".dfs." ]; then
  158. xmlstarlet ed -L -u "//property/name[contains(., '.blob.')]" -x "concat(substring-before(., '.blob.'),
  159. '$endpoint', substring-after(., '.blob.'))" "$OUTPUT_FILE"
  160. fi
  161. }
  162. # Change the value of fs.defaultFS
  163. handleDefaultFSValue() {
  164. if xmlstarlet sel -t -v "//property[name='fs.defaultFS']/value" "$OUTPUT_FILE" | grep -q "."; then
  165. if xmlstarlet sel -t -v "//property[name='fs.defaultFS']/value" "$OUTPUT_FILE" | grep -q ".blob."; then
  166. xmlstarlet ed -L -u "//property[name='fs.defaultFS']/value" -x "concat('abfs', substring-before(substring-after(., 'wasb'), '@'),
  167. '@', substring-before(substring-after(., '@'), '.blob.'), '$endpoint', 'core.windows.net')" "$OUTPUT_FILE"
  168. else
  169. echo "ERROR: 'fs.defaultFS' does not have 'Blob' as endpoint. Exiting..."
  170. echo "$contactTeamMsg"
  171. exit 1
  172. fi
  173. fi
  174. }
  175. # ------------------------------------------------------------------------------
  176. # Script Execution
  177. # ------------------------------------------------------------------------------
  178. init
  179. promptNamespaceType
  180. unsupportedConfigCheck
  181. removeObsoleteConfigs
  182. renameConfigs
  183. changeEndpointForHNS
  184. handleDefaultFSValue
  185. # Clean up any <property> blocks with empty <name> tags
  186. xmlstarlet ed -L -d "//property[not(name) or name='']" "$OUTPUT_FILE"
  187. echo "Updated file: $OUTPUT_FILE"