浏览代码

HUE-3441 [zookeeper] Support HA

Amit Kabra 9 年之前
父节点
当前提交
c8decd0
共有 2 个文件被更改,包括 22 次插入9 次删除
  1. 14 9
      apps/zookeeper/src/zookeeper/stats.py
  2. 8 0
      apps/zookeeper/src/zookeeper/templates/index.mako

+ 14 - 9
apps/zookeeper/src/zookeeper/stats.py

@@ -15,11 +15,12 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging
 import socket
 import re
 
 from StringIO import StringIO
-
+LOG = logging.getLogger(__name__)
 
 class Session(object):
 
@@ -43,6 +44,7 @@ class ZooKeeperStats(object):
     def __init__(self, host='localhost', port='2181', timeout=1):
         self._address = (host, int(port))
         self._timeout = timeout
+        self._host = host
 
     def get_stats(self):
         """ Get ZooKeeper server stats as a map """
@@ -84,13 +86,14 @@ class ZooKeeperStats(object):
         """ Send a 4letter word command to the server """
         s = self._create_socket()
         s.settimeout(self._timeout)
-
-        s.connect(self._address)
-        s.send(cmd)
-
-        data = s.recv(2048)
-        s.close()
-
+        data = ""
+        try:
+	    s.connect(self._address)
+	    s.send(cmd)
+	    data = s.recv(2048)
+	    s.close()
+        except Exception, e:
+	    LOG.error('Problem connecting to host %s, exception raised : %s' % (self._host, e))
         return data
 
     def _parse(self, data):
@@ -109,9 +112,11 @@ class ZooKeeperStats(object):
 
     def _parse_stat(self, data):
         """ Parse the output from the 'stat' 4letter word command """
-        h = StringIO(data)
 
         result = {}
+        if not data:
+	    return result
+        h = StringIO(data)
 
         version = h.readline()
         if version:

+ 8 - 0
apps/zookeeper/src/zookeeper/templates/index.mako

@@ -64,11 +64,19 @@ ${ shared.menubar() }
     <tbody>
     % for host, stats in overview[c].items():
       <tr>
+      % if stats:
         <td><a href="${ url('zookeeper:clients', id=c, host=host) }" data-row-selector="true">${ host }</a></td>
         <td>${stats.get('zk_server_state', '')}</td>
         <td>${stats.get('zk_avg_latency', '')}</td>
         <td>${stats.get('zk_watch_count', '')}</td>
         <td>${stats.get('zk_version', '')}</td>
+      % else:
+	<td><a href="${ url('zookeeper:clients', id=c, host=host) }" style="color:red" data-row-selector="true">${ host }</a></td>
+        <td>-</td>
+        <td>-</td>
+        <td>-</td>
+        <td>-</td>
+      % endif
       </tr>
     % endfor
     </tbody>