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:
parent
062507d09a
commit
680e314c0e
@ -14,11 +14,11 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
from zaqarclient.tests.queues import shard
|
from zaqarclient.tests.queues import pool
|
||||||
from zaqarclient.transport import http
|
from zaqarclient.transport import http
|
||||||
|
|
||||||
|
|
||||||
class QueuesV1ShardHttpFunctionalTest(shard.QueuesV1ShardFunctionalTest):
|
class QueuesV1PoolHttpFunctionalTest(pool.QueuesV1PoolFunctionalTest):
|
||||||
|
|
||||||
is_functional = True
|
is_functional = True
|
||||||
transport_cls = http.HttpTransport
|
transport_cls = http.HttpTransport
|
@ -193,25 +193,25 @@ class TestV1Core(base.TestBase):
|
|||||||
self.assertEqual(ids, req.params['ids'])
|
self.assertEqual(ids, req.params['ids'])
|
||||||
|
|
||||||
# ADMIN API
|
# ADMIN API
|
||||||
def test_shard_create(self):
|
def test_pool_create(self):
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
resp = response.Response(None, None)
|
resp = response.Response(None, None)
|
||||||
send_method.return_value = resp
|
send_method.return_value = resp
|
||||||
|
|
||||||
req = request.Request()
|
req = request.Request()
|
||||||
core.shard_create(self.transport, req,
|
core.pool_create(self.transport, req,
|
||||||
'test_shard', {'uri': 'sqlite://',
|
'test_pool', {'uri': 'sqlite://',
|
||||||
'weight': 0})
|
'weight': 0})
|
||||||
|
|
||||||
def test_shard_delete(self):
|
def test_pool_delete(self):
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
resp = response.Response(None, None)
|
resp = response.Response(None, None)
|
||||||
send_method.return_value = resp
|
send_method.return_value = resp
|
||||||
|
|
||||||
req = request.Request()
|
req = request.Request()
|
||||||
core.shard_delete(self.transport, req, 'test_shard')
|
core.pool_delete(self.transport, req, 'test_pool')
|
||||||
|
|
||||||
def test_health(self):
|
def test_health(self):
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
from zaqarclient.tests.queues import shard
|
from zaqarclient.tests.queues import pool
|
||||||
from zaqarclient.transport import http
|
from zaqarclient.transport import http
|
||||||
|
|
||||||
|
|
||||||
class QueuesV1ShardHttpUnitTest(shard.QueuesV1ShardUnitTest):
|
class QueuesV1PoolHttpUnitTest(pool.QueuesV1PoolUnitTest):
|
||||||
|
|
||||||
transport_cls = http.HttpTransport
|
transport_cls = http.HttpTransport
|
||||||
url = 'http://127.0.0.1:8888/v1'
|
url = 'http://127.0.0.1:8888/v1'
|
@ -154,21 +154,21 @@ class V1(api.Api):
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'shard_create': {
|
'pool_create': {
|
||||||
'ref': 'shards/{shard_name}',
|
'ref': 'pools/{pool_name}',
|
||||||
'method': 'PUT',
|
'method': 'PUT',
|
||||||
'required': ['shard_name'],
|
'required': ['pool_name'],
|
||||||
'properties': {
|
'properties': {
|
||||||
'shard_name': {'type': 'string'},
|
'pool_name': {'type': 'string'},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'shard_delete': {
|
'pool_delete': {
|
||||||
'ref': 'shards/{shard_name}',
|
'ref': 'pools/{pool_name}',
|
||||||
'method': 'DELETE',
|
'method': 'DELETE',
|
||||||
'required': ['shard_name'],
|
'required': ['pool_name'],
|
||||||
'properties': {
|
'properties': {
|
||||||
'shard_name': {'type': 'string'},
|
'pool_name': {'type': 'string'},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -14,11 +14,12 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
import warnings
|
||||||
|
|
||||||
from zaqarclient.queues.v1 import core
|
from zaqarclient.queues.v1 import core
|
||||||
from zaqarclient.queues.v1 import iterator
|
from zaqarclient.queues.v1 import iterator
|
||||||
|
from zaqarclient.queues.v1 import pool
|
||||||
from zaqarclient.queues.v1 import queues
|
from zaqarclient.queues.v1 import queues
|
||||||
from zaqarclient.queues.v1 import shard
|
|
||||||
from zaqarclient import transport
|
from zaqarclient import transport
|
||||||
from zaqarclient.transport import request
|
from zaqarclient.transport import request
|
||||||
|
|
||||||
@ -120,15 +121,20 @@ class Client(object):
|
|||||||
|
|
||||||
# ADMIN API
|
# ADMIN API
|
||||||
def shard(self, ref, **kwargs):
|
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`
|
:type ref: `six.text_type`
|
||||||
|
|
||||||
:returns: A shard instance
|
:returns: A pool instance
|
||||||
:rtype: `shard.Shard`
|
:rtype: `pool.Pool`
|
||||||
"""
|
"""
|
||||||
return shard.Shard(self, ref, **kwargs)
|
return pool.Pool(self, ref, **kwargs)
|
||||||
|
|
||||||
def health(self):
|
def health(self):
|
||||||
"""Gets the health status of Zaqar server."""
|
"""Gets the health status of Zaqar server."""
|
||||||
|
@ -28,6 +28,7 @@ Functions present in this module assume that:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import warnings
|
||||||
|
|
||||||
import zaqarclient.transport.errors as errors
|
import zaqarclient.transport.errors as errors
|
||||||
|
|
||||||
@ -385,38 +386,50 @@ def claim_delete(transport, request, queue_name, claim_id):
|
|||||||
transport.send(request)
|
transport.send(request)
|
||||||
|
|
||||||
|
|
||||||
def shard_create(transport, request, shard_name, shard_data):
|
def shard_create(transport, request, pool_name, pool_data):
|
||||||
"""Creates a shard called `shard_name`
|
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
|
:param transport: Transport instance to use
|
||||||
:type transport: `transport.base.Transport`
|
:type transport: `transport.base.Transport`
|
||||||
:param request: Request instance ready to be sent.
|
:param request: Request instance ready to be sent.
|
||||||
:type request: `transport.request.Request`
|
:type request: `transport.request.Request`
|
||||||
:param shard_name: Shard reference name.
|
:param pool_name: Pool reference name.
|
||||||
:type shard_name: `six.text_type`
|
:type pool_name: `six.text_type`
|
||||||
:param shard_data: Shard's properties, i.e: weight, uri, options.
|
:param pool_data: Pool's properties, i.e: weight, uri, options.
|
||||||
:type shard_data: `dict`
|
:type pool_data: `dict`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request.operation = 'shard_create'
|
request.operation = 'pool_create'
|
||||||
request.params['shard_name'] = shard_name
|
request.params['pool_name'] = pool_name
|
||||||
request.content = json.dumps(shard_data)
|
request.content = json.dumps(pool_data)
|
||||||
transport.send(request)
|
transport.send(request)
|
||||||
|
|
||||||
|
|
||||||
def shard_delete(transport, request, shard_name):
|
def pool_delete(transport, request, pool_name):
|
||||||
"""Deletes the shard `shard_name`
|
"""Deletes the pool `pool_name`
|
||||||
|
|
||||||
:param transport: Transport instance to use
|
:param transport: Transport instance to use
|
||||||
:type transport: `transport.base.Transport`
|
:type transport: `transport.base.Transport`
|
||||||
:param request: Request instance ready to be sent.
|
:param request: Request instance ready to be sent.
|
||||||
:type request: `transport.request.Request`
|
:type request: `transport.request.Request`
|
||||||
:param shard_name: Shard reference name.
|
:param pool_name: Pool reference name.
|
||||||
:type shard_name: `six.text_type`
|
:type pool_name: `six.text_type`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request.operation = 'shard_delete'
|
request.operation = 'pool_delete'
|
||||||
request.params['shard_name'] = shard_name
|
request.params['pool_name'] = pool_name
|
||||||
transport.send(request)
|
transport.send(request)
|
||||||
|
|
||||||
|
|
||||||
|
51
zaqarclient/queues/v1/pool.py
Normal file
51
zaqarclient/queues/v1/pool.py
Normal 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)
|
@ -13,39 +13,15 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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,
|
def __init__(self, *args, **kwargs):
|
||||||
weight=None, uri=None,
|
warnings.warn(_('Shard\'s been renamed to `Pool` '
|
||||||
auto_create=True, **options):
|
'please use `zaqarclient.queues.v1.pool.Pool` '
|
||||||
self.client = client
|
' instead'), DeprecationWarning, stacklevel=2)
|
||||||
|
super(Shard, self).__init__(*args, **kwargs)
|
||||||
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)
|
|
||||||
|
@ -19,11 +19,11 @@ from zaqarclient.tests.queues import base
|
|||||||
from zaqarclient.transport import response
|
from zaqarclient.transport import response
|
||||||
|
|
||||||
|
|
||||||
class QueuesV1ShardUnitTest(base.QueuesTestBase):
|
class QueuesV1PoolUnitTest(base.QueuesTestBase):
|
||||||
|
|
||||||
def test_shard_create(self):
|
def test_pool_create(self):
|
||||||
shard_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'uri': 'sqlite://'}
|
'uri': 'sqlite://'}
|
||||||
|
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
@ -34,13 +34,13 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase):
|
|||||||
# NOTE(flaper87): This will call
|
# NOTE(flaper87): This will call
|
||||||
# ensure exists in the client instance
|
# ensure exists in the client instance
|
||||||
# since auto_create's default is True
|
# since auto_create's default is True
|
||||||
shard = self.client.shard('test', **shard_data)
|
pool = self.client.pool('test', **pool_data)
|
||||||
self.assertEqual(shard.name, 'test')
|
self.assertEqual(pool.name, 'test')
|
||||||
self.assertEqual(shard.weight, 10)
|
self.assertEqual(pool.weight, 10)
|
||||||
|
|
||||||
def test_shard_delete(self):
|
def test_pool_delete(self):
|
||||||
shard_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'uri': 'sqlite://'}
|
'uri': 'sqlite://'}
|
||||||
|
|
||||||
with mock.patch.object(self.transport, 'send',
|
with mock.patch.object(self.transport, 'send',
|
||||||
autospec=True) as send_method:
|
autospec=True) as send_method:
|
||||||
@ -51,27 +51,27 @@ class QueuesV1ShardUnitTest(base.QueuesTestBase):
|
|||||||
# NOTE(flaper87): This will call
|
# NOTE(flaper87): This will call
|
||||||
# ensure exists in the client instance
|
# ensure exists in the client instance
|
||||||
# since auto_create's default is True
|
# since auto_create's default is True
|
||||||
shard = self.client.shard('test', **shard_data)
|
pool = self.client.pool('test', **pool_data)
|
||||||
shard.delete()
|
pool.delete()
|
||||||
|
|
||||||
# NOTE(flaper87): Nothing to assert here,
|
# NOTE(flaper87): Nothing to assert here,
|
||||||
# just checking our way down to the transport
|
# just checking our way down to the transport
|
||||||
# doesn't crash.
|
# doesn't crash.
|
||||||
|
|
||||||
|
|
||||||
class QueuesV1ShardFunctionalTest(base.QueuesTestBase):
|
class QueuesV1PoolFunctionalTest(base.QueuesTestBase):
|
||||||
|
|
||||||
def test_shard_create(self):
|
def test_pool_create(self):
|
||||||
shard_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'uri': 'sqlite://'}
|
'uri': 'sqlite://'}
|
||||||
|
|
||||||
shard = self.client.shard('test', **shard_data)
|
pool = self.client.pool('test', **pool_data)
|
||||||
self.assertEqual(shard.name, 'test')
|
self.assertEqual(pool.name, 'test')
|
||||||
self.assertEqual(shard.weight, 10)
|
self.assertEqual(pool.weight, 10)
|
||||||
|
|
||||||
def test_shard_delete(self):
|
def test_pool_delete(self):
|
||||||
shard_data = {'weight': 10,
|
pool_data = {'weight': 10,
|
||||||
'uri': 'sqlite://'}
|
'uri': 'sqlite://'}
|
||||||
|
|
||||||
shard = self.client.shard('test', **shard_data)
|
pool = self.client.pool('test', **pool_data)
|
||||||
shard.delete()
|
pool.delete()
|
Loading…
x
Reference in New Issue
Block a user