From: Călin-Andrei Burloiu Date: Mon, 20 Feb 2012 10:27:34 +0000 (+0200) Subject: Upload bugs solved: elim_dupl_res feature causes generation of a malformed content... X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?p=living-lab-site.git;a=commitdiff_plain;h=141bdb84bf143c29a6c50eef3aee18541d2fc0e4 Upload bugs solved: elim_dupl_res feature causes generation of a malformed content ingestion JSON and has been disabled for the moment; CIS file exists bug. Random CIS-LB implemented. --- diff --git a/application/config/content_ingestion.php b/application/config/content_ingestion.php index a21310f..76a6c69 100644 --- a/application/config/content_ingestion.php +++ b/application/config/content_ingestion.php @@ -18,7 +18,7 @@ | http://cis.org:31500/ | */ -$config['cis_url'] = 'http://p2p-next-03.grid.pub.ro:31500/'; +$config['cis_url'] = 'http://localhost:31500/'; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/video.php b/application/controllers/video.php index 283851d..5182b62 100644 --- a/application/controllers/video.php +++ b/application/controllers/video.php @@ -26,12 +26,9 @@ class Video extends CI_Controller { public function test() { - $this->load->model('videos_model'); - - $videos = $this->videos_model->get_videos_summary(1, NULL, 0, 10, - 'alphabetically', TRUE); + $this->load->helper('video'); - var_dump($videos); + var_dump(get_av_info('data/upload/test.ogv')); } /** diff --git a/application/helpers/video_helper.php b/application/helpers/video_helper.php index a172183..aa7c384 100644 --- a/application/helpers/video_helper.php +++ b/application/helpers/video_helper.php @@ -158,6 +158,7 @@ function get_av_info($file_name) . $file_name . '" 2> /dev/null', 'r'); $tag = NULL; + $codec_type = NULL; while ( ($r = fgets($h, 512)) !== FALSE) { @@ -175,10 +176,6 @@ function get_av_info($file_name) if ($tag == 'FORMAT') { - // Duration - if (preg_match('/^duration=/', $r)) - $duration = format_duration(floatval(_parse_value($r))); - // Size if (preg_match('/^size=/', $r)) $size = intval(_parse_value ($r)); @@ -197,6 +194,15 @@ function get_av_info($file_name) // DAR if (preg_match('/^display_aspect_ratio=/', $r)) $dar = _parse_value($r); + + // Codec Type + if (preg_match('/^codec_type=/', $r)) + $codec_type = _parse_value($r); + + // Duration + if (preg_match('/^duration=/', $r) + && strcmp($codec_type, 'video') == 0) + $duration = format_duration(floatval(_parse_value($r))); } } @@ -261,19 +267,19 @@ function prepare_formats($formats, $av_info, $elim_dupl_res=FALSE) } // Eliminate formats with duplicate resolutions. - if ($elim_dupl_res) - { - for ($i = 1; $i < count($transcode_configs); $i++) - { - if ($transcode_configs[$i]['v_resolution'] - === $transcode_configs[$i - 1]['v_resolution']) - { - unset($transcode_configs[$i - 1]); - unset($db_formats[$i - 1]); - $i--; - } - } - } +// if ($elim_dupl_res) +// { +// for ($i = 1; $i < count($transcode_configs); $i++) +// { +// if ($transcode_configs[$i]['v_resolution'] +// === $transcode_configs[$i - 1]['v_resolution']) +// { +// unset($transcode_configs[$i - 1]); +// unset($db_formats[$i - 1]); +// $i--; +// } +// } +// } return array('transcode_configs'=>$transcode_configs, 'db_formats'=>$db_formats); diff --git a/cis/cis.py b/cis/cis.py index d096a9e..e63b729 100755 --- a/cis/cis.py +++ b/cis/cis.py @@ -113,13 +113,18 @@ class CIWorker(threading.Thread): # Create torrent file. bt.create_torrent(transcode_config['output_file']) - # The torrent file is created in the same directory with the - # source file. Move it to the torrents directory. - shutil.move(transcode_config['output_file'] + '.tstream', \ - config.TORRENTS_PATH) - output_file = transcode_config['output_file'] + '.tstream' output_file = output_file[(output_file.rindex('/') + 1):] + + # The torrent file is created in the same directory with the + # source file. Move it to the torrents directory. + #if not os.path.exists( + # os.path.join(output_file, config.TORRENTS_PATH)): + try: + shutil.move(transcode_config['output_file'] + '.tstream', \ + config.TORRENTS_PATH) + except: + pass # * SEED TORRENTS Server.bit_torrent.start_torrent( \ diff --git a/cis/cis_lb/cis_lb.py b/cis/cis_lb/cis_lb.py index d1f228b..41529e2 100755 --- a/cis/cis_lb/cis_lb.py +++ b/cis/cis_lb/cis_lb.py @@ -7,7 +7,6 @@ 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 @@ -52,7 +51,7 @@ if __name__ == '__main__': # Create job threads. lb_workers = [] for i in range(0, config.JOB_THREADS_COUNT): - lb_worker = RandomLoadBalancer(i, Server.queue) + lb_worker = config.LOAD_BALANCER(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 878775b..410fe27 100644 --- a/cis/cis_lb/config.py +++ b/cis/cis_lb/config.py @@ -2,15 +2,20 @@ # CIS URLs CIS_URLS = [ \ 'http://p2p-next-01.grid.pub.ro:31500/', \ + 'http://p2p-next-02.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-09.grid.pub.ro:31500/', \ 'http://p2p-next-10.grid.pub.ro:31500/' \ ] +import load_balancer.random_lb +LOAD_BALANCER = load_balancer.random_lb.RandomLoadBalancer + import logger LOG_LEVEL = logger.LOG_LEVEL_DEBUG diff --git a/cis/cis_lb/__init__.py b/cis/cis_lb/load_balancer/__init__.py similarity index 100% rename from cis/cis_lb/__init__.py rename to cis/cis_lb/load_balancer/__init__.py diff --git a/cis/cis_lb/load_balancer/base.py b/cis/cis_lb/load_balancer/base.py index 9586c88..f4e9261 100644 --- a/cis/cis_lb/load_balancer/base.py +++ b/cis/cis_lb/load_balancer/base.py @@ -1,6 +1,7 @@ import threading import urllib +import config import logger class LoadBalancer(threading.Thread): @@ -19,16 +20,29 @@ class LoadBalancer(threading.Thread): while True: (request, data) = self.queue.get() + urls = config.CIS_URLS[:] - cis = self.choose() - logger.log_msg('Forwarding to %s' % cis, logger.LOG_LEVEL_DEBUG) - urllib.urlopen(cis + request, data) + while len(urls) != 0: + cis = self.choose(urls) + + # Request is forwarded to the chosen CIS. + try: + urllib.urlopen(cis + request, data) + except IOError: + logger.log_msg('Failed to forward request to %s' % cis, \ + logger.LOG_LEVEL_ERROR) + continue + + logger.log_msg('Request forwarded to %s' % cis, \ + logger.LOG_LEVEL_INFO) + break self.queue.task_done() - def choose(self): + def choose(self, urls): """ Implement load balancing policy in this method for child classes which - choses a CIS from config.CIS_URLS . + choses a CIS from urls parameter. The chosen URL should be deleted from + urls list. """ 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 index cbf9a48..f17d1bd 100644 --- a/cis/cis_lb/load_balancer/random_lb.py +++ b/cis/cis_lb/load_balancer/random_lb.py @@ -1,9 +1,13 @@ 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 + def choose(self, urls): + index = random.randint(0, len(urls) - 1) + cis = urls[index] + + del(urls[index]) + + return cis \ No newline at end of file diff --git a/cis/dummy_cis.py b/cis/dummy_cis.py new file mode 100755 index 0000000..cb94a1d --- /dev/null +++ b/cis/dummy_cis.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import web +import sys + +urls = ( + '/(.*)', 'Hello' +) + +LOAD = sys.argv[2] +print 'load is %s' % LOAD + +app = web.application(urls, globals()) + +class Hello: + def GET(self, name): + if request == 'get_load': + resp = {"load": LOAD} + web.header('Content-Type', 'application/json') + return json.dumps(resp) + + def POST(self, request): + print web.data() + + return request + +if __name__ == "__main__": + app.run() diff --git a/cis/tmp/dummy b/cis/tmp/dummy new file mode 100644 index 0000000..421376d --- /dev/null +++ b/cis/tmp/dummy @@ -0,0 +1 @@ +dummy diff --git a/cis/tmp/raw/dummy b/cis/tmp/raw/dummy new file mode 100644 index 0000000..421376d --- /dev/null +++ b/cis/tmp/raw/dummy @@ -0,0 +1 @@ +dummy diff --git a/cis/tmp/thumbs/dummy b/cis/tmp/thumbs/dummy new file mode 100644 index 0000000..421376d --- /dev/null +++ b/cis/tmp/thumbs/dummy @@ -0,0 +1 @@ +dummy diff --git a/data/upload/index.html b/data/upload/index.html new file mode 100644 index 0000000..c942a79 --- /dev/null +++ b/data/upload/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/tmp/dummy b/tmp/dummy new file mode 100644 index 0000000..421376d --- /dev/null +++ b/tmp/dummy @@ -0,0 +1 @@ +dummy