Revision 2fd11a01

b/snf-common/synnefo/lib/quotaholder/api/quotaholder.py
92 92
                                regex       =   '(ACCEPT|REJECT):.*',
93 93
                                maxlen      =   128         )
94 94

  
95
Bool                =   Integer(classname='Bool')
96

  
97 95
class QuotaholderAPI(Specificator):
98 96

  
99 97
    def create_entity   (
......
248 246
        rejected = ListOf(Entity, Resource)
249 247
        return rejected
250 248

  
251
    def ack_serial (
249
    def query_serials   (
252 250
                self,
253 251
                context     =   Context,
254 252
                clientkey   =   ClientKey,
255
                serial      =   Serial,
256
                fetch_args  =   Bool
253
                serials     =   ListOf(Serial)
254
        ):
255
        return ListOf(Serial)
256

  
257
    def ack_serials (
258
                self,
259
                context     =   Context,
260
                clientkey   =   ClientKey,
261
                serials     =   ListOf(Serial)
257 262
        ):
258
        return ListOf(Entity, Resource)
263
        return Nothing
259 264

  
260 265
    def issue_commission    (
261 266
                self,
b/snf-quotaholder-app/quotaholder_django/quotaholder_app/callpoint.py
49 49
                     now,
50 50
                     db_get_entity, db_get_holding, db_get_policy,
51 51
                     db_get_commission, db_filter_provision, db_get_callserial)
52
import json
53 52

  
54 53
class QuotaholderDjangoDBCallpoint(Callpoint):
55 54

  
......
570 569
            raise ReturnButFail(rejected)
571 570

  
572 571
        if serial is not None and clientkey is not None:
573
            data = json.dumps(all_pairs)
574
            CallSerial.objects.create(serial=serial,
575
                                      clientkey=clientkey,
576
                                      data=data)
572
            CallSerial.objects.create(serial=serial, clientkey=clientkey)
577 573
        return rejected
578 574

  
579
    def ack_serial(self, context={}, clientkey=None, serial=None,
580
                   fetch_args=False):
575
    def ack_serials(self, context={}, clientkey=None, serials=()):
576
        if clientkey is None:
577
            return
578

  
579
        for serial in serials:
580
            try:
581
                c = db_get_callserial(clientkey=clientkey,
582
                                      serial=serial,
583
                                      for_update=True)
584
                c.delete()
585
            except CallSerial.DoesNotExist:
586
                pass
587
        return
588

  
589
    def query_serials(self, context={}, clientkey=None, serials=()):
581 590
        result = []
582
        try:
583
            cs = db_get_callserial(clientkey=clientkey,
584
                                   serial=serial,
585
                                   for_update=True)
586
        except CallSerial.DoesNotExist:
591
        append = result.append
592

  
593
        if clientkey is None:
587 594
            return result
588 595

  
589
        if fetch_args:
590
            result = json.loads(cs.data)
596
        if not serials:
597
            cs = CallSerial.objects.filter(clientkey=clientkey)
598
            return [c.serial for c in cs]
599

  
600
        for serial in serials:
601
            try:
602
                db_get_callserial(clientkey=clientkey, serial=serial)
603
                append(serial)
604
            except CallSerial.DoesNotExist:
605
                pass
591 606

  
592
        cs.delete()
593 607
        return result
594 608

  
595 609
    def issue_commission(self,  context     =   {},
b/snf-quotaholder-app/quotaholder_django/quotaholder_app/models.py
191 191

  
192 192
    serial      =   BigIntegerField(null=False)
193 193
    clientkey   =   CharField(max_length=4096, null=False)
194
    data        =   CharField(max_length=256*1024)
194

  
195 195
    objects     =   ForUpdateManager()
196 196

  
197 197
    class Meta:
b/snf-quotaholder-app/quotaholder_django/test/simpletests.py
254 254
                                         (e0, resource1, k0, 0, None, (-5), 0)])
255 255
        self.assertEqual(r, [(e0, resource0), (e0, resource1)])
256 256

  
257
        r = self.qh.ack_serial(clientkey=self.client,
258
                               serial=1,
259
                               fetch_args=True)
257
        r = self.qh.query_serials(clientkey=self.client, serials=[1, 2])
258
        self.assertEqual(r, [1])
260 259

  
261
        self.assertEqual(r, [(e0, resource0), (e0, resource1)])
260
        r = self.qh.query_serials(clientkey=self.client, serials=[])
261
        self.assertEqual(r, [1])
262 262

  
263
        r = self.qh.ack_serial(clientkey=self.client,
264
                               serial=1,
265
                               fetch_args=True)
263
        r = self.qh.query_serials(clientkey=self.client, serials=[2])
264
        self.assertEqual(r, [])
265

  
266
        r = self.qh.ack_serials(clientkey=self.client, serials=[1])
266 267

  
268
        r = self.qh.query_serials(clientkey=self.client, serials=[1, 2])
267 269
        self.assertEqual(r, [])
268 270

  
271
        # idempotent
272
        r = self.qh.ack_serials(clientkey=self.client, serials=[1])
273

  
269 274
        # serial has been deleted
270 275
        r = self.qh.add_quota(clientkey=self.client,
271 276
                              serial=1,

Also available in: Unified diff