Search in sources :

Example 1 with ServiceRegistryClient

use of io.servicecomb.serviceregistry.client.ServiceRegistryClient in project java-chassis by ServiceComb.

the class ConsumerSchemaFactory method findMicroservice.

protected Microservice findMicroservice(MicroserviceMeta microserviceMeta, String microserviceVersionRule) {
    String appId = microserviceMeta.getAppId();
    String microserviceName = microserviceMeta.getName();
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    String microserviceId = client.getMicroserviceId(appId, microserviceMeta.getShortName(), microserviceVersionRule);
    if (StringUtils.isEmpty(microserviceId)) {
        LOGGER.error("can not get microservice id, {}:{}:{}", appId, microserviceName, microserviceVersionRule);
        return null;
    }
    Microservice microservice = client.getMicroservice(microserviceId);
    if (microservice == null) {
        LOGGER.error("can not get microservice, {}:{}:{}", appId, microserviceName, microserviceVersionRule);
        return null;
    }
    LOGGER.info("Found schema ids from service center, {}:{}:{}:{}", appId, microserviceName, microserviceVersionRule, microservice.getSchemas());
    return microservice;
}
Also used : Microservice(io.servicecomb.serviceregistry.api.registry.Microservice) ServiceRegistryClient(io.servicecomb.serviceregistry.client.ServiceRegistryClient)

Example 2 with ServiceRegistryClient

use of io.servicecomb.serviceregistry.client.ServiceRegistryClient in project java-chassis by ServiceComb.

the class CseDiscoveryClient method getInstances.

@Override
public List<ServiceInstance> getInstances(final String serviceId) {
    List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
    ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
    String versionRule = referenceConfig.getMicroserviceVersionRule();
    String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
    List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
    if (null != cseServices && !cseServices.isEmpty()) {
        for (MicroserviceInstance instance : cseServices) {
            List<String> eps = instance.getEndpoints();
            for (String ep : eps) {
                URIEndpointObject uri = new URIEndpointObject(ep);
                instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
            }
        }
    }
    return instances;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ArrayList(java.util.ArrayList) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) ServiceRegistryClient(io.servicecomb.serviceregistry.client.ServiceRegistryClient) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject)

Example 3 with ServiceRegistryClient

use of io.servicecomb.serviceregistry.client.ServiceRegistryClient in project java-chassis by ServiceComb.

the class ConsumerSchemaFactory method loadSwagger.

@Override
protected Swagger loadSwagger(ConsumerSchemaContext context) {
    Swagger swagger = super.loadSwagger(context);
    if (swagger != null) {
        return swagger;
    }
    if (context.getMicroservice() == null) {
        throw new Error(String.format("no schema in local, and can not get microservice from service center, %s:%s", context.getMicroserviceName(), context.getSchemaId()));
    }
    ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
    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(io.servicecomb.serviceregistry.client.ServiceRegistryClient)

Example 4 with ServiceRegistryClient

use of io.servicecomb.serviceregistry.client.ServiceRegistryClient in project java-chassis by ServiceComb.

the class CseDiscoveryClient method getServices.

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

Aggregations

ServiceRegistryClient (io.servicecomb.serviceregistry.client.ServiceRegistryClient)4 Microservice (io.servicecomb.serviceregistry.api.registry.Microservice)2 ArrayList (java.util.ArrayList)2 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceInstance (io.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 Swagger (io.swagger.models.Swagger)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1