コード例 #1
0
ファイル: manager.py プロジェクト: kjylmr/guts
    def __init__(self, destination_driver=None, service_name=None,
                 *args, **kwargs):
        """Load the destination driver."""
        # updated_service_capabilities needs service_name to be "source".
        super(DestinationManager, self).__init__(service_name='destination',
                                                 *args, **kwargs)
        self.configuration = config.Configuration(destination_manager_opts,
                                                  config_group=service_name)
        self.stats = {}

        if not destination_driver:
            # Get from configuration, which will get the default
            # if its not using the multi backend.
            destination_driver = self.configuration.destination_driver

        svc_host = utils.extract_host(self.host)
        try:
            objects.Service.get_by_args(context.get_admin_context(),
                                        svc_host, 'guts-destination')
        except exception.ServiceNotFound:
            LOG.info(_LI("Service not found for updating."))

        self.driver = importutils.import_object(
            destination_driver,
            configuration=self.configuration,
            host=self.host)
コード例 #2
0
ファイル: manager.py プロジェクト: aptira/guts
 def init_host(self):
     """Perform any required initialization."""
     if not os.path.isdir(CONF.conversion_dir):
         utils.execute('mkdir', '-m', '755', '-p',
                       CONF.conversion_dir, run_as_root=True)
     ctxt = context.get_admin_context()
     self.publish_service_capabilities(ctxt)
コード例 #3
0
ファイル: manage.py プロジェクト: kjylmr/guts
 def purge(self, age_in_days):
     """Purge deleted rows older than a given age from guts tables."""
     age_in_days = int(age_in_days)
     if age_in_days <= 0:
         print(_("Must supply a positive, non-zero value for age"))
         exit(1)
     ctxt = context.get_admin_context()
     db.purge_deleted_rows(ctxt, age_in_days)
コード例 #4
0
ファイル: service.py プロジェクト: Vaidyanath/guts
 def kill(self):
     """Destroy the service object in the datastore."""
     self.stop()
     try:
         service_ref = objects.Service.get_by_id(
             context.get_admin_context(), self.service_id)
         service_ref.destroy()
     except exception.NotFound:
         LOG.warning(_LW('Service killed that has no database entry'))
コード例 #5
0
ファイル: manager.py プロジェクト: aptira/guts
 def __init__(self, service_name=None, *args, **kwargs):
     super(MigrationManager, self).__init__(service_name='migration',
                                            *args, **kwargs)
     try:
         svc_host = utils.extract_host(self.host)
         objects.Service.get_by_args(context.get_admin_context(),
                                     svc_host, 'guts-migration')
     except exception.ServiceNotFound:
         LOG.info(_LI("Service not found for updating."))
コード例 #6
0
ファイル: migrations.py プロジェクト: curx/guts
def get_migration(ctxt, id):
    """Retrieves single source by ID."""
    if id is None:
        msg = _("ID cannot be None")
        raise exception.InvalidSource(reason=msg)

    if ctxt is None:
        ctxt = context.get_admin_context()
    return db.migration_get(ctxt, id)
コード例 #7
0
 def kill(self):
     """Destroy the service object in the datastore."""
     self.stop()
     try:
         service_ref = objects.Service.get_by_id(
             context.get_admin_context(), self.service_id)
         service_ref.destroy()
     except exception.NotFound:
         LOG.warning(_LW('Service killed that has no database entry'))
コード例 #8
0
ファイル: host_manager.py プロジェクト: kjylmr/guts
    def __init__(self):
        self.service_states = {}  # { <host>: {<service>: {cap k : v}}}
        self.host_state_map = {}
        self.filter_handler = filters.HostFilterHandler('guts.scheduler.'
                                                        'filters')
        self.filter_classes = self.filter_handler.get_all_classes()
        self.weight_handler = weights.HostWeightHandler('guts.scheduler.'
                                                        'weights')
        self.weight_classes = self.weight_handler.get_all_classes()

        self._no_capabilities_hosts = set()  # Hosts having no capabilities
        self._context = guts_context.get_admin_context()
        self._update_host_state_map(self._context)
コード例 #9
0
    def report_state(self):
        """Update the state of this service in the datastore."""
        if not self.manager.is_working():
            # NOTE(dulek): If manager reports a problem we're not sending
            # heartbeats - to indicate that service is actually down.
            LOG.error(
                _LE('Manager for service %(binary)s %(host)s is '
                    'reporting problems, not sending heartbeat. '
                    'Service will appear "down".'), {
                        'binary': self.binary,
                        'host': self.host
                    })
            return

        ctxt = context.get_admin_context()
        try:
            try:
                service_ref = objects.Service.get_by_id(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = objects.Service.get_by_id(ctxt, self.service_id)

            service_ref.report_count += 1
            service_ref.save()

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))

        except Exception:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('Exception encountered: '))
コード例 #10
0
ファイル: manager.py プロジェクト: kjylmr/guts
    def init_host(self):
        """Perform any required initialization."""
        ctxt = context.get_admin_context()

        LOG.info(_LI("Starting destination driver %(driver_name)s."),
                 {'driver_name': self.driver.__class__.__name__})
        try:
            self.driver.do_setup(ctxt)
        except Exception:
            LOG.exception(_LE("Failed to initialize driver."),
                          resource={'type': 'driver',
                                    'id': self.__class__.__name__})
            # we don't want to continue since we failed
            # to initialize the driver correctly.
            return
        self.publish_service_capabilities(ctxt)
コード例 #11
0
ファイル: service.py プロジェクト: Vaidyanath/guts
    def report_state(self):
        """Update the state of this service in the datastore."""
        if not self.manager.is_working():
            # NOTE(dulek): If manager reports a problem we're not sending
            # heartbeats - to indicate that service is actually down.
            LOG.error(_LE('Manager for service %(binary)s %(host)s is '
                          'reporting problems, not sending heartbeat. '
                          'Service will appear "down".'),
                      {'binary': self.binary,
                       'host': self.host})
            return

        ctxt = context.get_admin_context()
        try:
            try:
                service_ref = objects.Service.get_by_id(ctxt, self.service_id)
            except exception.NotFound:
                LOG.debug('The service database object disappeared, '
                          'recreating it.')
                self._create_service_ref(ctxt)
                service_ref = objects.Service.get_by_id(ctxt, self.service_id)

            service_ref.report_count += 1
            service_ref.save()

            # TODO(termie): make this pattern be more elegant.
            if getattr(self, 'model_disconnected', False):
                self.model_disconnected = False
                LOG.error(_LE('Recovered model server connection!'))

        except db_exc.DBConnectionError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('model server went away'))

        # NOTE(jsbryant) Other DB errors can happen in HA configurations.
        # such errors shouldn't kill this thread, so we handle them here.
        except db_exc.DBError:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('DBError encountered: '))

        except Exception:
            if not getattr(self, 'model_disconnected', False):
                self.model_disconnected = True
                LOG.exception(_LE('Exception encountered: '))
コード例 #12
0
ファイル: service.py プロジェクト: Vaidyanath/guts
def setup_profiler(binary, host):
    if CONF.profiler.profiler_enabled:
        _notifier = osprofiler.notifier.create(
            "Messaging", messaging, context.get_admin_context().to_dict(),
            rpc.TRANSPORT, "guts", binary, host)
        osprofiler.notifier.set(_notifier)
        LOG.warning(
            _LW("OSProfiler is enabled.\nIt means that person who knows "
                "any of hmac_keys that are specified in "
                "/etc/guts/api-paste.ini can trace his requests. \n"
                "In real life only operator can read this file so there "
                "is no security issue. Note that even if person can "
                "trigger profiler, only admin user can retrieve trace "
                "information.\n"
                "To disable OSprofiler set in guts.conf:\n"
                "[profiler]\nenabled=false"))
    else:
        osprofiler.web.disable()
コード例 #13
0
    def start(self):
        version_string = version.version_string()
        LOG.info(_LI('Starting %(topic)s node (version %(version_string)s)'), {
            'topic': self.topic,
            'version_string': version_string
        })
        self.model_disconnected = False
        self.manager.init_host()
        ctxt = context.get_admin_context()
        try:
            service_ref = objects.Service.get_by_args(ctxt, self.host,
                                                      self.binary)
            self.service_id = service_ref.id
        except exception.NotFound:
            self._create_service_ref(ctxt)

        LOG.debug("Creating RPC server for service %s", self.topic)

        target = messaging.Target(topic=self.topic, server=self.host)
        endpoints = [self.manager]
        endpoints.extend(self.manager.additional_endpoints)
        serializer = objects_base.GutsObjectSerializer()
        self.rpcserver = rpc.get_server(target, endpoints, serializer)
        self.rpcserver.start()

        self.manager.init_host_with_rpc()

        if self.report_interval:
            pulse = loopingcall.FixedIntervalLoopingCall(self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = loopingcall.FixedIntervalLoopingCall(
                self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
コード例 #14
0
def setup_profiler(binary, host):
    if CONF.profiler.profiler_enabled:
        _notifier = osprofiler.notifier.create(
            "Messaging", messaging,
            context.get_admin_context().to_dict(), rpc.TRANSPORT, "guts",
            binary, host)
        osprofiler.notifier.set(_notifier)
        LOG.warning(
            _LW("OSProfiler is enabled.\nIt means that person who knows "
                "any of hmac_keys that are specified in "
                "/etc/guts/api-paste.ini can trace his requests. \n"
                "In real life only operator can read this file so there "
                "is no security issue. Note that even if person can "
                "trigger profiler, only admin user can retrieve trace "
                "information.\n"
                "To disable OSprofiler set in guts.conf:\n"
                "[profiler]\nenabled=false"))
    else:
        osprofiler.web.disable()
コード例 #15
0
ファイル: service.py プロジェクト: Vaidyanath/guts
    def start(self):
        version_string = version.version_string()
        LOG.info(_LI('Starting %(topic)s node (version %(version_string)s)'),
                 {'topic': self.topic, 'version_string': version_string})
        self.model_disconnected = False
        self.manager.init_host()
        ctxt = context.get_admin_context()
        try:
            service_ref = objects.Service.get_by_args(
                ctxt, self.host, self.binary)
            self.service_id = service_ref.id
        except exception.NotFound:
            self._create_service_ref(ctxt)

        LOG.debug("Creating RPC server for service %s", self.topic)

        target = messaging.Target(topic=self.topic, server=self.host)
        endpoints = [self.manager]
        endpoints.extend(self.manager.additional_endpoints)
        serializer = objects_base.GutsObjectSerializer()
        self.rpcserver = rpc.get_server(target, endpoints, serializer)
        self.rpcserver.start()

        self.manager.init_host_with_rpc()

        if self.report_interval:
            pulse = loopingcall.FixedIntervalLoopingCall(
                self.report_state)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            self.timers.append(pulse)

        if self.periodic_interval:
            if self.periodic_fuzzy_delay:
                initial_delay = random.randint(0, self.periodic_fuzzy_delay)
            else:
                initial_delay = None

            periodic = loopingcall.FixedIntervalLoopingCall(
                self.periodic_tasks)
            periodic.start(interval=self.periodic_interval,
                           initial_delay=initial_delay)
            self.timers.append(periodic)
コード例 #16
0
 def periodic_tasks(self, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     ctxt = context.get_admin_context()
     self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
コード例 #17
0
ファイル: service.py プロジェクト: Vaidyanath/guts
 def periodic_tasks(self, raise_on_error=False):
     """Tasks to be run at a periodic interval."""
     ctxt = context.get_admin_context()
     self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
コード例 #18
0
ファイル: manager.py プロジェクト: aptira/guts
    def init_host_with_rpc(self):
        ctxt = context.get_admin_context()
        self.request_service_capabilities(ctxt)

        eventlet.sleep(CONF.periodic_interval)
        self._startup_delay = False
コード例 #19
0
ファイル: manager.py プロジェクト: kjylmr/guts
    def init_host_with_rpc(self):
        ctxt = context.get_admin_context()
        self.request_service_capabilities(ctxt)

        eventlet.sleep(CONF.periodic_interval)
        self._startup_delay = False