You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bigtop.apache.org by iw...@apache.org on 2022/10/07 12:21:38 UTC

[bigtop] branch master updated: BIGTOP-3831: Introduce bigtop-select rpm package to Bigtop (#1030)

This is an automated email from the ASF dual-hosted git repository.

iwasakims pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bigtop.git


The following commit(s) were added to refs/heads/master by this push:
     new 31ea9019 BIGTOP-3831: Introduce bigtop-select rpm package to Bigtop (#1030)
31ea9019 is described below

commit 31ea9019beb45781c192296833da1109a6da9ea1
Author: timyuer <52...@qq.com>
AuthorDate: Fri Oct 7 20:21:32 2022 +0800

    BIGTOP-3831: Introduce bigtop-select rpm package to Bigtop (#1030)
---
 bigtop-packages/src/common/bigtop-select/LICENSE   | 202 ++++++++++++
 .../src/common/bigtop-select/bigtop-select         | 360 +++++++++++++++++++++
 .../src/common/bigtop-select/conf-select           | 223 +++++++++++++
 .../src/common/bigtop-select/install_select.sh     |  76 +++++
 .../src/rpm/bigtop-select/RPMS/.gitignore          |   1 +
 .../src/rpm/bigtop-select/SPECS/.gitignore         |   1 +
 .../src/rpm/bigtop-select/SPECS/bigtop-select.spec |  75 +++++
 bigtop.bom                                         |   6 +
 8 files changed, 944 insertions(+)

diff --git a/bigtop-packages/src/common/bigtop-select/LICENSE b/bigtop-packages/src/common/bigtop-select/LICENSE
new file mode 100644
index 00000000..d6456956
--- /dev/null
+++ b/bigtop-packages/src/common/bigtop-select/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/bigtop-packages/src/common/bigtop-select/bigtop-select b/bigtop-packages/src/common/bigtop-select/bigtop-select
new file mode 100644
index 00000000..a99b80a1
--- /dev/null
+++ b/bigtop-packages/src/common/bigtop-select/bigtop-select
@@ -0,0 +1,360 @@
+#!/usr/bin/env python2
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import optparse
+import copy
+import os
+import re
+import sys
+
+# The global prefix and current directory
+root = "/usr/bigtop"
+bigtop_version = "3.2.0"
+current = root + "/current"
+lib_root = "/usr/lib"
+bin_directory = "/usr/bin"
+version_regex = re.compile('[-.]')
+
+spark_wrapper_scripts = ["run-example", "pyspark", "spark-class", "sparkR", "spark-shell", "spark-sql", "spark-submit"]
+
+# The packages and where in the release they should point to
+leaves = {
+           "hadoop-client": "hadoop",
+           "hadoop-hdfs-client": "hadoop-hdfs",
+           "hadoop-hdfs-datanode": "hadoop-hdfs",
+           "hadoop-hdfs-journalnode": "hadoop-hdfs",
+           "hadoop-hdfs-namenode": "hadoop-hdfs",
+           "hadoop-hdfs-secondarynamenode": "hadoop-hdfs",
+           "hadoop-hdfs-zkfc": "hadoop-hdfs",
+           "hadoop-yarn-client": "hadoop-yarn",
+           "hadoop-yarn-resourcemanager": "hadoop-yarn",
+           "hadoop-yarn-nodemanager": "hadoop-yarn",
+           "hadoop-mapreduce-client": "hadoop-mapreduce",
+           "hadoop-mapreduce-historyserver": "hadoop-mapreduce",
+           "hbase-client": "hbase",
+           "hbase-master": "hbase",
+           "hbase-regionserver": "hbase",
+           "tez-client": "tez",
+           "hive-client": "hive",
+           "hive-metastore": "hive",
+           "hive-server2": "hive",
+           "hive-webhcat": "hive-hcatalog",
+           "kafka-broker": "kafka",
+           "oozie-client": "oozie",
+           "oozie-server": "oozie",
+           "phoenix-client": "phoenix",
+           "phoenix-server": "phoenix",
+           "zeppelin-server": "zeppelin",
+           "zookeeper-client": "zookeeper",
+           "zookeeper-server": "zookeeper",
+           "solr-server" : "solr",
+           "flink-client" : "flink",
+           "flink-historyserver" : "flink",
+           "spark-client" : "spark",
+           "spark-thriftserver" : "spark",
+           "spark-historyserver" : "spark"
+}
+
+# Define the aliases and the list of leaves they correspond to
+aliases = {
+  "all": leaves.keys(),
+  "client" : ["hadoop-client",
+              "hbase-client",
+              "tez-client",
+              "hive-client",
+              "oozie-client",
+              "phoenix-client",
+              "zookeeper-client",
+              "flink-client",
+              "spark-client"],
+  "hadoop-hdfs-server": ["hadoop-hdfs-datanode",
+                         "hadoop-hdfs-journalnode",
+                         "hadoop-hdfs-namenode",
+                         "hadoop-hdfs-zkfc",
+                         "hadoop-hdfs-secondarynamenode"],
+  "hadoop-mapreduce-server": ["hadoop-mapreduce-historyserver"],
+  "hadoop-yarn-server": ["hadoop-yarn-resourcemanager",
+                         "hadoop-yarn-nodemanager"],
+  "hive-server": ["hive-metastore",
+                  "hive-server2",
+                  "hive-webhcat"],
+}
+
+locked_contexts = {
+  "hadoop-client": [("hadoop-hdfs-client", "hadoop-hdfs"),
+                    ("hadoop-yarn-client", "hadoop-yarn"),
+                    ("hadoop-mapreduce-client", "hadoop-mapreduce"),
+                    ("hive-client", "hive"),
+                    ("tez-client", "tez"),
+                    ("spark-client", "spark")]
+}
+
+command_symlinks = {
+  "hadoop" : "hadoop-client/bin/hadoop",
+  "hdfs" : "hadoop-hdfs-client/bin/hdfs",
+  "yarn" : "hadoop-yarn-client/bin/yarn",
+  "mapred" : "hadoop-mapreduce-client/bin/mapred",
+  "hbase" : "hbase-client/bin/hbase",
+  "beeline" : "hive-client/bin/beeline",
+  "hive" : "hive-client/bin/hive",
+  "hiveserver2" : "hive-server2/bin/hiveserver2",
+  "hcat" : "hive-webhcat/bin/hcat",
+  "zookeeper-client" : "zookeeper-client/../../bin/zookeeper-client",
+  "zookeeper-server" : "zookeeper-server/../../bin/zookeeper-server",
+  "zookeeper-server-cleanup" : "zookeeper-server/../../bin/zookeeper-server-cleanup",
+  "phoenix-sqlline" : "phoenix-client/bin/sqlline.py",
+  "phoenix-sqlline-thin" : "phoenix-client/bin/sqlline-thin.py",
+  "phoenix-psql" : "phoenix-client/bin/psql.py",
+  "phoenix-queryserver" : "phoenix-server/bin/queryserver.py",
+  "oozie" : "oozie-client/bin/oozie",
+  "oozied.sh" : "oozie-server/bin/oozied.sh",
+  "flink" : "flink-client/bin/flink",
+  "run-example" : "spark-client/bin/run-example",
+  "spark-class" : "spark-client/bin/spark-class",
+  "spark-shell" : "spark-client/bin/spark-shell",
+  "spark-sql" : "spark-client/bin/spark-sql",
+  "spark-submit" : "spark-client/bin/spark-submit",
+  "pyspark" : "spark-client/bin/pyspark"
+}
+
+
+# Given a package or alias name, get the full list of packages
+def getPackages( name ):
+  if name == None:
+    return leaves.keys()
+  if name in aliases:
+    return aliases[name]
+  if name in leaves:
+    return [ name ]
+
+  print("ERROR: Invalid package - " + name)
+  print('')
+  printPackages()
+  sys.exit(1)
+
+# Print the status of each of the given packages
+def listPackages( packages ):
+  if packages == None:
+    packages = leaves
+
+  packages.sort()
+  for pkg in packages:
+    linkname = current + "/" + pkg
+    if os.path.isdir(linkname):
+      print(pkg + " - " +
+             os.path.basename(os.path.dirname(os.path.dirname(os.path.dirname(os.readlink(linkname))))))
+    else:
+      print(pkg + " - None")
+
+# Print the avaialable package names
+def printPackages():
+  packages = leaves.keys()
+  packages.sort()
+  print("Packages:")
+  for pkg in packages:
+     print(" " + pkg)
+  groups = aliases.keys()
+  groups.sort()
+  print("Aliases:")
+  for pkg in groups:
+    print(" " + pkg)
+
+#Print whether given package is supported or not
+def isSupportedPacakge(package):
+    packages = leaves.keys()
+    if package in packages:
+      print("%s" % package)
+    else:
+      print(None)
+      sys.exit(1)
+
+# Print the installed packages
+def printVersions():
+  result = {}
+  for f in os.listdir(root):
+    if f not in [".", "..", "current", "share", "lost+found"]:
+      try:
+        result[tuple(map(int, version_regex.split(f)))] = f
+      except ValueError:
+        print("ERROR: Unexpected file/directory found in %s: %s" % (root, f))
+        sys.exit(1)
+
+  keys = result.keys()
+  keys.sort()
+  for k in keys:
+     print(result[k])
+
+# Set the list of packages to the given version
+def setPackages(packages, version, rpm_mode):
+  if packages == None or version == None:
+    print("ERROR: 'set' command must give both package and version")
+    print('')
+    printHelp()
+    sys.exit(1)
+
+  target = root + "/" + version + lib_root
+  if not os.path.isdir(target):
+    print("ERROR: Invalid version " + version)
+    print('')
+    print("Valid choices:")
+    printVersions()
+    sys.exit(1)
+
+  if not os.path.isdir(current):
+    os.mkdir(current, 0755)
+
+  packages.sort()
+  for pkg in packages:
+    linkname = current + "/" + pkg
+    if os.path.islink(linkname) and rpm_mode:
+      continue
+    elif os.path.islink(linkname):
+      os.remove(linkname)
+
+    if os.path.exists(linkname):
+      print("symlink target %s for %s already exists and it is not a symlink." % (linkname, leaves[pkg]))
+      sys.exit(1)
+
+    os.symlink(target + "/" + leaves[pkg], linkname)
+    if pkg in locked_contexts:
+      for (kid, dir) in locked_contexts[pkg]:
+        linkname = current + "/" + kid
+        if os.path.islink(linkname):
+          os.remove(linkname)
+        os.symlink(target + "/" + dir, linkname)
+
+# Create command symlinks
+def createCommandSymlinks(packages, rpm_mode):
+  work_packages = copy.copy(packages)
+  for pkg in packages:
+    if pkg in locked_contexts:
+      for (child, dir) in locked_contexts[pkg]:
+        work_packages.append(child)
+  for symlink in command_symlinks:
+    pkg = command_symlinks[symlink].split('/')[0]
+    filename = bin_directory + "/" + symlink
+    target = current + "/" + command_symlinks[symlink]
+    if rpm_mode and os.path.lexists(filename):
+      continue
+    if pkg in work_packages:
+      if not os.path.lexists(filename):
+        os.symlink(target, filename)
+      elif os.path.islink(filename):
+        old_value = os.readlink(filename)
+        if old_value != target:
+          print("WARNING: Replacing link", filename, "from", old_value)
+          os.remove(filename)
+          os.symlink(target, filename)
+      else:
+        if os.path.basename(filename) not in spark_wrapper_scripts:
+          print("ERROR:", filename, "is a regular file instead of symlink.")
+          print('')
+          print("Please ensure that the BIGTOP 2.1 (and earlier) packages are")
+          print("removed.")
+
+# Do a sanity check on the tables
+def sanityCheckTables():
+  for alias in aliases:
+    for child in aliases[alias]:
+      if not child in leaves:
+        print("ERROR: Alias", alias, "has bad child", child)
+        sys.exit(1)
+  locked = set()
+  for parent in locked_contexts:
+    for (kid, dir) in locked_contexts[parent]:
+      locked.add(kid)
+  for symlink in command_symlinks:
+    parts = command_symlinks[symlink].split('/')
+    if not parts[0] in leaves and not parts[0] in locked:
+      print("ERROR: command symlink", symlink, "points to an invalid package",\
+            parts[0])
+      sys.exit(1)
+
+def printHelp():
+  print("""
+usage: distro-select [-h] [<command>] [<package>] [<version>]
+
+Set the selected version of BIGTOP.
+
+positional arguments:
+  <command>   One of set, status, versions, or packages
+  <package>   the package name to set
+  <version>   the BIGTOP version to set
+
+optional arguments:
+  -h, --help  show this help message and exit
+  -r, --rpm-mode  if true checks if there is symlink exists and creates the symlink if it doesn't
+
+Commands:
+  set      : set the package to a specified version
+  status   : show the version of the package
+  versions : show the currently installed versions
+  packages : show the individual package names
+  supports : Check distro-select supports a specific package
+""")
+
+def checkCommandParameters(cmd, realLen, rightLen):
+  if realLen != rightLen:
+    print("ERROR:", cmd, "command takes", rightLen - 1,\
+          "parameters, instead of", realLen - 1)
+    printHelp()
+    sys.exit(1)
+
+ ############################
+ #
+ # Start of main
+
+sanityCheckTables()
+
+parser = optparse.OptionParser(add_help_option=False)
+parser.add_option("-h", "--help", action="store_true", dest="help",
+                  help="print help")
+parser.add_option("-v", "--version", action="store_true", dest="version",
+                  help="print bigtop version")
+parser.add_option("-r", "--rpm-mode", action="store_true", dest="rpm_mode", default=False,
+                  help="if true checks if there is symlink exists and creates the symlink if it doesn't")
+(options, args) = parser.parse_args()
+
+if options.help:
+  printHelp()
+elif options.version:
+  print(bigtop_version)
+else:
+  if len(args) == 0 or args[0] == 'status':
+    if len(args) > 1:
+      listPackages(getPackages(args[1]))
+    else:
+      listPackages(getPackages("all"))
+  elif args[0] == "set":
+    checkCommandParameters('set', len(args), 3)
+    pkgs = getPackages(args[1])
+    setPackages(pkgs, args[2], options.rpm_mode)
+    createCommandSymlinks(pkgs, options.rpm_mode)
+  elif args[0] == "versions":
+    checkCommandParameters('versions', len(args), 1)
+    printVersions()
+  elif args[0] == "packages":
+    checkCommandParameters('packages', len(args), 1)
+    printPackages()
+  elif args[0] == "supports":
+    checkCommandParameters('support', len(args), 2)
+    isSupportedPacakge(args[1])
+  else:
+    print("ERROR: Unknown command -", args[0])
+    printHelp()
+    sys.exit(1)
diff --git a/bigtop-packages/src/common/bigtop-select/conf-select b/bigtop-packages/src/common/bigtop-select/conf-select
new file mode 100644
index 00000000..52c4cc9f
--- /dev/null
+++ b/bigtop-packages/src/common/bigtop-select/conf-select
@@ -0,0 +1,223 @@
+#!/usr/bin/env python2
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import optparse
+import copy
+import os
+import re
+import sys
+import errno
+
+# The global prefix and current directory
+root = "/usr/bigtop"
+current = root + "/current"
+vconfroot = 'etc'
+lib_root = "usr/lib"
+vconf_name = "conf.dist"
+packages = ("hadoop", "hbase", "hive", "hive-hcatalog",
+            "kafka", "oozie", "spark", "tez",
+            "zookeeper", "zeppelin", "flink", "solr")
+''' conf link
+/usr/bigtop/3.2.0/usr/lib/${pname}/conf -> /etc/${pname}/conf -> /etc/alternatives/${pname}-conf -> /usr/bigtop/3.2.0/etc/${pname}/conf.dist.0
+'''
+
+
+def printHelp():
+    print("""
+usage: conf-select [-h] [<command>] --package --stack-version --conf-version
+arguments:
+  <command>          One of create-conf-dir, set-conf-dir
+  <--package>        package name to set
+  <--stack-version>  stack version number
+  <--conf-version>   conf version to set
+optional arguments:
+  -h, --help  show this help message and exit
+Commands:
+  set-conf-dir      : set the conf to a specified version
+  create-conf-dir   : create the specified conf directory
+  dry-run-set       : dry run for set conf
+  dry-run-create    : dry run for create conf
+""")
+
+
+def chkPkg(sver, pname):
+    '''
+    checks package name against the package tuple, check if the package directory exists and returns True
+    e.g. /usr/bigtop/3.2.0/usr/lib/zookeeper
+    '''
+    pkgdir = os.path.join(root, sver, lib_root, pname)
+    if not os.path.isdir(pkgdir) or pname not in packages:
+        print(pname + " not installed or incorrect package name")
+        sys.exit(1)
+    return True
+
+
+def chksVer(sver):
+    '''
+    returns True if the stack version number exists
+    e.g. /usr/bigtop/3.2.0/usr/lib
+    '''
+    if not os.path.isdir(os.path.join(root, sver, lib_root)):
+        print(sver + " Incorrect stack version")
+        sys.exit(1)
+    return True
+
+
+def chkPath(pname, sver, cver, method):
+    '''
+    e.g. /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.0
+    '''
+    confpath = os.path.join(root, sver, vconfroot, pname, vconf_name)
+    if cver:
+        confpath = os.path.join(root, sver, vconfroot, pname, vconf_name + '.' + cver)
+    if method == "create" and os.path.exists(confpath):
+        print(confpath+" exist already")
+        sys.exit(1)
+    if method == "set" and not os.path.exists(confpath):
+        print(confpath+" does not exist")
+        sys.exit(1)
+    return True
+
+
+def check(sver, pname, cver, method):
+    '''
+    Aggregates chksVer, chkPkg and checks if path exits.
+    Returns True if all the conditions are met
+    '''
+    chksVer(sver)
+    chkPkg(sver, pname)
+    chkPath(pname, sver, cver, method)
+
+
+def drcrtConfDir(pname, sver, cver):
+    '''
+    # Not really executing
+    # e.g. /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.0
+    '''
+    chksVer(sver)
+    chkPkg(sver, pname)
+    for confmapkey, confmapval in confmap.items():
+        path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name)
+        if cver:
+            path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name+'.'+cver)
+        print(path)
+
+
+def crtConfDir(pname, sver, cver):
+    '''
+    e.g. /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.0
+    '''
+    path = os.path.join(root, sver, vconfroot, pname, vconf_name)
+    check(sver, pname, cver, "create")
+    for confmapkey, confmapval in confmap.items():
+        path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name)
+        if cver:
+            path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name+'.'+cver)
+        try:
+            os.makedirs(path)
+            print(path)
+        except OSError as exc:
+            if exc.errno == errno.EACCES:
+                print("Permission denied")
+
+
+def drsetConfDir(pname, sver):
+    '''
+    Not really executing
+    '''
+    chksVer(sver)
+    chkPkg(sver, pname)
+    for confmapkey, confmapval in confmap.items():
+        # e.g. /usr/bigtop/3.2.0/usr/lib/hive/conf
+        confdir = os.path.join(root, sver, lib_root, pname, confmapval)
+        if os.path.exists(confdir) and os.path.islink(confdir):
+            print(confdir)
+        else:
+            print(confdir+" does not exist")
+            sys.exit(1)
+
+
+def setConfDir(pname, sver, cver):
+    '''
+    e.g. /usr/bigtop/3.2.0/usr/lib/zookeeper/conf -> /etc/zookeeper/conf -> /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.0
+    '''
+    check(sver, pname, cver, "set")
+    for confmapkey, confmapval in confmap.items():
+        # e.g. /usr/bigtop/3.2.0/etc/zookeeper/conf.dist.0
+        path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name)
+        if cver:
+            path = os.path.join(root, sver, vconfroot, confmapkey, vconf_name+'.'+cver)
+        # e.g. /usr/bigtop/3.2.0/usr/lib/zookeeper/conf
+        confdir = os.path.join(root, sver, lib_root, pname, confmapval)
+
+        if os.path.exists(confdir) and not os.path.islink(confdir):
+            raise Exception("Expected confdir %s to be a symlink." % confdir)
+
+        if os.path.islink(confdir) and not os.path.exists(confdir):
+            os.remove(confdir)
+
+        if os.path.exists(confdir):
+            if path == os.readlink(confdir):
+                return
+            else:
+                os.remove(confdir)
+
+        os.symlink('/etc/{0}/conf'.format(pname), confdir)
+        print(confdir + " -> " + '/etc/{0}/conf'.format(pname))
+        print('alternatives --install /etc/{0}/conf {0}-conf {1} 30'.format(pname, path))
+        os.system('alternatives --install /etc/{0}/conf {0}-conf {1} 30'.format(pname, path))
+        os.system('alternatives --set {0}-conf {1}'.format(pname, path))
+        print('/etc/{0}/conf'.format(pname) + " -> " + path)
+
+
+# Start of main
+parser = optparse.OptionParser(add_help_option=False)
+parser.add_option("-h", "--help", action="store_true", dest="help",
+                  help="print help")
+parser.add_option("-p", "--package", action="store", dest="pname",
+                  help="package name")
+parser.add_option("-s", "--stack-version", action="store", dest="sver",
+                  help="stack verison number")
+parser.add_option("-c", "--conf-version", action="store", dest="cver",
+                  help="conf verison number", default=None)
+
+(options, args) = parser.parse_args()
+'''default conf mapping'''
+confmap = {options.pname: "conf"}
+'''conf mapping if the pkg name is hive-hcatalog'''
+if options.pname == "hive-hcatalog":
+    confmap = {"hive-hcatalog": "etc/hcatalog",
+               "hive-webhcat": "etc/webhcat"}
+
+
+
+if options.help or len(args) == 0:
+    printHelp()
+elif not options.pname or not options.sver:
+    parser.error("Invalid option")
+    printHelp()
+elif args[0] == 'create-conf-dir':
+    crtConfDir(options.pname, options.sver, options.cver)
+elif args[0] == 'set-conf-dir':
+    setConfDir(options.pname, options.sver, options.cver)
+elif args[0] == 'dry-run-set':
+    drsetConfDir(options.pname, options.sver)
+elif args[0] == 'dry-run-create':
+    drcrtConfDir(options.pname, options.sver, options.cver)
+else:
+    printHelp()
diff --git a/bigtop-packages/src/common/bigtop-select/install_select.sh b/bigtop-packages/src/common/bigtop-select/install_select.sh
new file mode 100644
index 00000000..fbbabb21
--- /dev/null
+++ b/bigtop-packages/src/common/bigtop-select/install_select.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -ex
+
+usage() {
+  echo "
+usage: $0 <options>
+  Required not-so-options:
+     --distro-dir=DIR            path to distro specific files (debian/RPM)
+     --build-dir=DIR             path to build directory
+     --prefix=PREFIX             path to install into
+  "
+  exit 1
+}
+OPTS=$(getopt \
+  -n $0 \
+  -o '' \
+  -l 'prefix:' \
+  -l 'distro-dir:' \
+  -l 'build-dir:' \
+  -- "$@")
+if [ $? != 0 ] ; then
+    usage
+fi
+eval set -- "$OPTS"
+while true ; do
+    case "$1" in
+        --prefix)
+        PREFIX=$2 ; shift 2
+        ;;
+        --distro-dir)
+        DISTRO_DIR=$2 ; shift 2
+        ;;
+        --build-dir)
+        BUILD_DIR=$2 ; shift 2
+        ;;
+        --)
+        shift ; break
+        ;;
+        *)
+        echo "Unknown option: $1"
+        usage
+        exit 1
+        ;;
+    esac
+done
+
+DIST_DIR=${BUILD_DIR}/dist
+MAN_DIR=${MAN_DIR:-/usr/share/man/man1}
+DOC_DIR=${DOC_DIR:-/usr/share/doc/bigtop-select}
+LIB_DIR=${LIB_DIR:-/usr/lib/bigtop-select}
+BIN_DIR=${BIN_DIR:-/usr/bin}
+CONF_DIR=${CONF_DIR:-/etc/bigtop-select/conf.dist}
+stack_selector=bigtop-select
+conf_selector=conf-select
+
+# Install packages
+install -d -p -m 755 $PREFIX${LIB_DIR}/
+# install -d -p -m 555 $PREFIX${BIN_DIR}/
+install -p -m 755 ${DISTRO_DIR}/${conf_selector} $PREFIX${LIB_DIR}/
+install -p -m 755 ${DISTRO_DIR}/${stack_selector} $PREFIX${LIB_DIR}/
diff --git a/bigtop-packages/src/rpm/bigtop-select/RPMS/.gitignore b/bigtop-packages/src/rpm/bigtop-select/RPMS/.gitignore
new file mode 100644
index 00000000..1ab8c792
--- /dev/null
+++ b/bigtop-packages/src/rpm/bigtop-select/RPMS/.gitignore
@@ -0,0 +1 @@
+repodata
diff --git a/bigtop-packages/src/rpm/bigtop-select/SPECS/.gitignore b/bigtop-packages/src/rpm/bigtop-select/SPECS/.gitignore
new file mode 100644
index 00000000..1377554e
--- /dev/null
+++ b/bigtop-packages/src/rpm/bigtop-select/SPECS/.gitignore
@@ -0,0 +1 @@
+*.swp
diff --git a/bigtop-packages/src/rpm/bigtop-select/SPECS/bigtop-select.spec b/bigtop-packages/src/rpm/bigtop-select/SPECS/bigtop-select.spec
new file mode 100644
index 00000000..c0386194
--- /dev/null
+++ b/bigtop-packages/src/rpm/bigtop-select/SPECS/bigtop-select.spec
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+%define lib_dir /usr/lib/bigtop-select
+%define bin_dir /usr/bin
+
+Name: bigtop-select
+Version: %{bigtop_select_version}
+Release: %{bigtop_select_release}
+Summary: Collection of useful tools for Bigtop
+
+Group:      Applications/Engineering
+License:    ASL 2.0
+URL:        http://bigtop.apache.org/
+BuildRoot:  %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
+BuildArch:  noarch
+Source0:    install_select.sh
+Source1:    LICENSE
+Source2:    conf-select
+Source3:    bigtop-select
+Requires:   bash
+
+# "which" command is needed for a lot of projects.
+# It is part of the package "util-linux" on suse and "which" everywhere else
+%if  %{?suse_version:1}0
+Requires:  util-linux
+%else
+Requires:       which
+%endif
+
+%description
+This includes a collection of useful tools and files for Bigtop and Ambari
+
+
+%prep
+%setup -q -T -c
+install -p -m 755 %{SOURCE0} .
+install -p -m 755 %{SOURCE1} .
+install -p -m 755 %{SOURCE2} .
+install -p -m 755 %{SOURCE3} .
+
+%build
+
+
+%install
+bash %{SOURCE0} \
+  --distro-dir=${RPM_SOURCE_DIR} \
+  --build-dir=${PWD} \
+  --prefix=${RPM_BUILD_ROOT}
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+
+%files
+%defattr(-,root,root,-)
+%doc LICENSE
+
+%{lib_dir}
+#%{bin_dir}
+
+%changelog
+
diff --git a/bigtop.bom b/bigtop.bom
index eddd4a60..89da0ad0 100644
--- a/bigtop.bom
+++ b/bigtop.bom
@@ -258,6 +258,12 @@ bigtop {
       version { base = bigtop.version; pkg = base-"-SNAPSHOT"; release = 1 }
       tarball { destination = "bigtop-utils-${version.base}.tar.gz" }
     }
+    'bigtop-select' {
+      name    = "bigtop-select"
+      relNotes = "Service package for Apache Bigtop information to use Ambari"
+      version { base = bigtop.version; pkg = base-"-SNAPSHOT"; release = 1 }
+      tarball { destination = "bigtop-select-${version.base}.tar.gz" }
+    }
     'bigtop-jsvc' {
       name    = "bigtop-jsvc"
       relNotes = "Apache Common Daemon (jsvc) service package"