solr.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. from resource_management import *
  18. from resource_management.libraries.functions import conf_select
  19. import sys
  20. import os
  21. def solr(type = None, upgrade_type=None):
  22. import params
  23. if type == 'server':
  24. effective_version = params.iop_stack_version if upgrade_type is None else format_hdp_stack_version(params.version)
  25. params.HdfsResource(params.solr_hdfs_home_dir,
  26. type="directory",
  27. action="create_on_execute",
  28. owner=params.solr_user,
  29. mode=params.solr_hdfs_user_mode
  30. )
  31. params.HdfsResource(None, action="execute")
  32. Directory([params.log_dir,params.pid_dir,params.solr_conf_dir],
  33. mode=0755,
  34. cd_access='a',
  35. owner=params.solr_user,
  36. recursive=True,
  37. group=params.user_group
  38. )
  39. XmlConfig("solr-site.xml",
  40. conf_dir=params.solr_conf_dir,
  41. configurations=params.solr_site,
  42. configuration_attributes=params.config['configuration_attributes']['solr-site'],
  43. owner=params.solr_user,
  44. group=params.user_group,
  45. mode=0644
  46. )
  47. File(format("{solr_conf_dir}/solr.in.sh"),
  48. content=InlineTemplate(params.solr_in_sh_template),
  49. owner=params.solr_user,
  50. group=params.user_group
  51. )
  52. File(format("{solr_conf_dir}/log4j.properties"),
  53. mode=0644,
  54. group=params.user_group,
  55. owner=params.solr_user,
  56. content=params.log4j_props
  57. )
  58. File(format("{solr_conf_dir}/log4j.properties"),
  59. mode=0644,
  60. group=params.user_group,
  61. owner=params.solr_user,
  62. content=params.log4j_props
  63. )
  64. Directory(params.lib_dir,
  65. mode=0755,
  66. cd_access='a',
  67. owner=params.solr_user,
  68. recursive=True,
  69. group=params.user_group
  70. )
  71. if effective_version is not None and effective_version != "" and compare_versions(effective_version, '4.2.0.0') >= 0:
  72. File(format("{lib_dir}/solr.xml"),
  73. mode=0644,
  74. group=params.user_group,
  75. owner=params.solr_user,
  76. content=Template("solr.xml.j2")
  77. )
  78. else:
  79. Directory(format("{lib_dir}/data"),
  80. owner=params.solr_user,
  81. recursive=True,
  82. group=params.user_group
  83. )
  84. File(format("{lib_dir}/data/solr.xml"),
  85. mode=0644,
  86. group=params.user_group,
  87. owner=params.solr_user,
  88. content=Template("solr.xml.j2")
  89. )
  90. #solr-webapp is temp dir, need to own by solr in order for it to wirte temp files into.
  91. Directory(format("{solr_home}/server/solr-webapp"),
  92. owner=params.solr_user,
  93. recursive=True,
  94. )
  95. elif type == '4103':
  96. solr41_conf_dir = "/usr/iop/4.1.0.0/solr/conf"
  97. solr41_etc_dir="/etc/solr/4.1.0.0/0"
  98. if not os.path.exists(solr41_etc_dir):
  99. Execute("mkdir -p /etc/solr/4.1.0.0/0")
  100. content_path=solr41_conf_dir
  101. if not os.path.isfile("/usr/iop/4.1.0.0/solr/conf/solr.in.sh"):
  102. content_path = "/etc/solr/conf.backup"
  103. for each in os.listdir(content_path):
  104. File(os.path.join(solr41_etc_dir, each),
  105. owner=params.solr_user,
  106. content = StaticFile(os.path.join(content_path,each)))
  107. if not os.path.islink(solr41_conf_dir):
  108. Directory(solr41_conf_dir,
  109. action="delete",
  110. recursive=True)
  111. if os.path.islink(solr41_conf_dir):
  112. os.unlink(solr41_conf_dir)
  113. if not os.path.islink(solr41_conf_dir):
  114. Link(solr41_conf_dir,
  115. to=solr41_etc_dir
  116. )
  117. conf_select.select(params.stack_name, "solr", "4.1.0.0")