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
def POST(self, request):
- Server.queue.put( ('POST', request, web.data()) )
+ Server.queue.put( (request, web.data()) )
#return web.data()
# 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)
+# 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.
--- /dev/null
+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
--- /dev/null
+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
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
_createSwarmPlayerInstall: function() {
var widget = this;
var msg;
+ var $box;
if (widget.options.error == 'none')
{
}
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">'
}
else
{
- var $box = $('<div id="install-swarmplayer"></div>')
+ $box = $('<div id="install-swarmplayer"></div>')
.appendTo(widget.element);
$box
_createNextSharePCInstall: function() {
var widget = this;
+ var msg;
+ var $box;
if (widget.options.error == 'none')
{
}
else if (widget.options.error == 'already installed')
{
- var $box = $('<div id="install-nextsharepc"></div>')
+ $box = $('<div id="install-nextsharepc"></div>')
.appendTo(widget.element);
$box
+ '</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
+ '</div>'
+ '</div>');
- var msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
+ msg = 'NextSharePC ' + widget.options.msg[widget.options.error];
$('#install-nextsharepc-msg').html(msg);
}
},
},
isSwarmPlayerAlreadyInstalled: function() {
+ if (typeof swarmTransport != 'undefined')
+ return true;
+
return false;
},