Пример #1
0
 def DelExpireVod(self,ExpireDate):
      try:
          DBConn = MySQLdb.connect(host=self.MysqlServer,user=self.MysqlUser,passwd=self.MysqlPasswd)
          DBCursor = DBConn.cursor()
          DBConn.select_db(self.MysqlDB)
          sql = "select instu_id,device_id,rec_date from t_video where expire_date=%s"
          RecordNum = DBCursor.execute(sql,(ExpireDate))
          if RecordNum == 0:
              self.logger.info("No expire vod in %s for all cid in local caiji server"%ExpireDate)
          elif RecordNum > 0:
              for row in DBCursor.fetchall():
                  oid = row[0]
                  cid = row[1]
                  VodGenDate = row[2]
                  self.logger.info("for cid:%s,vod create in %s will be delete"%(cid,VodGenDate))
                  HdfsSavePath = "/vod/%s/%s/%s"%(oid,cid,VodGenDate)
                  WebHdfsObj = WebHadoop(self.HDFSInterfaces,self.HDFSInterfacePort,self.HDFSUser,self.logger)
                  if WebHdfsObj.remove(str(HdfsSavePath)):
                      self.logger.info("expire vod file delete success!")
                  else:
                      self.logger.warning("for cid %s,vod create in %s delete fail"%(cid,VodGenDate))  
              #删除数据库中过期VOD记录
              sql = "delete from t_video where expire_date=%s"
              paras = (ExpireDate)
              RetValNum = DBCursor.execute(sql,(ExpireDate))
              if RetValNum == RecordNum:
                  self.logger.info("Del expire vod record in db success!!!")
              else:
                  self.logger.error("Del expire vod record in db fail!!!,select record is : %s,delete record is : %s"%(RecordNum,RetValNum))                    
          else:
              self.logger.error("Obtain expire vod record fail,no quit!!!")                 
      except Exception,e:
          self.logger.error("Obtain expire vod record exception.no quit!!!")
Пример #2
0
 def UploadFileToHDFS(self,VodTsDir,VodStartTsNum,VodTsNum):
     PrePicFilePath = VodTsDir + "/" + self.PrePicFileName
     M3u8FilePath = VodTsDir + "/" + self.M3u8FileName
     #DebugLog = GetLog(self.cid+"_"+self.M3u8FileName.split(".")[0])
     self.logger.info("Prepare upload File to hdfs,File in dir is : %s"%VodTsDir)
     if os.path.isfile(M3u8FilePath) and os.path.isfile(PrePicFilePath) and len(glob.glob(VodTsDir+"/*.ts")) != 0:
         WebHdfsObj = WebHadoop(self.HDFSInterfaces,self.HDFSInterfacePort,self.HDFSUser,self.logger)
         HdfsTsSaveDir = "/vod/%s/%s/%s"%(self.oid,self.cid,self.VodDate)
         if WebHdfsObj.mkdir(str(HdfsTsSaveDir)) == True:
             self.logger.info("Create dir %s in hdfs success!!!"%HdfsTsSaveDir)
             #上传TS文件到HDFS
             for i in range(VodTsNum):
                 TsNum = VodStartTsNum + i
                 VodTsName = self.VodDate+"%05d"%TsNum+".ts"
                 VodTsPath = VodTsDir+"/"+VodTsName
                 HdfsTsSavePath = "/vod/%s/%s/%s/%s"%(self.oid,self.cid,self.VodDate,VodTsName)     
                 WebHdfsObj.put_file(str(VodTsPath),str(HdfsTsSavePath),overwrite="true")                               
             #上传m3u8文件到HDFS
             HdfsM3u8SavePath = "/vod/%s/%s/%s/%s"%(self.oid,self.cid,self.VodDate,self.M3u8FileName)
             WebHdfsObj.put_file(str(M3u8FilePath),str(HdfsM3u8SavePath),overwrite="true")      
             #上传预览图到HDFS
             HdfsPrePicSavePath = "/vod/%s/%s/%s/%s"%(self.oid,self.cid,self.VodDate,self.PrePicFileName)
             WebHdfsObj.put_file(str(PrePicFilePath),str(HdfsPrePicSavePath),overwrite="true") 
         else:
             self.logger.error("Create dir %s in hdfs fail,quit!!!"%HdfsTsSaveDir)
             sys.exit()                                 
     else:
         self.logger.error("Upload condiition is not satisfied,quit!!!")
         sys.exit()
Пример #3
0
 def DelExpireVod(self, ExpireDate):
     try:
         DBConn = MySQLdb.connect(host=self.MysqlServer,
                                  user=self.MysqlUser,
                                  passwd=self.MysqlPasswd)
         DBCursor = DBConn.cursor()
         DBConn.select_db(self.MysqlDB)
         sql = "select instu_id,device_id,rec_date from t_video where expire_date=%s"
         RecordNum = DBCursor.execute(sql, (ExpireDate))
         if RecordNum == 0:
             self.logger.info(
                 "No expire vod in %s for all cid in local caiji server" %
                 ExpireDate)
         elif RecordNum > 0:
             for row in DBCursor.fetchall():
                 oid = row[0]
                 cid = row[1]
                 VodGenDate = row[2]
                 self.logger.info(
                     "for cid:%s,vod create in %s will be delete" %
                     (cid, VodGenDate))
                 HdfsSavePath = "/vod/%s/%s/%s" % (oid, cid, VodGenDate)
                 WebHdfsObj = WebHadoop(self.HDFSInterfaces,
                                        self.HDFSInterfacePort,
                                        self.HDFSUser, self.logger)
                 if WebHdfsObj.remove(str(HdfsSavePath)):
                     self.logger.info("expire vod file delete success!")
                 else:
                     self.logger.warning(
                         "for cid %s,vod create in %s delete fail" %
                         (cid, VodGenDate))
             #删除数据库中过期VOD记录
             sql = "delete from t_video where expire_date=%s"
             paras = (ExpireDate)
             RetValNum = DBCursor.execute(sql, (ExpireDate))
             if RetValNum == RecordNum:
                 self.logger.info("Del expire vod record in db success!!!")
             else:
                 self.logger.error(
                     "Del expire vod record in db fail!!!,select record is : %s,delete record is : %s"
                     % (RecordNum, RetValNum))
         else:
             self.logger.error("Obtain expire vod record fail,no quit!!!")
     except Exception, e:
         self.logger.error("Obtain expire vod record exception.no quit!!!")
Пример #4
0
 def UploadFileToHDFS(self, VodTsDir, VodStartTsNum, VodTsNum):
     PrePicFilePath = VodTsDir + "/" + self.PrePicFileName
     M3u8FilePath = VodTsDir + "/" + self.M3u8FileName
     #DebugLog = GetLog(self.cid+"_"+self.M3u8FileName.split(".")[0])
     self.logger.info("Prepare upload File to hdfs,File in dir is : %s" %
                      VodTsDir)
     if os.path.isfile(M3u8FilePath) and os.path.isfile(
             PrePicFilePath) and len(glob.glob(VodTsDir + "/*.ts")) != 0:
         WebHdfsObj = WebHadoop(self.HDFSInterfaces, self.HDFSInterfacePort,
                                self.HDFSUser, self.logger)
         HdfsTsSaveDir = "/vod/%s/%s/%s" % (self.oid, self.cid,
                                            self.VodDate)
         if WebHdfsObj.mkdir(str(HdfsTsSaveDir)) == True:
             self.logger.info("Create dir %s in hdfs success!!!" %
                              HdfsTsSaveDir)
             #上传TS文件到HDFS
             for i in range(VodTsNum):
                 TsNum = VodStartTsNum + i
                 VodTsName = self.VodDate + "%05d" % TsNum + ".ts"
                 VodTsPath = VodTsDir + "/" + VodTsName
                 HdfsTsSavePath = "/vod/%s/%s/%s/%s" % (
                     self.oid, self.cid, self.VodDate, VodTsName)
                 WebHdfsObj.put_file(str(VodTsPath),
                                     str(HdfsTsSavePath),
                                     overwrite="true")
             #上传m3u8文件到HDFS
             HdfsM3u8SavePath = "/vod/%s/%s/%s/%s" % (
                 self.oid, self.cid, self.VodDate, self.M3u8FileName)
             WebHdfsObj.put_file(str(M3u8FilePath),
                                 str(HdfsM3u8SavePath),
                                 overwrite="true")
             #上传预览图到HDFS
             HdfsPrePicSavePath = "/vod/%s/%s/%s/%s" % (
                 self.oid, self.cid, self.VodDate, self.PrePicFileName)
             WebHdfsObj.put_file(str(PrePicFilePath),
                                 str(HdfsPrePicSavePath),
                                 overwrite="true")
         else:
             self.logger.error("Create dir %s in hdfs fail,quit!!!" %
                               HdfsTsSaveDir)
             sys.exit()
     else:
         self.logger.error("Upload condiition is not satisfied,quit!!!")
         sys.exit()
Пример #5
0
    def __init__(self, date, cid, logger):

        self.logger = logger
        self.date = date
        self.cid = cid

        self.uid = None
        self.LocalFileDir = None
        self.HdfsFileDir = None

        self.CutTsTime = 10

        self.MysqlServer = "10.2.10.12"
        self.MysqlUser = "******"
        self.MysqlPasswd = "c10udiya"
        self.MysqlDB = "weitongnian"

        self.RedisServer = "10.2.10.19"
        self.RedisPort = 6379
        self.RedisDB = 0

        self.WebHdfsObj = WebHadoop("10.2.0.8,10.2.0.10", 14000,
                                    "cloudiyadatauser", logger)
Пример #6
0
import logging.handlers

def getLog(logflag,loglevel="debug"):
    logger = logging.Logger(logflag)
    logfile = "/var/log/%s.log"%logflag
    hdlr = logging.handlers.RotatingFileHandler(logfile, maxBytes = 5*1024*1024, backupCount = 5)
    formatter = logging.Formatter("%(asctime)s -- [ %(name)s ] -- %(levelname)s -- %(message)s")
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)    
    if loglevel == "debug": 
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    return logger

hosts = "10.2.0.8,10.2.0.10"

port = 14000

username = "******"


logger = getLog("GenVod")

WebHadoopObj = WebHadoop(hosts,port,username,logger)

#WebHadoopObj.put_file("/tmp/debug.txt","/vod/debug.txt")

print WebHadoopObj.mkdir("/kqvod/wyehaha")

Пример #7
0
        if status != 0 and QuitFlag:
            self.logger.error("Cmd : \"%s\" ,Exit code : %s" %
                              (cmd, self.exit))
            self.logger.error("Cmd : \"%s\" ,Stderr : %s" % (cmd, self.stderr))
            self.logger.error("Exec Cmd fail,quit!")
            raise CustomVodException("ExecShellCmdFail",
                                     "Execute Shell Command Exception")
            #sys.exit(self.status)


CutTsTime = 10
FFPROBE = "/usr/local/bin/ffprobe"

logger = GetLog("CjsHttpApi")
ExeShellCmdObj = runCmd(logger)
WebHdfsObj = WebHadoop("10.2.0.8,10.2.0.10", 14000, "cloudiyadatauser", logger)


@mybottle.route('/getplaylist/<uid>/<cid>/<attents>')
def getplaylist(uid, cid, attents):
    try:
        if len(uid) == 6 and len(cid) == 8:
            try:
                TimeStamp_Attenance = int(attents)
            except ValueError:
                return '{"status":1,"info":"Parameters Format Error"}'

            Date = datetime.datetime.fromtimestamp(
                TimeStamp_Attenance).strftime("%Y%m%d")
            Today = datetime.datetime.now().strftime("%Y%m%d")
Пример #8
0
def getLog(logflag, loglevel="debug"):
    logger = logging.Logger(logflag)
    logfile = "/var/log/%s.log" % logflag
    hdlr = logging.handlers.RotatingFileHandler(logfile,
                                                maxBytes=5 * 1024 * 1024,
                                                backupCount=5)
    formatter = logging.Formatter(
        "%(asctime)s -- [ %(name)s ] -- %(levelname)s -- %(message)s")
    hdlr.setFormatter(formatter)
    logger.addHandler(hdlr)
    if loglevel == "debug":
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)
    return logger


hosts = "10.2.0.8,10.2.0.10"

port = 14000

username = "******"

logger = getLog("GenVod")

WebHadoopObj = WebHadoop(hosts, port, username, logger)

#WebHadoopObj.put_file("/tmp/debug.txt","/vod/debug.txt")

print WebHadoopObj.mkdir("/kqvod/wyehaha")