use of org.apache.servicecomb.loadbalance.ServiceCombServer in project java-chassis by ServiceComb.
the class DarklaunchServerListFilter method divideServerGroup.
private void divideServerGroup(List<ServiceCombServer> serverList, DarklaunchRule rule, List<ServiceCombServer> defaultGroup) {
for (ServiceCombServer server : serverList) {
boolean hasGroup = false;
for (DarklaunchRuleItem item : rule.getRuleItems()) {
Microservice microservice = MicroserviceCache.getInstance().getService(server.getInstance().getServiceId());
item.getGroupCondition().setActual(DarklaunchRule.PROP_VERSION, microservice.getVersion());
if (item.getGroupCondition().match()) {
item.addServer(server);
hasGroup = true;
}
}
if (!hasGroup) {
defaultGroup.add(server);
}
}
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project java-chassis by ServiceComb.
the class TestServerDiscoveryFilter method createEndpoint_TransportNotExist.
@Test
public void createEndpoint_TransportNotExist() {
new Expectations(transportManager) {
{
transportManager.findTransport(anyString);
result = null;
}
};
ServiceCombServer server = (ServiceCombServer) filter.createEndpoint(null, Const.RESTFUL, null, null);
Assert.assertNull(server);
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project java-chassis by ServiceComb.
the class TestClientTimeout method getServiceCombServerStats.
private static ServiceCombServerStats getServiceCombServerStats() {
InstanceCache instanceCache = DiscoveryManager.INSTANCE.getInstanceCacheManager().getOrCreate(RegistrationManager.INSTANCE.getAppId(), "jaxrs", "0+");
org.apache.servicecomb.registry.api.registry.MicroserviceInstance microserviceInstance = instanceCache.getInstanceMap().values().iterator().next();
ServiceCombServer serviceCombServer = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(microserviceInstance);
return ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(serviceCombServer);
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project java-chassis by ServiceComb.
the class IsolationDiscoveryFilter method allowVisit.
private boolean allowVisit(Invocation invocation, MicroserviceInstance instance) {
ServiceCombServer server = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServer(instance);
if (server == null) {
// first time accessed.
return true;
}
ServiceCombServerStats serverStats = ServiceCombLoadBalancerStats.INSTANCE.getServiceCombServerStats(server);
Settings settings = createSettings(invocation);
if (!checkThresholdAllowed(settings, serverStats)) {
if (serverStats.isIsolated() && (System.currentTimeMillis() - serverStats.getLastVisitTime()) > settings.singleTestTime) {
return ServiceCombServerStats.applyForTryingChance(invocation);
}
if (!serverStats.isIsolated()) {
// checkThresholdAllowed is not concurrent control, may print several logs/events in current access.
serverStats.markIsolated(true);
eventBus.post(new IsolationServerEvent(invocation, instance, serverStats, settings, Type.OPEN, server.getEndpoint()));
LOGGER.warn("Isolate service {}'s instance {}.", invocation.getMicroserviceName(), instance.getInstanceId());
}
return false;
}
if (serverStats.isIsolated()) {
// high volume of concurrent requests with a percentage of error(e.g. 50%) scenario with no isolation
if ((System.currentTimeMillis() - serverStats.getIsolatedTime()) <= settings.minIsolationTime) {
return false;
}
serverStats.markIsolated(false);
eventBus.post(new IsolationServerEvent(invocation, instance, serverStats, settings, Type.CLOSE, server.getEndpoint()));
LOGGER.warn("Recover service {}'s instance {} from isolation.", invocation.getMicroserviceName(), instance.getInstanceId());
}
return true;
}
use of org.apache.servicecomb.loadbalance.ServiceCombServer in project java-chassis by ServiceComb.
the class ServerDiscoveryFilter method createEndpoint.
@Override
protected Object createEndpoint(DiscoveryContext context, String transportName, String endpoint, MicroserviceInstance instance) {
Transport transport = SCBEngine.getInstance().getTransportManager().findTransport(transportName);
if (transport == null) {
LOGGER.info("not deployed transport {}, ignore {}.", transportName, endpoint);
return null;
}
Invocation invocation = context.getInputParameters();
return new ServiceCombServer(invocation.getMicroserviceName(), transport, new CacheEndpoint(endpoint, instance));
}
Aggregations