Search in sources :

Example 1 with ServiceRegistryClient

use of org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient in project incubator-servicecomb-java-chassis by apache.

the class ConsumerSchemaFactory method loadSwagger.

@Override
protected Swagger loadSwagger(ConsumerSchemaContext context) {
    Swagger swagger = super.loadSwagger(context);
    if (swagger != null) {
        return swagger;
    }
    ServiceRegistryClient client = RegistryUtils.getServiceRegistryClient();
    String schemaContent = client.getSchema(context.getMicroservice().getServiceId(), context.getSchemaId());
    LOGGER.info("load schema from service center, microservice={}:{}:{}, schemaId={}, result={}", context.getMicroservice().getAppId(), context.getMicroservice().getServiceName(), context.getMicroservice().getVersion(), context.getSchemaId(), !StringUtils.isEmpty(schemaContent));
    if (schemaContent != null) {
        return SchemaUtils.parseSwagger(schemaContent);
    }
    throw new Error(String.format("no schema in local, and can not get schema from service center, %s:%s", context.getMicroserviceName(), context.getSchemaId()));
}
Also used : Swagger(io.swagger.models.Swagger) ServiceRegistryClient(org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)

Example 2 with ServiceRegistryClient

use of org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient in project incubator-servicecomb-java-chassis by apache.

the class CseDiscoveryClient method getServices.

@Override
public List<String> getServices() {
    ServiceRegistryClient client = RegistryUtils.getServiceRegistryClient();
    List<Microservice> services = client.getAllMicroservices();
    List<String> serviceIDList = new ArrayList<>();
    if (null != services && !services.isEmpty()) {
        for (Microservice service : services) {
            serviceIDList.add(service.getServiceName());
        }
    }
    return serviceIDList;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ArrayList(java.util.ArrayList) ServiceRegistryClient(org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)

Example 3 with ServiceRegistryClient

use of org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient in project incubator-servicecomb-java-chassis by apache.

the class TestServiceRegistryFactory method testGetRemoteRegistryClient.

@Test
public void testGetRemoteRegistryClient() {
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Collections.emptyList());
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof ServiceRegistryClientImpl);
    serviceRegistry = ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition);
    Assert.assertTrue(serviceRegistry instanceof RemoteServiceRegistry);
    Assert.assertEquals(serviceRegistry, ServiceRegistryFactory.getServiceRegistry());
    Deencapsulation.setField(ServiceRegistryFactory.class, "serviceRegistry", null);
    System.setProperty("local.registry.file", "/tmp/test.yaml");
    serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof LocalServiceRegistryClientImpl);
    Assert.assertTrue(ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition) instanceof LocalServiceRegistry);
    System.clearProperty("local.registry.file");
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) ServiceRegistryClient(org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient) EventBus(com.google.common.eventbus.EventBus) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) ServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl) Test(org.junit.Test)

Aggregations

ServiceRegistryClient (org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)3 EventBus (com.google.common.eventbus.EventBus)1 Swagger (io.swagger.models.Swagger)1 ArrayList (java.util.ArrayList)1 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)1 LocalServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl)1 ServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl)1 ServiceRegistryConfig (org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig)1 MicroserviceDefinition (org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)1 Test (org.junit.Test)1