本文整理汇总了Python中Library.dbconn方法的典型用法代码示例。如果您正苦于以下问题:Python Library.dbconn方法的具体用法?Python Library.dbconn怎么用?Python Library.dbconn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Library
的用法示例。
在下文中一共展示了Library.dbconn方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dbWriter
# 需要导入模块: import Library [as 别名]
# 或者: from Library import dbconn [as 别名]
def dbWriter (distributionID,runNo,message,executed):
try:
conn =Library.dbconn()
c = conn.cursor()
c.execute('UPDATE runLog SET executed=? ,message=? WHERE distributionID =? and runNo=?',(executed,message,distributionID,runNo))
conn.commit()
except sqlite.Error, e:
c.close()
conn.close()
schedFileLogger.debug("Values: "+str(distributionID)+"-"+str(runNo)+"-"+str(message)+"-"+str(executed))
schedFileLogger.error("Unable to connect to DB")
schedFileLogger.exception(str(e))
sys.exit(1)
示例2: dateOverlapCheck
# 需要导入模块: import Library [as 别名]
# 或者: from Library import dbconn [as 别名]
def dateOverlapCheck(self, startTime, stopTime):
startTimeSec = Library.timestamp(Library.timeConv(startTime))
stopTimeSec = startTimeSec + float(stopTime)
# print startTimeSec
# print stopTimeSec
dtNowSec = Library.timestamp(dt.now())
# print "dt.now():",dt.now()
# print "dtNow:",dtNowSec
if startTimeSec <= dtNowSec or stopTimeSec <= dtNowSec:
print "Error: Dates cannot be in the past"
return "Error: Dates cannot be in the past"
if startTimeSec >= stopTimeSec:
print "Start Date cannot be the same or later than stop time"
return
n = "1"
try:
conn = Library.dbconn()
c = conn.cursor()
c.execute('SELECT startTime, stopTime FROM emulationLifetime')
emulationLifetimeFetch = c.fetchall()
if emulationLifetimeFetch:
for row in emulationLifetimeFetch:
# print row
startTimeDBsec = Library.timestamp(Library.timeConv(row[0]))
stopTimeDBsec = startTimeDBsec + float(row[1])
if startTimeSec >= startTimeDBsec and startTimeSec <= stopTimeDBsec:
# print "Emulation already exist for this date change the date(1)"
n = "Emulation already exist for this date change the date(1)"
if stopTimeSec >= startTimeDBsec and stopTimeSec <= stopTimeDBsec:
# print "Emulation already exist for this date change the date(2)"
n = "Emulation already exist for this date change the date(2)"
if startTimeSec <= startTimeDBsec and stopTimeSec >= stopTimeDBsec:
# print "Emulation already exist for this date change the date(3)"
n = "Emulation already exist for this date change the date(3)"
else:
pass
conn.commit()
c.close()
except Exception, e:
print "dateOverlapCheck() SQL Error %s:" % e.args[0]
print e
return str(e)
示例3: createDistribution
# 需要导入模块: import Library [as 别名]
# 或者: from Library import dbconn [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)
示例4: createDistributionRuns
# 需要导入模块: import Library [as 别名]
# 或者: from Library import dbconn [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()
#.........这里部分代码省略.........