def test_get_open_api_override(self): open_api_content = "swagger yaml content" # recreate service with new configuration self.service.close(None) config = rest_config.set_defaults( ConfigParams.from_tuples("swagger.auto", False)) ctrl = DummyController() self.service = DummyCommandableHttpService() self.service.configure(config) references = References.from_tuples( Descriptor('pip-services-dummies', 'controller', 'default', 'default', '1.0'), ctrl, Descriptor('pip-services-dummies', 'service', 'http', 'default', '1.0'), self.service) self.service.set_references(references) try: self.service.open(None) response = requests.request('GET', 'http://localhost:3005/dummy/swagger') assert response.text == open_api_content finally: self.service.close(None)
class DefaultStateStoreFactory(Factory): """ Creates :class:`IStateStore <pip_services3_components.state.IStateStore.IStateStore>` components by their descriptors. See: :class:`Factory <pip_services3_components.build.Factory.Factory>`, :class:`IStateStore <pip_services3_components.state.IStateStore.IStateStore>`, :class:`MemoryStateStore <pip_services3_components.state.MemoryStateStore.MemoryStateStore>`, :class:`NullStateStore <pip_services3_components.state.NullStateStore.NullStateStore>` """ descriptor = Descriptor("pip-services", "factory", "state-store", "default", "1.0") NullStateStoreDescriptor = Descriptor("pip-services", "state-store", "null", "*", "1.0") MemoryStateStoreDescriptor = Descriptor("pip-services", "state-store", "memory", "*", "1.0") def __init__(self): """ Create a new instance of the factory. """ super().__init__() self.register_as_type( DefaultStateStoreFactory.MemoryStateStoreDescriptor, MemoryStateStore) self.register_as_type( DefaultStateStoreFactory.NullStateStoreDescriptor, NullStateStore)
class DefaultTracerFactory(Factory): """ Creates :class:`ITracer <pip_services3_components.trace.ITracer.ITracer>` components by their descriptors. See :class:`Factory <pip_services3_components.build.Factory.Factory>`, :class:`NullTracer <pip_services3_components.trace.NullTracer.NullTracer>`, :class:`ConsoleTracer <pip_services3_components.trace.ConsoleTracer.ConsoleTracer>`, :class:`CompositeTracer <pip_services3_components.trace.CompositeTracer.CompositeTracer>` """ NullTracerDescriptor = Descriptor("pip-services", "tracer", "null", "*", "1.0") LogTracerDescriptor = Descriptor("pip-services", "tracer", "log", "*", "1.0") CompositeTracerDescriptor = Descriptor("pip-services", "tracer", "composite", "*", "1.0") def __init__(self): """ Create a new instance of the factory. """ super(DefaultTracerFactory, self).__init__() self.register_as_type(DefaultTracerFactory.NullTracerDescriptor, NullTracer) self.register_as_type(DefaultTracerFactory.LogTracerDescriptor, LogTracer) self.register_as_type(DefaultTracerFactory.CompositeTracerDescriptor, CompositeTracer)
class DefaultPrometheusFactory(Factory): """ Creates Prometheus components by their descriptors. See :class:`Factory <pip_services3_components.build.Factory.Factory>`, :class:`PrometheusCounters <pip_services3_prometheus.count.PrometheusCounters.PrometheusCounters>`, :class:`PrometheusMetricsService <pip_services3_prometheus.services.PrometheusMetricsService.PrometheusMetricsService>` """ PrometheusCountersDescriptor = Descriptor("pip-services", "counters", "prometheus", "*", "1.0") PrometheusMetricsServiceDescriptor = Descriptor("pip-services", "metrics-service", "prometheus", "*", "1.0") def __init__(self): """ Create a new instance of the factory. """ super(DefaultPrometheusFactory, self).__init__() self.register_as_type( DefaultPrometheusFactory.PrometheusCountersDescriptor, PrometheusCounters) self.register_as_type( DefaultPrometheusFactory.PrometheusMetricsServiceDescriptor, PrometheusMetricsService)
def setup_class(cls): cls.controller = BeaconsController() cls.persistence = BeaconsMemoryPersistence() cls.service = BeaconsHttpServiceV1() cls.service.configure(http_config) cls.client = BeaconsHttpClientV1() cls.client.configure(http_config) cls.references = References.from_tuples( Descriptor('beacons', 'persistence', 'memory', 'default', '1.0'), cls.persistence, Descriptor('beacons', 'controller', 'default', 'default', '1.0'), cls.controller, Descriptor('beacons', 'service', 'http', 'default', '1.0'), cls.service, Descriptor('beacons', 'client', 'http', 'default', '1.0'), cls.client ) cls.controller.set_references(cls.references) cls.client.set_references(cls.references) cls.service.set_references(cls.references) cls.fixture = BeaconsClientV1Fixture(cls.client) cls.persistence.open(None) cls.service.open(None) cls.client.open(None)
def test_to_string(self): descriptor1 = Descriptor("pip-services-dummies", "controller", "default", "default", "1.0") assert "pip-services-dummies:controller:default:default:1.0" == str( descriptor1) descriptor2 = Descriptor(None, None, None, None, None) assert "*:*:*:*:*" == str(descriptor2)
def __init__(self): super(HelloWorldServiceFactory, self).__init__() ControllerDescriptor = Descriptor('hello-world', 'controller', 'default', '*', '1.0') HttpServiceDescriptor = Descriptor('hello-world', 'service', 'http', '*', '1.0') self.register_as_type(ControllerDescriptor, HelloWorldController) self.register_as_type(HttpServiceDescriptor, HelloWorldRestService)
def setup_class(cls): cls._persistence = BeaconsMemoryPersistence() cls._controller = BeaconsController() references = References.from_tuples(Descriptor('beacons', 'persistence', 'memory', 'default', '1.0'), cls._persistence, Descriptor('beacons', 'controller', 'default', 'default', '1.0'), cls._controller) cls._controller.set_references(references) cls._persistence.open(None)
def __init__(self): super().__init__() self.__roles_client: IRolesClientV1 = None self.__sessions_client: ISessionsClientV1 = None self.__sites_client: ISitesClientV1 = None self._dependency_resolver.put('roles', Descriptor('pip-services-roles', 'client', '*', '*', '1.0')) self._dependency_resolver.put('sessions', Descriptor('pip-services-sessions', 'client', '*', '*', '1.0')) self._dependency_resolver.put('sites', Descriptor('pip-services-sites', 'client', '*', '*', '1.0'))
def setup_class(cls): cls.controller = DummyController() cls.client = DummyDirectClient() cls.references = References.from_tuples( Descriptor("pip-services-dummies", "controller", "default", "default", "1.0"), cls.controller, Descriptor("pip-services-dummies", "client", "direct", "default", "1.0"), cls.client ) cls.client.set_references(cls.references) cls.fixture = DummyClientFixture(cls.client)
def setup_class(cls): cls.controller = DummyController() cls.service = DummyRestService() cls.service.configure(rest_config) references = References.from_tuples( Descriptor("pip-services-dummies", "controller", "default", "default", "1.0"), cls.controller, Descriptor("pip-services-dummies", "service", "http", "default", "1.0"), cls.service) cls.service.set_references(references)
def setup_class(cls): cls.controller = DummyController() cls.service = DummyCommandableGrpcService() cls.service.configure(grpc_config) cls.references = References.from_tuples( Descriptor('pip-services-dummies', 'controller', 'default', 'default', '1.0'), cls.controller, Descriptor('pip-services-dummies', 'service', 'grpc', 'default', '1.0'), cls.service) cls.service.set_references(cls.references) cls.service.open(None)
def setup_class(cls): cls.service = StatusRestService() cls.service.configure(rest_config) contextInfo = ContextInfo() contextInfo.name = "Test" contextInfo.description = "This is a test container" cls.references = References.from_tuples( Descriptor("pip-services", "context-info", "default", "default", "1.0"), contextInfo, Descriptor("pip-services-dummies", "service", "http", "default", "1.0"), cls.service) cls.service.set_references(cls.references)
class ClientFacadeFactory(Factory): SettingsNullClientV1Descriptor = Descriptor("pip-services-settings", "client", "null", "*", "1.0") AccountsMemoryClientV1Descriptor = Descriptor("pip-services-accounts", "client", "memory", "*", "1.0") PasswordNullClientV1Descriptor = Descriptor("pip-services-passwords", "client", "null", "*", "1.0") RolesMemoryClientV1Descriptor = Descriptor("pip-services-roles", "client", "memory", "*", "1.0") SessionsMemoryClientV1Descriptor = Descriptor("pip-services-sessions", "client", "memory", "*", "1.0") EmailSettingsMemoryClientV1Descriptor = Descriptor( "pip-services-emailsettings", "client", "memory", "*", "1.0") SitesMemoryClientV1Descriptor = Descriptor("pip-services-sites", "client", "memory", "*", "1.0") InvitationsNullClientV1Descriptor = Descriptor("pip-services-invitations", "client", "null", "*", "1.0") BeaconsMemoryClientV1Descriptor = Descriptor("beacons", "client", "memory", "*", "1.0") def __init__(self): super(ClientFacadeFactory, self).__init__() self.register_as_type( ClientFacadeFactory.SettingsNullClientV1Descriptor, SettingsNullClientV1) self.register_as_type( ClientFacadeFactory.AccountsMemoryClientV1Descriptor, AccountsMemoryClientV1) self.register_as_type( ClientFacadeFactory.PasswordNullClientV1Descriptor, PasswordsNullClientV1) self.register_as_type( ClientFacadeFactory.RolesMemoryClientV1Descriptor, RolesMemoryClientV1) self.register_as_type( ClientFacadeFactory.SessionsMemoryClientV1Descriptor, SessionsMemoryClientV1) self.register_as_type( ClientFacadeFactory.EmailSettingsMemoryClientV1Descriptor, EmailSettingsMemoryClientV1) self.register_as_type( ClientFacadeFactory.SitesMemoryClientV1Descriptor, SitesMemoryClientV1) self.register_as_type( ClientFacadeFactory.InvitationsNullClientV1Descriptor, InvitationsNullClientV1) self.register_as_type( ClientFacadeFactory.BeaconsMemoryClientV1Descriptor, BeaconsMemoryClientV1)
def __init__(self): """ Creates a new instance of this service. """ super(PrometheusMetricsService, self).__init__() self.__cached_counters: CachedCounters = None self.__source: str = None self.__instance: str = None self._dependency_resolver.put( "cached-counters", Descriptor("pip-services", "counters", "cached", "*", "1.0")) self._dependency_resolver.put( "prometheus-counters", Descriptor("pip-services", "counters", "prometheus", "*", "1.0"))
def open(self, correlation_id): """ Opens the component. :param correlation_id: (optional) transaction id to trace execution through call chain. """ if self._references is not None: raise InvalidStateException(correlation_id, "ALREADY_OPENED", "Container was already opened") try: self._logger.trace(correlation_id, "Starting container.") # Create references with configured components self._references = ContainerReferences() self._init_references(self._references) self._references.put_from_config(self._config) self.set_references(self._references) # Get custom description if available info_descriptor = Descriptor("*", "context-info", "*", "*", "*") self._info = self._references.get_one_optional(info_descriptor) # Reference and open components self._references.open(correlation_id) # Get reference to logger self._logger = CompositeLogger(self._references) self._logger.info(correlation_id, "Container " + self._info.name + " started.") except Exception as ex: self._logger.error(correlation_id, ex, "Failed to start container") traceback.print_exc() raise ex
class MemoryMessageQueueFactory(MessageQueueFactory): """ Creates :class:`MemoryMessageQueue <pip_services3_messaging.queues.MemoryMessageQueue.MemoryMessageQueue>` components by their descriptors. Name of created message queue is taken from its descriptor. """ MemoryQueueDescriptor = Descriptor("pip-services", "message-queue", "memory", "*", "*") def __init__(self): """ Create a new instance of the factory. """ super(MemoryMessageQueueFactory, self).__init__() self.register(MemoryMessageQueueFactory.MemoryQueueDescriptor, lambda locator: self.create_queue( None if not callable(locator.get_name) else locator.get_name() )) def create_queue(self, name: str) -> IMessageQueue: """ Creates a message queue component and assigns its name. :param name: a name of the created message queue. :return: IMessageQueue instance """ queue = MemoryMessageQueue(name) if self._config is not None: queue.configure(self._config) if self._references is not None: queue.set_references(self._references) return queue
class BeaconsServiceFactory(Factory): MemoryPersistenceDescriptor = Descriptor('beacons', 'persistence', 'memory', '*', '1.0') FilePersistenceDescriptor = Descriptor('beacons', 'persistence', 'file', '*', '1.0') MongoDbPersistenceDescriptor = Descriptor('beacons', 'persistence', 'mongodb', '*', '1.0') ControllerDescriptor = Descriptor('beacons', 'controller', 'default', '*', '1.0') HttpServiceV1Descriptor = Descriptor('beacons', 'service', 'http', '*', '1.0') def __init__(self): super(BeaconsServiceFactory, self).__init__() self.register_as_type(BeaconsServiceFactory.MemoryPersistenceDescriptor, BeaconsMemoryPersistence) self.register_as_type(BeaconsServiceFactory.FilePersistenceDescriptor, BeaconsFilePersistence) self.register_as_type(BeaconsServiceFactory.MongoDbPersistenceDescriptor, BeaconsMongoDbPersistence) self.register_as_type(BeaconsServiceFactory.ControllerDescriptor, BeaconsController) self.register_as_type(BeaconsServiceFactory.HttpServiceV1Descriptor, BeaconsHttpServiceV1)
def test_resolve_depedencies(self): ref1 = "AAA" ref2 = "BBB" refs = References.from_tuples( "Reference1", ref1, Descriptor("pip-services-commons", "reference", "object", "ref2", "1.0"), ref2) resolver = DependencyResolver.from_tuples( "ref1", "Reference1", "ref2", Descriptor("pip-services-commons", "reference", "*", "*", "*")) resolver.set_references(refs) assert ref1 == resolver.get_one_required("ref1") assert ref2 == resolver.get_one_required("ref2") assert None == resolver.get_one_optional("ref3")
def setup_class(cls): cls.rest = RestClientTest() cls.references = ReferencesTest() cls.references.put(Descriptor('beacons', 'client', 'memory', 'default', '1.0'), BeaconsMemoryClientV1()) cls.references.open(None)
def test_descriptor(self): component_config = ComponentConfig() assert None == component_config.descriptor descriptor = Descriptor("group", "type", "kind", "name", "version") component_config.descriptor = descriptor assert component_config.descriptor == descriptor
def setup_method(self): self.rest = RestClientTest() self.references = ReferencesTest() self.references.put( Descriptor('iqs-services-facade', 'operations', 'invitations', 'default', '1.0'), InvitationsOperationsV1()) self.references.open(None)
def setup_class(cls): controller = DummyController() cls.service = DummyCommandableHttpService() cls.service.configure(rest_config) references = References.from_tuples( Descriptor("pip-services-dummies", "controller", "default", "default", "1.0"), controller, Descriptor("pip-services-dummies", "service", "http", "default", "1.0"), cls.service ) cls.service.set_references(references) cls.service.open(None) time.sleep(0.5)
class DefaultRpcFactory(Factory): """ Creates RPC components by their descriptors. """ HttpEndpointDescriptor = Descriptor("pip-services", "endpoint", "http", "*", "1.0") StatusServiceDescriptor = Descriptor("pip-services", "status-service", "http", "*", "1.0") HeartbeatServiceDescriptor = Descriptor("pip-services", "heartbeat-service", "http", "*", "1.0") def __init__(self): """ Create a new instance of the factory. """ super(DefaultRpcFactory, self).__init__() self.register_as_type(self.HttpEndpointDescriptor, HttpEndpoint) self.register_as_type(self.StatusServiceDescriptor, StatusRestService) self.register_as_type(self.HeartbeatServiceDescriptor, HeartbeatRestService)
def test_autocreate_component(self): refs = ManagedReferences() factory = DefaultLoggerFactory() refs.put(None, factory) logger = refs.get_one_required(Descriptor("*", "logger", "*", "*", "*")) assert None != logger
def setup_class(cls): cls.controller = DummyController() cls.service = DummyGrpcService() cls.service.configure(grpc_config) cls.references = References.from_tuples( Descriptor('pip-services-dummies', 'controller', 'default', 'default', '1.0'), cls.controller, Descriptor('pip-services-dummies', 'service', 'grpc', 'default', '1.0'), cls.service) cls.service.set_references(cls.references) cls.service.open(None) cls.chanel = grpc.insecure_channel('localhost:' + str(port)) cls.client = dummies_pb2_grpc.DummiesStub(cls.chanel)
def __init__(self): """ Creates a new instance of this service. """ super(StatusRestService, self).__init__() self._dependency_resolver.put( "context-info", Descriptor("pip-services", "context-info", "default", "*", "1.0"))
def __init__(self): super(HelloWorldRestService, self).__init__() self._base_route = "/hello_world" ControllerDescriptor = Descriptor('hello-world', 'controller', '*', '*', '1.0') self._dependency_resolver.put('controller', ControllerDescriptor) self._controller = None
def __init__(self): super(DummyRestService, self).__init__() self._dependency_resolver.put('controller', Descriptor("pip-services-dummies", "controller", "default", "*", "*")) self._controller: IDummyController = None self._number_of_calls = 0 self._swagger_content = None self._swagger_path = None
def set_references(self, references: IReferences): """ Sets references to dependent components. :param references: references to locate the component dependencies. """ context_info = references.get_one_optional(Descriptor("pip-services", "context-info", "*", "*", "1.0")) if context_info is not None and self._source is None: self._source = context_info.name