コード例 #1
0
ファイル: WorkQueueBackend.py プロジェクト: vytjan/WMCore
    def insertElements(self, units, parent=None):
        """
        Insert element to database

        @param parent is the parent WorkQueueObject these element's belong to.
                                            i.e. a workflow which has been split
        """
        if not units:
            return
        # store spec file separately - assume all elements share same spec
        self.insertWMSpec(units[0]['WMSpec'])
        newUnitsInserted = []
        for unit in units:

            # cast to couch
            if not isinstance(unit, CouchWorkQueueElement):
                unit = CouchWorkQueueElement(self.db, elementParams=dict(unit))

            if parent:
                unit['ParentQueueId'] = parent.id
                unit['TeamName'] = parent['TeamName']
                unit['WMBSUrl'] = parent['WMBSUrl']

            if unit._couch.documentExists(unit.id):
                self.logger.info(
                    'Element "%s" already exists, skip insertion.' % unit.id)
                continue
            else:
                newUnitsInserted.append(unit)
            unit.save()
            unit._couch.commit(all_or_nothing=True)

        return newUnitsInserted
コード例 #2
0
ファイル: WorkQueueBackend.py プロジェクト: ticoann/WMCore
    def insertElements(self, units, parent = None):
        """
        Insert element to database

        @param parent is the parent WorkQueueObject these element's belong to.
                                            i.e. a workflow which has been split
        """
        if not units:
            return
        # store spec file separately - assume all elements share same spec
        self.insertWMSpec(units[0]['WMSpec'])
        for unit in units:

            # cast to couch
            if not isinstance(unit, CouchWorkQueueElement):
                unit = CouchWorkQueueElement(self.db, elementParams = dict(unit))

            if parent:
                unit['ParentQueueId'] = parent.id
                unit['TeamName'] = parent['TeamName']
                unit['WMBSUrl'] = parent['WMBSUrl']

            if unit._couch.documentExists(unit.id):
                self.logger.info('Element "%s" already exists, skip insertion.' % unit.id)
                continue
            unit.save()

        unit._couch.commit(all_or_nothing = True)
        return
コード例 #3
0
 def testIdSaved(self):
     """Generated id used as db id"""
     ele = CouchWorkQueueElement(self.couch_db, elementParams = {'RequestName' : 'test'})
     ele.save()
     self.couch_db.commit(timestamp = True)
     self.assertTrue(self.couch_db.documentExists(ele.id))
     self.assertEqual(self.couch_db.info()['doc_count'], 1)
コード例 #4
0
 def testIdSaved(self):
     """Generated id used as db id"""
     ele = CouchWorkQueueElement(self.couch_db,
                                 elementParams={'RequestName': 'test'})
     ele.save()
     self.couch_db.commit(timestamp=True)
     self.assertTrue(self.couch_db.documentExists(ele.id))
     self.assertEqual(self.couch_db.info()['doc_count'], 1)
コード例 #5
0
 def testIdFromDbImmutable(self):
     """Modifying element id algorithm doesn't change existing id's"""
     ele = CouchWorkQueueElement(self.couch_db, elementParams = {'RequestName' : 'test'})
     ele.save()
     self.couch_db.commit(timestamp = True)
     ele2 = CouchWorkQueueElement(self.couch_db, id = ele.id).load()
     ele2['RequestName'] = 'ThisWouldCauseIdToChange'
     # id should not change
     self.assertEqual(ele.id, ele2.id)
     # save should modify existing element
     ele2.save()
     self.couch_db.commit(timestamp = True)
     self.assertEqual(self.couch_db.info()['doc_count'], 1)
コード例 #6
0
 def testIdFromDbImmutable(self):
     """Modifying element id algorithm doesn't change existing id's"""
     ele = CouchWorkQueueElement(self.couch_db,
                                 elementParams={'RequestName': 'test'})
     ele.save()
     self.couch_db.commit(timestamp=True)
     ele2 = CouchWorkQueueElement(self.couch_db, id=ele.id).load()
     ele2['RequestName'] = 'ThisWouldCauseIdToChange'
     # id should not change
     self.assertEqual(ele.id, ele2.id)
     # save should modify existing element
     ele2.save()
     self.couch_db.commit(timestamp=True)
     self.assertEqual(self.couch_db.info()['doc_count'], 1)