Rename shard to pool

The server's shard feature has been renamed to pool. This patch reflects
that change in the client library. The patch keeps old `shard*` methods
and functions for backwards compatibility and it also raises a
deprecation warning whenever they are used. These functions will be
removed right after k-1

Change-Id: I842bfbcf075845750bc4fff345086636cc775371
Closes-bug: #1348196
This commit is contained in:
Flavio Percoco 2014-09-15 12:09:16 +02:00
parent 062507d09a
commit 680e314c0e
9 changed files with 142 additions and 96 deletions

View File

@ -14,11 +14,11 @@
# limitations under the License.
from zaqarclient.tests.queues import shard
from zaqarclient.tests.queues import pool
from zaqarclient.transport import http
class QueuesV1ShardHttpFunctionalTest(shard.QueuesV1ShardFunctionalTest):
class QueuesV1PoolHttpFunctionalTest(pool.QueuesV1PoolFunctionalTest):
is_functional = True
transport_cls = http.HttpTransport

View File

@ -193,25 +193,25 @@ class TestV1Core(base.TestBase):
self.assertEqual(ids, req.params['ids'])
# ADMIN API
def test_shard_create(self):
def test_pool_create(self):
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
resp = response.Response(None, None)
send_method.return_value = resp
req = request.Request()
core.shard_create(self.transport, req,
'test_shard', {'uri': 'sqlite://',
'weight': 0})
core.pool_create(self.transport, req,
'test_pool', {'uri': 'sqlite://',
'weight': 0})
def test_shard_delete(self):
def test_pool_delete(self):
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
resp = response.Response(None, None)
send_method.return_value = resp
req = request.Request()
core.shard_delete(self.transport, req, 'test_shard')
core.pool_delete(self.transport, req, 'test_pool')
def test_health(self):
with mock.patch.object(self.transport, 'send',

View File

@ -14,11 +14,11 @@
# limitations under the License.
from zaqarclient.tests.queues import shard
from zaqarclient.tests.queues import pool
from zaqarclient.transport import http
class QueuesV1ShardHttpUnitTest(shard.QueuesV1ShardUnitTest):
class QueuesV1PoolHttpUnitTest(pool.QueuesV1PoolUnitTest):
transport_cls = http.HttpTransport
url = 'http://127.0.0.1:8888/v1'

View File

@ -154,21 +154,21 @@ class V1(api.Api):
}
},
'shard_create': {
'ref': 'shards/{shard_name}',
'pool_create': {
'ref': 'pools/{pool_name}',
'method': 'PUT',
'required': ['shard_name'],
'required': ['pool_name'],
'properties': {
'shard_name': {'type': 'string'},
'pool_name': {'type': 'string'},
}
},
'shard_delete': {
'ref': 'shards/{shard_name}',
'pool_delete': {
'ref': 'pools/{pool_name}',
'method': 'DELETE',
'required': ['shard_name'],
'required': ['pool_name'],
'properties': {
'shard_name': {'type': 'string'},
'pool_name': {'type': 'string'},
}
},

View File

@ -14,11 +14,12 @@
# limitations under the License.
import uuid
import warnings
from zaqarclient.queues.v1 import core
from zaqarclient.queues.v1 import iterator
from zaqarclient.queues.v1 import pool
from zaqarclient.queues.v1 import queues
from zaqarclient.queues.v1 import shard
from zaqarclient import transport
from zaqarclient.transport import request
@ -120,15 +121,20 @@ class Client(object):
# ADMIN API
def shard(self, ref, **kwargs):
"""Returns a shard instance
warnings.warn(_('`shard_create`\'s been renamed to `pool_create` '),
DeprecationWarning, stacklevel=2)
return self.pool(ref, **kwargs)
:param ref: Shard's reference name.
def pool(self, ref, **kwargs):
"""Returns a pool instance
:param ref: Pool's reference name.
:type ref: `six.text_type`
:returns: A shard instance
:rtype: `shard.Shard`
:returns: A pool instance
:rtype: `pool.Pool`
"""
return shard.Shard(self, ref, **kwargs)
return pool.Pool(self, ref, **kwargs)
def health(self):
"""Gets the health status of Zaqar server."""

View File

@ -28,6 +28,7 @@ Functions present in this module assume that:
"""
import json
import warnings
import zaqarclient.transport.errors as errors
@ -385,38 +386,50 @@ def claim_delete(transport, request, queue_name, claim_id):
transport.send(request)
def shard_create(transport, request, shard_name, shard_data):
"""Creates a shard called `shard_name`
def shard_create(transport, request, pool_name, pool_data):
warnings.warn(_('`shard_create`\'s been renamed to `pool_create` '),
DeprecationWarning, stacklevel=2)
return pool_create(transport, request, pool_name, pool_data)
def shard_delete(transport, request, pool_name):
warnings.warn(_('`shard_delete`\'s been renamed to `pool_delete` '),
DeprecationWarning, stacklevel=2)
return pool_delete(transport, request, pool_name)
def pool_create(transport, request, pool_name, pool_data):
"""Creates a pool called `pool_name`
:param transport: Transport instance to use
:type transport: `transport.base.Transport`
:param request: Request instance ready to be sent.
:type request: `transport.request.Request`
:param shard_name: Shard reference name.
:type shard_name: `six.text_type`
:param shard_data: Shard's properties, i.e: weight, uri, options.
:type shard_data: `dict`
:param pool_name: Pool reference name.
:type pool_name: `six.text_type`
:param pool_data: Pool's properties, i.e: weight, uri, options.
:type pool_data: `dict`
"""
request.operation = 'shard_create'
request.params['shard_name'] = shard_name
request.content = json.dumps(shard_data)
request.operation = 'pool_create'
request.params['pool_name'] = pool_name
request.content = json.dumps(pool_data)
transport.send(request)
def shard_delete(transport, request, shard_name):
"""Deletes the shard `shard_name`
def pool_delete(transport, request, pool_name):
"""Deletes the pool `pool_name`
:param transport: Transport instance to use
:type transport: `transport.base.Transport`
:param request: Request instance ready to be sent.
:type request: `transport.request.Request`
:param shard_name: Shard reference name.
:type shard_name: `six.text_type`
:param pool_name: Pool reference name.
:type pool_name: `six.text_type`
"""
request.operation = 'shard_delete'
request.params['shard_name'] = shard_name
request.operation = 'pool_delete'
request.params['pool_name'] = pool_name
transport.send(request)

View File

@ -0,0 +1,51 @@
# Copyright (c) 2014 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from zaqarclient.queues.v1 import core
class Pool(object):
def __init__(self, client, name,
weight=None, uri=None,
auto_create=True, **options):
self.client = client
self.uri = uri
self.name = name
self.weight = weight
self.options = options
if auto_create:
self.ensure_exists()
def ensure_exists(self):
"""Ensures pool exists
This method is not race safe,
the pool could've been deleted
right after it was called.
"""
req, trans = self.client._request_and_transport()
data = {'uri': self.uri,
'weight': self.weight,
'options': self.options}
core.pool_create(trans, req, self.name, data)
def delete(self):
req, trans = self.client._request_and_transport()
core.pool_delete(trans, req, self.name)

View File

@ -13,39 +13,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from zaqarclient.queues.v1 import core
import warnings
from zaqarclient.queues.v1 import pool
class Shard(object):
class Shard(pool.Pool):
def __init__(self, client, name,
weight=None, uri=None,
auto_create=True, **options):
self.client = client
self.uri = uri
self.name = name
self.weight = weight
self.options = options
if auto_create:
self.ensure_exists()
def ensure_exists(self):
"""Ensures shard exists
This method is not race safe,
the shard could've been deleted
right after it was called.
"""
req, trans = self.client._request_and_transport()
data = {'uri': self.uri,
'weight': self.weight,
'options': self.options}
core.shard_create(trans, req, self.name, data)
def delete(self):
req, trans = self.client._request_and_transport()
core.shard_delete(trans, req, self.name)
def __init__(self, *args, **kwargs):
warnings.warn(_('Shard\'s been renamed to `Pool` '
'please use `zaqarclient.queues.v1.pool.Pool` '
' instead'), DeprecationWarning, stacklevel=2)
super(Shard, self).__init__(*args, **kwargs)

View File

@ -19,11 +19,11 @@ from zaqarclient.tests.queues import base
from zaqarclient.transport import response
class QueuesV1ShardUnitTest(base.QueuesTestBase):
class QueuesV1PoolUnitTest(base.QueuesTestBase):
def test_shard_create(self):
shard_data = {'weight': 10,
'uri': 'sqlite://'}
def test_pool_create(self):
pool_data = {'weight': 10,
'uri': 'sqlite://'}
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
@ -34,13 +34,13 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase):
# NOTE(flaper87): This will call
# ensure exists in the client instance
# since auto_create's default is True
shard = self.client.shard('test', **shard_data)
self.assertEqual(shard.name, 'test')
self.assertEqual(shard.weight, 10)
pool = self.client.pool('test', **pool_data)
self.assertEqual(pool.name, 'test')
self.assertEqual(pool.weight, 10)
def test_shard_delete(self):
shard_data = {'weight': 10,
'uri': 'sqlite://'}
def test_pool_delete(self):
pool_data = {'weight': 10,
'uri': 'sqlite://'}
with mock.patch.object(self.transport, 'send',
autospec=True) as send_method:
@ -51,27 +51,27 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase):
# NOTE(flaper87): This will call
# ensure exists in the client instance
# since auto_create's default is True
shard = self.client.shard('test', **shard_data)
shard.delete()
pool = self.client.pool('test', **pool_data)
pool.delete()
# NOTE(flaper87): Nothing to assert here,
# just checking our way down to the transport
# doesn't crash.
class QueuesV1ShardFunctionalTest(base.QueuesTestBase):
class QueuesV1PoolFunctionalTest(base.QueuesTestBase):
def test_shard_create(self):
shard_data = {'weight': 10,
'uri': 'sqlite://'}
def test_pool_create(self):
pool_data = {'weight': 10,
'uri': 'sqlite://'}
shard = self.client.shard('test', **shard_data)
self.assertEqual(shard.name, 'test')
self.assertEqual(shard.weight, 10)
pool = self.client.pool('test', **pool_data)
self.assertEqual(pool.name, 'test')
self.assertEqual(pool.weight, 10)
def test_shard_delete(self):
shard_data = {'weight': 10,
'uri': 'sqlite://'}
def test_pool_delete(self):
pool_data = {'weight': 10,
'uri': 'sqlite://'}
shard = self.client.shard('test', **shard_data)
shard.delete()
pool = self.client.pool('test', **pool_data)
pool.delete()