فهرست منبع

AMBARI-11325 - [WinTP2] Metrics Collector Start reports failure but still succeeds

Artem Baranchuk 10 سال پیش
والد
کامیت
e79cf4ee3b

+ 6 - 4
ambari-agent/conf/windows/service_wrapper.py

@@ -139,8 +139,9 @@ def setup(options):
 #     possibly run.
 #
 def svcstart(options):
-  if 0 != AmbariAgentService.Start(15):
-    options.exit_message = None
+  (ret, msg) = AmbariAgentService.Start(15)
+  if 0 != ret:
+    options.exit_message = msg
   pass
 
 
@@ -148,8 +149,9 @@ def svcstart(options):
 # Stops the Ambari Agent.
 #
 def svcstop(options):
-  if 0 != AmbariAgentService.Stop():
-    options.exit_message = None
+  (ret, msg) = AmbariAgentService.Stop()
+  if 0 != ret:
+    options.exit_message = msg
 
 
 #

+ 6 - 4
ambari-common/src/main/python/ambari_commons/os_windows.py

@@ -510,18 +510,20 @@ class WinServiceController:
   @staticmethod
   def Start(serviceName, waitSecs=30):
     err = 0
+    msg = ''
     try:
       win32serviceutil.StartService(serviceName)
       if waitSecs:
         win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_RUNNING, waitSecs)
     except win32service.error, exc:
-      print "Error starting service: %s" % exc.strerror
+      msg = "Error starting service: %s" % exc.strerror
       err = exc.winerror
-    return err
+    return err, msg
 
   @staticmethod
   def Stop(serviceName, waitSecs=30):
     err = 0
+    msg = ''
     try:
       if waitSecs:
         win32serviceutil.StopServiceWithDeps(serviceName, waitSecs=waitSecs)
@@ -530,9 +532,9 @@ class WinServiceController:
         if waitSecs:
           win32serviceutil.WaitForServiceStatus(serviceName, win32service.SERVICE_STOPPED, waitSecs)
     except win32service.error, exc:
-      print "Error stopping service: %s (%d)" % (exc.strerror, exc.winerror)
+      msg = "Error stopping service: %s (%d)" % (exc.strerror, exc.winerror)
       err = exc.winerror
-    return err
+    return err, msg
 
   @staticmethod
   def QueryStatus(serviceName):

+ 1 - 1
ambari-common/src/main/python/resource_management/core/providers/package/choco.py

@@ -42,7 +42,7 @@ REMOVE_CMD = {
 
 CHECK_CMD = {
   True: ['cmd', '/c', 'choco', 'list', '--pre', '--local-only', '-v'],
-  False: ['cmd', '/c', 'choco', 'list', '--pre', '-local-only'],
+  False: ['cmd', '/c', 'choco', 'list', '--pre', '--local-only'],
 }
 
 class ChocoProvider(PackageProvider):

+ 6 - 2
ambari-common/src/main/python/resource_management/core/providers/windows/service.py

@@ -53,10 +53,14 @@ def safe_open_service(hSCM, service_name):
 
 class ServiceProvider(Provider):
   def action_start(self):
-    WinServiceController.Start(self.resource.service_name, 5)
+    (ret, msg) = WinServiceController.Start(self.resource.service_name, 5)
+    if 0 != ret:
+      raise Fail(msg)
 
   def action_stop(self):
-    WinServiceController.Stop(self.resource.service_name, 5)
+    (ret, msg) = WinServiceController.Stop(self.resource.service_name, 5)
+    if 0 != ret:
+      raise Fail(msg)
 
   def action_restart(self):
     self.action_stop()

+ 2 - 3
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/ams.py

@@ -20,7 +20,6 @@ limitations under the License.
 
 from resource_management import *
 from ambari_commons import OSConst
-from service_mapping import *
 from ambari_commons.os_family_impl import OsFamilyFuncImpl, OsFamilyImpl
 from ambari_commons.str_utils import compress_backslashes
 import glob
@@ -30,7 +29,7 @@ import os
 def ams(name=None):
   import params
   if name == 'collector':
-    if not check_windows_service_exists(collector_win_service_name):
+    if not check_windows_service_exists(params.ams_collector_win_service_name):
       Execute(format("cmd /C cd {ams_collector_home_dir} & ambari-metrics-collector.cmd setup"))
 
     Directory(params.ams_collector_conf_dir,
@@ -124,7 +123,7 @@ def ams(name=None):
     pass
 
   elif name == 'monitor':
-    if not check_windows_service_exists(monitor_win_service_name):
+    if not check_windows_service_exists(params.ams_monitor_win_service_name):
       Execute(format("cmd /C cd {ams_monitor_home_dir} & ambari-metrics-monitor.cmd setup"))
 
     # creating symbolic links on ams jars to make them available to services

+ 3 - 3
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/ams_service.py

@@ -25,11 +25,11 @@ from hbase_service import hbase_service
 
 @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
 def ams_service(name, action):
-  import service_mapping
+  import params
   if name == 'collector':
-    Service(service_mapping.collector_win_service_name, action=action)
+    Service(params.ams_collector_win_service_name, action=action)
   elif name == 'monitor':
-    Service(service_mapping.monitor_win_service_name, action=action)
+    Service(params.ams_monitor_win_service_name, action=action)
 
 @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)
 def ams_service(name, action):

+ 2 - 3
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_check.py

@@ -44,7 +44,6 @@ class AMSServiceCheck(Script):
   @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
   def service_check(self, env):
     from resource_management.libraries.functions.windows_service_utils import check_windows_service_exists
-    from service_mapping import collector_win_service_name, monitor_win_service_name
     import params
 
     env.set_params(params)
@@ -52,12 +51,12 @@ class AMSServiceCheck(Script):
     #Just check that the services were correctly installed
     #Check the monitor on all hosts
     Logger.info("Metrics Monitor service check was started.")
-    if not check_windows_service_exists(monitor_win_service_name):
+    if not check_windows_service_exists(params.ams_monitor_win_service_name):
       raise Fail("Metrics Monitor service was not properly installed. Check the logs and retry the installation.")
     #Check the collector only where installed
     if params.ams_collector_home_dir and os.path.isdir(params.ams_collector_home_dir):
       Logger.info("Metrics Collector service check was started.")
-      if not check_windows_service_exists(collector_win_service_name):
+      if not check_windows_service_exists(params.ams_collector_win_service_name):
         raise Fail("Metrics Collector service was not properly installed. Check the logs and retry the installation.")
 
   @OsFamilyFuncImpl(os_family=OsFamilyImpl.DEFAULT)

+ 0 - 21
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/service_mapping.py

@@ -1,21 +0,0 @@
-"""
-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.
-
-"""
-
-collector_win_service_name = "AmbariMetricsCollector"
-monitor_win_service_name = "AmbariMetricsHostMonitoring"

+ 3 - 3
ambari-server/src/main/resources/common-services/AMBARI_METRICS/0.1.0/package/scripts/status.py

@@ -35,8 +35,8 @@ def check_service_status(name):
 
 @OsFamilyFuncImpl(os_family=OSConst.WINSRV_FAMILY)
 def check_service_status(name):
-  import service_mapping
+  import params
   if name=='collector':
-    check_windows_service_status(service_mapping.collector_win_service_name)
+    check_windows_service_status(params.ams_collector_win_service_name)
   elif name == 'monitor':
-    check_windows_service_status(service_mapping.monitor_win_service_name)
+    check_windows_service_status(params.ams_monitor_win_service_name)