示例#1
0
    def createDirs(self, deliveryConf):
        """
            Create Nginx directories

            Args:                
                deliveryConf - Delivery Configuration                    
        """

        # Directories To Create
        ###########################
        dirsToCreate = [
            deliveryConf.ngxLogDir, deliveryConf.ngxRecordsDir,
            deliveryConf.ngxConfDir, deliveryConf.ngxStatusDir,
            deliveryConf.ngxVolatilePrefixDir, deliveryConf.ngxContentBase,
            deliveryConf.ngxLogDirBase
        ]
        for dirToCreate in dirsToCreate:
            try:
                a.infra.file.utils.makeDirs(dirToCreate, reuseExisting=True)
                self.__log("create-log-dir").info(
                    "Create/Validate Nginx Directory - %s", dirToCreate)
            except OSError, e:
                self.__log("create-dir-err").error(
                    "Failed to create Nginx directory - %s", dirToCreate,
                    utils.parseErrnoToString(e))
                return False
示例#2
0
    def prepareConfFile(self, deliveryConf):
        """
            Create Nginx Configuration file From Template Configuration File and Received Configuration

            Args:
                deliveryConf - Delivery Configuration                    

            Returns: True in success

        """
        self.__log("prepare-conf").debug1("Prepare Nginx Confiuration")

        # open template file for reading
        #=================================
        filePath = os.path.join(deliveryConf.imageDir,
                                deliveryConf.kConf.kTemplateFileName)

        try:
            templateFile = open(filePath, 'r')
            self.__log("open-template-conf").debug1(
                "Open Nginx Template configuration File, Path - %s", filePath)
        except IOError, e:
            self.__log("open-template-conf-failed").error(
                "Failed to open Nginx Template configuration File, Path - %s - %s",
                filePath, utils.parseErrnoToString(e))
            return False
示例#3
0
    def __createFlowRecordHeaderFile(self, headersFilePath):

        try:
            headersFile = open(headersFilePath, 'wb')
            self.__log("header-file").debug1(
                "Open/Create Topper Headers File, Path - %s", headersFilePath)
        except IOError, e:
            self.__log("header-file-failed").error(
                "Failed to Open/Create Topper Headers File, Path - %s - %s",
                headersFilePath, utils.parseErrnoToString(e))
            return False
示例#4
0
    def __writeRecord(self):

        self.__outputString = self.__outputString + self.__lineFeed

        try:
            self.__log("write-v-record").debug3(
                "Start Write V Record to FD = %s", self.__dataFileFd)
            os.write(self.__dataFileFd, self.__outputString)
            self.__log("finish-write").debug3(
                "Finish Write V Record %s to FD = %s", self.__outputString,
                self.__dataFileFd)
        except (IOError, OSError) as e:
            self.__log("write-v-record-err").error(
                "Failed to write V Record - %s - FD = %d",
                utils.parseErrnoToString(e), self.__dataFileFd)
示例#5
0
    def __createTopperDirectories(self):

        # Create Topper Data Directory
        #--------------------------------------
        dataDir = os.path.join(self.__conf.topperDir,
                               self.__conf.kConf.kTopperDataDir)

        try:
            a.infra.file.utils.makeDirs(dataDir, reuseExisting=True)
            self.__log("create-topper-dir").info(
                "create Topper data directory - %s", dataDir)

        except OSError, e:
            self.__log("create-topper-dir-err").error(
                "Failed to create Topper data directory - %s", dataDir,
                utils.parseErrnoToString(e))
            return False
示例#6
0
    def __openFile(self):

        fileName = self.__conf.actualNgxRecordsLogFile

        # Create Data File - this file shoud be rotated
        #-------------------------------------------------
        try:
            self.__dataFileFd = os.open(fileName,
                                        os.O_WRONLY | os.O_APPEND | os.O_CREAT,
                                        0644)
            self.__log("records-file-ok").debug1(
                "Create/Open Records Data File, Path - %s - FD - %s", fileName,
                str(self.__dataFileFd))
            self.__isActive = True
        except (OSError, IOError) as e:
            self.__log("records-file-err").error(
                "Failed to Create/Open Records Data File, Path - %s - %s",
                fileName, utils.parseErrnoToString(e))
            self.__isActive = False

        return self.__isActive
示例#7
0
class TopperReporter(object):
    def __init__(self, name, logger):

        self.__name = name
        self.__log = logger.createLogger(
            G_NAME_MODULE_DELIVERY, G_NAME_GROUP_DELIVERY_TOPPER_REPORTER)
        self.__outputString = ""
        self.__fieldSeperator = "\t"
        self.__lineFeed = "\t\t\n"
        self.__filePrefix = "data"
        self.__isActive = False
        self.__dataFileFd = 0

    #-------------------------------------------------------------------------------------------------
    def init(self, conf):

        self.__conf = conf

        if not self.__createTopperDirectories():
            return False

        return True

    #-------------------------------------------------------------------------------------------------
    def start(self):

        return self.__openFile()

    #-------------------------------------------------------------------------------------------------
    def repoen(self):

        oldFd = self.__dataFileFd

        if not self.__openFile():
            return False

        os.close(oldFd)
        self.__log("close-fd").debug1("Close FD = %s", str(oldFd))

        return True

    #-------------------------------------------------------------------------------------------------
    def end(self):

        if self.__isActive:
            self.__log("close-records-file").debug1(
                "Close Records Data File, Path - %s",
                self.__conf.actualNgxRecordsLogFile)
            os.close(self.__dataFileFd)
            self.__dataFileFd = 0

    #-------------------------------------------------------------------------------------------------
    def reportVolume(self, bw):

        if not self.__isActive:
            return False

        self.__beginCommonRecord("V")

        # totalBytesDeliveryPort0In
        self.__appendField(bw.volumeCounters[0].bytesIn)
        # totalBytesDeliveryPort0Out
        self.__appendField(bw.volumeCounters[0].bytesOut)

        # Line Total Bytes
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        # videoBytesDeliveryPort0In
        self.__appendField(bw.volumeCounters[0].bytesIn)
        # videoBytesDeliveryPort0Out
        self.__appendField(bw.volumeCounters[0].bytesOut)

        # Line Video Bytes
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        # is delivery
        self.__appendField(1)

        # totalBytesDeliveryPort1In
        self.__appendField(bw.volumeCounters[1].bytesIn)
        # totalBytesDeliveryPort1Out
        self.__appendField(bw.volumeCounters[1].bytesOut)

        # videoBytesDeliveryPort1In
        self.__appendField(bw.volumeCounters[1].bytesIn)
        # videoBytesDeliveryPort1Out
        self.__appendField(bw.volumeCounters[1].bytesOut)

        # Line Total Bytes ports 4 - 7
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        # Line Video Bytes ports 4 - 7
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)
        self.__appendField(0)

        self.__writeRecord()

        return True

    #private
    #-------------------------------------------------------------------------------------------------
    def __openFile(self):

        fileName = self.__conf.actualNgxRecordsLogFile

        # Create Data File - this file shoud be rotated
        #-------------------------------------------------
        try:
            self.__dataFileFd = os.open(fileName,
                                        os.O_WRONLY | os.O_APPEND | os.O_CREAT,
                                        0644)
            self.__log("records-file-ok").debug1(
                "Create/Open Records Data File, Path - %s - FD - %s", fileName,
                str(self.__dataFileFd))
            self.__isActive = True
        except (OSError, IOError) as e:
            self.__log("records-file-err").error(
                "Failed to Create/Open Records Data File, Path - %s - %s",
                fileName, utils.parseErrnoToString(e))
            self.__isActive = False

        return self.__isActive

    #-------------------------------------------------------------------------------------------------
    # Create Topper Data and Headers Directories
    def __createTopperDirectories(self):

        # Create Topper Data Directory
        #--------------------------------------
        dataDir = os.path.join(self.__conf.topperDir,
                               self.__conf.kConf.kTopperDataDir)

        try:
            a.infra.file.utils.makeDirs(dataDir, reuseExisting=True)
            self.__log("create-topper-dir").info(
                "create Topper data directory - %s", dataDir)

        except OSError, e:
            self.__log("create-topper-dir-err").error(
                "Failed to create Topper data directory - %s", dataDir,
                utils.parseErrnoToString(e))
            return False

        # Create Topper Headers Directory and Write Headers File
        #---------------------------------------------------------
        headersFile = os.path.join(self.__conf.topperDir,
                                   self.__conf.kConf.kTopperHeadersDir)

        headersDir = os.path.dirname(headersFile)

        try:
            a.infra.file.utils.makeDirs(headersDir, reuseExisting=True)
            self.__log("create-topper-hdr-dir").debug2(
                "create Topper header directory - %s", headersDir)
        except OSError, e:
            self.__log("create-topper-hdr-err").error(
                "Failed to create Topper Headers directory - %s", headersDir,
                utils.parseErrnoToString(e))
            return False
示例#8
0
    def prepareConfFile (self,deliveryConf):

        """
            Create Nginx Configuration file From Template Configuration File and Received Configuration

            Args:
                deliveryConf - Delivery Configuration                    

            Returns: True in success

        """
        self.__log("prepare-conf").debug1("Prepare Nginx Confiuration")
        
        
        # open template file for reading
        #=================================
        filePath = os.path.join(deliveryConf.imageDir, deliveryConf.kConf.kTemplateFileName)

        try:
            templateFile = open(filePath,'r')
            self.__log("open-template-conf").debug1("Open Nginx Template configuration File, Path - %s",filePath)
        except IOError, e:
            self.__log("open-template-conf-failed").error("Failed to open Nginx Template configuration File, Path - %s - %s",filePath,utils.parseErrnoToString(e))
            return False        
示例#9
0
    def createDirs(self,deliveryConf):
        """
            Create Nginx directories

            Args:                
                deliveryConf - Delivery Configuration                    
        """

        # Directories To Create
        ###########################
        dirsToCreate = [deliveryConf.ngxLogDir, deliveryConf.ngxRecordsDir, deliveryConf.ngxConfDir, deliveryConf.ngxStatusDir, 
                        deliveryConf.ngxVolatilePrefixDir, deliveryConf.ngxContentBase, deliveryConf.ngxLogDirBase]
        for dirToCreate in dirsToCreate:
            try:
                a.infra.file.utils.makeDirs(dirToCreate,reuseExisting = True)
                self.__log("create-log-dir").info("Create/Validate Nginx Directory - %s",dirToCreate)
            except OSError, e:
                self.__log("create-dir-err").error("Failed to create Nginx directory - %s",dirToCreate,utils.parseErrnoToString(e))
                return False
示例#10
0
        try:
            templateFile = open(filePath,'r')
            self.__log("open-template-conf").debug1("Open Nginx Template configuration File, Path - %s",filePath)
        except IOError, e:
            self.__log("open-template-conf-failed").error("Failed to open Nginx Template configuration File, Path - %s - %s",filePath,utils.parseErrnoToString(e))
            return False        

        # open for write and truncate nginx configuration file
        #======================================================
        confPath = deliveryConf.ngxConfFile

        try:
            confFile = open(confPath,'w')
            self.__log("open-conf").debug1(" Open/Create Nginx Configuration File, Path - %s", confPath)
        except IOError, e:
            self.__log("open-conf-failed").error("Failed to Open/Create Nginx Configuration File, Path - %s - %s",confPath,utils.parseErrnoToString(e))
            templateFile.close()
            return False


        confTemplate = templateFile.read()
        self.__log("read-conf").debug1(" Read Nginx Template Configuration File, Path - %s", templateFile)
        
        # calc conf        
        mask                     = self.__createCpuAffinityMask(deliveryConf)
        logLevel                 = self.__createModuleLog(deliveryConf)
        deliveryInterfacesNames  = self.__createDeliveryInterfacesNames(deliveryConf)
        deliveryPacingParameters = self.__cretaeDeliveryPacingConf(deliveryConf)

        (enableDiskThreads,diskThreadsAio) = self.__createEnableDiskThreadsConf(deliveryConf)
            
示例#11
0
                "Failed to open Nginx Template configuration File, Path - %s - %s",
                filePath, utils.parseErrnoToString(e))
            return False

        # open for write and truncate nginx configuration file
        #======================================================
        confPath = deliveryConf.ngxConfFile

        try:
            confFile = open(confPath, 'w')
            self.__log("open-conf").debug1(
                " Open/Create Nginx Configuration File, Path - %s", confPath)
        except IOError, e:
            self.__log("open-conf-failed").error(
                "Failed to Open/Create Nginx Configuration File, Path - %s - %s",
                confPath, utils.parseErrnoToString(e))
            templateFile.close()
            return False

        confTemplate = templateFile.read()
        self.__log("read-conf").debug1(
            " Read Nginx Template Configuration File, Path - %s", templateFile)

        # calc conf
        mask = self.__createCpuAffinityMask(deliveryConf)
        logLevel = self.__createModuleLog(deliveryConf)
        deliveryInterfacesNames = self.__createDeliveryInterfacesNames(
            deliveryConf)
        deliveryPacingParameters = self.__cretaeDeliveryPacingConf(
            deliveryConf)