"Fossies" - the Fresh Open Source Software Archive

Member "zaqar-10.0.0/zaqar/bootstrap.py" (13 May 2020, 4725 Bytes) of package /linux/misc/openstack/zaqar-10.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "bootstrap.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 9.0.0_vs_10.0.0.

    1 # Copyright (c) 2013 Rackspace, Inc.
    2 #
    3 # Licensed under the Apache License, Version 2.0 (the "License");
    4 # you may not use this file except in compliance with the License.
    5 # You may obtain a copy of the License at
    6 #
    7 #    http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 # Unless required by applicable law or agreed to in writing, software
   10 # distributed under the License is distributed on an "AS IS" BASIS,
   11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   12 # implied.
   13 # See the License for the specific language governing permissions and
   14 # limitations under the License.
   15 
   16 import socket
   17 
   18 from oslo_log import log
   19 from osprofiler import opts as profiler_opts
   20 from osprofiler import profiler
   21 from stevedore import driver
   22 
   23 from zaqar.api import handler
   24 from zaqar.common import cache as oslo_cache
   25 from zaqar.common import consts
   26 from zaqar.common import decorators
   27 from zaqar.common import errors
   28 from zaqar.conf import drivers as driver_opts
   29 from zaqar.conf import opts as opts_tool
   30 from zaqar.storage import pipeline
   31 from zaqar.storage import pooling
   32 from zaqar.storage import utils as storage_utils
   33 from zaqar.transport import base
   34 from zaqar.transport.middleware import profile
   35 from zaqar.transport import validation
   36 
   37 LOG = log.getLogger(__name__)
   38 
   39 
   40 class Bootstrap(object):
   41     """Defines the Zaqar bootstrapper.
   42 
   43     The bootstrap loads up drivers per a given configuration, and
   44     manages their lifetimes.
   45     """
   46 
   47     def __init__(self, conf):
   48         self.conf = conf
   49 
   50         for group, opts in opts_tool.list_opts_by_group():
   51             self.conf.register_opts(opts, group=group)
   52         profiler_opts.set_defaults(self.conf)
   53 
   54         # TODO(wangxiyuan): Now the OSprofiler feature in Zaqar only support
   55         # wsgi. Websocket part will be added in the future.
   56         profile.setup(self.conf, 'Zaqar-server', socket.gethostname())
   57 
   58         self.driver_conf = self.conf[driver_opts.GROUP_NAME]
   59 
   60     @decorators.lazy_property(write=False)
   61     def api(self):
   62         LOG.debug(u'Loading API handler')
   63         validate = validation.Validator(self.conf)
   64         defaults = base.ResourceDefaults(self.conf)
   65         return handler.Handler(self.storage, self.control, validate, defaults)
   66 
   67     @decorators.lazy_property(write=False)
   68     def storage(self):
   69         LOG.debug(u'Loading storage driver')
   70         if self.conf.pooling:
   71             LOG.debug(u'Storage pooling enabled')
   72             storage_driver = pooling.DataDriver(self.conf, self.cache,
   73                                                 self.control)
   74             if self.conf.profiler.enabled:
   75                 storage_driver = profiler.trace_cls("pooling_data_"
   76                                                     "driver")(storage_driver)
   77         else:
   78             storage_driver = storage_utils.load_storage_driver(
   79                 self.conf, self.cache, control_driver=self.control)
   80 
   81         LOG.debug(u'Loading storage pipeline')
   82         return pipeline.DataDriver(self.conf, storage_driver,
   83                                    self.control)
   84 
   85     @decorators.lazy_property(write=False)
   86     def control(self):
   87         LOG.debug(u'Loading storage control driver')
   88         return storage_utils.load_storage_driver(self.conf, self.cache,
   89                                                  control_mode=True)
   90 
   91     @decorators.lazy_property(write=False)
   92     def cache(self):
   93         LOG.debug(u'Loading proxy cache driver')
   94         try:
   95             oslo_cache.register_config(self.conf)
   96             return oslo_cache.get_cache(self.conf)
   97         except RuntimeError as exc:
   98             LOG.exception('Error loading proxy cache.')
   99             raise errors.InvalidDriver(exc)
  100 
  101     @decorators.lazy_property(write=False)
  102     def transport(self):
  103         transport_name = self.driver_conf.transport
  104         LOG.debug(u'Loading transport driver: %s', transport_name)
  105 
  106         if transport_name == consts.TRANSPORT_WEBSOCKET:
  107             args = [self.conf, self.api, self.cache]
  108         else:
  109             args = [
  110                 self.conf,
  111                 self.storage,
  112                 self.cache,
  113                 self.control,
  114             ]
  115 
  116         try:
  117             mgr = driver.DriverManager('zaqar.transport',
  118                                        transport_name,
  119                                        invoke_on_load=True,
  120                                        invoke_args=args)
  121             return mgr.driver
  122         except RuntimeError as exc:
  123             LOG.exception(u'Failed to load transport driver zaqar.transport.'
  124                           u'%(driver)s with args %(args)s',
  125                           {'driver': transport_name, 'args': args})
  126             raise errors.InvalidDriver(exc)
  127 
  128     def run(self):
  129         self.transport.listen()