当前位置: 首页>>代码示例>>Python>>正文


Python Library.getDaemon方法代码示例

本文整理汇总了Python中Library.getDaemon方法的典型用法代码示例。如果您正苦于以下问题:Python Library.getDaemon方法的具体用法?Python Library.getDaemon怎么用?Python Library.getDaemon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Library的用法示例。


在下文中一共展示了Library.getDaemon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fuzzLoad

# 需要导入模块: import Library [as 别名]
# 或者: from Library import getDaemon [as 别名]
def fuzzLoad(emulationID, distributionID, runNo, min, fuzzRange, serverip, serverport, protocol, salt, timedelay):
    runBackfuzzPidNo=0

    if (timedelay == 0 or timedelay == "0"):
        timedelay = 0.8

    try:
        print "python", BACKFUZZ_PATH, "-h", str(serverip), "-p", str(serverport), "-min", str(min), "-max", str(int(min) + int(fuzzRange)), "-s ", str(salt), "-pl", str(protocol).upper(), "-t", str(timedelay)

        runBackfuzz = subprocess.Popen(["python",BACKFUZZ_PATH, "-h", str(serverip), "-p", str(serverport), "-min", str(min), "-max", str(int(min) + int(fuzzRange)), "-s", str(salt), "-pl", str(protocol).upper(), "-t", str(timedelay), "&&"], cwd= BACKFUZZ_PATH[:-11], stdin=subprocess.PIPE)#,stdout=subprocess.PIPE)
        runBackfuzz.stdin.flush()
        runBackfuzz.stdin.write("\r\n")
        runBackfuzzPidNo =runBackfuzz.pid

        if zombieBuster(runBackfuzzPidNo, "backfuzz"):
            print "Job failed, sending wait()."
            runBackfuzz.wait()
            message="Error in the emulator execution"
            executed="False"
            dbWriter(distributionID,runNo,message,executed)
            return False
        else:
            print "Success! waiting on process to finish running"
            runBackfuzz.wait()
            
            print "Process finished, writing into DB"
            message="Success"
            executed="True"
            dbWriter(distributionID,runNo,message,executed)
            
            print "Process stopped, trying to schedule next job"
            try:
                import Library,DistributionManager 
            
                daemon=Library.getDaemon()
                newEmulation=daemon.getEmuObject(emulationID)
                DistributionManager.createDistributionRuns(newEmulation)
            except Exception,e:
                print "Emulation object error: ",e
            
            return True

    except Exception, e:
        return "run_backfuzzer job exception: ", e
开发者ID:cragusa,项目名称:cocoma,代码行数:46,代码来源:run_backfuzz.py

示例2: createDistribution

# 需要导入模块: import Library [as 别名]
# 或者: from Library import getDaemon [as 别名]
def createDistribution(newEmulation):
    daemon=Library.getDaemon()
    
    global producer
    if producer is None:
        # print "In distributionManager, copying producer"
        producer = producer()

    # print "Who calls "+sys._getframe(0).f_code.co_name+": "+sys._getframe(1).f_code.co_name
#    distLoggerDM = ""
    
    # if distLoggerDM is None:
    #        distLoggerDM=Library.loggerSet("Distribution Manager",str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)+"-syslog"+"_"+str(newEmulation.startTimeEmu)+".csv")



    # connecting to the DB and storing parameters
    loggerJobReply = "No logger scheduled"
    try:

        conn = Library.dbconn()
        c = conn.cursor()
                
        # 1. Populate "emulation"
        c.execute('INSERT INTO emulation (emulationName,emulationType,resourceType,active,logging,logFrequency,logLevel,xmlData) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [newEmulation.emulationName, newEmulation.emulationType, newEmulation.resourceTypeEmulation, 1, newEmulation.emulationLog, newEmulation.emulationLogFrequency, newEmulation.emulationLogLevel, newEmulation.xmlData])
        newEmulation.setEmulationID(c.lastrowid)
        # start logger here once we know emulation ID
#        distLoggerDM = singleLogger("Distribution Manager", None, str(newEmulation.emulationID) + "-" + str(newEmulation.emulationName) + "-syslog" + "_" + str(newEmulation.startTimeEmu) + ".csv")
        
        c.execute('UPDATE emulation SET emulationName=? WHERE emulationID =?', (str(newEmulation.emulationID) + "-" + newEmulation.emulationName, newEmulation.emulationID))
        
        # 2. We populate "emulationLifetime" table  
        c.execute('INSERT INTO emulationLifetime (startTime,stopTime,emulationID) VALUES (?,?,?)', [newEmulation.startTimeEmu, newEmulation.stopTimeEmu, newEmulation.emulationID])
        emulationLifetimeID = c.lastrowid

        newEmulation.setEmulationLifetimeID(emulationLifetimeID)
        c.execute('UPDATE emulationLifetime SET stopTime=? WHERE emulationLifetimeID =?',(newEmulation.stopTimeEmu,emulationLifetimeID))
        c.execute('UPDATE emulation SET emulationLifetimeID=? WHERE emulationID=?',(emulationLifetimeID,newEmulation.emulationID))
        
        conn.commit()
        c.close()
        
        """
        # Here we create runs
        """

#        raise Exception ("newEmulation.emulationLog = " + str(newEmulation.emulationLog))
        if newEmulation.emulationLog == "1":
            
            # creating run for logger with probe interval of 2 seconds
            distLoggerDM = singleLogger("Distribution Manager", None, str(newEmulation.emulationID) + "-" + str(newEmulation.emulationName) + "-syslog" + "_" + str(newEmulation.startTimeEmu) + ".csv")
            interval = int(newEmulation.emulationLogFrequency)
            singleRunStartTime = Library.timeConv(newEmulation.startTimeEmu)
            loggerJobReply = daemon.createLoggerJob(singleRunStartTime, newEmulation.stopTimeEmu, interval, newEmulation.emulationID, newEmulation.emulationName, newEmulation.startTimeEmu)       
        
        createEndJob(daemon, newEmulation)
        
    except sqlite.Error, e:
        print e
        return "SQL error:", e
        sys.exit(1)
开发者ID:cragusa,项目名称:cocoma,代码行数:63,代码来源:DistributionManager.py

示例3: createDistributionRuns

# 需要导入模块: import Library [as 别名]
# 或者: from Library import getDaemon [as 别名]
def createDistributionRuns(newEmulation):
    daemon=Library.getDaemon()
    daemon.setEmuObject(newEmulation)
    
    for distro in newEmulation.distroList:

        if distro.getDistributionID() != "none":
            #do nothing continue to next element, because this distribution was already scheduled.
            print "Already scheduled"

        else:
                        
            try:
                conn = Library.dbconn()
                c = conn.cursor()
                    
                # 1. We populate "distribution" table      
                c.execute('INSERT INTO distribution (distributionGranularity, distributionType,emulator,distributionName,startTime,duration,emulationID) VALUES (?, ?, ?, ?,?, ?,?)', [distro.granularity, distro.type, distro.emulatorName,distro.name,distro.startTime,distro.duration,newEmulation.emulationID])
                distro.setDistributionID(c.lastrowid)
                daemon.setEmuObject(newEmulation)
                '''
                {'startLoad': u'10', 'stopLoad': u'90'}
                '''
                #print "distributionArg:", distributionArg
                #print "emulatorArg:",emulatorArg
                
                #2. populate DistributionParameters, of table determined by distributionType name in our test it is "linearDistributionParameters"
                for d in distro.distroArgs :
                    c.execute('INSERT INTO DistributionParameters (paramName,value,distributionID) VALUES (?, ?, ?)',[d,distro.distroArgs[d],distro.ID])
                distributionParametersID=c.lastrowid
                
                
                c.execute('UPDATE distribution SET distributionParametersID=? WHERE distributionID =?',(distributionParametersID,distro.ID))
                
                
                for emu in distro.emulatorArg :
                    c.execute('INSERT INTO EmulatorParameters (paramName,value,resourceType,distributionID) VALUES (?, ?, ?,?)',[emu,distro.emulatorArg[emu],distro.resourceType,distro.ID])
                distributionParametersID=c.lastrowid
                
                conn.commit()
                c.close()
            except sqlite.Error, e:
                print "Error %s:" % e.args[0]
                print e
                sys.exit(1)                        
                   
            startTime= Library.timeConv(newEmulation.startTimeEmu)
            startTimesec=time.mktime(startTime.timetuple()) + float(distro.startTime)
            #making sure that the run after event has valid date for scheduling
            nowTime = Library.timeSinceEpoch(5)
            if startTimesec < nowTime:
                startTimesec = nowTime + float(distro.startTime)
                
            '''
            1. Load the module according to Distribution Type to create runs
            '''
    
            #1. Get required module loaded
            modhandleMy=Library.loadDistribution(distro.type)
            #Check if error returned
            if (type(modhandleMy) is str):
                raise Exception (modhandleMy)
             
            #2. Use this module for calculation and run creation   
            stressValues,runStartTime,runDurations,triggerType=modhandleMy(newEmulation.emulationID,newEmulation.emulationName,newEmulation.getEmulationLifetimeID(),startTimesec,distro.duration, int(distro.granularity),distro.distroArgs,distro.resourceType,HOMEPATH)

            if (distro.type != "event"): #event distributions don't require a minjobtime
                try:
                    if (distro.distroArgs.has_key("minjobtime")):
                        minJobTime = distro.distroArgs["minjobtime"]
                    else:
                        minJobTime = 2
                    (stressValues, runStartTime, runDurations) = Library.checkMinJobTime(distro.name, stressValues, runStartTime, runDurations, distro.distroArgs["minjobtime"])
                except Exception, e:
                    print "Could not enforce minimum job time. " + str(e)

            runStartTime = Library.staggerStartTimes(runStartTime)
            (stressValues, runStartTime, runDurations) = Library.removeZeroJobs(stressValues, runStartTime, runDurations) #Remove jobs with a stressValue of 0
            #event and time type disro's separation
            try :
                    n=0
                    for vals in stressValues:
                        #print "stressValues: ",vals
                        try:
                            #print "Things that are sent to daemon:\n",emulationID,emulationName,distributionName,emulationLifetimeID,runDurations[n],emulator,emulatorArg,resourceTypeDist,vals,runStartTime[n],str(n)
                            daemon.hello()
                            #Sending emulation name already including ID stamp
                            emulationNameID =str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)
                            
                            schedulerReply = str(daemon.createJob(newEmulation.emulationID,emulationNameID,distro.ID,distro.name,newEmulation.getEmulationLifetimeID(),runDurations[n],distro.emulatorName,distro.emulatorArg,distro.resourceType,vals,runStartTime[n],str(n),runDurations[n]))
                            distLoggerDM=singleLogger("Distribution Manager",None,str(newEmulation.emulationID)+"-"+str(newEmulation.emulationName)+"-syslog"+"_"+str(newEmulation.startTimeEmu)+".csv")
                            distLoggerDM.info("Job Created: "+schedulerReply)
            
                            
                            
                            #adding values to the table for recovery
                            try:
                                conn = Library.dbconn()
                                c = conn.cursor()
                                    
#.........这里部分代码省略.........
开发者ID:cragusa,项目名称:cocoma,代码行数:103,代码来源:DistributionManager.py


注:本文中的Library.getDaemon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。