diff options
Diffstat (limited to 'taskflow/locks/drivers')
-rw-r--r-- | taskflow/locks/drivers/__init__.py | 17 | ||||
-rw-r--r-- | taskflow/locks/drivers/db.py | 28 | ||||
-rw-r--r-- | taskflow/locks/drivers/file.py | 28 | ||||
-rw-r--r-- | taskflow/locks/drivers/memory.py | 28 | ||||
-rw-r--r-- | taskflow/locks/drivers/zk.py | 62 |
5 files changed, 163 insertions, 0 deletions
diff --git a/taskflow/locks/drivers/__init__.py b/taskflow/locks/drivers/__init__.py new file mode 100644 index 0000000..830dd2e --- /dev/null +++ b/taskflow/locks/drivers/__init__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# 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. diff --git a/taskflow/locks/drivers/db.py b/taskflow/locks/drivers/db.py new file mode 100644 index 0000000..214332b --- /dev/null +++ b/taskflow/locks/drivers/db.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# 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 nova.workflow.locks import api + + +class Lock(api.Lock): + pass + + +class LockProvider(api.LockProvider): + def provide(self, resource_uri, blocking=True): + return Lock(resource_uri, blocking) diff --git a/taskflow/locks/drivers/file.py b/taskflow/locks/drivers/file.py new file mode 100644 index 0000000..214332b --- /dev/null +++ b/taskflow/locks/drivers/file.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# 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 nova.workflow.locks import api + + +class Lock(api.Lock): + pass + + +class LockProvider(api.LockProvider): + def provide(self, resource_uri, blocking=True): + return Lock(resource_uri, blocking) diff --git a/taskflow/locks/drivers/memory.py b/taskflow/locks/drivers/memory.py new file mode 100644 index 0000000..214332b --- /dev/null +++ b/taskflow/locks/drivers/memory.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# 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 nova.workflow.locks import api + + +class Lock(api.Lock): + pass + + +class LockProvider(api.LockProvider): + def provide(self, resource_uri, blocking=True): + return Lock(resource_uri, blocking) diff --git a/taskflow/locks/drivers/zk.py b/taskflow/locks/drivers/zk.py new file mode 100644 index 0000000..e4eaac2 --- /dev/null +++ b/taskflow/locks/drivers/zk.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- + +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved. +# +# 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 kazoo import client as kazoo_client +from kazoo.recipe import lock as kazoo_lock + +from nova.workflow.locks import api + +from oslo.config import cfg + + +CONF = cfg.CONF +CONF.import_opt('address', 'nova.servicegroup.zk', group='zookeeper') +CONF.import_opt('recv_timeout', 'nova.servicegroup.zk', group='zookeeper') + + +class Lock(api.Lock): + def __init__(self, resource_uri, blocking, client): + super(Lock, self).__init__(resource_uri, blocking) + self._client = client + self._lock = kazoo_lock.Lock(client, resource_uri) + + def acquire(self): + return self._lock.acquire(self._blocking) + + def is_locked(self): + return self._lock.is_acquired + + def release(self): + return self._lock.release() + + def cancel(self): + return self._lock.cancel() + + +class LockProvider(api.LockProvider): + def __init__(self, *args, **kwargs): + self._client = kazoo_client.KazooClient(hosts=CONF.address, + timeout=CONF.recv_timeout) + self._client.start() + + def provide(self, resource_uri, blocking=True): + return Lock(self._client, resource_uri, blocking) + + def close(self): + if self._client: + self._client.stop() |