Commit d1768170 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Merge branch 'feature-astakos-wheezy' into develop

parents f82fa2e3 ba070c39
......@@ -36,8 +36,8 @@ from django.utils import simplejson as json
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from django.db.models import Q
from django.db import transaction
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.api.util import json_response
from snf_django.lib import api
......@@ -271,7 +271,7 @@ def projects(request):
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def get_projects(request):
user = request.user
input_data = read_json_body(request, default={})
......@@ -299,7 +299,7 @@ def _get_projects(query, request_user=None):
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def create_project(request):
user = request.user
data = request.body
......@@ -319,7 +319,7 @@ def project(request, project_id):
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def get_project(request, project_id):
user = request.user
with ExceptionHandler():
......@@ -337,7 +337,7 @@ def _get_project(project_id, request_user=None):
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def modify_project(request, project_id):
user = request.user
data = request.body
......@@ -466,7 +466,7 @@ PROJECT_ACTION = {
@csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def project_action(request, project_id):
user = request.user
data = request.body
......@@ -497,7 +497,7 @@ def make_application_query(input_data):
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def get_applications(request):
user = request.user
input_data = read_json_body(request, default={})
......@@ -520,7 +520,7 @@ def _get_applications(query, request_user=None):
@csrf_exempt
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def application(request, app_id):
user = request.user
with ExceptionHandler():
......@@ -547,7 +547,7 @@ APPLICATION_ACTION = {
@csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def application_action(request, app_id):
user = request.user
data = request.body
......@@ -581,7 +581,7 @@ def make_membership_query(input_data):
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def get_memberships(request):
user = request.user
input_data = read_json_body(request, default={})
......@@ -631,7 +631,7 @@ MEMBERSHIPS_ACTION = {
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def post_memberships(request):
user = request.user
data = request.body
......@@ -642,7 +642,7 @@ def post_memberships(request):
@api.api_method(http_method="GET", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def membership(request, memb_id):
user = request.user
with ExceptionHandler():
......@@ -669,7 +669,7 @@ MEMBERSHIP_ACTION = {
@csrf_exempt
@api.api_method(http_method="POST", token_required=True, user_required=False)
@user_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def membership_action(request, memb_id):
user = request.user
input_data = read_json_body(request, default={})
......
......@@ -34,8 +34,7 @@
from django.utils import simplejson as json
from django.views.decorators.csrf import csrf_exempt
from django.http import HttpResponse
from snf_django.lib.db.transaction import commit_on_success_strict
from django.db import transaction
from snf_django.lib import api
from snf_django.lib.api.faults import BadRequest, ItemNotFound
......@@ -175,7 +174,7 @@ def issue_commission(request):
return json_response(data, status_code=status_code)
@commit_on_success_strict()
@transaction.commit_on_success
def _issue_commission(clientkey, provisions, name, force, accept):
serial = qh.issue_commission(clientkey=clientkey,
provisions=provisions,
......@@ -204,7 +203,7 @@ def conflictingCF(serial):
@csrf_exempt
@api.api_method(http_method='POST', token_required=True, user_required=False)
@component_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def resolve_pending_commissions(request):
data = request.body
try:
......@@ -260,7 +259,7 @@ def get_commission(request, serial):
@csrf_exempt
@api.api_method(http_method='POST', token_required=True, user_required=False)
@component_from_token
@commit_on_success_strict()
@transaction.commit_on_success
def serial_action(request, serial):
data = request.body
try:
......
......@@ -290,7 +290,7 @@ def get_project_by_id(project_id):
def get_project_for_update(project_id):
try:
return Project.objects.get_for_update(id=project_id)
return Project.objects.select_for_update().get(id=project_id)
except Project.DoesNotExist:
m = _(astakos_messages.UNKNOWN_PROJECT_ID) % project_id
raise ProjectNotFound(m)
......@@ -302,7 +302,7 @@ def get_project_of_application_for_update(app_id):
def get_project_lock():
ProjectLock.objects.get_for_update(pk=1)
ProjectLock.objects.select_for_update().get(pk=1)
def get_application(application_id):
......@@ -965,7 +965,7 @@ def get_pending_app_diff(user, project):
def qh_add_pending_app(user, project=None, force=False):
user = AstakosUser.forupdate.get_for_update(id=user.id)
user = AstakosUser.objects.select_for_update().get(id=user.id)
diff = get_pending_app_diff(user, project)
return register_pending_apps(user, diff, force)
......@@ -982,5 +982,5 @@ def check_pending_app_quota(user, project=None):
def qh_release_pending_app(user, locked=False):
if not locked:
user = AstakosUser.forupdate.get_for_update(id=user.id)
user = AstakosUser.objects.select_for_update().get(id=user.id)
register_pending_apps(user, -1)
......@@ -32,15 +32,15 @@
# or implied, of GRNET S.A.
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from astakos.im.models import Component
from snf_django.lib.db.transaction import commit_on_success_strict
class Command(BaseCommand):
args = "<component ID or name>"
help = "Remove a component along with its registered services"
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Please provide a component ID or name")
......
......@@ -33,11 +33,11 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from astakos.im.functions import (terminate, suspend, unsuspend,
reinstate, check_expiration,
approve_application, deny_application)
from snf_django.lib.db.transaction import commit_on_success_strict
class Command(BaseCommand):
......@@ -86,7 +86,7 @@ class Command(BaseCommand):
"e.g. when denying a project")),
)
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
message = options['message']
......
......@@ -33,13 +33,13 @@
from optparse import make_option
from django.core.management.base import CommandError
from django.db import transaction
from astakos.im.models import AstakosUser
from astakos.im.quotas import (
qh_sync_users_diffs, list_user_quotas, add_base_quota)
from astakos.im.functions import get_user_by_uuid
from astakos.im.management.commands._common import is_uuid, is_email
from snf_django.lib.db.transaction import commit_on_success_strict
from snf_django.management.commands import SynnefoCommand
from snf_django.management import utils
from ._common import show_quotas, style_options, check_style, units
......@@ -87,7 +87,7 @@ class Command(SynnefoCommand):
),
)
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
sync = options['sync']
verify = options['verify']
......
......@@ -34,9 +34,9 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from django.db import transaction
from snf_django.management.utils import pprint_table
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.models import Component, AstakosUser
from astakos.im.quotas import service_get_quotas, SYSTEM
from astakos.im.functions import count_pending_app
......@@ -67,7 +67,7 @@ class Command(BaseCommand):
" the quota, independently of their value.")
)
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
write = self.stdout.write
force = options['force']
......
......@@ -33,10 +33,10 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.utils import simplejson as json
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.register import add_resource, RegisterException
from ._common import read_from_file
......@@ -69,7 +69,7 @@ class Command(BaseCommand):
raise CommandError(m)
self.add_resources(data)
@commit_on_success_strict()
@transaction.commit_on_success
def add_resources(self, resources):
output = []
for resource in resources:
......
......@@ -109,7 +109,7 @@ class Command(BaseCommand):
def get_resource(self, resource_name):
try:
return Resource.objects.get_for_update(name=resource_name)
return Resource.objects.select_for_update().get(name=resource_name)
except Resource.DoesNotExist:
raise CommandError("Resource %s does not exist."
% resource_name)
......
......@@ -33,10 +33,10 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.utils import simplejson as json
from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im.register import add_service, add_resource, RegisterException
from astakos.im.models import Component
from ._common import read_from_file
......@@ -52,7 +52,7 @@ class Command(BaseCommand):
help="Load service definitions from a json file"),
)
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
json_file = options['json']
......
......@@ -33,10 +33,10 @@
from optparse import make_option
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
from snf_django.lib.db import transaction
from astakos.im.models import AstakosUser
......@@ -67,7 +67,7 @@ class Command(BaseCommand):
help="Add user permission (may be used multiple times)")
)
@transaction.commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
if len(args) != 3:
raise CommandError("Invalid number of arguments")
......
......@@ -36,6 +36,7 @@ import string
from optparse import make_option
from django.core import management
from django.db import transaction
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group
from django.core.exceptions import ValidationError
......@@ -47,7 +48,6 @@ from astakos.im import quotas
from astakos.im import activation_backends
from ._common import (remove_user_permission, add_user_permission, is_uuid,
show_resource_value)
from snf_django.lib.db.transaction import commit_on_success_strict
activation_backend = activation_backends.get_backend()
......@@ -151,7 +151,7 @@ class Command(BaseCommand):
help="Delete user"),
)
@commit_on_success_strict()
@transaction.commit_on_success
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("Please provide a user ID")
......
......@@ -19,9 +19,7 @@ class Migration(DataMigration):
checked_chain = chain.pk
projs.append(orm.Project(id=chain, application=app, state=1))
# use bulk_create in 1.4
for proj in projs:
proj.save()
orm.Project.objects.bulk_create(projs)
def backwards(self, orm):
"Write your backwards methods here."
......
......@@ -61,9 +61,7 @@ class Migration(DataMigration):
membership=m, date=m.leave_request_date,
from_state=ACCEPTED, to_state=LEAVE_REQUESTED))
# use bulk_create in 1.4
for log in logs:
log.save()
orm.ProjectMembershipLog.objects.bulk_create(logs)
membs = {}
for m in memberships:
......@@ -79,9 +77,7 @@ class Migration(DataMigration):
person_id=mh.person, project_id=mh.project,
state=H2S[mh.reason])
# use bulk_create in 1.4
for nm in new_membs.values():
nm.save()
orm.ProjectMembership.objects.bulk_create(new_membs.values())
memberships = orm.ProjectMembership.objects.all()
membs = {}
......@@ -98,9 +94,7 @@ class Migration(DataMigration):
membership=m, date=mh.date,
from_state=from_state, to_state=to_state))
# use bulk_create in 1.4
for log in logs:
log.save()
orm.ProjectMembershipLog.objects.bulk_create(logs)
def backwards(self, orm):
"Write your backwards methods here."
......
......@@ -27,9 +27,7 @@ class Migration(DataMigration):
reason=project.deactivation_reason,
from_state=NORMAL, to_state=TERMINATED))
# use bulk_create in 1.4
for log in logs:
log.save()
orm.ProjectLog.objects.bulk_create(logs)
def backwards(self, orm):
"Write your backwards methods here."
......
......@@ -62,7 +62,6 @@ from astakos.im import settings as astakos_settings
from astakos.im import auth_providers as auth
import astakos.im.messages as astakos_messages
from snf_django.lib.db.managers import ForUpdateManager
from synnefo.lib.ordereddict import OrderedDict
from snf_django.lib.db.fields import intDecimalField
......@@ -237,8 +236,6 @@ class Resource(models.Model):
uplimit = intDecimalField(default=0)
allow_in_projects = models.BooleanField(default=True)
objects = ForUpdateManager()
def __str__(self):
return self.name
......@@ -455,7 +452,6 @@ class AstakosUser(User):
default=False, db_index=True)
objects = AstakosUserManager()
forupdate = ForUpdateManager()
def __init__(self, *args, **kwargs):
super(AstakosUser, self).__init__(*args, **kwargs)
......@@ -1261,8 +1257,6 @@ class UserSetting(models.Model):
setting = models.CharField(max_length=255)
value = models.IntegerField()
objects = ForUpdateManager()
class Meta:
unique_together = ("user", "setting")
......@@ -1272,7 +1266,6 @@ class UserSetting(models.Model):
class Chain(models.Model):
chain = models.AutoField(primary_key=True)
objects = ForUpdateManager()
def __str__(self):
return "%s" % (self.chain,)
......@@ -1283,7 +1276,7 @@ def new_chain():
return c
class ProjectApplicationManager(ForUpdateManager):
class ProjectApplicationManager(models.Manager):
def pending_per_project(self, projects):
apps = self.filter(state=self.model.PENDING,
......@@ -1527,7 +1520,7 @@ def invert_dict(d):
return dict((v, k) for k, v in d.iteritems())
class ProjectManager(ForUpdateManager):
class ProjectManager(models.Manager):
def all_with_pending(self, flt=None):
flt = Q() if flt is None else flt
......@@ -1564,7 +1557,7 @@ class ProjectManager(ForUpdateManager):
relevant = model.o_states_q(model.RELEVANT_STATES)
return self.filter(flt, relevant).order_by(
'application__issue_date').select_related(
'application', 'application__owner', 'application__applicant')
'application', 'application__owner', 'application__applicant')
def search_by_name(self, *search_strings):
q = Q()
......@@ -1802,10 +1795,10 @@ class ProjectLog(models.Model):
class ProjectLock(models.Model):
objects = ForUpdateManager()
pass
class ProjectMembershipManager(ForUpdateManager):
class ProjectMembershipManager(models.Manager):
def any_accepted(self):
q = self.model.Q_ACCEPTED_STATES
......
......@@ -255,7 +255,7 @@ def list_user_quotas(users):
def get_users_for_update(user_ids):
uids = sorted(user_ids)
objs = AstakosUser.forupdate
objs = AstakosUser.objects
return list(objs.filter(id__in=uids).order_by('id').select_for_update())
......@@ -313,8 +313,8 @@ def qh_sync_project(project):
def qh_add_resource_limit(resource, diff):
objs = AstakosUser.forupdate.filter(Q(email_verified=True) &
~Q(policy=resource))
objs = AstakosUser.objects.filter(Q(email_verified=True) &
~Q(policy=resource))
users = objs.order_by('id').select_for_update()
uuids = [u.uuid for u in users]
qh.add_resource_limit(holders=uuids, sources=[SYSTEM],
......@@ -322,7 +322,7 @@ def qh_add_resource_limit(resource, diff):
def qh_sync_new_resource(resource, limit):
users = AstakosUser.forupdate.filter(
users = AstakosUser.objects.filter(
email_verified=True).order_by('id').select_for_update()
resource_name = resource.name
......
......@@ -59,7 +59,7 @@ def add_resource(resource_dict):
raise RegisterException(m)
try:
r = Resource.objects.get_for_update(name=name)
r = Resource.objects.select_for_update().get(name=name)
exists = True
if r.service_type != service_type:
m = ("There already exists a resource named %s with service "
......
......@@ -48,8 +48,7 @@ from django.utils.translation import ugettext as _
from django.views.generic.list_detail import object_list, object_detail
from django.core.exceptions import PermissionDenied
from django.views.decorators.http import require_http_methods
from snf_django.lib.db.transaction import commit_on_success_strict
from django.db import transaction
import astakos.im.messages as astakos_messages
......@@ -123,13 +122,14 @@ def project_add(request):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def create_app_object(request, extra_context=None):
try:
summary = 'im/projects/projectapplication_form_summary.html'
return _create_object(
request,
template_name='im/projects/projectapplication_form.html',
summary_template_name='im/projects/projectapplication_form_summary.html',
summary_template_name=summary,
extra_context=extra_context,
post_save_redirect=reverse('project_list'),
form_class=ProjectApplicationForm,
......@@ -190,7 +190,7 @@ def project_app_cancel(request, application_id):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def _project_app_cancel(request, application_id):
chain_id = None
try:
......@@ -263,14 +263,15 @@ def project_modify(request, application_id):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def update_app_object(request, object_id, extra_context=None):
try:
summary = 'im/projects/projectapplication_form_summary.html'
return _update_object(
request,
object_id=object_id,
template_name='im/projects/projectapplication_form.html',
summary_template_name='im/projects/projectapplication_form_summary.html',
summary_template_name=summary,
extra_context=extra_context,
post_save_redirect=reverse('project_list'),
form_class=ProjectApplicationForm,
......@@ -294,7 +295,7 @@ def project_detail(request, chain_id):
return common_detail(request, chain_id)
@commit_on_success_strict()
@transaction.commit_on_success
def addmembers(request, chain_id, addmembers_form):
if addmembers_form.is_valid():
try:
......@@ -474,7 +475,7 @@ def project_join(request, chain_id):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def _project_join(request, chain_id):
try:
chain_id = int(chain_id)
......@@ -503,7 +504,7 @@ def project_leave(request, memb_id):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def _project_leave(request, memb_id):
try:
memb_id = int(memb_id)
......@@ -532,7 +533,7 @@ def project_cancel_member(request, memb_id):
return redirect(next)
@commit_on_success_strict()
@transaction.commit_on_success
def _project_cancel_member(request, memb_id):
try:
cancel_membership(memb_id, request.user)
......@@ -553,7 +554,7 @@ def project_accept_member(request, memb_id):
return redirect_back(request, 'project_list')
@commit_on_success_strict()
@transaction.commit_on_success
def _project_accept_member(request, memb_id):
try:
memb_id = int(memb_id)
......@@ -578,7 +579,7 @@ def project_remove_member(request, memb_id):
return redirect_back(request, 'project_list')
@commit_on_success_strict()
@transaction.commit_on_success
def _project_remove_member(request, memb_id):
try:
memb_id = int(memb_id)
......@@ -602,7 +603,7 @@ def project_reject_member(request, memb_id):
return redirect_back(request, 'project_list')
@commit_on_success_strict()
@transaction.commit_on_success
def _project_reject_member(request, memb_id):
try:
memb_id = int(memb_id)
......@@ -639,7 +640,7 @@ def project_app_approve(request, application_id):
return redirect(reverse('project_detail', args=(chain_id,)))
@commit_on_success_strict()
@transaction.commit_on_success
def _project_app_approve(request, application_id):
approve_application(application_id)
......@@ -669,7 +670,7 @@ def project_app_deny(request, application_id):
return redirect(reverse('project_list'))
@commit_on_success_strict()
@transaction.commit_on_success
def _project_app_deny(request, application_id, reason):
deny_application(application_id, reason=reason)
......
......@@ -35,7 +35,6 @@ from snf_django.lib.db.fields import intDecimalField