Revision b0727daf

b/snf-astakos-app/astakos/quotaholder/api.py
1
QH_PRACTICALLY_INFINITE =   10**32
b/snf-astakos-app/astakos/quotaholder/callpoint.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from synnefo.lib.quotaholder.api import (
35
    QuotaholderAPI,
36
    QH_PRACTICALLY_INFINITE,
34
from astakos.quotaholder.exception import (
35
    QuotaholderError,
36
    CorruptedError, InvalidDataError,
37 37
    InvalidKeyError, NoEntityError,
38 38
    NoQuantityError, NoCapacityError,
39 39
    ExportLimitError, ImportLimitError,
40 40
    DuplicateError)
41 41

  
42
from synnefo.lib.commissioning import (
43
    Callpoint, CorruptedError, InvalidDataError, ReturnButFail)
44
from synnefo.lib.commissioning.utils.newname import newname
42
from astakos.quotaholder.utils.newname import newname
43
from astakos.quotaholder.api import QH_PRACTICALLY_INFINITE
45 44

  
46 45
from django.db.models import Q, Count
47
from django.db import transaction
48 46
from .models import (Entity, Policy, Holding,
49 47
                     Commission, Provision, ProvisionLog, CallSerial,
50 48
                     now,
......
52 50
                     db_get_commission, db_filter_provision, db_get_callserial)
53 51

  
54 52

  
55
class QuotaholderDjangoDBCallpoint(Callpoint):
56

  
57
    api_spec = QuotaholderAPI()
58

  
59
    def init_connection(self, connection):
60
        if connection is not None:
61
            raise ValueError("Cannot specify connection args with %s" %
62
                             type(self).__name__)
63

  
64
    def commit(self):
65
        transaction.commit()
66

  
67
    def rollback(self):
68
        transaction.rollback()
69

  
70
    def do_make_call(self, call_name, data):
71
        call_fn = getattr(self, call_name, None)
72
        if not call_fn:
73
            m = "cannot find call '%s'" % (call_name,)
74
            raise CorruptedError(m)
75

  
76
        return call_fn(**data)
53
class QuotaholderDjangoDBCallpoint(object):
77 54

  
78 55
    def create_entity(self, context=None, create_entity=()):
79 56
        rejected = []
......
95 72
                                          key=key)
96 73

  
97 74
        if rejected:
98
            raise ReturnButFail(rejected)
75
            raise QuotaholderError(rejected)
99 76
        return rejected
100 77

  
101 78
    def set_entity_key(self, context=None, set_entity_key=()):
......
113 90
            e.save()
114 91

  
115 92
        if rejected:
116
            raise ReturnButFail(rejected)
93
            raise QuotaholderError(rejected)
117 94
        return rejected
118 95

  
119 96
    def list_entities(self, context=None, entity=None, key=None):
......
233 210
                                           policy=p, flags=flags)
234 211

  
235 212
        if rejected:
236
            raise ReturnButFail(rejected)
213
            raise QuotaholderError(rejected)
237 214
        return rejected
238 215

  
239 216
    def _init_holding(self,
......
287 264
                               returned, released,
288 265
                               flags)
289 266
        if rejected:
290
            raise ReturnButFail(rejected)
267
            raise QuotaholderError(rejected)
291 268
        return rejected
292 269

  
293 270
    def reset_holding(self, context=None, reset_holding=()):
......
320 297
                continue
321 298

  
322 299
        if rejected:
323
            raise ReturnButFail(rejected)
300
            raise QuotaholderError(rejected)
324 301
        return rejected
325 302

  
326 303
    def _check_pending(self, entity, resource):
......
384 361
            h.delete()
385 362

  
386 363
        if rejected:
387
            raise ReturnButFail(rejected)
364
            raise QuotaholderError(rejected)
388 365
        return rejected
389 366

  
390 367
    def list_resources(self, context=None, entity=None, key=None):
......
507 484
        objs.filter(policy__in=old_policies, refs=0).delete()
508 485

  
509 486
        if rejected:
510
            raise ReturnButFail(rejected)
487
            raise QuotaholderError(rejected)
511 488
        return rejected
512 489

  
513 490
    def add_quota(self,
......
519 496
        if serial is not None:
520 497
            if clientkey is None:
521 498
                all_pairs = [(q[0], q[1]) for q in sub_quota + add_quota]
522
                raise ReturnButFail(all_pairs)
499
                raise QuotaholderError(all_pairs)
523 500
            try:
524 501
                cs = CallSerial.objects.get(serial=serial, clientkey=clientkey)
525 502
                all_pairs = [(q[0], q[1]) for q in sub_quota + add_quota]
526
                raise ReturnButFail(all_pairs)
503
                raise QuotaholderError(all_pairs)
527 504
            except CallSerial.DoesNotExist:
528 505
                pass
529 506

  
......
601 578
        objs.filter(policy__in=old_policies, refs=0).delete()
602 579

  
603 580
        if rejected:
604
            raise ReturnButFail(rejected)
581
            raise QuotaholderError(rejected)
605 582

  
606 583
        if serial is not None and clientkey is not None:
607 584
            CallSerial.objects.create(serial=serial, clientkey=clientkey)
......
998 975
            e.delete()
999 976

  
1000 977
        if rejected:
1001
            raise ReturnButFail(rejected)
978
            raise QuotaholderError(rejected)
1002 979
        return rejected
1003 980

  
1004 981
    def get_timeline(self, context=None, after="", before="Z", get_timeline=()):
b/snf-astakos-app/astakos/quotaholder/exception.py
1
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34

  
35
class QuotaholderError(Exception):
36
    pass
37

  
38

  
39

  
40
class InvalidKeyError(QuotaholderError):
41
    pass
42

  
43

  
44
class NoEntityError(QuotaholderError):
45
    pass
46

  
47

  
48
class CorruptedError(QuotaholderError):
49
    pass
50

  
51

  
52
class InvalidDataError(QuotaholderError):
53
    pass
54

  
55

  
56
class CommissionException(QuotaholderError):
57
    pass
58

  
59

  
60
class CommissionValueException(CommissionException):
61
    def __init__(self, *args, **kwargs):
62

  
63
        self.source    = kwargs['source']
64
        self.target    = kwargs['target']
65
        self.resource  = kwargs['resource']
66
        self.requested = kwargs['requested']
67
        self.current   = kwargs['current']
68
        self.limit     = kwargs['limit']
69

  
70

  
71
class NoQuantityError(CommissionValueException):
72
    pass
73

  
74

  
75
class NoCapacityError(CommissionValueException):
76
    pass
77

  
78

  
79
class ExportLimitError(CommissionValueException):
80
    pass
81

  
82

  
83
class ImportLimitError(CommissionValueException):
84
    pass
85

  
86

  
87
class DuplicateError(CommissionException):
88
    pass
b/snf-astakos-app/astakos/quotaholder/models.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34

  
35
from synnefo.lib.commissioning import CorruptedError
36 35
from synnefo.lib.db.intdecimalfield import intDecimalField
37 36

  
38 37
from django.db.models import (Model, BigIntegerField, CharField,
b/snf-astakos-app/astakos/quotaholder/utils/newname.py
1
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2
#
3
# Redistribution and use in source and binary forms, with or
4
# without modification, are permitted provided that the following
5
# conditions are met:
6
#
7
#   1. Redistributions of source code must retain the above
8
#      copyright notice, this list of conditions and the following
9
#      disclaimer.
10
#
11
#   2. Redistributions in binary form must reproduce the above
12
#      copyright notice, this list of conditions and the following
13
#      disclaimer in the documentation and/or other materials
14
#      provided with the distribution.
15
#
16
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
# POSSIBILITY OF SUCH DAMAGE.
28
#
29
# The views and conclusions contained in the software and
30
# documentation are those of the authors and should not be
31
# interpreted as representing official policies, either expressed
32
# or implied, of GRNET S.A.
33

  
34
from time import time
35

  
36
_counter = 0
37

  
38
def newname(prefix):
39
    global _counter;
40
    _counter += 1
41
    ident = id(locals())
42
    nonce = int(time() * 1000) + _counter
43
    return "%s%x%x" % (prefix, ident, nonce)

Also available in: Unified diff