Revision b830f774

b/snf-astakos-app/astakos/api/quotas.py
35 35
from django.views.decorators.csrf import csrf_exempt
36 36
from django.http import HttpResponse
37 37

  
38
from synnefo.lib.db.transaction import commit_on_success_strict
38
from snf_django.lib.db.transaction import commit_on_success_strict
39 39
from astakos.api.util import json_response
40 40

  
41 41
from snf_django.lib import api
b/snf-astakos-app/astakos/im/management/commands/astakos-quota.py
38 38
from astakos.im.quotas import sync_all_users, sync_users
39 39
from astakos.im.functions import get_user_by_uuid
40 40
from astakos.im.management.commands._common import is_uuid, is_email
41
from synnefo.lib.db.transaction import commit_on_success_strict
41
from snf_django.lib.db.transaction import commit_on_success_strict
42 42

  
43 43
import logging
44 44
logger = logging.getLogger(__name__)
b/snf-astakos-app/astakos/im/management/commands/project-control.py
36 36
from django.core.management.base import BaseCommand, CommandError
37 37
from astakos.im.functions import (terminate, suspend, resume, check_expiration,
38 38
                                  approve_application, deny_application)
39
from synnefo.lib.db.transaction import commit_on_success_strict
39
from snf_django.lib.db.transaction import commit_on_success_strict
40 40

  
41 41

  
42 42
class Command(BaseCommand):
b/snf-astakos-app/astakos/im/management/commands/resource-import.py
37 37
from django.db.utils import IntegrityError
38 38
from django.utils import simplejson as json
39 39

  
40
from synnefo.lib.db.transaction import commit_on_success_strict
40
from snf_django.lib.db.transaction import commit_on_success_strict
41 41
from astakos.im.resources import add_resource
42 42

  
43 43

  
b/snf-astakos-app/astakos/im/management/commands/user-update.py
44 44
                                  set_pending_application_limit,
45 45
                                  unset_pending_application_limit)
46 46
from ._common import remove_user_permission, add_user_permission
47
from synnefo.lib.db.transaction import commit_on_success_strict
47
from snf_django.lib.db.transaction import commit_on_success_strict
48 48

  
49 49

  
50 50
class Command(BaseCommand):
b/snf-astakos-app/astakos/im/views.py
114 114
from astakos.im import settings as astakos_settings
115 115
from astakos.im.api.callpoint import AstakosCallpoint
116 116
from astakos.im import auth_providers as auth
117
from synnefo.lib.db.transaction import commit_on_success_strict
117
from snf_django.lib.db.transaction import commit_on_success_strict
118 118
from astakos.im.ctx import ExceptionHandler
119 119

  
120 120
logger = logging.getLogger(__name__)
b/snf-astakos-app/astakos/test/stress.py
50 50
from astakos.im.api.callpoint import AstakosCallpoint
51 51
from astakos.im.functions import get_chain_of_application_id
52 52
from views import submit, approve, join, leave
53
from synnefo.lib.db.transaction import commit_on_success_strict
53
from snf_django.lib.db.transaction import commit_on_success_strict
54 54

  
55 55
USERS = {}
56 56
PROJECTS = {}
b/snf-astakos-app/astakos/test/views.py
36 36
from astakos.im.models import AstakosUser
37 37
from astakos.im.functions import (join_project, leave_project,
38 38
                                  submit_application, approve_application)
39
from synnefo.lib.db.transaction import commit_on_success_strict
39
from snf_django.lib.db.transaction import commit_on_success_strict
40 40

  
41 41
@commit_on_success_strict()
42 42
def join(proj_id, user_id, ctx=None):
/dev/null
1
# Copyright 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
from django.db import transaction
36
import logging
37

  
38
logger = logging.getLogger(__name__)
39

  
40

  
41
def commit_on_success_strict(**kwargs):
42
    def wrap(func):
43
        @transaction.commit_manually(**kwargs)
44
        def inner(*args, **kwargs):
45
            try:
46
                result = func(*args, **kwargs)
47
                transaction.commit()
48
                return result
49
            except BaseException as e:
50
                logger.exception(e)
51
                transaction.rollback()
52
                raise
53
        return inner
54
    return wrap
b/snf-django-lib/snf_django/lib/db/transaction.py
1
# Copyright 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
from django.db import transaction
36
import logging
37

  
38
logger = logging.getLogger(__name__)
39

  
40

  
41
def commit_on_success_strict(**kwargs):
42
    def wrap(func):
43
        @transaction.commit_manually(**kwargs)
44
        def inner(*args, **kwargs):
45
            try:
46
                result = func(*args, **kwargs)
47
                transaction.commit()
48
                return result
49
            except BaseException as e:
50
                logger.exception(e)
51
                transaction.rollback()
52
                raise
53
        return inner
54
    return wrap

Also available in: Unified diff