Upload bugs solved: elim_dupl_res feature causes generation of a malformed content...
authorCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Mon, 20 Feb 2012 10:27:34 +0000 (12:27 +0200)
committerCălin-Andrei Burloiu <calin.burloiu@gmail.com>
Mon, 20 Feb 2012 10:27:34 +0000 (12:27 +0200)
15 files changed:
application/config/content_ingestion.php
application/controllers/video.php
application/helpers/video_helper.php
cis/cis.py
cis/cis_lb/cis_lb.py
cis/cis_lb/config.py
cis/cis_lb/load_balancer/__init__.py [moved from cis/cis_lb/__init__.py with 100% similarity]
cis/cis_lb/load_balancer/base.py
cis/cis_lb/load_balancer/random_lb.py
cis/dummy_cis.py [new file with mode: 0755]
cis/tmp/dummy [new file with mode: 0644]
cis/tmp/raw/dummy [new file with mode: 0644]
cis/tmp/thumbs/dummy [new file with mode: 0644]
data/upload/index.html [new file with mode: 0644]
tmp/dummy [new file with mode: 0644]

index a21310f..76a6c69 100644 (file)
@@ -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/';
 
 /*
 |--------------------------------------------------------------------------
index 283851d..5182b62 100644 (file)
@@ -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'));
        }
        
        /**
index a172183..aa7c384 100644 (file)
@@ -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);
index d096a9e..e63b729 100755 (executable)
@@ -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( \
index d1f228b..41529e2 100755 (executable)
@@ -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)
index 878775b..410fe27 100644 (file)
@@ -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
index 9586c88..f4e9261 100644 (file)
@@ -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
index cbf9a48..f17d1bd 100644 (file)
@@ -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 (executable)
index 0000000..cb94a1d
--- /dev/null
@@ -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 (file)
index 0000000..421376d
--- /dev/null
@@ -0,0 +1 @@
+dummy
diff --git a/cis/tmp/raw/dummy b/cis/tmp/raw/dummy
new file mode 100644 (file)
index 0000000..421376d
--- /dev/null
@@ -0,0 +1 @@
+dummy
diff --git a/cis/tmp/thumbs/dummy b/cis/tmp/thumbs/dummy
new file mode 100644 (file)
index 0000000..421376d
--- /dev/null
@@ -0,0 +1 @@
+dummy
diff --git a/data/upload/index.html b/data/upload/index.html
new file mode 100644 (file)
index 0000000..c942a79
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<head>
+       <title>403 Forbidden</title>
+</head>
+<body>
+
+<p>Directory access is forbidden.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/tmp/dummy b/tmp/dummy
new file mode 100644 (file)
index 0000000..421376d
--- /dev/null
+++ b/tmp/dummy
@@ -0,0 +1 @@
+dummy