ソースを参照

AMBARI-9542 Ams Service Check failed on 3-node cluster

Fixed HTTP ping retry loop
Florian Barca 10 年 前
コミット
f5fe049eb7

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

@@ -85,13 +85,13 @@ class AMSServiceCheck(Script):
         conn.request("POST", self.AMS_METRICS_POST_URL, metric_json, headers)
         break
       except (httplib.HTTPException, socket.error) as ex:
-        time.sleep(self.AMS_CONNECT_TIMEOUT)
-        Logger.info("Connection failed. Next retry in %s seconds."
-                    % (self.AMS_CONNECT_TIMEOUT))
-
-    if i == self.AMS_CONNECT_TRIES:
-      raise Fail("Metrics were not saved. Service check has failed. "
-           "\nConnection failed.")
+        if i < self.AMS_CONNECT_TRIES - 1:  #range/xrange returns items from start to end-1
+          time.sleep(self.AMS_CONNECT_TIMEOUT)
+          Logger.info("Connection failed. Next retry in %s seconds."
+                      % (self.AMS_CONNECT_TIMEOUT))
+        else:
+          raise Fail("Metrics were not saved. Service check has failed. "
+               "\nConnection failed.")
 
     response = conn.getresponse()
     Logger.info("Http response: %s %s" % (response.status, response.reason))