SwarmPlayer is now detected; CIS-LB random load balancer created
authorCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Sun, 19 Feb 2012 01:28:33 +0000 (03:28 +0200)
committerCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Sun, 19 Feb 2012 01:28:33 +0000 (03:28 +0200)
cis/cis_lb/cis_lb.py
cis/cis_lb/config.py
cis/cis_lb/load_balancer/base.py [new file with mode: 0644]
cis/cis_lb/load_balancer/random_lb.py [new file with mode: 0644]
cis/post-json.sh
js/jquery.ui.nsinstall.js

index e2ad381..d1f228b 100755 (executable)
@@ -7,6 +7,7 @@ import time
 import threading
 from Queue import Queue
 
+from load_balancer.random_lb import RandomLoadBalancer
 # Located in the parent directory; execute from that location or put it in PYTHONPATH
 import logger
 import config
@@ -40,7 +41,7 @@ class Server:
     
     def POST(self, request):
         
-        Server.queue.put( ('POST', request, web.data()) )
+        Server.queue.put( (request, web.data()) )
         
         #return web.data()
 
@@ -51,7 +52,7 @@ if __name__ == '__main__':
     # Create job threads.
     lb_workers = []
     for i in range(0, config.JOB_THREADS_COUNT):
-        lb_worker = LBWorker(i)
+        lb_worker = RandomLoadBalancer(i, Server.queue)
         lb_worker.daemon = True
         lb_worker.start()
         lb_workers.append(lb_worker)
index a1a2c32..878775b 100644 (file)
@@ -1,4 +1,20 @@
 
+# CIS URLs
+CIS_URLS = [ \
+    'http://p2p-next-01.grid.pub.ro:31500/', \
+    'http://p2p-next-03.grid.pub.ro:31500/', \
+    'http://p2p-next-04.grid.pub.ro:31500/', \
+    'http://p2p-next-05.grid.pub.ro:31500/', \
+    'http://p2p-next-06.grid.pub.ro:31500/', \
+    'http://p2p-next-07.grid.pub.ro:31500/', \
+    'http://p2p-next-08.grid.pub.ro:31500/', \
+    'http://p2p-next-10.grid.pub.ro:31500/' \
+]
+
+import logger
+
+LOG_LEVEL = logger.LOG_LEVEL_DEBUG
+
 # Number of threads which execute load balancing jobs through LBWorker class.
 JOB_THREADS_COUNT = 5
 # Number of threads controlled by job which make HTTP requests.
diff --git a/cis/cis_lb/load_balancer/base.py b/cis/cis_lb/load_balancer/base.py
new file mode 100644 (file)
index 0000000..9586c88
--- /dev/null
@@ -0,0 +1,34 @@
+import threading
+import urllib
+
+import logger
+
+class LoadBalancer(threading.Thread):
+    
+    def __init__(self, id, queue):
+        """
+        Initialize Load Balancer,
+        """
+
+        threading.Thread.__init__(self, \
+                name = '%s%02d' % (self.__class__.__name__, id))
+        
+        self.queue = queue
+    
+    def run(self):
+        
+        while True:
+            (request, data) = self.queue.get()
+            
+            cis = self.choose()
+            logger.log_msg('Forwarding to %s' % cis, logger.LOG_LEVEL_DEBUG)
+            urllib.urlopen(cis + request, data)
+            
+            self.queue.task_done()
+        
+    def choose(self):
+        """
+        Implement load balancing policy in this method for child classes which
+        choses a CIS from config.CIS_URLS .
+        """        
+        pass
\ No newline at end of file
diff --git a/cis/cis_lb/load_balancer/random_lb.py b/cis/cis_lb/load_balancer/random_lb.py
new file mode 100644 (file)
index 0000000..cbf9a48
--- /dev/null
@@ -0,0 +1,9 @@
+import random
+
+from base import LoadBalancer
+import config
+
+class RandomLoadBalancer(LoadBalancer):
+    
+    def choose(self):
+        return config.CIS_URLS[random.randint(0, len(config.CIS_URLS) - 1)]
\ No newline at end of file
index aaca00e..21128d0 100755 (executable)
@@ -6,6 +6,7 @@ if [ $# -ne 1 ]; then
 fi
 
 JSON_FILE="$1"
-CIS_URL="http://p2p-next-03.grid.pub.ro:8080/"
+#CIS_URL="http://p2p-next-03.grid.pub.ro:8080/"
+CIS_URL="http://localhost:31500/"
 
 curl -H 'Content-Type: application/json' --data-binary @"$JSON_FILE" ${CIS_URL}ingest_content
index 772fa6f..9b14ad1 100644 (file)
@@ -109,6 +109,7 @@ $.widget( "ui.nsinstall", {
        _createSwarmPlayerInstall: function() {
                var widget = this;
                var msg;
+               var $box;
                
                if (widget.options.error == 'none')
                {
@@ -126,6 +127,9 @@ $.widget( "ui.nsinstall", {
                }
                else if (widget.options.error == 'already installed')
                {
+                       $box = $('<div id="install-swarmplayer"></div>')
+                               .appendTo(widget.element);
+                       
                        $box
                                .html('<div class="ui-widget">'
                                                + '<div style="padding: 0 .7em;" class="ui-state-highlight ui-corner-all">' 
@@ -139,7 +143,7 @@ $.widget( "ui.nsinstall", {
                }
                else
                {
-                       var $box = $('<div id="install-swarmplayer"></div>')
+                       $box = $('<div id="install-swarmplayer"></div>')
                                .appendTo(widget.element);
                        
                        $box
@@ -158,6 +162,8 @@ $.widget( "ui.nsinstall", {
        
        _createNextSharePCInstall: function() {
                var widget = this;
+               var msg;
+               var $box;
                
                if (widget.options.error == 'none')
                {
@@ -175,7 +181,7 @@ $.widget( "ui.nsinstall", {
                }
                else if (widget.options.error == 'already installed')
                {
-                       var $box = $('<div id="install-nextsharepc"></div>')
+                       $box = $('<div id="install-nextsharepc"></div>')
                                .appendTo(widget.element);
                        
                        $box
@@ -186,12 +192,12 @@ $.widget( "ui.nsinstall", {
                                + '</div>'
                        + '</div>');
                        
-                       var msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
+                       msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
                        $('#install-nextsharepc-msg').html(msg);
                }
                else
                {
-                       var $box = $('<div id="install-nextsharepc"></div>')
+                       $box = $('<div id="install-nextsharepc"></div>')
                                .appendTo(widget.element);
                        
                        $box
@@ -202,7 +208,7 @@ $.widget( "ui.nsinstall", {
                                        + '</div>'
                                + '</div>');
                        
-                       var msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
+                       msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
                        $('#install-nextsharepc-msg').html(msg);
                }
        },
@@ -231,6 +237,9 @@ $.widget( "ui.nsinstall", {
        },
        
        isSwarmPlayerAlreadyInstalled: function() {
+               if (typeof swarmTransport != 'undefined')
+                       return true;
+               
                return false;
        },