Add some hooks for managers when service starts
Adds pre_start_hook() and post_start_hook() and fixes a couple of hard coded binary name checks in service.py Change-Id: I062790a88ed7f15a6f28961d6ddc1f230e19e0cb
This commit is contained in:
@@ -183,10 +183,30 @@ class Manager(base.Base):
|
||||
locals())
|
||||
|
||||
def init_host(self):
|
||||
"""Handle initialization if this is a standalone service.
|
||||
"""Hook to do additional manager initialization when one requests
|
||||
the service be started. This is called before any service record
|
||||
is created.
|
||||
|
||||
Child classes should override this method.
|
||||
"""
|
||||
pass
|
||||
|
||||
def pre_start_hook(self):
|
||||
"""Hook to provide the manager the ability to do additional
|
||||
start-up work before any RPC queues/consumers are created. This is
|
||||
called after other initialization has succeeded and a service
|
||||
record is created.
|
||||
|
||||
Child classes should override this method.
|
||||
"""
|
||||
pass
|
||||
|
||||
def post_start_hook(self):
|
||||
"""Hook to provide the manager the ability to do additional
|
||||
start-up work immediately after a service creates RPC consumers
|
||||
and starts 'running'.
|
||||
|
||||
Child classes should override this method.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import sys
|
||||
from nova.compute import rpcapi as compute_rpcapi
|
||||
from nova.compute import utils as compute_utils
|
||||
from nova.compute import vm_states
|
||||
import nova.context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
@@ -62,6 +63,13 @@ class SchedulerManager(manager.Manager):
|
||||
self.driver = importutils.import_object(scheduler_driver)
|
||||
super(SchedulerManager, self).__init__(*args, **kwargs)
|
||||
|
||||
def post_start_hook(self):
|
||||
"""After we start up and can receive messages via RPC, tell all
|
||||
compute nodes to send us their capabilities.
|
||||
"""
|
||||
ctxt = nova.context.get_admin_context()
|
||||
compute_rpcapi.ComputeAPI().publish_service_capabilities(ctxt)
|
||||
|
||||
def update_service_capabilities(self, context, service_name,
|
||||
host, capabilities):
|
||||
"""Process a capability update from a service node."""
|
||||
@@ -259,6 +267,3 @@ class SchedulerManager(manager.Manager):
|
||||
@manager.periodic_task
|
||||
def _expire_reservations(self, context):
|
||||
QUOTAS.expire(context)
|
||||
|
||||
def request_service_capabilities(self, context):
|
||||
compute_rpcapi.ComputeAPI().publish_service_capabilities(context)
|
||||
|
||||
@@ -397,8 +397,7 @@ class Service(object):
|
||||
except exception.NotFound:
|
||||
self._create_service_ref(ctxt)
|
||||
|
||||
if 'nova-compute' == self.binary:
|
||||
self.manager.update_available_resource(ctxt)
|
||||
self.manager.pre_start_hook()
|
||||
|
||||
self.conn = rpc.create_connection(new=True)
|
||||
LOG.debug(_("Creating Consumer connection for Service %s") %
|
||||
@@ -417,8 +416,7 @@ class Service(object):
|
||||
# Consume from all consumers in a thread
|
||||
self.conn.consume_in_thread()
|
||||
|
||||
if 'nova-scheduler' == self.binary:
|
||||
self.manager.request_service_capabilities(ctxt)
|
||||
self.manager.post_start_hook()
|
||||
|
||||
if self.report_interval:
|
||||
pulse = utils.LoopingCall(self.report_state)
|
||||
@@ -612,7 +610,10 @@ class WSGIService(object):
|
||||
"""
|
||||
if self.manager:
|
||||
self.manager.init_host()
|
||||
self.manager.pre_start_hook()
|
||||
self.server.start()
|
||||
if self.manager:
|
||||
self.manager.post_start_hook()
|
||||
|
||||
def stop(self):
|
||||
"""Stop serving this API.
|
||||
|
||||
Reference in New Issue
Block a user