浏览代码

[load-balancer] Automatically discover static file dir, avoid kt_indexer role

Erick Tryzelaar 10 年之前
父节点
当前提交
9dd78ce950

+ 28 - 1
tools/load-balancer/bin/monitor-hue-lb

@@ -113,7 +113,7 @@ class MonitorHue(object):
         for cluster in self.cm_client.get_all_clusters():
             for service in cluster.get_all_services():
                 if service.type == 'HUE':
-                    for role in service.get_all_roles():
+                    for role in service.get_roles_by_type("HUE_SERVER"):
                         host = self.cm_client.get_host(role.hostRef.hostId)
                         hostname = host.hostname
 
@@ -202,6 +202,33 @@ class HAProxyListener(ConfigListener):
 # ------------------------------------------------------------------------------
 
 class NginxListener(ConfigListener):
+    def __init__(self, *args, **kwargs):
+        super(NginxListener, self).__init__(*args, **kwargs)
+
+        self.alias_file = self.config['alias_file']
+        self.generate_alias_file()
+
+
+    def find_static_files(self):
+        paths = (
+            '/opt/cloudera/parcels/CDH/lib/hue/build/static/',
+            '/usr/lib/hue/build/static/',
+            os.path.join(os.path.dirname(__file__), '../../../build/static/'),
+        )
+
+        for path in paths:
+            if os.path.exists(path):
+                return path
+        else:
+            raise Exception('could not find the Hue static files')
+
+
+    def generate_alias_file(self):
+        static_files = self.find_static_files()
+        with open(self.alias_file, 'w') as f:
+            print >> f, 'alias %s;' % static_files
+
+
     def expand_server_template(self, index, server):
         """Expand the Nginx server line"""
 

+ 1 - 0
tools/load-balancer/etc/hue-lb.toml

@@ -7,6 +7,7 @@ password = "admin"
 config_file = "var/nginx-hue.conf"
 config_template = "etc/nginx-hue.conf.in"
 server_template = "etc/nginx-hue-server.conf.in"
+alias_file = "var/nginx-alias.conf"
 
 [haproxy]
 config_file = "var/haproxy-hue.conf"

+ 3 - 5
tools/load-balancer/etc/nginx.conf

@@ -36,16 +36,14 @@ http {
             # Uncomment to expose the static file directories.
             ## autoindex on;
 
-            # The default Hue staticfile packaging installation directory.
-            alias /usr/lib/hue/build/static/;
-
-            # The default Hue staticfile parcel installation directory.
-            ## /opt/cloudera/parcels/CDH/lib/hue/build/static/;
+            # Generated by the monitor-hue-lb script.
+            include ../var/nginx-alias.conf;
 
             expires 30d;
             add_header Cache-Control public;
         }
     }
 
+    # Generated by the monitor-hue-lb script.
     include ../var/nginx-hue.conf;
 }

+ 8 - 1
tools/scripts/hue-review

@@ -17,4 +17,11 @@ REVIEWER=$2;
 SUMMARY=$3;
 shift 3;
 
-exec $RBT post -o --description="$(git whatchanged $REVLIST)" --target-groups=hue --target-people="$REVIEWER" --summary="$SUMMARY" $REVLIST $@
+exec $RBT post \
+	-o \
+	--description="$(git whatchanged $REVLIST)" \
+	--target-groups=hue \
+	--target-people="$REVIEWER" \
+	--summary="$SUMMARY" \
+	$REVLIST \
+	$@