Repository: ambari
Updated Branches:
  refs/heads/trunk e7303b1ce -> 19e972cf9


http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/ambari-metrics/ambari-metrics-timelineservice/src/main/python/amc_service.py
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/python/amc_service.py 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/amc_service.py
new file mode 100644
index 0000000..b901e5c
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/amc_service.py
@@ -0,0 +1,174 @@
+#!/usr/bin/env python
+
+'''
+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 os
+import sys
+
+from ambari_commons.ambari_service import AmbariService
+from ambari_commons.exceptions import FatalException
+from ambari_commons.os_utils import remove_file
+from ambari_commons.os_windows import SvcStatusCallback, WinServiceController
+from ambari_metrics_collector.serviceConfiguration import get_properties, 
get_value_from_properties, DEBUG_MODE_KEY, \
+  SUSPEND_START_MODE_KEY, PID_OUT_FILE, SERVER_OUT_FILE_KEY, SERVER_OUT_FILE, 
SERVICE_USERNAME_KEY, SERVICE_PASSWORD_KEY, \
+  DEFAULT_CONF_DIR, EMBEDDED_HBASE_MASTER_SERVICE
+from embedded_hbase_service import EmbeddedHBaseService
+from main import server_process_main
+
+
+class AMCollectorService(AmbariService):
+  AmbariService._svc_name_ = "AmbariMetricsCollector"
+  AmbariService._svc_display_name_ = "Ambari Metrics Collector"
+  AmbariService._svc_description_ = "Ambari Metrics Collector Service"
+
+  AmbariService._AdjustServiceVersion()
+
+  # Adds the necessary script dir(s) to the Python's modules path.
+  # Modify this as the deployed product's dir structure changes.
+  def _adjustPythonPath(self, current_dir):
+    python_path = os.path.join(current_dir, "sbin")
+    sys.path.insert(0, python_path)
+    pass
+
+  @classmethod
+  def Install(cls, startupMode = "auto", username = None, password = None, 
interactive = False,
+              perfMonIni = None, perfMonDll = None):
+    script_path = os.path.dirname(__file__.replace('/', os.sep))
+    classPath = os.path.join(script_path, cls.__module__) + "." + cls.__name__
+
+    return AmbariService.Install(classPath, startupMode, username, password, 
interactive,
+                                                    perfMonIni, perfMonDll)
+
+  def SvcDoRun(self):
+    scmStatus = SvcStatusCallback(self)
+
+    properties = get_properties()
+    self.options.debug = get_value_from_properties(properties, DEBUG_MODE_KEY, 
self.options.debug)
+    self.options.suspend_start = get_value_from_properties(properties, 
SUSPEND_START_MODE_KEY, self.options.suspend_start)
+
+    self.redirect_output_streams()
+
+    childProc = server_process_main(self.options, scmStatus)
+
+    if not self._StopOrWaitForChildProcessToFinish(childProc):
+      return
+
+    remove_file(PID_OUT_FILE)
+    pass
+
+  def _InitOptionsParser(self):
+    return init_options_parser()
+
+  def redirect_output_streams(self):
+    properties = get_properties()
+
+    outFilePath = properties[SERVER_OUT_FILE_KEY]
+    if (outFilePath is None or outFilePath == ""):
+      outFilePath = SERVER_OUT_FILE
+
+    self._RedirectOutputStreamsToFile(outFilePath)
+    pass
+
+def ctrlHandler(ctrlType):
+  AMCollectorService.DefCtrlCHandler()
+  return True
+
+def svcsetup():
+  AMCollectorService.set_ctrl_c_handler(ctrlHandler)
+
+  # we don't save password between 'setup' runs, so we can't run Install every 
time. We run 'setup' only if user and
+  # password provided or if service not installed
+  if (SERVICE_USERNAME_KEY in os.environ and SERVICE_PASSWORD_KEY in 
os.environ):
+    EmbeddedHBaseService.Install(username=os.environ[SERVICE_USERNAME_KEY], 
password=os.environ[SERVICE_PASSWORD_KEY])
+    AMCollectorService.Install(username=os.environ[SERVICE_USERNAME_KEY], 
password=os.environ[SERVICE_PASSWORD_KEY])
+  else:
+    EmbeddedHBaseService.Install()
+    AMCollectorService.Install()
+  pass
+
+#
+# Starts the Ambari Metrics Collector. The server can start as a service or 
standalone process.
+# args:
+#  options.is_process = True - start the server as a process. For now, there 
is no restrictions for the number of
+#     server instances that can run like this.
+#  options.is_process = False - start the server in normal mode, as a Windows 
service. If the Ambari Metrics Collector
+#     is not registered as a service, the function fails. By default, only one 
instance of the service can
+#     possibly run.
+#
+def start(options):
+  AMCollectorService.set_ctrl_c_handler(ctrlHandler)
+
+  if options.is_process:
+    #Run as a normal process. Invoke the ServiceMain directly.
+    childProc = server_process_main(options)
+
+    childProc.wait()
+
+    remove_file(PID_OUT_FILE)
+  else:
+    AMCollectorService.Start()
+
+#
+# Stops the Ambari Metrics Collector. Ineffective when the server is started 
as a standalone process.
+#
+def stop():
+  AMCollectorService.Stop()
+
+#
+# Prints the Ambari Metrics Collector service status.
+#
+def svcstatus(options):
+  options.exit_message = None
+
+  statusStr = AMCollectorService.QueryStatus()
+  print "Ambari Metrics Collector is " + statusStr
+
+
+def setup(options):
+  svcsetup()
+
+def init_options_parser():
+  parser = optparse.OptionParser(usage="usage: %prog action [options]", )
+  parser.add_option('--config', dest="conf_dir",
+                    default=DEFAULT_CONF_DIR,
+                    help="Configuration files directory")
+  parser.add_option('--debug', action="store_true", dest='debug', 
default=False,
+                    help="Start ambari-metrics-collector in debug mode")
+  parser.add_option('--suspend-start', action="store_true", 
dest='suspend_start', default=False,
+                    help="Freeze ambari-metrics-collector Java process at 
startup in debug mode")
+  parser.add_option('--process', action="store_true", dest='is_process', 
default=False,
+                    help="Start ambari-metrics-collector as a process, not as 
a service")
+  parser.add_option('--noembedded', action="store_true", 
dest='no_embedded_hbase', default=False,
+                    help="Don't attempt to start the HBASE services. Expect 
them to be already installed and running.")
+
+  # --help reserved for help
+  return parser
+
+
+def init_service_debug(options):
+  if options.debug:
+    sys.frozen = 'windows_exe'  # Fake py2exe so we can debug
+
+
+def ensure_hdp_service_soft_dependencies():
+  ret = 
WinServiceController.EnsureServiceIsStarted(EMBEDDED_HBASE_MASTER_SERVICE)
+  if ret != 0:
+    err = 'ERROR: Cannot start service "{0}". Error = 
{1}'.format(EMBEDDED_HBASE_MASTER_SERVICE, ret)
+    raise FatalException(1, err)

http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/ambari-metrics/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
new file mode 100644
index 0000000..a699774
--- /dev/null
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/embedded_hbase_service.py
@@ -0,0 +1,201 @@
+#!/usr/bin/env python
+
+'''
+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 os
+import win32service
+import win32api
+from win32serviceutil import RemoveService, SmartOpenService
+import winerror
+
+from ambari_commons.xml_utils import ConvertToXml
+from ambari_metrics_collector.serviceConfiguration import 
EMBEDDED_HBASE_MASTER_SERVICE, EMBEDDED_HBASE_SUBDIR, \
+  find_jdk, get_java_exe_path, build_jvm_args
+
+MASTER_JVM_ARGS = '{0} ' \
+  '"-XX:+UseConcMarkSweepGC" "-Djava.net.preferIPv4Stack=true" ' \
+  '-Dhadoop.home.dir="{1}" -Dhbase.log.dir="{2}" -Dhbase.log.file={3} 
-Dhbase.home.dir="{1}" -Dhbase.id.str="{4}" ' \
+  '-Dhbase.root.logger="INFO,DRFA" -Dhbase.security.logger="INFO,RFAS" ' \
+  '-classpath "{5}" org.apache.hadoop.hbase.master.HMaster start'
+
+#-Xmx1000m "-XX:+UseConcMarkSweepGC" "-Djava.net.preferIPv4Stack=true"
+# 
-Dhbase.log.dir="C:\test\ambari-metrics-timelineservice-0.1.0-SNAPSHOT\hbase\logs"
 -Dhbase.log.file="hbase.log" 
-Dhbase.home.dir="C:\test\ambari-metrics-timelineservice-0.1.0-SNAPSHOT\hbase" 
-Dhbase.id.str="Administrator"
+# -XX:OnOutOfMemoryError="taskkill /F /PID p" 
-Dhbase.root.logger="INFO,console" -Dhbase.security.logger="INFO,DRFAS"
+# -classpath 
"C:\test\ambari-metrics-timelineservice-0.1.0-SNAPSHOT\hbase\conf;C:\jdk1.7.0_67\lib\tools.jar;C:\test\ambari-metrics-timelineservice-0.1.0-SNAPSHOT\hbase;C:\test\ambari-metrics-timelineservice-0.1.0-SNAPSHOT\hbase\lib\*"
+# org.apache.hadoop.hbase.master.HMaster start
+def _build_master_java_args(username = None):
+  hbase_home_dir = os.path.abspath(EMBEDDED_HBASE_SUBDIR)
+  hbase_log_dir = os.path.join(os.sep, "var", "log", 
EMBEDDED_HBASE_MASTER_SERVICE)
+  hbase_log_file = "hbase.log"
+  hbase_user_id = username if username else "SYSTEM"
+
+  if not os.path.exists(hbase_log_dir):
+    os.makedirs(hbase_log_dir)
+
+  java_class_path = os.path.join(hbase_home_dir, "conf")
+  java_class_path += os.pathsep + os.path.join(find_jdk(), "lib", "tools.jar")
+  java_class_path += os.pathsep + hbase_home_dir
+  java_class_path += os.pathsep + os.path.join(hbase_home_dir, "lib", "*")
+
+  args = MASTER_JVM_ARGS.format(build_jvm_args(), hbase_home_dir, 
hbase_log_dir, hbase_log_file, hbase_user_id, java_class_path)
+
+  return args
+
+
+def _get_config_file_path():
+  config_file_path = os.path.join(os.getcwd(), EMBEDDED_HBASE_SUBDIR, "bin", 
EMBEDDED_HBASE_MASTER_SERVICE + ".xml")
+  return config_file_path
+
+class EmbeddedHBaseService:
+  _svc_name_ = EMBEDDED_HBASE_MASTER_SERVICE
+  _svc_display_name_ = "Apache Ambari Metrics " + EMBEDDED_HBASE_MASTER_SERVICE
+  _exe_name_ = os.path.join(EMBEDDED_HBASE_SUBDIR, "bin", 
EMBEDDED_HBASE_MASTER_SERVICE + ".exe")
+
+  @classmethod
+  def _get_start_type(cls, startupMode):
+    if startupMode == "auto":
+      startType = win32service.SERVICE_AUTO_START
+    elif startupMode == "disabled":
+      startType = win32service.SERVICE_DISABLED
+    else:
+      startType = win32service.SERVICE_DEMAND_START
+    return startType
+
+  @classmethod
+  def Install(cls, startupMode = "auto", username = None, password = None):
+    print "Installing service %s" % (cls._svc_name_)
+
+    # Configure master.xml, which drives the java subprocess
+    java_path = get_java_exe_path()
+    java_args = _build_master_java_args(username)
+
+    config_file_path = _get_config_file_path()
+
+    xmlFileContents = _MasterXml()
+    xmlFileContents.service.id = EMBEDDED_HBASE_MASTER_SERVICE
+    xmlFileContents.service.name = EMBEDDED_HBASE_MASTER_SERVICE
+    xmlFileContents.service.description = "This service runs " + 
EMBEDDED_HBASE_MASTER_SERVICE
+    xmlFileContents.service.executable = java_path
+    xmlFileContents.service.arguments = java_args
+
+    xmlFile = open(config_file_path, "w")
+    xmlFile.write( str(xmlFileContents) )
+    xmlFile.close()
+
+    startType = cls._get_start_type(startupMode)
+    serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
+    errorControl = win32service.SERVICE_ERROR_NORMAL
+
+    commandLine = os.path.abspath(cls._exe_name_)
+    hscm = 
win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
+    try:
+      try:
+        hs = win32service.CreateService(hscm,
+                                        cls._svc_name_,
+                                        cls._svc_display_name_,
+                                        win32service.SERVICE_ALL_ACCESS,       
  # desired access
+                                        serviceType,        # service type
+                                        startType,
+                                        errorControl,       # error control 
type
+                                        commandLine,
+                                        None,
+                                        0,
+                                        None,
+                                        username,
+                                        password)
+        print "Service installed"
+        win32service.CloseServiceHandle(hs)
+      finally:
+        win32service.CloseServiceHandle(hscm)
+    except win32service.error, exc:
+      if exc.winerror==winerror.ERROR_SERVICE_EXISTS:
+        cls.Update(username, password)
+      else:
+        print "Error installing service: %s (%d)" % (exc.strerror, 
exc.winerror)
+        err = exc.winerror
+    except ValueError, msg: # Can be raised by custom option handler.
+      print "Error installing service: %s" % str(msg)
+      err = -1
+      # xxx - maybe I should remove after _any_ failed install - however,
+      # xxx - it may be useful to help debug to leave the service as it failed.
+      # xxx - We really _must_ remove as per the comments above...
+      # As we failed here, remove the service, so the next installation
+      # attempt works.
+      try:
+        RemoveService(cls._svc_name_)
+      except win32api.error:
+        print "Warning - could not remove the partially installed service."
+
+  @classmethod
+  def Update(cls, startupMode = "auto", username = None, password = None):
+    # Handle the default arguments.
+    if startupMode is None:
+      startType = win32service.SERVICE_NO_CHANGE
+    else:
+      startType = cls._get_start_type(startupMode)
+
+    hscm = 
win32service.OpenSCManager(None,None,win32service.SC_MANAGER_ALL_ACCESS)
+    serviceType = win32service.SERVICE_WIN32_OWN_PROCESS
+
+    commandLine = os.path.abspath(cls._exe_name_)
+
+    try:
+      hs = SmartOpenService(hscm, cls._svc_name_, 
win32service.SERVICE_ALL_ACCESS)
+      try:
+        win32service.ChangeServiceConfig(hs,
+                                         serviceType,  # service type
+                                         startType,
+                                         win32service.SERVICE_NO_CHANGE,       
# error control type
+                                         commandLine,
+                                         None,
+                                         0,
+                                         None,
+                                         username,
+                                         password,
+                                         cls._svc_display_name_)
+        print "Service updated"
+      finally:
+        win32service.CloseServiceHandle(hs)
+    finally:
+      win32service.CloseServiceHandle(hscm)
+
+class _MasterXml(ConvertToXml):
+  service = ""  #Service entity
+
+  def __init__(self):
+    self.service = _ServiceXml()
+
+  def __str__(self):
+    result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+    result += str(self.service)
+    return result
+
+class _ServiceXml(ConvertToXml):
+  def __init__(self):
+    self.id = ""
+    self.name = ""
+    self.description = ""
+    self.executable = ""
+    self.arguments = ""
+
+  def __str__(self):
+    result = "<service>\n"
+    result += self.attributesToXml()
+    result += "</service>"
+    return result

http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/ambari-metrics/ambari-metrics-timelineservice/src/main/python/main.py
----------------------------------------------------------------------
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/python/main.py 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/main.py
new file mode 100644
index 0000000..172861e
--- /dev/null
+++ b/ambari-metrics/ambari-metrics-timelineservice/src/main/python/main.py
@@ -0,0 +1,214 @@
+#!/usr/bin/env python
+
+'''
+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 os
+import subprocess
+import sys
+
+from ambari_commons.exceptions import FatalException, NonFatalException
+from ambari_commons.logging_utils import print_info_msg, print_warning_msg, 
print_error_msg
+from ambari_metrics_collector.serviceConfiguration import get_java_exe_path, 
get_java_cp, build_jvm_args, \
+  SETUP_ACTION, START_ACTION, STOP_ACTION, RESTART_ACTION, STATUS_ACTION, 
PID_DIR, EXITCODE_OUT_FILE, \
+  SERVER_OUT_FILE, PID_OUT_FILE, SERVER_LOG_FILE
+
+
+# debug settings
+SERVER_START_DEBUG = False
+SUSPEND_START_MODE = False
+
+AMS_ENV_CMD = "ams-env.cmd"
+
+SERVER_START_CMD = \
+  "-cp {0} {1} " + \
+  "-Djava.net.preferIPv4Stack=true " \
+  "-Dproc_timelineserver " + \
+  
"org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer"
+SERVER_START_CMD_DEBUG = \
+  "-cp {0} {1} " + \
+  "-Djava.net.preferIPv4Stack=true " \
+  "-Dproc_timelineserver " + \
+  " -Xdebug -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend={2} " 
+ \
+  
"org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer"
+
+AMC_DIE_MSG = "Ambari Metrics Collector java process died with exitcode {0}. 
Check {1} for more information."
+
+
+def save_pid(pid, pidfile):
+  """
+    Save pid to pidfile.
+  """
+  try:
+    pfile = open(pidfile, "w")
+    pfile.write("%s\n" % pid)
+  except IOError:
+    pass
+  finally:
+    try:
+      pfile.close()
+    except:
+      pass
+
+
+def exec_ams_env_cmd(options):
+  ams_env_cmd = os.path.join(options.conf_dir, AMS_ENV_CMD)
+  if os.path.exists(ams_env_cmd):
+    cmds = ["cmd.exe", "/C", ams_env_cmd]
+    procAms = subprocess.Popen(cmds, env=os.environ)
+    out, err = procAms.communicate()
+    if err is not None and err is not "":
+      print_warning_msg(AMS_ENV_CMD + " error output: " + err)
+    if out is not None and out is not "":
+      print_info_msg(AMS_ENV_CMD + " output: " + out)
+  else:
+    err = 'ERROR: Cannot execute "{0}"'.format(ams_env_cmd)
+    raise FatalException(1, err)
+
+
+def server_process_main(options, scmStatus=None):
+  if scmStatus is not None:
+    scmStatus.reportStartPending()
+
+  # debug mode
+  try:
+    global DEBUG_MODE
+    DEBUG_MODE = options.debug
+  except AttributeError:
+    pass
+
+  # stop Java process at startup?
+  try:
+    global SUSPEND_START_MODE
+    SUSPEND_START_MODE = options.suspend_start
+  except AttributeError:
+    pass
+
+  #options.conf_dir <= --config
+  if not os.path.isdir(options.conf_dir):
+    err = 'ERROR: Cannot find configuration directory 
"{0}"'.format(options.conf_dir)
+    raise FatalException(1, err)
+
+  #execute ams-env.cmd
+  exec_ams_env_cmd(options)
+
+  #Ensure the 3 Hadoop services required are started on the local machine
+  if not options.no_embedded_hbase:
+    from amc_service import ensure_hdp_service_soft_dependencies
+    ensure_hdp_service_soft_dependencies()
+
+  if scmStatus is not None:
+    scmStatus.reportStartPending()
+
+  java_exe = get_java_exe_path()
+  java_class_path = get_java_cp()
+  java_heap_max = build_jvm_args()
+  command_base = SERVER_START_CMD_DEBUG if (DEBUG_MODE or SERVER_START_DEBUG) 
else SERVER_START_CMD
+  suspend_mode = 'y' if SUSPEND_START_MODE else 'n'
+  command = command_base.format(java_class_path, java_heap_max, suspend_mode)
+  if not os.path.exists(PID_DIR):
+    os.makedirs(PID_DIR, 0755)
+
+  #Ignore the requirement to run as root. In Windows, by default the child 
process inherits the security context
+  # and the environment from the parent process.
+  param_list = java_exe + " " + command
+
+  print_info_msg("Running server: " + str(param_list))
+  procJava = subprocess.Popen(param_list, env=os.environ)
+
+  #wait for server process for SERVER_START_TIMEOUT seconds
+  print "Waiting for server start..."
+
+  pidJava = procJava.pid
+  if pidJava <= 0:
+    procJava.terminate()
+    exitcode = procJava.returncode
+    save_pid(exitcode, EXITCODE_OUT_FILE)
+
+    if scmStatus is not None:
+      scmStatus.reportStopPending()
+
+    raise FatalException(-1, AMC_DIE_MSG.format(exitcode, SERVER_OUT_FILE))
+  else:
+    save_pid(pidJava, PID_OUT_FILE)
+    print "Server PID at: " + PID_OUT_FILE
+    print "Server out at: " + SERVER_OUT_FILE
+    print "Server log at: " + SERVER_LOG_FILE
+
+  if scmStatus is not None:
+    scmStatus.reportStarted()
+
+  return procJava
+
+def main():
+  from amc_service import init_options_parser, init_service_debug, setup, 
start, stop, svcstatus
+
+  parser = init_options_parser()
+  (options, args) = parser.parse_args()
+
+  options.warnings = []
+  options.exit_message = None
+
+  init_service_debug(options)
+
+  if len(args) == 0:
+    print parser.print_help()
+    parser.error("No action entered")
+
+  action = args[0]
+
+  try:
+    if action == SETUP_ACTION:
+      setup(options)
+    elif action == START_ACTION:
+      start(options)
+    elif action == STOP_ACTION:
+      stop()
+    elif action == RESTART_ACTION:
+      stop()
+      start(options)
+    elif action == STATUS_ACTION:
+      svcstatus(options)
+    else:
+      parser.error("Invalid action")
+
+    if options.warnings:
+      for warning in options.warnings:
+        print_warning_msg(warning)
+        pass
+      options.exit_message = "Ambari Metrics Collector '%s' completed with 
warnings." % action
+      pass
+  except FatalException as e:
+    if e.reason is not None:
+      print_error_msg("Exiting with exit code {0}. \nREASON: 
{1}".format(e.code, e.reason))
+    sys.exit(e.code)
+  except NonFatalException as e:
+    options.exit_message = "Ambari Metrics Collector '%s' completed with 
warnings." % action
+    if e.reason is not None:
+      print_warning_msg(e.reason)
+
+  if options.exit_message is not None:
+    print options.exit_message
+
+
+if __name__ == "__main__":
+  try:
+    main()
+  except (KeyboardInterrupt, EOFError):
+    print("\nAborting ... Keyboard Interrupt.")
+    sys.exit(1)

http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/ambari-metrics/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-metrics/pom.xml b/ambari-metrics/pom.xml
index da7fc14..d99cc82 100644
--- a/ambari-metrics/pom.xml
+++ b/ambari-metrics/pom.xml
@@ -57,6 +57,33 @@
   <build>
     <plugins>
       <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.8</version>
+        <executions>
+          <execution>
+            <id>parse-version</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>parse-version</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>regex-property</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>ambariVersion</name>
+              <value>${project.version}</value>
+              <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)(\.|-).*</regex>
+              <replacement>$1.$2.$3</replacement>
+              <failIfNoMatch>false</failIfNoMatch>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <artifactId>maven-assembly-plugin</artifactId>
         <configuration>
           <descriptors>

http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/ambari-server/src/main/python/ambari-server-state/Entities.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari-server-state/Entities.py 
b/ambari-server/src/main/python/ambari-server-state/Entities.py
index 379c95f..b9f61c3 100644
--- a/ambari-server/src/main/python/ambari-server-state/Entities.py
+++ b/ambari-server/src/main/python/ambari-server-state/Entities.py
@@ -1,5 +1,3 @@
-import inspect
-
 # 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
@@ -16,20 +14,7 @@ import inspect
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-class ConvertToXml:
-  "Template class, allow to output fields in xml format"
-  def getField(self):
-    return [name for name, obj in inspect.getmembers(self)
-            if not name.startswith("__") and not inspect.isroutine(obj)]
-
-  def attributesToXml(self):
-    result = ""
-    listOfAttr = self.getField()
-    for attrName in listOfAttr:
-      result += "<" + attrName + ">"
-      result += str(getattr(self, attrName))
-      result += "</" + attrName + ">"
-    return result
+from ambari_commons.xml_utils import ConvertToXml
 
 
 class Configurations(ConvertToXml):

http://git-wip-us.apache.org/repos/asf/ambari/blob/19e972cf/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index af4fc01..d33828b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -179,6 +179,8 @@
             <exclude>derby.log</exclude>
             <exclude>CHANGES.txt</exclude>
             <exclude>pass.txt</exclude>
+            
<exclude>ambari-metrics/ambari-metrics-host-monitoring/conf/unix/metric_groups.conf</exclude>
+            
<exclude>ambari-metrics/ambari-metrics-host-monitoring/conf/windows/metric_groups.conf</exclude>
             
<exclude>contrib/addons/test/dataServices/jmx/data/cluster_configuration.json.nohbase</exclude>
             <exclude>contrib/ambari-scom/msi/src/GUI_Ambari.sln</exclude>
             <exclude>version</exclude>

Reply via email to