hue_change_dashboard_owner.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #!/bin/bash
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with 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. #Changes owner of Search Dashboard
  18. PARCEL_DIR=/opt/cloudera/parcels/CDH
  19. DASHBOARD=$1
  20. NEWOWNER=$2
  21. USAGE="usage: $0 <dashboardname> <new_owner_name>"
  22. if [[ ! ${USER} =~ .*root* ]]
  23. then
  24. echo "Script must be run as root: exiting"
  25. exit 1
  26. fi
  27. if [[ -z ${NEWOWNER} ]]
  28. then
  29. echo "No new_owner_name specified:"
  30. echo ${USAGE}
  31. exit 1
  32. fi
  33. if [[ -z ${DASHBOARD} ]]
  34. then
  35. echo "No dashboard_name specified:"
  36. echo ${USAGE}
  37. exit 1
  38. fi
  39. if [ ! -d "/usr/lib/hadoop" ]
  40. then
  41. CDH_HOME=$PARCEL_DIR
  42. else
  43. CDH_HOME=/usr
  44. fi
  45. if [ -d "/var/run/cloudera-scm-agent/process" ]
  46. then
  47. HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -1 /var/run/cloudera-scm-agent/process | grep HUE_SERVER | sort -n | tail -1 `"
  48. else
  49. HUE_CONF_DIR="/etc/hue/conf"
  50. fi
  51. if [ -d "${CDH_HOME}/lib/hue/build/env/bin" ]
  52. then
  53. COMMAND="${CDH_HOME}/lib/hue/build/env/bin/hue shell"
  54. else
  55. COMMAND="${CDH_HOME}/share/hue/build/env/bin/hue shell"
  56. fi
  57. ORACLE_HOME=/opt/cloudera/parcels/ORACLE_INSTANT_CLIENT/instantclient_11_2/
  58. LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ORACLE_HOME}
  59. export CDH_HOME HUE_CONF_DIR ORACLE_HOME LD_LIBRARY_PATH COMMAND
  60. echo "HUE_CONF_DIR: ${HUE_CONF_DIR}"
  61. echo "COMMAND: ${COMMAND}"
  62. ${COMMAND} <<EOF
  63. dashboard = "${DASHBOARD}"
  64. newowner = "${NEWOWNER}"
  65. from django.contrib.auth.models import User
  66. from search.models import Collection
  67. user = User.objects.get(username=newowner)
  68. #for collection in Collection.objects.filter(name=dashboard):
  69. #collection = Collection.objects.get(name=dashboard)
  70. for collection in Collection.objects.filter(name=dashboard):
  71. print "Changing owner of colection(%s) from user(%s) to user(%s)" % (collection.name, collection.owner, user.username)
  72. collection.owner = user
  73. collection.save()
  74. #collection = Collection.objects.get(name=dashboard)
  75. for collection in Collection.objects.filter(name=dashboard):
  76. print "Owner of colection(%s) is now user(%s)" % (collection.name, collection.owner)
  77. #Useful other examples:
  78. #from django.contrib.auth.models import User, Group
  79. #user = User.objects.get(username="tuser4")
  80. #user2 = User.objects.get(username="cconner")
  81. #from search.models import Collection
  82. #for collection in Collection.objects.filter(owner=user):
  83. # collection.name
  84. # collection.owner
  85. # print ""
  86. # collection.owner = user2
  87. # collection.save()
  88. #from django.contrib.auth.models import User, Group
  89. #dashboardname = "students"
  90. #user = User.objects.get(username="tuser4")
  91. #user2 = User.objects.get(username="cconner")
  92. #from search.models import Collection
  93. #for collection in Collection.objects.filter(name=dashboardname):
  94. # collection.name
  95. # collection.owner
  96. # print ""
  97. # collection.owner = user2
  98. # collection.save()
  99. EOF