Ejemplo n.º 1
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.logger = logger.get_logger()
     self.obs = None
     self.sleep_time = 3
     self.analyzer = Analyzer()
     self.obs_lock = threading.Lock()
     self.stream_model = StreamModel()
     self.sample_model = SampleModel()
    def _get_exist_samples(self):
        sm = StreamModel()
        
        stream = sm.get_by_stream_id(self.stream_id)

        if len(stream) == 0:
            return []

        sp_model = SampleModel()
        return sp_model.get_by_mms_stream_id(stream[0]['id'])
Ejemplo n.º 3
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.logger = logger.get_logger()
     self.obs = None
     self.sleep_time = 3
     self.analyzer = Analyzer()
     self.obs_lock = threading.Lock()
     self.stream_model = StreamModel() 
     self.sample_model = SampleModel()
Ejemplo n.º 4
0
 def __init__(self, get_stream_api_url, read_token, monitor_cdn_in_api,
              analyze_thread, extra_streams):
     threading.Thread.__init__(self)
     self.api_server_model = ApiServerModel(get_stream_api_url, read_token,
                                            monitor_cdn_in_api)
     self.analyze_thread = analyze_thread
     self.stream_db = StreamModel()
     self.logger = logger.get_logger()
     self.extra_streams = extra_streams
     self.api_return_streams = None
     self.retrieve_interval = 60
Ejemplo n.º 5
0
class AnalyzeThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.logger = logger.get_logger()
        self.obs = None
        self.sleep_time = 3
        self.analyzer = Analyzer()
        self.obs_lock = threading.Lock()
        self.stream_model = StreamModel()
        self.sample_model = SampleModel()

    def notify_obs_changed(self, new_obs):
        self.obs_lock.acquire()
        self.obs = new_obs
        self.obs_lock.release()

    def _get_obs(self):
        ret = None
        self.obs_lock.acquire()
        ret = self.obs
        self.obs_lock.release()

        return ret

    def _get_map_stream_ids(self, _map):
        return [msq.stream_id for msq in _map.items]

    def run(self):
        while True:
            all_streams = self._get_obs()
            streams_in_db = self.stream_model.get_all()
            if all_streams == None:
                all_streams = streams_in_db

            sended_requests = []
            _map = {}
            for stream in all_streams:
                sended_requests.append(
                    MediaServerAdminQueryer(self.analyzer, stream['stream_id'],
                                            stream['sample_interface'], _map))

            asyncore.loop(map=_map)

            delete_streams, update_streams, add_streams = self._get_changed_streams(
                streams_in_db, all_streams)

            try:
                self._update_db(delete_streams, update_streams, add_streams,
                                sended_requests)
            except MySQLdb.Error, e:
                self.logger.warn("update_db failed")

            time.sleep(self.sleep_time)
Ejemplo n.º 6
0
class AnalyzeThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.logger = logger.get_logger()
        self.obs = None
        self.sleep_time = 3
        self.analyzer = Analyzer()
        self.obs_lock = threading.Lock()
        self.stream_model = StreamModel() 
        self.sample_model = SampleModel()
    
    def notify_obs_changed(self, new_obs):
        self.obs_lock.acquire()
        self.obs = new_obs
        self.obs_lock.release()

    def _get_obs(self):
        ret = None
        self.obs_lock.acquire()
        ret = self.obs
        self.obs_lock.release()

        return ret 

    def _get_map_stream_ids(self, _map):
        return [msq.stream_id for msq in _map.items]
    
    def run(self):
        while True:
            all_streams = self._get_obs()
            streams_in_db = self.stream_model.get_all()
            if all_streams == None:
                all_streams = streams_in_db
            
            sended_requests = []
            _map = {}
            for stream in all_streams:
                sended_requests.append(MediaServerAdminQueryer(self.analyzer, stream['stream_id'], stream['sample_interface'], _map))

            asyncore.loop(map = _map)
            
            delete_streams, update_streams, add_streams = self._get_changed_streams(streams_in_db, all_streams)

            try:
                self._update_db(delete_streams, update_streams, add_streams, sended_requests)
            except MySQLdb.Error, e:
                self.logger.warn("update_db failed")

            time.sleep(self.sleep_time)