Search in sources :

Example 1 with DiscoveryTree

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;
}
Also used : DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) DiscoveryContext(org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) DefaultServiceInstance(org.springframework.cloud.client.DefaultServiceInstance) ServiceInstance(org.springframework.cloud.client.ServiceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) DiscoveryTree(org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree)

Aggregations

ArrayList (java.util.ArrayList)1 VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)1 DiscoveryContext (org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext)1 DiscoveryTree (org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree)1 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)1 ServiceInstance (org.springframework.cloud.client.ServiceInstance)1