Revision a3e3917f

b/snf-astakos-app/astakos/api/projects.py
36 36
from django.views.decorators.csrf import csrf_exempt
37 37
from django.http import HttpResponse
38 38
from django.db.models import Q
39
from django.db import transaction
39 40

  
40
from snf_django.lib.db.transaction import commit_on_success_strict
41 41
from astakos.api.util import json_response
42 42

  
43 43
from snf_django.lib import api
......
271 271

  
272 272
@api.api_method(http_method="GET", token_required=True, user_required=False)
273 273
@user_from_token
274
@commit_on_success_strict()
274
@transaction.commit_on_success
275 275
def get_projects(request):
276 276
    user = request.user
277 277
    input_data = read_json_body(request, default={})
......
299 299

  
300 300
@api.api_method(http_method="POST", token_required=True, user_required=False)
301 301
@user_from_token
302
@commit_on_success_strict()
302
@transaction.commit_on_success
303 303
def create_project(request):
304 304
    user = request.user
305 305
    data = request.body
......
319 319

  
320 320
@api.api_method(http_method="GET", token_required=True, user_required=False)
321 321
@user_from_token
322
@commit_on_success_strict()
322
@transaction.commit_on_success
323 323
def get_project(request, project_id):
324 324
    user = request.user
325 325
    with ExceptionHandler():
......
337 337

  
338 338
@api.api_method(http_method="POST", token_required=True, user_required=False)
339 339
@user_from_token
340
@commit_on_success_strict()
340
@transaction.commit_on_success
341 341
def modify_project(request, project_id):
342 342
    user = request.user
343 343
    data = request.body
......
466 466
@csrf_exempt
467 467
@api.api_method(http_method="POST", token_required=True, user_required=False)
468 468
@user_from_token
469
@commit_on_success_strict()
469
@transaction.commit_on_success
470 470
def project_action(request, project_id):
471 471
    user = request.user
472 472
    data = request.body
......
497 497

  
498 498
@api.api_method(http_method="GET", token_required=True, user_required=False)
499 499
@user_from_token
500
@commit_on_success_strict()
500
@transaction.commit_on_success
501 501
def get_applications(request):
502 502
    user = request.user
503 503
    input_data = read_json_body(request, default={})
......
520 520
@csrf_exempt
521 521
@api.api_method(http_method="GET", token_required=True, user_required=False)
522 522
@user_from_token
523
@commit_on_success_strict()
523
@transaction.commit_on_success
524 524
def application(request, app_id):
525 525
    user = request.user
526 526
    with ExceptionHandler():
......
547 547
@csrf_exempt
548 548
@api.api_method(http_method="POST", token_required=True, user_required=False)
549 549
@user_from_token
550
@commit_on_success_strict()
550
@transaction.commit_on_success
551 551
def application_action(request, app_id):
552 552
    user = request.user
553 553
    data = request.body
......
581 581

  
582 582
@api.api_method(http_method="GET", token_required=True, user_required=False)
583 583
@user_from_token
584
@commit_on_success_strict()
584
@transaction.commit_on_success
585 585
def get_memberships(request):
586 586
    user = request.user
587 587
    input_data = read_json_body(request, default={})
......
631 631

  
632 632
@api.api_method(http_method="POST", token_required=True, user_required=False)
633 633
@user_from_token
634
@commit_on_success_strict()
634
@transaction.commit_on_success
635 635
def post_memberships(request):
636 636
    user = request.user
637 637
    data = request.body
......
642 642

  
643 643
@api.api_method(http_method="GET", token_required=True, user_required=False)
644 644
@user_from_token
645
@commit_on_success_strict()
645
@transaction.commit_on_success
646 646
def membership(request, memb_id):
647 647
    user = request.user
648 648
    with ExceptionHandler():
......
669 669
@csrf_exempt
670 670
@api.api_method(http_method="POST", token_required=True, user_required=False)
671 671
@user_from_token
672
@commit_on_success_strict()
672
@transaction.commit_on_success
673 673
def membership_action(request, memb_id):
674 674
    user = request.user
675 675
    input_data = read_json_body(request, default={})
b/snf-astakos-app/astakos/api/quotas.py
34 34
from django.utils import simplejson as json
35 35
from django.views.decorators.csrf import csrf_exempt
36 36
from django.http import HttpResponse
37

  
38
from snf_django.lib.db.transaction import commit_on_success_strict
37
from django.db import transaction
39 38

  
40 39
from snf_django.lib import api
41 40
from snf_django.lib.api.faults import BadRequest, ItemNotFound
......
175 174
    return json_response(data, status_code=status_code)
176 175

  
177 176

  
178
@commit_on_success_strict()
177
@transaction.commit_on_success
179 178
def _issue_commission(clientkey, provisions, name, force, accept):
180 179
    serial = qh.issue_commission(clientkey=clientkey,
181 180
                                 provisions=provisions,
......
204 203
@csrf_exempt
205 204
@api.api_method(http_method='POST', token_required=True, user_required=False)
206 205
@component_from_token
207
@commit_on_success_strict()
206
@transaction.commit_on_success
208 207
def resolve_pending_commissions(request):
209 208
    data = request.body
210 209
    try:
......
260 259
@csrf_exempt
261 260
@api.api_method(http_method='POST', token_required=True, user_required=False)
262 261
@component_from_token
263
@commit_on_success_strict()
262
@transaction.commit_on_success
264 263
def serial_action(request, serial):
265 264
    data = request.body
266 265
    try:
b/snf-astakos-app/astakos/im/management/commands/component-remove.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from django.core.management.base import BaseCommand, CommandError
35
from django.db import transaction
35 36
from astakos.im.models import Component
36
from snf_django.lib.db.transaction import commit_on_success_strict
37 37

  
38 38

  
39 39
class Command(BaseCommand):
40 40
    args = "<component ID or name>"
41 41
    help = "Remove a component along with its registered services"
42 42

  
43
    @commit_on_success_strict()
43
    @transaction.commit_on_success
44 44
    def handle(self, *args, **options):
45 45
        if len(args) != 1:
46 46
            raise CommandError("Please provide a component ID or name")
b/snf-astakos-app/astakos/im/management/commands/project-control.py
33 33

  
34 34
from optparse import make_option
35 35

  
36
from django.db import transaction
36 37
from django.core.management.base import BaseCommand, CommandError
37 38
from astakos.im.functions import (terminate, suspend, unsuspend,
38 39
                                  reinstate, check_expiration,
39 40
                                  approve_application, deny_application)
40
from snf_django.lib.db.transaction import commit_on_success_strict
41 41

  
42 42

  
43 43
class Command(BaseCommand):
......
86 86
                          "e.g. when denying a project")),
87 87
    )
88 88

  
89
    @commit_on_success_strict()
89
    @transaction.commit_on_success
90 90
    def handle(self, *args, **options):
91 91

  
92 92
        message = options['message']
b/snf-astakos-app/astakos/im/management/commands/quota.py
33 33

  
34 34
from optparse import make_option
35 35
from django.core.management.base import CommandError
36
from django.db import transaction
36 37

  
37 38
from astakos.im.models import AstakosUser
38 39
from astakos.im.quotas import (
39 40
    qh_sync_users_diffs, list_user_quotas, add_base_quota)
40 41
from astakos.im.functions import get_user_by_uuid
41 42
from astakos.im.management.commands._common import is_uuid, is_email
42
from snf_django.lib.db.transaction import commit_on_success_strict
43 43
from snf_django.management.commands import SynnefoCommand
44 44
from snf_django.management import utils
45 45
from ._common import show_quotas, style_options, check_style, units
......
87 87
                    ),
88 88
    )
89 89

  
90
    @commit_on_success_strict()
90
    @transaction.commit_on_success
91 91
    def handle(self, *args, **options):
92 92
        sync = options['sync']
93 93
        verify = options['verify']
b/snf-astakos-app/astakos/im/management/commands/reconcile-resources-astakos.py
34 34
from optparse import make_option
35 35

  
36 36
from django.core.management.base import BaseCommand, CommandError
37
from django.db import transaction
37 38

  
38 39
from snf_django.management.utils import pprint_table
39
from snf_django.lib.db.transaction import commit_on_success_strict
40 40
from astakos.im.models import Component, AstakosUser
41 41
from astakos.im.quotas import service_get_quotas, SYSTEM
42 42
from astakos.im.functions import count_pending_app
......
67 67
                         " the quota, independently of their value.")
68 68
    )
69 69

  
70
    @commit_on_success_strict()
70
    @transaction.commit_on_success
71 71
    def handle(self, *args, **options):
72 72
        write = self.stdout.write
73 73
        force = options['force']
b/snf-astakos-app/astakos/im/management/commands/resource-import.py
33 33

  
34 34
from optparse import make_option
35 35

  
36
from django.db import transaction
36 37
from django.core.management.base import BaseCommand, CommandError
37 38
from django.utils import simplejson as json
38 39

  
39
from snf_django.lib.db.transaction import commit_on_success_strict
40 40
from astakos.im.register import add_resource, RegisterException
41 41
from ._common import read_from_file
42 42

  
......
69 69
                raise CommandError(m)
70 70
        self.add_resources(data)
71 71

  
72
    @commit_on_success_strict()
72
    @transaction.commit_on_success
73 73
    def add_resources(self, resources):
74 74
        output = []
75 75
        for resource in resources:
b/snf-astakos-app/astakos/im/management/commands/service-import.py
33 33

  
34 34
from optparse import make_option
35 35

  
36
from django.db import transaction
36 37
from django.core.management.base import BaseCommand, CommandError
37 38
from django.utils import simplejson as json
38 39

  
39
from snf_django.lib.db.transaction import commit_on_success_strict
40 40
from astakos.im.register import add_service, add_resource, RegisterException
41 41
from astakos.im.models import Component
42 42
from ._common import read_from_file
......
52 52
                    help="Load service definitions from a json file"),
53 53
    )
54 54

  
55
    @commit_on_success_strict()
55
    @transaction.commit_on_success
56 56
    def handle(self, *args, **options):
57 57

  
58 58
        json_file = options['json']
b/snf-astakos-app/astakos/im/management/commands/user-add.py
33 33

  
34 34
from optparse import make_option
35 35

  
36
from django.db import transaction
36 37
from django.core.management.base import BaseCommand, CommandError
37 38
from django.core.validators import validate_email
38 39
from django.core.exceptions import ValidationError
39
from snf_django.lib.db import transaction
40 40

  
41 41
from astakos.im.models import AstakosUser
42 42

  
......
67 67
                    help="Add user permission (may be used multiple times)")
68 68
    )
69 69

  
70
    @transaction.commit_on_success_strict()
70
    @transaction.commit_on_success
71 71
    def handle(self, *args, **options):
72 72
        if len(args) != 3:
73 73
            raise CommandError("Invalid number of arguments")
b/snf-astakos-app/astakos/im/management/commands/user-modify.py
36 36
from optparse import make_option
37 37

  
38 38
from django.core import management
39
from django.db import transaction
39 40
from django.core.management.base import BaseCommand, CommandError
40 41
from django.contrib.auth.models import Group
41 42
from django.core.exceptions import ValidationError
......
47 48
from astakos.im import activation_backends
48 49
from ._common import (remove_user_permission, add_user_permission, is_uuid,
49 50
                      show_resource_value)
50
from snf_django.lib.db.transaction import commit_on_success_strict
51 51

  
52 52
activation_backend = activation_backends.get_backend()
53 53

  
......
151 151
                    help="Delete user"),
152 152
    )
153 153

  
154
    @commit_on_success_strict()
154
    @transaction.commit_on_success
155 155
    def handle(self, *args, **options):
156 156
        if len(args) != 1:
157 157
            raise CommandError("Please provide a user ID")
b/snf-astakos-app/astakos/im/views/projects.py
48 48
from django.views.generic.list_detail import object_list, object_detail
49 49
from django.core.exceptions import PermissionDenied
50 50
from django.views.decorators.http import require_http_methods
51

  
52
from snf_django.lib.db.transaction import commit_on_success_strict
51
from django.db import transaction
53 52

  
54 53
import astakos.im.messages as astakos_messages
55 54

  
......
123 122
    return redirect(next)
124 123

  
125 124

  
126
@commit_on_success_strict()
125
@transaction.commit_on_success
127 126
def create_app_object(request, extra_context=None):
128 127
    try:
129 128
        summary = 'im/projects/projectapplication_form_summary.html'
......
191 190
    return redirect(next)
192 191

  
193 192

  
194
@commit_on_success_strict()
193
@transaction.commit_on_success
195 194
def _project_app_cancel(request, application_id):
196 195
    chain_id = None
197 196
    try:
......
264 263
    return redirect(next)
265 264

  
266 265

  
267
@commit_on_success_strict()
266
@transaction.commit_on_success
268 267
def update_app_object(request, object_id, extra_context=None):
269 268
    try:
270 269
        summary = 'im/projects/projectapplication_form_summary.html'
......
296 295
    return common_detail(request, chain_id)
297 296

  
298 297

  
299
@commit_on_success_strict()
298
@transaction.commit_on_success
300 299
def addmembers(request, chain_id, addmembers_form):
301 300
    if addmembers_form.is_valid():
302 301
        try:
......
476 475
    return redirect(next)
477 476

  
478 477

  
479
@commit_on_success_strict()
478
@transaction.commit_on_success
480 479
def _project_join(request, chain_id):
481 480
    try:
482 481
        chain_id = int(chain_id)
......
505 504
    return redirect(next)
506 505

  
507 506

  
508
@commit_on_success_strict()
507
@transaction.commit_on_success
509 508
def _project_leave(request, memb_id):
510 509
    try:
511 510
        memb_id = int(memb_id)
......
534 533
    return redirect(next)
535 534

  
536 535

  
537
@commit_on_success_strict()
536
@transaction.commit_on_success
538 537
def _project_cancel_member(request, memb_id):
539 538
    try:
540 539
        cancel_membership(memb_id, request.user)
......
555 554
    return redirect_back(request, 'project_list')
556 555

  
557 556

  
558
@commit_on_success_strict()
557
@transaction.commit_on_success
559 558
def _project_accept_member(request, memb_id):
560 559
    try:
561 560
        memb_id = int(memb_id)
......
580 579
    return redirect_back(request, 'project_list')
581 580

  
582 581

  
583
@commit_on_success_strict()
582
@transaction.commit_on_success
584 583
def _project_remove_member(request, memb_id):
585 584
    try:
586 585
        memb_id = int(memb_id)
......
604 603
    return redirect_back(request, 'project_list')
605 604

  
606 605

  
607
@commit_on_success_strict()
606
@transaction.commit_on_success
608 607
def _project_reject_member(request, memb_id):
609 608
    try:
610 609
        memb_id = int(memb_id)
......
641 640
    return redirect(reverse('project_detail', args=(chain_id,)))
642 641

  
643 642

  
644
@commit_on_success_strict()
643
@transaction.commit_on_success
645 644
def _project_app_approve(request, application_id):
646 645
    approve_application(application_id)
647 646

  
......
671 670
    return redirect(reverse('project_list'))
672 671

  
673 672

  
674
@commit_on_success_strict()
673
@transaction.commit_on_success
675 674
def _project_app_deny(request, application_id, reason):
676 675
    deny_application(application_id, reason=reason)
677 676

  
b/snf-astakos-app/astakos/test/stress.py
46 46
os.environ['SYNNEFO_SETTINGS_DIR'] = path + '/settings'
47 47
os.environ['DJANGO_SETTINGS_MODULE'] = 'synnefo.settings'
48 48

  
49
from django.db import transaction
49 50
from astakos.im.models import AstakosUser
50 51
from astakos.im.functions import ProjectError
51 52
from astakos.im import quotas
52 53
from views import submit, approve, join, leave
53
from snf_django.lib.db.transaction import commit_on_success_strict
54 54

  
55 55
USERS = {}
56 56
PROJECTS = {}
......
90 90
    return None
91 91

  
92 92

  
93
@commit_on_success_strict()
93
@transaction.commit_on_success
94 94
def new_users(count):
95 95
    for i in range(count):
96 96
        while True:
b/snf-astakos-app/astakos/test/views.py
33 33

  
34 34
from datetime import datetime, timedelta
35 35

  
36
from django.db import transaction
36 37
from astakos.im.models import AstakosUser, Project
37 38
from astakos.im.functions import (join_project, leave_project,
38 39
                                  submit_application, approve_application,
39 40
                                  check_pending_app_quota,
40 41
                                  ProjectForbidden)
41
from snf_django.lib.db.transaction import commit_on_success_strict
42 42

  
43 43

  
44
@commit_on_success_strict()
44
@transaction.commit_on_success
45 45
def join(proj_id, user):
46 46
    return join_project(proj_id, user)
47 47

  
48 48

  
49
@commit_on_success_strict()
49
@transaction.commit_on_success
50 50
def leave(memb_id, request_user):
51 51
    return leave_project(memb_id, request_user)
52 52

  
53 53

  
54
@commit_on_success_strict()
54
@transaction.commit_on_success
55 55
def submit(name, user_id, project_id=None):
56 56
    try:
57 57
        owner = AstakosUser.objects.get(id=user_id)
......
79 79
    return app.id, app.chain_id
80 80

  
81 81

  
82
@commit_on_success_strict()
82
@transaction.commit_on_success
83 83
def approve(app_id):
84 84
    approve_application(app_id)
/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 functools import wraps
36
from django.db import transaction
37

  
38

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

Also available in: Unified diff