Commit 97d01204 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis Committed by Sofia Papagiannaki
Browse files

WIP astakosclient for quotas in pithos

parent 1bedd066
......@@ -76,9 +76,9 @@ POOL_SIZE = 8
_pithos_backend_pool = \
PithosBackendPool(
POOL_SIZE,
quotaholder_enabled=settings.CYCLADES_USE_QUOTAHOLDER,
quotaholder_url=settings.CYCLADES_QUOTAHOLDER_URL,
quotaholder_token=settings.CYCLADES_QUOTAHOLDER_TOKEN,
quotaholder_enabled=True,
quotaholder_url=settings.ASTAKOS_URL,
quotaholder_token=settings.CYCLADES_ASTAKOS_SERVICE_TOKEN,
quotaholder_client_poolsize=settings.CYCLADES_QUOTAHOLDER_POOLSIZE,
db_connection=settings.BACKEND_DB_CONNECTION,
block_path=settings.BACKEND_BLOCK_PATH)
......
......@@ -57,8 +57,7 @@ class Command(NoArgsCommand):
b = get_backend()
try:
pending_commissions = b.quotaholder.get_pending_commissions(
clientkey=CLIENTKEY
)
token=b.quotaholder_token)
if pending_commissions:
self.stdout.write(
......@@ -70,23 +69,23 @@ class Command(NoArgsCommand):
if options['fix']:
to_accept = b.quotaholder_serials.lookup(pending_commissions)
b.quotaholder.accept_commission(
context = {},
clientkey = CLIENTKEY,
serials = to_accept
)
self.stdout.write("Accepted commissions: %s\n" % to_accept)
response = b.quotaholder.resolve_commissions(
token=b.quotaholder_token,
accept_serials=to_accept,
reject_serials=[])
accepted = response['accepted']
self.stdout.write("Accepted commissions: %s\n" % accepted)
b.quotaholder_serials.delete_many(to_accept)
self.stdout.write("Deleted serials: %s\n" % to_accept)
to_reject = list(set(pending_commissions) - set(to_accept))
b.quotaholder.reject_commission(
context = {},
clientkey = CLIENTKEY,
serials = to_reject
)
self.stdout.write("Rejected commissions: %s\n" % to_reject)
response = b.quotaholder.resolve_commissions(
token=b.quotaholder_token,
accept_serials=[],
reject_serials=to_reject)
rejected = response['rejected']
self.stdout.write("Rejected commissions: %s\n" % rejected)
except Exception, e:
logger.exception(e)
raise CommandError(e)
......
......@@ -54,9 +54,9 @@ from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION,
BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH,
BACKEND_BLOCK_UMASK,
BACKEND_QUEUE_MODULE, BACKEND_QUEUE_HOSTS,
BACKEND_QUEUE_EXCHANGE, USE_QUOTAHOLDER,
QUOTAHOLDER_URL, QUOTAHOLDER_TOKEN,
BACKEND_QUEUE_EXCHANGE,
QUOTAHOLDER_POOLSIZE,
SERVICE_TOKEN,
ASTAKOS_URL,
BACKEND_ACCOUNT_QUOTA, BACKEND_CONTAINER_QUOTA,
BACKEND_VERSIONING,
......@@ -953,9 +953,9 @@ _pithos_backend_pool = PithosBackendPool(
queue_module=BACKEND_QUEUE_MODULE,
queue_hosts=BACKEND_QUEUE_HOSTS,
queue_exchange=BACKEND_QUEUE_EXCHANGE,
quotaholder_enabled=USE_QUOTAHOLDER,
quotaholder_url=QUOTAHOLDER_URL,
quotaholder_token=QUOTAHOLDER_TOKEN,
quotaholder_enabled=True,
quotaholder_url=ASTAKOS_URL,
quotaholder_token=SERVICE_TOKEN,
quotaholder_client_poolsize=QUOTAHOLDER_POOLSIZE,
free_versioning=BACKEND_FREE_VERSIONING,
block_params=BLOCK_PARAMS,
......@@ -1009,7 +1009,7 @@ def get_pithos_usage(token):
user_info = user_for_token(token, astakos_url, usage=True)
usage = user_info.get("usage", [])
for u in usage:
if u.get('name') == 'pithos+.diskspace':
if u.get('name') == 'pithos.diskspace':
return u
......
......@@ -37,7 +37,7 @@ import logging
import hashlib
import binascii
from synnefo.lib.quotaholder import QuotaholderClient
from astakosclient import AstakosClient
from base import (DEFAULT_ACCOUNT_QUOTA, DEFAULT_CONTAINER_QUOTA,
DEFAULT_CONTAINER_VERSIONING, NotAllowedError, QuotaError,
......@@ -46,7 +46,6 @@ from base import (DEFAULT_ACCOUNT_QUOTA, DEFAULT_CONTAINER_QUOTA,
# Stripped-down version of the HashMap class found in tools.
class HashMap(list):
def __init__(self, blocksize, blockhash):
......@@ -99,6 +98,7 @@ inf = float('inf')
ULTIMATE_ANSWER = 42
DEFAULT_SOURCE = 'system'
logger = logging.getLogger(__name__)
......@@ -141,10 +141,10 @@ def backend_method(func=None, autocommit=1):
return ret
except:
if serials:
self.quotaholder.reject_commission(
context = {},
clientkey = 'pithos',
serials = serials)
self.quotaholder.resolve_commissions(
token=self.quotaholder_token,
accept_serials=[],
reject_serials=serials)
self.wrapper.rollback()
raise
return fn
......@@ -241,10 +241,10 @@ class ModularBackend(BaseBackend):
if quotaholder_enabled:
self.quotaholder_url = quotaholder_url
self.quotaholder_token = quotaholder_token
self.quotaholder = QuotaholderClient(
quotaholder_url,
token=quotaholder_token,
poolsize=quotaholder_client_poolsize)
self.quotaholder = AstakosClient(
quotaholder_url,
use_pool=True,
pool_size=quotaholder_client_poolsize)
self.serials = []
self.messages = []
......@@ -1365,15 +1365,14 @@ class ModularBackend(BaseBackend):
return
try:
serial = self.quotaholder.issue_commission(
context = {},
target = account,
key = '1',
clientkey = 'pithos',
ownerkey = '',
name = details['path'] if 'path' in details else '',
provisions = (('pithos+', 'pithos+.diskspace', size),)
)
name = details['path'] if 'path' in details else ''
serial = self.quotaholder.issue_one_commission(
token=self.quotaholder_token,
holder=account,
source=DEFAULT_SOURCE,
provisions={'pithos.diskspace': size},
name=name
)
except BaseException, e:
raise QuotaError(e)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment