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;
}
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;
}
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()));
}
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;
}
Aggregations