From 1fc9c837263ec3094024bcfc7ef3b2cdb8c0a5cd Mon Sep 17 00:00:00 2001 From: Corey Goldberg Date: Fri, 20 Feb 2015 11:57:51 -0500 Subject: [PATCH] Added listener and beacon for video cdn eval. --- .../xmodule/video_module/video_module.py | 17 +++++++++++++ .../courseware/tests/test_video_mongo.py | 21 ++++++++++++++++ lms/templates/video.html | 25 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index d6007513b7..f12347fd4f 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -16,6 +16,7 @@ Examples of html5 videos for manual testing: import copy import json import logging +import random from collections import OrderedDict from operator import itemgetter @@ -232,10 +233,26 @@ class VideoModule(VideoFields, VideoTranscriptsMixin, VideoStudentViewHandlers, track_url, transcript_language, sorted_languages = self.get_transcripts_for_student() + # CDN_VIDEO_URLS is only to be used here and will be deleted + # TODO(ali@edx.org): Delete this after the CDN experiment has completed. + if getattr(settings, 'PERFORMANCE_GRAPHITE_URL', '') != '' and \ + self.system.user_location == 'CN' and \ + getattr(settings, 'ENABLE_VIDEO_BEACON', False) and \ + self.edx_video_id in getattr(settings, 'CDN_VIDEO_URLS', {}).keys(): + cdn_urls = getattr(settings, 'CDN_VIDEO_URLS', {})[self.edx_video_id] + cdn_exp_group, sources[0] = random.choice(zip(range(len(cdn_urls)), cdn_urls)) + cdn_eval = True + else: + cdn_eval = False + cdn_exp_group = None + return self.system.render_template('video.html', { 'ajax_url': self.system.ajax_url + '/save_user_state', 'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False), 'branding_info': branding_info, + 'cdn_eval': cdn_eval, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': cdn_exp_group, # This won't work when we move to data that # isn't on the filesystem 'data_dir': getattr(self, 'data_dir', None), diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 789cc388d4..d1a59ef78a 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -29,6 +29,9 @@ class TestVideoYouTube(TestVideo): 'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state', 'autoplay': settings.FEATURES.get('AUTOPLAY_VIDEOS', False), 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'display_name': u'A Name', 'end': 3610.0, @@ -93,6 +96,9 @@ class TestVideoNonYouTube(TestVideo): expected_context = { 'ajax_url': self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state', 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, @@ -197,6 +203,9 @@ class TestGetHtmlMethod(BaseTestXmodule): expected_context = { 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, @@ -314,6 +323,9 @@ class TestGetHtmlMethod(BaseTestXmodule): initial_context = { 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, @@ -454,6 +466,9 @@ class TestGetHtmlMethod(BaseTestXmodule): # Video found for edx_video_id initial_context = { 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, @@ -572,6 +587,9 @@ class TestGetHtmlMethod(BaseTestXmodule): # Video found for edx_video_id initial_context = { 'branding_info': None, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, @@ -691,6 +709,9 @@ class TestGetHtmlMethod(BaseTestXmodule): 'logo_tag': 'Video hosted by XuetangX.com', 'url': 'http://www.xuetangx.com' }, + 'cdn_eval': False, + 'cdn_eval_endpoint': getattr(settings, 'PERFORMANCE_GRAPHITE_URL', ''), + 'cdn_exp_group': None, 'data_dir': getattr(self, 'data_dir', None), 'show_captions': 'true', 'handout': None, diff --git a/lms/templates/video.html b/lms/templates/video.html index 772e797dd1..cc73172e9a 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -150,3 +150,28 @@ % endif +% if cdn_eval: + +% endif;