use of org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree in project incubator-servicecomb-java-chassis by apache.
the class CseDiscoveryClient method getInstances.
@Override
public List<ServiceInstance> getInstances(final String serviceId) {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(serviceId);
DiscoveryTree discoveryTree = discoveryTrees.computeIfAbsent(serviceId, key -> {
return new DiscoveryTree();
});
VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistryUtils.getAppId(), serviceId, DefinitionConst.VERSION_RULE_ALL);
Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
List<ServiceInstance> instances = new ArrayList<>(servers.size());
for (MicroserviceInstance s : servers.values()) {
for (String endpoint : s.getEndpoints()) {
URIEndpointObject uri = new URIEndpointObject(endpoint);
instances.add(new DefaultServiceInstance(serviceId, uri.getHostOrIp(), uri.getPort(), uri.isSslEnabled()));
}
}
return instances;
}
Aggregations