From 66dc2204a919e2c29b2aa9330ea18026d58540d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C4=83lin-Andrei=20Burloiu?= Date: Sun, 19 Feb 2012 03:28:33 +0200 Subject: [PATCH] SwarmPlayer is now detected; CIS-LB random load balancer created --- cis/cis_lb/cis_lb.py | 5 ++-- cis/cis_lb/config.py | 16 +++++++++++++ cis/cis_lb/load_balancer/base.py | 34 +++++++++++++++++++++++++++ cis/cis_lb/load_balancer/random_lb.py | 9 +++++++ cis/post-json.sh | 3 ++- js/jquery.ui.nsinstall.js | 19 +++++++++++---- 6 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 cis/cis_lb/load_balancer/base.py create mode 100644 cis/cis_lb/load_balancer/random_lb.py diff --git a/cis/cis_lb/cis_lb.py b/cis/cis_lb/cis_lb.py index e2ad381..d1f228b 100755 --- a/cis/cis_lb/cis_lb.py +++ b/cis/cis_lb/cis_lb.py @@ -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) diff --git a/cis/cis_lb/config.py b/cis/cis_lb/config.py index a1a2c32..878775b 100644 --- a/cis/cis_lb/config.py +++ b/cis/cis_lb/config.py @@ -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 index 0000000..9586c88 --- /dev/null +++ b/cis/cis_lb/load_balancer/base.py @@ -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 index 0000000..cbf9a48 --- /dev/null +++ b/cis/cis_lb/load_balancer/random_lb.py @@ -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 diff --git a/cis/post-json.sh b/cis/post-json.sh index aaca00e..21128d0 100755 --- a/cis/post-json.sh +++ b/cis/post-json.sh @@ -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 diff --git a/js/jquery.ui.nsinstall.js b/js/jquery.ui.nsinstall.js index 772fa6f..9b14ad1 100644 --- a/js/jquery.ui.nsinstall.js +++ b/js/jquery.ui.nsinstall.js @@ -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 = $('
') + .appendTo(widget.element); + $box .html('
' + '
' @@ -139,7 +143,7 @@ $.widget( "ui.nsinstall", { } else { - var $box = $('
') + $box = $('
') .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 = $('
') + $box = $('
') .appendTo(widget.element); $box @@ -186,12 +192,12 @@ $.widget( "ui.nsinstall", { + '
' + '
'); - 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 = $('
') + $box = $('
') .appendTo(widget.element); $box @@ -202,7 +208,7 @@ $.widget( "ui.nsinstall", { + '' + ''); - 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; }, -- 2.20.1