本文整理汇总了Python中WMCore.Database.CMSCouch.Database.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Database.commit方法的具体用法?Python Database.commit怎么用?Python Database.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WMCore.Database.CMSCouch.Database
的用法示例。
在下文中一共展示了Database.commit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testA
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
def testA(self):
""" make some documents and own them"""
guInt = Interface(self.testInit.couchUrl, self.testInit.couchDbName)
#create a couple of docs
couch = Database(self.testInit.couchDbName, self.testInit.couchUrl)
for x in range(10):
doc = Document("document%s" % x, {"Test Data": [1,2,3,4] })
couch.queue(doc)
couch.commit()
self.assertEqual(len(guInt.documentsOwned(self.owner1.group.name, self.owner1.name)), 0)
self.assertEqual(len(guInt.documentsOwned(self.owner2.group.name, self.owner2.name)), 0)
guInt.callUpdate("ownthis","document1", group = self.owner1.group.name, user = self.owner1.name)
self.failUnless("document1" in guInt.documentsOwned(self.owner1.group.name, self.owner1.name))
self.assertEqual(len(guInt.documentsOwned(self.owner1.group.name, self.owner1.name)), 1)
self.assertEqual(len(guInt.documentsOwned(self.owner2.group.name, self.owner2.name)), 0)
guInt.callUpdate("ownthis","document2", group = self.owner2.group.name, user = self.owner2.name)
self.failUnless("document2" in guInt.documentsOwned(self.owner2.group.name, self.owner2.name))
self.assertEqual(len(guInt.documentsOwned(self.owner1.group.name, self.owner1.name)), 1)
self.assertEqual(len(guInt.documentsOwned(self.owner2.group.name, self.owner2.name)), 1)
guInt.callUpdate("newgroup", "group-DataOps", group = "DataOps")
self.failUnless(couch.documentExists("group-DataOps") )
guInt.callUpdate("newuser", "user-damason", group = "DataOps", user = "damason")
self.failUnless(couch.documentExists("user-damason") )
示例2: main
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
def main():
reader = WMStatsReader("http://dummy.cern.ch:5984", "wmagent_summary")
wmstats = Database('wmagent_summary', 'http://dummy.cern.ch:5984')
suspiciousWorkflows = reader.workflowsByStatus(["Processing Done"], stale = False)
for entry in suspiciousWorkflows:
requestDoc = wmstats.document(entry)
statusList = requestDoc['request_status']
if statusList[-2]['status'] == 'normal-archived':
statusList = statusList[:-1]
requestDoc['request_status'] = statusList
wmstats.queue(requestDoc)
wmstats.commit()
示例3: main
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
def main():
requestName = sys.argv[1]
x = Database('workqueue', 'https://cmsweb.cern.ch/couchdb')
y = x.loadView('WorkQueue', 'elementsByParent', {'include_docs' : True}, [requestName])
runningElements = []
for entry in y['rows']:
doc = entry['doc']
element = doc['WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement']
if element['Status'] == 'Running':
runningElements.append(doc)
print "Found %d elements running, fix them?" % len(runningElements)
inputData = raw_input("Type y/n: ")
if inputData != "y":
print "Aborting operation..."
return 0
for doc in runningElements:
doc['WMCore.WorkQueue.DataStructs.WorkQueueElement.WorkQueueElement']['Status'] = 'Done'
x.queue(doc)
x.commit()
print "Operation complete!"
return 0
示例4: test06UploadACDC
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
def test06UploadACDC(self):
# get previous request we can piggyback on
for request in reversed(self.__class__.reqmgr.getRequest()):
request = request['WMCore.RequestManager.DataStructs.Request.Request']['RequestName']
if 'RequestCancellation_t' in request:
self.__class__.requestParams['OriginalRequestName'] = request
break
else:
raise nose.SkipTest("no suitable request in reqmgr to resubmit")
self.__class__.requestParams['InitialTaskPath'] = self.__class__.requestParams['InitialTaskPath'] % self.__class__.requestParams['OriginalRequestName']
self.__class__.requestParams['ACDCServer'] = self.__class__.endpoint + '/couchdb'
# create and upload acdc
service = DataCollectionService(url=self.__class__.endpoint + '/couchdb', database = 'wmagent_acdc')
service.createCollection(self.__class__.requestParams['OriginalRequestName'], 'integration', 'DMWM')
with open(os.path.join(getTestBase(), '..', 'data', 'ACDC', 'linacre_ACDC_ReReco13JulCosmics_120809_130020_117_120823_200309_5735.json')) as infile:
acdc_json = infile.read().replace('linacre_ACDC_ReReco13JulCosmics_120809_130020_117_120823_200309_5735',
self.__class__.requestParams['OriginalRequestName'])
acdc_json = loads(acdc_json)
acdc_database = Database('wmagent_acdc', self.__class__.endpoint + '/couchdb')
acdc_database.commit(acdc_json)
示例5: RESTSink
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
class RESTSink(object):
"""
Alert sink for posting alerts to a REST server.
The class acts as a REST client.
"""
def __init__(self, config):
# configuration values:
# 'uri' attribute (URL of the REST server and resource name)
# in case of CouchDB, the resource name is the database name
# http://servername:port/databaseName
self.config = config
logging.info("Instantiating ...")
# the class currently relies only on 1 REST server possibility - the
# CouchDB server. as explained above, .database will be replaced by
# .connection if both a generic REST server as well as CouchDB are to
# be talked to
split = self.config.uri.rfind('/')
dbName = self.config.uri[split + 1:] # get last item of URI - database name
url = self.config.uri[:split]
# as opposed to CouchSink, here it's assumed the resource (the database name)
# does exist, fail here otherwise
# this check / rest of the constructed may be revised for
# general REST server
server = CouchServer(url)
databases = server.listDatabases()
# there needs to be this database created upfront and also
# couchapp associated with it installed, if it's there, fail
if dbName not in databases:
raise Exception("REST URI: %s (DB name: %s) does not exist." %
(self.config.uri, dbName))
self._database = Database(dbName, url)
logging.info("Initialized.")
def send(self, alerts):
"""
Send a list of alerts to a REST server.
"""
for a in alerts:
doc = Document(None, a)
self._database.queue(doc)
# two options here: either to call commit on the couch myself
# or leave the alerts buffered in the Database queue which means
# the .commit() would be called automatically if size is exceeded
# 1st option:
retVal = self._database.commit()
logging.debug("Stored %s alerts to REST resource, retVals: %s" % (len(alerts), retVal))
return retVal
示例6: DatabaseNotFoundException
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
#.........这里部分代码省略.........
return False
self.logger.log('Trying to delete document "%s"...' % (prepid))
try:
self.db.delete_doc(id=prepid)
if self.cache:
self.__save_to_cache(prepid, None)
return True
except Exception as ex:
self.logger.error('Could not delete document: %s . Reason: %s ' % (prepid, ex))
return False
def update(self, doc={}):
if '_id' in doc:
self.logger.log('Updating document "%s" in "%s"' % (doc['_id'],self.db_name))
if self.__document_exists(doc):
if self.cache:
##JR the revision in the cache is not the one in the DB at this point
# will be retaken at next get
self.__save_to_cache(doc['_id'], None)
return self.save(doc)
self.logger.error('Failed to update document: %s' % (json.dumps(doc)))
return False
def update_all(self, docs=[]):
if not docs:
return False
for doc in docs:
if self.__document_exists(doc):
self.db.queue(doc)
try:
self.db.commit()
return True
except Exception as ex:
self.logger.error('Could not commit changes to database. Reason: %s' % (ex))
return False
def get_all(self, page_num=-1):
try:
limit, skip = self.__pagify(page_num)
if limit >= 0 and skip >= 0:
result = self.db.loadView(self.db_name, "all", options={'limit':limit,'skip':skip, 'include_docs':True})['rows']
res = map(lambda r : r['doc'], result)
return res
result = self.db.loadView(self.db_name, "all",options={'include_docs':True})['rows']
res = map(lambda r : r['doc'], result)
return res
except Exception as ex:
self.logger.error('Could not access view. Reason: %s' % (ex))
return []
def query(self, query='', page_num=0):
if not query:
result = self.get_all(page_num)
#res = map(lambda r : r['doc'], result)
return result
try:
result = self.__query(query, page=page_num)
#res = map(lambda r : r['doc'], result)
return result
except Exception as ex:
self.logger.error('Could not load view for query: <%s> . Reason: %s' % (query, ex))
return []
示例7: main
# 需要导入模块: from WMCore.Database.CMSCouch import Database [as 别名]
# 或者: from WMCore.Database.CMSCouch.Database import commit [as 别名]
def main():
parser = OptionParser()
parser.add_option("-f", "--input-acdc", dest="acdcList")
parser.add_option("-m", "--input-mapfile", dest="mapFile")
parser.add_option("-u", "--url", dest="url")
parser.add_option("-d", "--dry-run", dest="dryRun",
action="store_true", default=False)
parser.add_option("-l", "--log-file", dest="logFile")
(options, _) = parser.parse_args()
handle = open(options.logFile, 'w')
url = options.url
database = 'wmagent_acdc'
acdcDB = Database(database, url)
handle.write('Opening ACDC database in %s/%s\n' % (url, database))
inputACDC = readACDCInput(options.acdcList)
usersMap = readUsersMap(options.mapFile)
handle.write('Have %d workflows to fix\n' % len(inputACDC))
handle.write('=================================================================\n')
for workflow in inputACDC:
collection_name = workflow['collection_name']
fileset_name = workflow['fileset_name']
original_dn = workflow['original_dn']
handle.write('Original workflow: %s\n' % collection_name)
handle.write('Original task: %s\n' % fileset_name)
handle.write('Original owner DN: %s\n' % original_dn)
if original_dn in usersMap:
handle.write('This DN maps to %s-%s\n' % (usersMap[original_dn][1], usersMap[original_dn][0]))
else:
handle.write('The original DN can not be found in the map file, skipping the workflow\n')
continue
params = {'reduce' : False,
'key' : [usersMap[original_dn][1], usersMap[original_dn][0], collection_name, fileset_name]}
result = acdcDB.loadView('ACDC', 'owner_coll_fileset_docs', params)
rows = result['rows']
docIds = map(lambda x : x['id'], rows)
handle.write('Found %d documents to change\n' % len(rows))
handle.write('Changing from %s-%s to %s-%s\n' % (usersMap[original_dn][1], usersMap[original_dn][0],
workflow['group'], workflow['owner']))
for docId in docIds:
doc = acdcDB.document(docId)
doc['owner'] = {'group' : workflow['group'], 'user' : workflow['owner']}
if not options.dryRun:
acdcDB.queue(doc)
if not options.dryRun:
response = acdcDB.commit()
else:
response = 'This is a dry-run no changes were made'
handle.write('Response to write operation: %s\n'% str(response))
handle.write('Response length: %d\n' % len(response))
handle.write('=================================================================\n')
handle.write('Finished script')
handle.close()