Merge "use worker from neutron-lib"
This commit is contained in:
commit
3f7815ae64
@ -980,10 +980,10 @@ class MechanismDriver(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def get_workers(self):
|
def get_workers(self):
|
||||||
"""Get any NeutronWorker instances that should have their own process
|
"""Get any worker instances that should have their own process
|
||||||
|
|
||||||
Any driver that needs to run processes separate from the API or RPC
|
Any driver that needs to run processes separate from the API or RPC
|
||||||
workers, can return a sequence of NeutronWorker instances.
|
workers, can return a sequence of worker instances.
|
||||||
"""
|
"""
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ from neutron_lib.callbacks import registry
|
|||||||
from neutron_lib.callbacks import resources
|
from neutron_lib.callbacks import resources
|
||||||
from neutron_lib import context
|
from neutron_lib import context
|
||||||
from neutron_lib.plugins import directory
|
from neutron_lib.plugins import directory
|
||||||
|
from neutron_lib import worker as neutron_worker
|
||||||
from oslo_concurrency import processutils
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@ -38,7 +39,6 @@ from neutron.common import profiler
|
|||||||
from neutron.common import rpc as n_rpc
|
from neutron.common import rpc as n_rpc
|
||||||
from neutron.conf import service
|
from neutron.conf import service
|
||||||
from neutron.db import api as session
|
from neutron.db import api as session
|
||||||
from neutron import worker as neutron_worker
|
|
||||||
from neutron import wsgi
|
from neutron import wsgi
|
||||||
|
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ def serve_wsgi(cls):
|
|||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
class RpcWorker(neutron_worker.NeutronWorker):
|
class RpcWorker(neutron_worker.BaseWorker):
|
||||||
"""Wraps a worker to be handled by ProcessLauncher"""
|
"""Wraps a worker to be handled by ProcessLauncher"""
|
||||||
start_listeners_method = 'start_rpc_listeners'
|
start_listeners_method = 'start_rpc_listeners'
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ def _get_plugins_workers():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class AllServicesNeutronWorker(neutron_worker.NeutronWorker):
|
class AllServicesNeutronWorker(neutron_worker.BaseWorker):
|
||||||
def __init__(self, services, worker_process_count=1):
|
def __init__(self, services, worker_process_count=1):
|
||||||
super(AllServicesNeutronWorker, self).__init__(worker_process_count)
|
super(AllServicesNeutronWorker, self).__init__(worker_process_count)
|
||||||
self._services = services
|
self._services = services
|
||||||
|
@ -21,6 +21,7 @@ import traceback
|
|||||||
|
|
||||||
import httplib2
|
import httplib2
|
||||||
import mock
|
import mock
|
||||||
|
from neutron_lib import worker as neutron_worker
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
@ -28,7 +29,6 @@ from neutron.common import utils
|
|||||||
from neutron import manager
|
from neutron import manager
|
||||||
from neutron import service
|
from neutron import service
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
from neutron import worker as neutron_worker
|
|
||||||
from neutron import wsgi
|
from neutron import wsgi
|
||||||
|
|
||||||
|
|
||||||
@ -273,7 +273,7 @@ class TestPluginWorker(TestNeutronServer):
|
|||||||
plugin_workers_launcher.wait()
|
plugin_workers_launcher.wait()
|
||||||
|
|
||||||
def test_start(self):
|
def test_start(self):
|
||||||
class FakeWorker(neutron_worker.NeutronWorker):
|
class FakeWorker(neutron_worker.BaseWorker):
|
||||||
def start(self):
|
def start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -10,11 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib.callbacks import events
|
from neutron_lib import worker
|
||||||
from neutron_lib.callbacks import registry
|
|
||||||
from neutron_lib.callbacks import resources
|
|
||||||
from oslo_service import loopingcall
|
from oslo_service import loopingcall
|
||||||
from oslo_service import service
|
|
||||||
|
|
||||||
|
|
||||||
class WorkerSupportServiceMixin(object):
|
class WorkerSupportServiceMixin(object):
|
||||||
@ -28,12 +25,13 @@ class WorkerSupportServiceMixin(object):
|
|||||||
return self.__workers
|
return self.__workers
|
||||||
|
|
||||||
def get_workers(self):
|
def get_workers(self):
|
||||||
"""Returns a collection NeutronWorker instances needed by this service
|
"""Returns a collection neutron_lib.worker.BaseWorker instances
|
||||||
|
needed by this service
|
||||||
"""
|
"""
|
||||||
return list(self._workers)
|
return list(self._workers)
|
||||||
|
|
||||||
def add_worker(self, worker):
|
def add_worker(self, worker):
|
||||||
"""Adds NeutronWorker needed for this service
|
"""Adds neutron_lib.worker.BaseWorker needed for this service
|
||||||
|
|
||||||
If a object needs to define workers thread/processes outside of API/RPC
|
If a object needs to define workers thread/processes outside of API/RPC
|
||||||
workers then it will call this method to register worker. Should be
|
workers then it will call this method to register worker. Should be
|
||||||
@ -42,57 +40,14 @@ class WorkerSupportServiceMixin(object):
|
|||||||
self._workers.append(worker)
|
self._workers.append(worker)
|
||||||
|
|
||||||
def add_workers(self, workers):
|
def add_workers(self, workers):
|
||||||
"""Adds NeutronWorker list needed for this service
|
"""Adds neutron_lib.worker.BaseWorker list needed for this service
|
||||||
|
|
||||||
The same as add_worker but adds a list of workers
|
The same as add_worker but adds a list of workers
|
||||||
"""
|
"""
|
||||||
self._workers.extend(workers)
|
self._workers.extend(workers)
|
||||||
|
|
||||||
|
|
||||||
class NeutronWorker(service.ServiceBase):
|
class PeriodicWorker(worker.BaseWorker):
|
||||||
"""Partial implementation of the ServiceBase ABC
|
|
||||||
|
|
||||||
Subclasses will still need to add the other abstract methods defined in
|
|
||||||
service.ServiceBase. See oslo_service for more details.
|
|
||||||
|
|
||||||
If a plugin needs to handle synchronization with the Neutron database and
|
|
||||||
do this only once instead of in every API worker, for instance, it would
|
|
||||||
define a NeutronWorker class and the plugin would have get_workers return
|
|
||||||
an array of NeutronWorker instances. For example:
|
|
||||||
class MyPlugin(...):
|
|
||||||
def get_workers(self):
|
|
||||||
return [MyPluginWorker()]
|
|
||||||
|
|
||||||
class MyPluginWorker(NeutronWorker):
|
|
||||||
def start(self):
|
|
||||||
super(MyPluginWorker, self).start()
|
|
||||||
do_sync()
|
|
||||||
"""
|
|
||||||
|
|
||||||
# default class value for case when super().__init__ is not called
|
|
||||||
_worker_process_count = 1
|
|
||||||
|
|
||||||
def __init__(self, worker_process_count=_worker_process_count):
|
|
||||||
"""
|
|
||||||
Initialize worker
|
|
||||||
|
|
||||||
:param worker_process_count: Defines how many processes to spawn for
|
|
||||||
worker:
|
|
||||||
0 - spawn 1 new worker thread,
|
|
||||||
1..N - spawn N new worker processes
|
|
||||||
"""
|
|
||||||
self._worker_process_count = worker_process_count
|
|
||||||
|
|
||||||
@property
|
|
||||||
def worker_process_count(self):
|
|
||||||
return self._worker_process_count
|
|
||||||
|
|
||||||
def start(self):
|
|
||||||
if self.worker_process_count > 0:
|
|
||||||
registry.notify(resources.PROCESS, events.AFTER_INIT, self.start)
|
|
||||||
|
|
||||||
|
|
||||||
class PeriodicWorker(NeutronWorker):
|
|
||||||
"""A worker that runs a function at a fixed interval."""
|
"""A worker that runs a function at a fixed interval."""
|
||||||
|
|
||||||
def __init__(self, check_func, interval, initial_delay):
|
def __init__(self, check_func, interval, initial_delay):
|
||||||
|
@ -24,6 +24,7 @@ import time
|
|||||||
import eventlet.wsgi
|
import eventlet.wsgi
|
||||||
from neutron_lib import context
|
from neutron_lib import context
|
||||||
from neutron_lib import exceptions as exception
|
from neutron_lib import exceptions as exception
|
||||||
|
from neutron_lib import worker as neutron_worker
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import oslo_i18n
|
import oslo_i18n
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@ -43,7 +44,6 @@ from neutron.common import config
|
|||||||
from neutron.common import exceptions as n_exc
|
from neutron.common import exceptions as n_exc
|
||||||
from neutron.conf import wsgi as wsgi_config
|
from neutron.conf import wsgi as wsgi_config
|
||||||
from neutron.db import api
|
from neutron.db import api
|
||||||
from neutron import worker as neutron_worker
|
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
wsgi_config.register_socket_opts()
|
wsgi_config.register_socket_opts()
|
||||||
@ -59,7 +59,7 @@ def encode_body(body):
|
|||||||
return encodeutils.to_utf8(body)
|
return encodeutils.to_utf8(body)
|
||||||
|
|
||||||
|
|
||||||
class WorkerService(neutron_worker.NeutronWorker):
|
class WorkerService(neutron_worker.BaseWorker):
|
||||||
"""Wraps a worker to be handled by ProcessLauncher"""
|
"""Wraps a worker to be handled by ProcessLauncher"""
|
||||||
def __init__(self, service, application, disable_ssl=False,
|
def __init__(self, service, application, disable_ssl=False,
|
||||||
worker_process_count=0):
|
worker_process_count=0):
|
||||||
|
Loading…
Reference in New Issue
Block a user