upgrade.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. """
  3. Licensed to the Apache Software Foundation (ASF) under one
  4. or more contributor license agreements. See the NOTICE file
  5. distributed with this work for additional information
  6. regarding copyright ownership. The ASF licenses this file
  7. to you under the Apache License, Version 2.0 (the
  8. "License"); you may not use this file except in compliance
  9. with the License. You may obtain a copy of the License at
  10. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing, software
  12. distributed under the License is distributed on an "AS IS" BASIS,
  13. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. See the License for the specific language governing permissions and
  15. limitations under the License.
  16. """
  17. import os
  18. from resource_management.core.resources.system import Execute
  19. from resource_management.libraries.functions import format
  20. from resource_management.libraries.functions import Direction
  21. from resource_management.core.exceptions import Fail
  22. from resource_management.core.logger import Logger
  23. def run_migration(env, upgrade_type):
  24. """
  25. If the acl migration script is present, then run it for either upgrade or downgrade.
  26. That script was introduced in HDP 2.3.4.0 and requires stopping all Kafka brokers first.
  27. Requires configs to be present.
  28. :param env: Environment.
  29. :param upgrade_type: "rolling" or "nonrolling
  30. """
  31. import params
  32. if upgrade_type is None:
  33. raise Fail('Parameter "upgrade_type" is missing.')
  34. if params.upgrade_direction is None:
  35. raise Fail('Parameter "upgrade_direction" is missing.')
  36. if params.upgrade_direction == Direction.DOWNGRADE and params.downgrade_from_version is None:
  37. raise Fail('Parameter "downgrade_from_version" is missing.')
  38. if not params.security_enabled:
  39. Logger.info("Skip running the Kafka ACL migration script since cluster security is not enabled.")
  40. return
  41. Logger.info("Upgrade type: {0}, direction: {1}".format(str(upgrade_type), params.upgrade_direction))
  42. # If the schema upgrade script exists in the version upgrading to, then attempt to upgrade/downgrade it while still using the present bits.
  43. kafka_acls_script = None
  44. command_suffix = ""
  45. if params.upgrade_direction == Direction.UPGRADE:
  46. kafka_acls_script = format("{stack_root}/{version}/kafka/bin/kafka-acls.sh")
  47. command_suffix = "--upgradeAcls"
  48. elif params.upgrade_direction == Direction.DOWNGRADE:
  49. kafka_acls_script = format("{stack_root}/{downgrade_from_version}/kafka/bin/kafka-acls.sh")
  50. command_suffix = "--downgradeAcls"
  51. if kafka_acls_script is not None:
  52. if os.path.exists(kafka_acls_script):
  53. Logger.info("Found Kafka acls script: {0}".format(kafka_acls_script))
  54. if params.zookeeper_connect is None:
  55. raise Fail("Could not retrieve property kafka-broker/zookeeper.connect")
  56. acls_command = "{0} --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect={1} {2}".\
  57. format(kafka_acls_script, params.zookeeper_connect, command_suffix)
  58. Execute(acls_command,
  59. user=params.kafka_user,
  60. logoutput=True)
  61. else:
  62. Logger.info("Did not find Kafka acls script: {0}".format(kafka_acls_script))