def export(self, pos): elements = [] delta_pos = self.gen_pos_delta(pos) for tile in self.view.tiles: tile_html = TileHtmlElement() tile_html.pos = list( map(lambda x: x[0] + x[1], zip(tile.pos, delta_pos))) tile_html.size = tile.size for facet in tile.facets: f = FacetHtmlElement(facet.pic, facet.title) if facet.typecode not in api_module.api_mapping: err("ViewExport::export() no typecode found in api mapping " "structure: %s" % facet.typecode) exit(0) if facet.typecode not in api_module.module_mapping: errtrace("Facet::self_verify() no api module defined for " "typecode %s" % facet.typecode.encode()) exit(0) cl = api_module.module_mapping[facet.typecode] m = cl(facet.id, facet.title) f.url = m.export_html(settings.POSTER_HOME, settings.override) om_output("Facet %s export html %s" % (facet.title, f.url)) if f.url is False: f.url = "#" tile_html.facets.append(f) elements.append(tile_html) s = "" for e in elements: s += e.export() + "\n" return s
def export(self, pos): elements = [] delta_pos = self.gen_pos_delta(pos) for tile in self.view.tiles: tile_html = TileHtmlElement() tile_html.pos = list(map(lambda x: x[0]+x[1], zip(tile.pos, delta_pos))) tile_html.size = tile.size for facet in tile.facets: f = FacetHtmlElement(facet.pic, facet.title) if facet.typecode not in api_module.api_mapping: err("ViewExport::export() no typecode found in api mapping " "structure: %s"%facet.typecode) exit(0) if facet.typecode not in api_module.module_mapping: errtrace("Facet::self_verify() no api module defined for " "typecode %s"%facet.typecode.encode()) exit(0) cl = api_module.module_mapping[facet.typecode] m = cl(facet.id, facet.title) f.url = m.export_html(settings.POSTER_HOME, settings.override) om_output("Facet %s export html %s"%(facet.title, f.url)) if f.url is False: f.url = "#" tile_html.facets.append(f) elements.append(tile_html) s = "" for e in elements: s += e.export() + "\n" return s
def self_verify(self): om_output("verifying the tile %s"%self._short()) settings.exam_stack_push(self) for f in self.facets: if not f.self_verify(): om_err_output("fail to verify %s"%self._short()) return False settings.exam_stack_pop() return True
def refresh_recom_data(user, cnum): import importlib try: m = importlib.import_module("production") fresh_func = getattr(m, "recom_refresh") fresh_func(user, cnum) except Exception, e: om_output("launcher_monitor3::refresh_recom_data() fail to refresh" " recom data, err(%s)"%str(e)) return False
def self_verify(self): om_output("verify view name %s" % self.name) settings.exam_stack_push(self) for t in self.tiles: if not t.self_verify(): om_err_output("fail to verify %s" % self._short()) #return False settings.exam_stack_pop() om_output("complete verifying view %s" % self.name) return True
def self_verify(self): om_output("verify view name %s"%self.name) settings.exam_stack_push(self) for t in self.tiles: if not t.self_verify(): om_err_output("fail to verify %s"%self._short()) #return False settings.exam_stack_pop() om_output("complete verifying view %s"%self.name) return True
def call_alarm_monitor(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) om_output("alarm server bind to %s:%s" % (settings.alarm_server_host, settings.alarm_server_port)) sock.bind((settings.alarm_server_host, settings.alarm_server_port)) while True: data, addr = sock.recvfrom(2048) if not data: continue alarm_obj = cPickle.loads(data) alarm_obj.report_alarm()
def call_alarm_monitor(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) om_output("alarm server bind to %s:%s"%(settings.alarm_server_host, settings.alarm_server_port)) sock.bind((settings.alarm_server_host, settings.alarm_server_port)) while True: data, addr = sock.recvfrom(2048) if not data: continue alarm_obj = cPickle.loads(data) alarm_obj.report_alarm()
def self_verify_basic(self): om_output("Basic verify view name %s" % self.name) settings.exam_stack_push(self) has_false = False for t in self.tiles: if not t.self_verify_basic(): om_err_output("fail to basic verify %s" % self._short()) has_false = True #return False settings.exam_stack_pop() om_output("complete basic verified view %s" % self.name) return not has_false
def self_verify_basic(self): om_output("Basic verify view name %s"%self.name) settings.exam_stack_push(self) has_false = False for t in self.tiles: if not t.self_verify_basic(): om_err_output("fail to basic verify %s"%self._short()) has_false = True #return False settings.exam_stack_pop() om_output("complete basic verified view %s"%self.name) return not has_false
def self_verify(self): om_output("verify the tile %s"%self._short()) settings.exam_stack_push(self) for f in self.facets: if not f.self_verify(): om_err_output("fail to verify %s"%self._short()) # note currently there is only on facet in one tile # and we can return when we found an error, # if you want to check all the facet, and return together # just do not return here settings.exam_stack_pop() return False settings.exam_stack_pop() return True
def export(self, pos): if len(self.view.tiles) == 0: return "" cell = 3 elements = [] i = 0 x = pos[0] for tile in self.view.tiles: tile_html = TileHtmlElement() tile_html.pos = [x, pos[1]] x += view.tiles[i].size[1] + cell i += 1 tile_html.size = tile.size for facet in tile.facets: f = FacetHtmlElement(facet.pic, facet.title) if facet.typecode not in api_module.api_mapping: err("ViewExport::export() no typecode found in api" "mapping structure: %s" % facet.typecode) exit(0) if facet.typecode not in api_module.module_mapping: om_err_output( "Facet::self_verify() no api module defined for " "typecode %s" % facet.typecode.encode()) exit(0) cl = api_module.module_mapping[facet.typecode] m = cl(facet.id) # if the facet is the VIP, the export html will return the dialog # related html text, just attach it to the poster div part if facet.typecode != "5006": f.url = m.export_html(settings.POSTER_HOME, settings.override) else: f.url = "#" f.addtion = m.export_html(settings.POSTER_HOME, settings.override) f.vip_dialog_name = api_module.getVIPinfo.VIP_TITLE_INDEX om_output("Facet %s export html %s" % (facet.title, f.url)) if f.url is False: f.url = "#" else: f.url += "?uuid=%s" % str(settings.uuid) tile_html.facets.append(f) elements.append(tile_html) s = "" for e in elements: s += e.export() + "\n" return s
def self_verify(self): om_output("verify the tile %s" % self._short()) settings.exam_stack_push(self) for f in self.facets: if not f.self_verify(): om_err_output("fail to verify %s" % self._short()) # note currently there is only on facet in one tile # and we can return when we found an error, # if you want to check all the facet, and return together # just do not return here settings.exam_stack_pop() return False settings.exam_stack_pop() return True
def self_verify_basic(self): om_output("Basic verify the Facet %s" % self._short()) settings.exam_stack_push(self) if not self.pic_verify(): settings.exam_stack_pop() return False api = api_module.api_mapping[self.typecode] if self.typecode not in api_module.module_mapping: om_err_output( "Facet::self_verify_basic() no api module defined for " "typecode %s" % self.typecode) settings.exam_stack_pop() return False # get class type related to the typecode cl = api_module.module_mapping[self.typecode] m = cl(self.id) if not m.valid(): om_err_output("apimodule is not valid for typecode %s" % self.typecode) settings.exam_stack_pop() return False if not m.verify_basic(): for ecode, emsgs in m.last_err.items(): om_err_output("fail to basic verify %s" % (self._short())) alarm_msg = "" for m in emsgs: om_err_output("meet error %s, %s" % (ecode, m)) alarm_msg += m + "\n" alm = None # check every error code for the api module, and send related # alarm according to the severity level alarm_msg += "\nlocation:\n%s" % settings.show_exam_stack() if ecode == ErrCode.RESOURCE_CANT_ACCESS: alarm(ALARM_LEVEL.CRITICAL, ALM_NETWORK_ISSUE, alarm_msg) elif ecode == ErrCode.RESOURCE_OFFLINE: alarm(ALARM_LEVEL.CRITICAL, ALM_MEDIA_OFFLINE, alarm_msg) elif ecode == ErrCode.DATA_INVALID: alarm(ALARM_LEVEL.HIGH, ALM_MEDIA_DATA_INVALID, alarm_msg) elif ecode == ErrCode.BAD_LIST_VIEW_MEDIA or \ ecode == ErrCode.BAD_LIST_VIEW_IMAGE: alarm(ALARM_LEVEL.HIGH, ALM_CATEGORY_HAS_BAD_MEDIAS, alarm_msg) else: alarm(ALARM_LEVEL.NORMAL, ALM_BASIC, alarm_msg) settings.exam_stack_pop() return False settings.exam_stack_pop() return True
def self_verify_basic(self): om_output("Basic verify the Facet %s"%self._short()) settings.exam_stack_push(self) if not self.pic_verify(): settings.exam_stack_pop() return False api = api_module.api_mapping[self.typecode] if self.typecode not in api_module.module_mapping: om_err_output("Facet::self_verify_basic() no api module defined for " "typecode %s"%self.typecode) settings.exam_stack_pop() #return False # currently the not support api module need not return fail return True # get class type related to the typecode cl = api_module.module_mapping[self.typecode] m = cl(self.id) if not m.valid(): om_err_output("apimodule is not valid for typecode %s"%self.typecode) settings.exam_stack_pop() return False if not m.verify_basic(): for ecode, emsgs in m.last_err.items(): om_err_output("fail to basic verify %s"%(self._short())) alarm_msg = "" for m in emsgs: om_err_output("meet error %s, %s"%(ecode, m)) alarm_msg += m + "\n" alm = None # check every error code for the api module, and send related # alarm according to the severity level alarm_msg += "\nlocation:\n%s"%settings.show_exam_stack() if ecode == ErrCode.RESOURCE_CANT_ACCESS: alarm(ALARM_LEVEL.CRITICAL, ALM_NETWORK_ISSUE, alarm_msg) elif ecode == ErrCode.RESOURCE_OFFLINE: alarm(ALARM_LEVEL.CRITICAL, ALM_MEDIA_OFFLINE, alarm_msg) elif ecode == ErrCode.DATA_INVALID: alarm(ALARM_LEVEL.HIGH, ALM_MEDIA_DATA_INVALID, alarm_msg) elif ecode == ErrCode.BAD_LIST_VIEW_MEDIA or \ ecode == ErrCode.BAD_LIST_VIEW_IMAGE: alarm(ALARM_LEVEL.HIGH, ALM_CATEGORY_HAS_BAD_MEDIAS, alarm_msg) else: alarm(ALARM_LEVEL.NORMAL, ALM_BASIC, alarm_msg) settings.exam_stack_pop() return False settings.exam_stack_pop() return True
def self_verify_basic(self): """ quickly verify the basic information, return False if found any problem """ om_output("Basic verify the tile %s" % self._short()) settings.exam_stack_push(self) for f in self.facets: if not f.self_verify_basic(): om_err_output("fail to verify %s" % self._short()) settings.exam_stack_pop() # note currently there is only on facet in one tile # and we can return when we found an error, # if you want to check all the facet, and return together # just do not return here return False settings.exam_stack_pop() return True
def self_verify_basic(self): """ quickly verify the basic information, return False if found any problem """ om_output("Basic verify the tile %s"%self._short()) settings.exam_stack_push(self) for f in self.facets: if not f.self_verify_basic(): om_err_output("fail to verify %s"%self._short()) settings.exam_stack_pop() # note currently there is only on facet in one tile # and we can return when we found an error, # if you want to check all the facet, and return together # just do not return here return False settings.exam_stack_pop() return True
def export(self, pos): if len(self.view.tiles) == 0: return "" cell = 3 elements = [] i = 0 x = pos[0] for tile in self.view.tiles: tile_html = TileHtmlElement() tile_html.pos = [x, pos[1]] x += view.tiles[i].size[1] + cell i += 1 tile_html.size = tile.size for facet in tile.facets: f = FacetHtmlElement(facet.pic, facet.title) if facet.typecode not in api_module.api_mapping: err("ViewExport::export() no typecode found in api" "mapping structure: %s"%facet.typecode) exit(0) if facet.typecode not in api_module.module_mapping: om_err_output("Facet::self_verify() no api module defined for " "typecode %s"%facet.typecode.encode()) exit(0) cl = api_module.module_mapping[facet.typecode] m = cl(facet.id) # if the facet is the VIP, the export html will return the dialog # related html text, just attach it to the poster div part if facet.typecode != "5006": f.url = m.export_html(settings.POSTER_HOME, settings.override) else: f.url = "#" f.addtion=m.export_html(settings.POSTER_HOME, settings.override) f.vip_dialog_name = api_module.getVIPinfo.VIP_TITLE_INDEX om_output("Facet %s export html %s"%(facet.title, f.url)) if f.url is False: f.url = "#" else: f.url += "?uuid=%s"%str(settings.uuid) tile_html.facets.append(f) elements.append(tile_html) s = "" for e in elements: s += e.export() + "\n" return s
def parse_facet(data): if not isinstance(data, dict): om_fatal_output("parse_facet()::facet data is not a dict type, exit now") om_output(str(data)) exit(-1) f = Facet(str(data['typeCode']), data['title']) f.id = data['id'] if len(data['backgroundImages']) == 0: # for no backgroundimage problem just set the picture to empty # and the later verification will report related error with alarm om_err_output("parse_facet() fail to parse facet %s due to no " "backgroudImages found"%data['title']) f.pic = "" else: f.pic = data['backgroundImages'][0]['url'] return f
def get_frontpage_data(): data = "" om_output("going to get frontpage data from url %s" %settings.VOD_FRONTPAGE_URL) c = pycurl.Curl() b = StringIO.StringIO() c.setopt(pycurl.URL, settings.VOD_FRONTPAGE_URL) c.setopt(pycurl.CONNECTTIMEOUT, 60) c.setopt(pycurl.WRITEFUNCTION, b.write) try: c.perform() data = b.getvalue() return data except Exception, e: om_err_output("exception meet when getting frontapge data (%s)" %settings.VOD_FRONTPAGE_URL) om_err_output(str(e))
def get_recom_data(): data = "" url = settings.RE_COLUMN_URL + "?uuid={0}&model_id={1}&re_num={2}".\ format(settings.uuid, settings.model_id, settings.re_num) om_output("going to get recom data from url %s"%url) try: c = pycurl.Curl() b = StringIO.StringIO() c.setopt(pycurl.URL, url) c.setopt(pycurl.CONNECTTIMEOUT, 60) c.setopt(pycurl.WRITEFUNCTION, b.write) c.perform() data = b.getvalue() except Exception, e: om_err_output("exception meet when getting recom data (%s)"%url) om_err_output(str(e)) data = None
def parse_facet(data): if not isinstance(data, dict): om_fatal_output( "parse_facet()::facet data is not a dict type, exit now") om_output(str(data)) exit(-1) f = Facet(str(data['typeCode']), data['title']) f.id = data['id'] if len(data['backgroundImages']) == 0: # for no backgroundimage problem just set the picture to empty # and the later verification will report related error with alarm om_err_output("parse_facet() fail to parse facet %s due to no " "backgroudImages found" % data['title']) f.pic = "" else: f.pic = data['backgroundImages'][0]['url'] return f
def get_frontpage_data(): data = "" om_output("get frontpage data from %s"%settings.VOD_FRONTPAGE_URL) try: c = pycurl.Curl() b = StringIO.StringIO() c.setopt(pycurl.URL, settings.VOD_FRONTPAGE_URL) c.setopt(pycurl.CONNECTTIMEOUT, 8) c.setopt(pycurl.WRITEFUNCTION, b.write) c.setopt(pycurl.LOW_SPEED_LIMIT, 1) c.setopt(pycurl.LOW_SPEED_TIME, 20) c.perform() data = b.getvalue() except: om_err_output("exception meet when getting frontapge data (%s)"% settings.VOD_FRONTPAGE_URL) data = None return data
def notify_alarm_by_mail(): if not os.path.exists(alarm_file): return fd = open(alarm_file, "r") content = fd.read() fd.close() if len(content.strip()) == 0: return subject = ("production frontpage service(%s) has alarm need your " "attention" % settings.VENDER) signature = ("\nregards\n" "*****@*****.**") content += "\n" + signature + "\n" from mail import send_mail send_mail(subject, content) om_output("alarm found, mail notification send")
def get_frontpage_data(): data = "" om_output("get frontpage data from %s" % settings.VOD_FRONTPAGE_URL) try: c = pycurl.Curl() b = StringIO.StringIO() c.setopt(pycurl.URL, settings.VOD_FRONTPAGE_URL) c.setopt(pycurl.CONNECTTIMEOUT, 8) c.setopt(pycurl.WRITEFUNCTION, b.write) c.setopt(pycurl.LOW_SPEED_LIMIT, 1) c.setopt(pycurl.LOW_SPEED_TIME, 20) c.perform() data = b.getvalue() except: om_err_output("exception meet when getting frontapge data (%s)" % settings.VOD_FRONTPAGE_URL) data = None return data
def notify_alarm_by_mail(): if not os.path.exists(alarm_file): return fd = open(alarm_file, "r") content = fd.read() fd.close() if len(content.strip()) == 0: return subject = ("production frontpage service(%s) has alarm need your " "attention"%settings.VENDER) signature = ("\nregards\n" "*****@*****.**") content += "\n" + signature + "\n" from mail import send_mail send_mail(subject, content) om_output("alarm found, mail notification send")
def examine(): # quickly verify the basic data of the service, and return fail # as quickly as possible, just return after all the basic data # checking. meet_error = False om_output("firstly start to verify the basic service data, and try " "to return quickly if some basic error found") for view in settings.master_views: if not view.self_verify_basic(): meet_error = True if meet_error: om_err_output("Basic verification fail, just stop not going detail " "data verification") return False # for detail verification, just return false after all data checking # finished, and save all the errors together om_output("start to verify the detail service data") for view in settings.master_views: view.self_verify() return True
def self_verify(self): om_output("verifying the Facet %s"%self._short()) settings.exam_stack_push(self) if not self.pic_verify(): return False api = api_module.api_mapping[self.typecode] if self.typecode not in api_module.module_mapping: om_err_output("Facet::self_verify() no api module defined for typecode %s"% self.typecode) return False cl = api_module.module_mapping[self.typecode] m = cl(self.id) if not m.valid(): om_err_output("apimodule is not valid for typecode %s"%self.typecode) return False if not m.verify(): om_err_output("fail to verify %s"%(self._short())) return False settings.exam_stack_pop() return True
def data_initialize(): om_output("start to initialize frontpage data") retry_times_left = 3 while retry_times_left > 0: frontpage_data = get_frontpage_data() if frontpage_data is not None and len(frontpage_data) > 0: break retry_times_left -= 1 if retry_times_left <= 0: alarm( ALARM_LEVEL.CRITICAL, "NETWORK_ISSUE", "cannot get frontpage " "data after several reties, url(%s) is not accessable" % settings.VOD_FRONTPAGE_URL) exit(-1) try: frontj = json.loads(frontpage_data) except: om_fatal_output("frontpage data can not be jsonlized, exit now") exit(-1) if 'apiMapping' not in frontj: om_fatal_output( "no apiMapping information in frontpage data, exit now") exit(-1) parse_api_mapping(frontj['apiMapping']) if 'masterViews' not in frontj: om_fatal_output( "no apiMapping information in masterViews data, exit now") exit(-1) for v in frontj['masterViews']: view = parse_view(v) if view is None: return False settings.master_views.append(view) return True
def data_initialize(): om_output("start to initialize frontpage data") retry_times_left = 3 while retry_times_left > 0: frontpage_data = get_frontpage_data() if frontpage_data is not None and len(frontpage_data) > 0: break retry_times_left -= 1 if retry_times_left <= 0: alarm(ALARM_LEVEL.CRITICAL, "NETWORK_ISSUE", "cannot get frontpage " "data after several reties, url(%s) is not accessable" %settings.VOD_FRONTPAGE_URL) exit(-1) try: frontj = json.loads(frontpage_data) except: om_fatal_output("frontpage data can not be jsonlized, exit now") exit(-1) if 'apiMapping' not in frontj: om_fatal_output("no apiMapping information in frontpage data, exit now") exit(-1) parse_api_mapping(frontj['apiMapping']) if 'masterViews' not in frontj: om_fatal_output("no apiMapping information in masterViews data, exit now") exit(-1) for v in frontj['masterViews']: view = parse_view(v) if view is None: return False settings.master_views.append(view) return True