milvus/shards/tracer/factory.py

28 lines
829 B
Python
Raw Normal View History

2019-10-25 12:24:03 +00:00
import os
import logging
2019-10-25 12:39:44 +00:00
from tracer import Tracer
2019-10-26 09:19:57 +00:00
from utils.plugins import BaseMixin
2019-10-25 12:24:03 +00:00
logger = logging.getLogger(__name__)
PLUGIN_PACKAGE_NAME = 'tracer.plugins'
2019-10-26 09:19:57 +00:00
class TracerFactory(BaseMixin):
PLUGIN_TYPE = 'Tracer'
2019-10-25 12:24:03 +00:00
2019-10-26 09:19:57 +00:00
def __init__(self, searchpath=None):
super().__init__(searchpath=searchpath, package_name=PLUGIN_PACKAGE_NAME)
2019-10-25 12:24:03 +00:00
2019-10-26 09:19:57 +00:00
def create(self, class_name, **kwargs):
if not class_name:
2019-10-25 12:24:03 +00:00
return Tracer()
2019-10-26 09:19:57 +00:00
return super().create(class_name, **kwargs)
def _create(self, plugin_class, **kwargs):
plugin_config = kwargs.pop('plugin_config', None)
if not plugin_config:
raise RuntimeError('\'{}\' Plugin Config is Required!'.format(self.PLUGIN_TYPE))
2019-10-25 12:24:03 +00:00
2019-10-26 09:19:57 +00:00
plugin = plugin_class.Create(plugin_config=plugin_config, **kwargs)
return plugin