use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java by polarismesh.
the class ConsumerTest method testUseBuiltinAsDiscover.
@Test
public void testUseBuiltinAsDiscover() {
ValidParam validParam = validParams.get(Operation.ALL_HEALTHY);
Configuration configuration = TestUtils.configWithEnvAddress();
ConfigurationImpl configImpl = (ConfigurationImpl) configuration;
configImpl.setDefault();
try (ConsumerAPI consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration)) {
for (int i = 0; i < ITERATE_COUNT; i++) {
GetOneInstanceRequest request = new GetOneInstanceRequest();
request.setNamespace(NAMESPACE_TEST);
request.setService(validParam.getServiceName());
InstancesResponse instancesResponse = consumerAPI.getOneInstance(request);
Assert.assertEquals(1, instancesResponse.getInstances().length);
Instance instance = instancesResponse.getInstances()[0];
Assert.assertTrue(instance.isHealthy());
Assert.assertFalse(instance.isIsolated());
Assert.assertEquals(100, instance.getWeight());
}
}
}
use of com.tencent.polaris.factory.config.ConfigurationImpl in project sofa-rpc by sofastack.
the class PolarisRegistry method init.
@Override
public void init() {
if (providerAPI != null) {
return;
}
ConfigurationImpl configuration = new ConfigurationImpl();
// init configuration
configuration.setDefault();
ServerConnectorConfigImpl serverConnector = configuration.getGlobal().getServerConnector();
serverConnector.setAddresses(Arrays.asList(registryConfig.getAddress()));
serverConnector.setConnectTimeout((long) registryConfig.getConnectTimeout());
serverConnector.setProtocol(properties.getConnectorProtocol());
providerAPI = DiscoveryAPIFactory.createProviderAPIByConfig(configuration);
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByConfig(configuration);
int coreSize = properties.getHeartbeatCoreSize();
heartbeatExecutor = Executors.newScheduledThreadPool(coreSize);
}
use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java-agent by polarismesh.
the class PolarisOperator method init.
public void init() {
if (inited.get()) {
return;
}
synchronized (lock) {
if (inited.get()) {
return;
}
String agentDir = polarisConfig.getAgentDir();
Configuration configuration;
try {
configuration = loadPolarisConfig(agentDir);
} catch (IOException e) {
LOGGER.error("fail to load polaris config: {}", e.getMessage());
return;
}
((ConfigurationImpl) configuration).setDefault();
((ConfigurationImpl) configuration).getGlobal().getServerConnector().setAddresses(Collections.singletonList(polarisConfig.getRegistryAddress()));
sdkContext = SDKContext.initContextByConfig(configuration);
consumerAPI = DiscoveryAPIFactory.createConsumerAPIByContext(sdkContext);
providerAPI = DiscoveryAPIFactory.createProviderAPIByContext(sdkContext);
limitAPI = LimitAPIFactory.createLimitAPIByContext(sdkContext);
routerAPI = RouterAPIFactory.createRouterAPIByContext(sdkContext);
inited.set(true);
}
}
use of com.tencent.polaris.factory.config.ConfigurationImpl in project spring-cloud-tencent by Tencent.
the class PolarisContextProperties method configuration.
protected Configuration configuration() {
// 1. Read user-defined polaris.yml configuration
ConfigurationImpl configuration = (ConfigurationImpl) ConfigAPIFactory.defaultConfig(ConfigProvider.DEFAULT_CONFIG);
// 2. Override user-defined polaris.yml configuration with SCT configuration
String defaultHost = getHost();
configuration.getGlobal().getAPI().setBindIP(defaultHost);
Collection<PolarisConfigModifier> modifiers = modifierList;
modifiers = modifiers.stream().sorted(Comparator.comparingInt(PolarisConfigModifier::getOrder)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(modifiers)) {
for (PolarisConfigModifier modifier : modifiers) {
modifier.modify(configuration);
}
}
return configuration;
}
use of com.tencent.polaris.factory.config.ConfigurationImpl in project polaris-java by polarismesh.
the class ConfigAPIFactory method defaultConfig.
/**
* 默认配置对象,优先获取当前目录下polaris.yml配置文件,假如没有,则创建默认的配置对象
*
* @param defaultConfigName 默认配置名
* @return 默认配置对象
* @throws PolarisException 加载异常
*/
public static Configuration defaultConfig(String defaultConfigName) throws PolarisException {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(DEFAULT_CONFIG_PATH);
ConfigurationImpl configuration;
if (null != inputStream) {
LOG.info("[Configuration]success to load config stream from {}", DEFAULT_CONFIG_PATH);
configuration = (ConfigurationImpl) loadConfig(inputStream);
} else {
configuration = new ConfigurationImpl(defaultConfigName);
}
configuration.setDefault();
return configuration;
}
Aggregations