use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.
the class FaultBaseTest method getProviderInfoByHost.
static ProviderInfo getProviderInfoByHost(ConsumerConfig consumerConfig, String host) {
ConsumerBootstrap consumerBootStrap = consumerConfig.getConsumerBootstrap();
AddressHolder addressHolder = consumerBootStrap.getCluster().getAddressHolder();
List<ProviderGroup> providerGroups = addressHolder.getProviderGroups();
for (ProviderGroup providerGroup : providerGroups) {
for (ProviderInfo providerInfo : providerGroup.getProviderInfos()) {
if (providerInfo.getHost().equals(host)) {
return providerInfo;
}
}
}
return null;
}
use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.
the class RegistryRouter method route.
@Override
public List<ProviderInfo> route(SofaRequest request, List<ProviderInfo> providerInfos) {
// has address. FIXME
if (CommonUtils.isNotEmpty(providerInfos)) {
return providerInfos;
}
AddressHolder addressHolder = consumerBootstrap.getCluster().getAddressHolder();
if (addressHolder != null) {
List<ProviderInfo> current = addressHolder.getProviderInfos(RpcConstants.ADDRESS_DEFAULT_GROUP);
if (providerInfos != null) {
providerInfos.addAll(current);
} else {
providerInfos = current;
}
}
recordRouterWay(RPC_REGISTRY_ROUTER);
return providerInfos;
}
use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.
the class MeshRouter method route.
@Override
public List<ProviderInfo> route(SofaRequest request, List<ProviderInfo> providerInfos) {
AddressHolder addressHolder = consumerBootstrap.getCluster().getAddressHolder();
if (addressHolder != null) {
List<ProviderInfo> current = addressHolder.getProviderInfos(RpcConstants.ADDRESS_DEFAULT_GROUP);
if (providerInfos != null) {
providerInfos.addAll(current);
} else {
providerInfos = current;
}
}
recordRouterWay(RPC_MESH_ROUTER);
return providerInfos;
}
use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.
the class DirectUrlRouter method route.
@Override
public List<ProviderInfo> route(SofaRequest request, List<ProviderInfo> providerInfos) {
AddressHolder addressHolder = consumerBootstrap.getCluster().getAddressHolder();
if (addressHolder != null) {
List<ProviderInfo> current = addressHolder.getProviderInfos(RpcConstants.ADDRESS_DIRECT_GROUP);
if (providerInfos != null) {
providerInfos.addAll(current);
} else {
providerInfos = current;
}
}
recordRouterWay(RPC_DIRECT_URL_ROUTER);
return providerInfos;
}
use of com.alipay.sofa.rpc.client.AddressHolder in project sofa-rpc by sofastack.
the class ZookeeperOverrideObserverTest method testAll.
@Test
public void testAll() throws Exception {
try {
RegistryConfig registryConfig = new RegistryConfig().setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK).setAddress("127.0.0.1:2181");
ZookeeperRegistry registry = (ZookeeperRegistry) RegistryFactory.getRegistry(registryConfig);
registry.start();
ServerConfig serverConfig = new ServerConfig().setPort(22222).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
ProviderConfig<OverrideService> providerConfig = new ProviderConfig<OverrideService>().setInterfaceId(OverrideService.class.getName()).setRef(new OverrideServiceImpl(22222)).setServer(serverConfig).setRegistry(registryConfig).setParameter(ProviderInfoAttrs.ATTR_WARMUP_TIME, "2000").setParameter(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT, "100").setWeight(0);
ServerConfig serverConfig2 = new ServerConfig().setPort(22111).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
ProviderConfig<OverrideService> providerConfig2 = new ProviderConfig<OverrideService>().setInterfaceId(OverrideService.class.getName()).setRef(new OverrideServiceImpl(22111)).setServer(serverConfig2).setRegistry(registryConfig).setRepeatedExportLimit(-1).setWeight(0);
providerConfig.export();
providerConfig2.export();
ConsumerConfig<OverrideService> consumerConfig = new ConsumerConfig<OverrideService>().setInterfaceId(OverrideService.class.getName()).setRegistry(registryConfig).setTimeout(3333).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
OverrideService overrideService = consumerConfig.refer();
AddressHolder addressHolder = consumerConfig.getConsumerBootstrap().getCluster().getAddressHolder();
Assert.assertTrue(addressHolder.getAllProviderSize() == 2);
providerConfig2.unExport();
Assert.assertTrue(delayGetSize(addressHolder, 1, 100) == 1);
List<String> path = registry.getZkClient().getChildren().forPath("/sofa-rpc/" + OverrideService.class.getCanonicalName() + "/providers");
String url = URLDecoder.decode(path.get(0), "UTF-8");
ProviderInfo providerInfo = ProviderHelper.toProviderInfo(url);
// 模拟下发一个override
String override1 = providerInfo.getProtocolType() + "://" + providerInfo.getHost() + ":" + providerInfo.getPort() + "?timeout=2345";
String overridePath1 = "/sofa-rpc/" + OverrideService.class.getCanonicalName() + "/overrides/" + URLEncoder.encode(override1, "UTF-8");
registry.getZkClient().create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(overridePath1);
Assert.assertTrue(delayGetTimeout(consumerConfig, 2345, 100) == 2345);
// 删除目前没有影响
registry.getZkClient().delete().forPath(overridePath1);
Thread.sleep(500);
Assert.assertTrue(delayGetTimeout(consumerConfig, 2345, 100) == 2345);
// 恢复到3333
String override2 = providerInfo.getProtocolType() + "://" + providerInfo.getHost() + ":" + providerInfo.getPort() + "?timeout=3333";
String overridePath2 = "/sofa-rpc/" + OverrideService.class.getCanonicalName() + "/overrides/" + URLEncoder.encode(override2, "UTF-8");
registry.getZkClient().create().creatingParentContainersIfNeeded().withMode(CreateMode.PERSISTENT).forPath(overridePath2);
Assert.assertTrue(delayGetTimeout(consumerConfig, 3333, 100) == 3333);
// 清除持久化的 path
registry.getZkClient().delete().forPath(overridePath2);
} catch (Throwable e) {
LOGGER.error("ZookeeperOverrideObserver test case failed", e);
Assert.assertTrue(e.getMessage(), false);
}
}
Aggregations