use of org.apache.servicecomb.foundation.common.cache.VersionedCache 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;
}
use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project incubator-servicecomb-java-chassis by apache.
the class ServiceCombServerList method getInitialListOfServers.
@Override
public List<Server> getInitialListOfServers() {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(serviceId);
VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistryUtils.getAppId(), serviceId, DefinitionConst.VERSION_RULE_ALL);
Map<String, MicroserviceInstance> servers = serversVersionedCache.data();
List<Server> instances = new ArrayList<>(servers.size());
for (MicroserviceInstance s : servers.values()) {
for (String endpoint : s.getEndpoints()) {
URIEndpointObject uri = new URIEndpointObject(endpoint);
instances.add(new Server(uri.getHostOrIp(), uri.getPort()));
}
}
return instances;
}
use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project incubator-servicecomb-java-chassis by apache.
the class LoadbalanceHandler method getOrCreateLoadBalancer.
protected LoadBalancer getOrCreateLoadBalancer(Invocation invocation) {
DiscoveryContext context = new DiscoveryContext();
context.setInputParameters(invocation);
VersionedCache serversVersionedCache = discoveryTree.discovery(context, invocation.getAppId(), invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule());
LoadBalancer loadBalancer = loadBalancerMap.computeIfAbsent(serversVersionedCache.name(), name -> {
return createLoadBalancer(invocation.getMicroserviceName(), name);
});
LOGGER.debug("invocation {} use loadBalancer {}.", invocation.getMicroserviceQualifiedName(), loadBalancer.getName());
loadBalancer.setServerList(serversVersionedCache.data());
return loadBalancer;
}
use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project incubator-servicecomb-java-chassis by apache.
the class TestLoadbalanceHandler method getOrCreateLoadBalancer.
@Test
public void getOrCreateLoadBalancer() throws Exception {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("id");
instance.getEndpoints().add("rest://localhost:8080");
Map<String, MicroserviceInstance> instanceMap = new HashMap<>();
instanceMap.put(instance.getInstanceId(), instance);
VersionedCache instanceVersionedCache = new VersionedCache().autoCacheVersion().name("instanceCache").data(instanceMap);
new Expectations() {
{
invocation.getConfigTransportName();
result = "rest";
instanceCacheManager.getOrCreateVersionedCache(anyString, anyString, anyString);
result = instanceVersionedCache;
}
};
LoadBalancer lb = handler.getOrCreateLoadBalancer(invocation);
Assert.assertEquals(2, lb.getFilterSize());
Assert.assertEquals("instanceCache/rest", lb.getName());
Assert.assertEquals("[rest://localhost:8080]", Deencapsulation.getField(lb, "serverList").toString());
}
Aggregations