pacemaker.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 sys
  18. from resource_management.libraries.functions import check_process_status
  19. from resource_management.libraries.script import Script
  20. from resource_management.libraries.functions import conf_select
  21. from resource_management.libraries.functions import stack_select
  22. from resource_management.libraries.functions import format
  23. from resource_management.core.resources.system import Execute
  24. from resource_management.libraries.functions.stack_features import check_stack_feature
  25. from resource_management.libraries.functions import StackFeature
  26. from storm import storm
  27. from service import service
  28. from service_check import ServiceCheck
  29. from resource_management.libraries.functions.security_commons import build_expectations, \
  30. cached_kinit_executor, get_params_from_filesystem, validate_security_config_properties, \
  31. FILE_TYPE_JAAS_CONF
  32. class PaceMaker(Script):
  33. def get_component_name(self):
  34. return "storm-client"
  35. def install(self, env):
  36. self.install_packages(env)
  37. self.configure(env)
  38. def configure(self, env):
  39. import params
  40. env.set_params(params)
  41. storm()
  42. def pre_upgrade_restart(self, env, upgrade_type=None):
  43. import params
  44. env.set_params(params)
  45. if params.version and check_stack_feature(StackFeature.ROLLING_UPGRADE, params.version):
  46. conf_select.select(params.stack_name, "storm", params.version)
  47. stack_select.select("storm-client", params.version)
  48. def start(self, env, upgrade_type=None):
  49. import params
  50. env.set_params(params)
  51. self.configure(env)
  52. service("pacemaker", action="start")
  53. def stop(self, env, upgrade_type=None):
  54. import params
  55. env.set_params(params)
  56. service("pacemaker", action="stop")
  57. def status(self, env):
  58. import status_params
  59. env.set_params(status_params)
  60. check_process_status(status_params.pid_pacemaker)
  61. def security_status(self, env):
  62. import status_params
  63. env.set_params(status_params)
  64. if status_params.security_enabled:
  65. # Expect the following files to be available in status_params.config_dir:
  66. # storm_jaas.conf
  67. try:
  68. props_value_check = None
  69. props_empty_check = ['StormServer/keyTab', 'StormServer/principal']
  70. props_read_check = ['StormServer/keyTab']
  71. storm_env_expectations = build_expectations('storm_jaas', props_value_check, props_empty_check,
  72. props_read_check)
  73. storm_expectations = {}
  74. storm_expectations.update(storm_env_expectations)
  75. security_params = get_params_from_filesystem(status_params.conf_dir,
  76. {'storm_jaas.conf': FILE_TYPE_JAAS_CONF})
  77. result_issues = validate_security_config_properties(security_params, storm_expectations)
  78. if not result_issues: # If all validations passed successfully
  79. # Double check the dict before calling execute
  80. if ( 'storm_jaas' not in security_params
  81. or 'StormServer' not in security_params['storm_jaas']
  82. or 'keyTab' not in security_params['storm_jaas']['StormServer']
  83. or 'principal' not in security_params['storm_jaas']['StormServer']):
  84. self.put_structured_out({"securityState": "ERROR"})
  85. self.put_structured_out({"securityIssuesFound": "Keytab file or principal are not set property."})
  86. return
  87. cached_kinit_executor(status_params.kinit_path_local,
  88. status_params.storm_user,
  89. security_params['storm_jaas']['StormServer']['keyTab'],
  90. security_params['storm_jaas']['StormServer']['principal'],
  91. status_params.hostname,
  92. status_params.tmp_dir)
  93. self.put_structured_out({"securityState": "SECURED_KERBEROS"})
  94. else:
  95. issues = []
  96. for cf in result_issues:
  97. issues.append("Configuration file %s did not pass the validation. Reason: %s" % (cf, result_issues[cf]))
  98. self.put_structured_out({"securityIssuesFound": ". ".join(issues)})
  99. self.put_structured_out({"securityState": "UNSECURED"})
  100. except Exception as e:
  101. self.put_structured_out({"securityState": "ERROR"})
  102. self.put_structured_out({"securityStateErrorInfo": str(e)})
  103. else:
  104. self.put_structured_out({"securityState": "UNSECURED"})
  105. def get_log_folder(self):
  106. import params
  107. return params.log_dir
  108. def get_user(self):
  109. import params
  110. return params.storm_user
  111. if __name__ == "__main__":
  112. PaceMaker().execute()