generateNodeFiles.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. property=$1
  2. OutputDir=$2
  3. [ -f $property ] && source $property
  4. `echo $HDPNameNodeHost > $OutputDir/namenode`
  5. `echo $HDPSecondaryNameNodeHost > $OutputDir/snamenode`
  6. `echo $HDPJobTrackerHost > $OutputDir/jobtracker`
  7. `echo $HDPHBaseMasterHost > $OutputDir/hbasemaster`
  8. `echo $HDPHCatalogServerHost > $OutputDir/hcatserver`
  9. `echo $HDPGangliaCollectorHost > $OutputDir/gangliaserver`
  10. `echo $HDPNagiosServerHost > $OutputDir/nagiosserver`
  11. `echo $HDPOozieServerHost > $OutputDir/oozieserver`
  12. `echo $HDPTempletonNodeHost > $OutputDir/templetonnode`
  13. ## dashboardhost same as nagios.
  14. `echo $HDPNagiosServerHost > $OutputDir/dashboardhost`
  15. ## slaves are present in the file referred by the nodes env variable
  16. ## gateway = any slave.
  17. `cat $HDPClusterHostsFile | grep -vwE "$HDPNameNodeHost|$HDPSecondaryNameNode|$HDPJobTrackerHost|$HDPHBaseMasterHost|$HDPHCatServerHost|$HDPGangliaCollectorHost|$HDPNagiosServerHost|$HDPOozieServerHost|$HDPTempletonHost" | sort | uniq > $OutputDir/nodes`
  18. maxNodes=
  19. getLineCountofNodes()
  20. {
  21. lineCount=`wc -l $OutputDir/nodes`
  22. for words in $lineCount
  23. do
  24. maxNodes=$words
  25. break
  26. done
  27. }
  28. getLineCountofNodes
  29. [ $maxNodes == 0 ] `cat $HDPClusterHostsFile > $OutputDir/nodes`
  30. getLineCountofNodes
  31. linenum=0
  32. getNodeAtLineNum()
  33. {
  34. linenum=$((linenum+1))
  35. if [ "$linenum" -gt "$maxNodes" ]; then
  36. if [ "$maxNodes" -gt 0 ]; then
  37. linenum=1
  38. else
  39. linenum=$maxNodes
  40. fi
  41. fi
  42. }
  43. outFile=
  44. writeNodeToFile()
  45. {
  46. `awk "NR==$linenum{print;exit}" $OutputDir/nodes > $outFile`
  47. }
  48. appendNodeToFile()
  49. {
  50. `awk "NR==$linenum{print;exit}" $OutputDir/nodes >> $outFile`
  51. }
  52. ## Gateway host out
  53. outFile=$OutputDir/gateway
  54. if [ "$gwhost" != "" ]; then
  55. `echo $gwhost > $outFile`
  56. else
  57. getNodeAtLineNum
  58. writeNodeToFile
  59. fi
  60. ## Zookeeper
  61. ## zknodes = 3 or lesser if lesser slaves.
  62. outFile=$OutputDir/zknodes
  63. if [ $maxNodes -gt 3 ]; then
  64. getNodeAtLineNum
  65. writeNodeToFile
  66. getNodeAtLineNum
  67. appendNodeToFile
  68. getNodeAtLineNum
  69. appendNodeToFile
  70. else
  71. `cat $OutputDir/nodes > $outFile`
  72. fi
  73. ## HBase slaves are all slave nodes
  74. `cat $OutputDir/nodes > $OutputDir/hbasenodes`
  75. getNameNodeMountPoint()
  76. {
  77. cmd="df -klh | sed \"1 d\" | grep -vw \"/boot\" | grep -vw \"/dev\/shm\" | grep -vw \"/home\" | grep -vw \/ | awk '{ print \$(NF)}'"
  78. [ "$HDPClusterDeployUserIdentityFile" == "" ] && `ssh -o StrictHostKeyChecking=no $HDPClusterDeployUser@$HDPNameNodeHost $cmd > $1`
  79. [ "$HDPClusterDeployUserIdentityFile" != "" ] && `ssh -o StrictHostKeyChecking=no -i $HDPClusterDeployUserIdentityFile $HDPClusterDeployUser@$HDPNameNodeHost $cmd > $1`
  80. }
  81. outfile=$OutputDir/NameNodeMountPointsSuggest.out
  82. getNameNodeMountPoint $outfile