Search in sources :

Example 1 with ConfigurationImpl

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());
        }
    }
}
Also used : Configuration(com.tencent.polaris.api.config.Configuration) Instance(com.tencent.polaris.api.pojo.Instance) GetOneInstanceRequest(com.tencent.polaris.api.rpc.GetOneInstanceRequest) ConsumerAPI(com.tencent.polaris.api.core.ConsumerAPI) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl) InstancesResponse(com.tencent.polaris.api.rpc.InstancesResponse) Test(org.junit.Test)

Example 2 with ConfigurationImpl

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);
}
Also used : ServerConnectorConfigImpl(com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 3 with ConfigurationImpl

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);
    }
}
Also used : Configuration(com.tencent.polaris.api.config.Configuration) IOException(java.io.IOException) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 4 with ConfigurationImpl

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;
}
Also used : ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Example 5 with ConfigurationImpl

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;
}
Also used : InputStream(java.io.InputStream) ConfigurationImpl(com.tencent.polaris.factory.config.ConfigurationImpl)

Aggregations

ConfigurationImpl (com.tencent.polaris.factory.config.ConfigurationImpl)10 Configuration (com.tencent.polaris.api.config.Configuration)3 ConsumerAPI (com.tencent.polaris.api.core.ConsumerAPI)1 PolarisException (com.tencent.polaris.api.exception.PolarisException)1 PluginType (com.tencent.polaris.api.plugin.PluginType)1 TypeProvider (com.tencent.polaris.api.plugin.TypeProvider)1 ValueContext (com.tencent.polaris.api.plugin.common.ValueContext)1 PluginManager (com.tencent.polaris.api.plugin.impl.PluginManager)1 Instance (com.tencent.polaris.api.pojo.Instance)1 GetOneInstanceRequest (com.tencent.polaris.api.rpc.GetOneInstanceRequest)1 InstancesResponse (com.tencent.polaris.api.rpc.InstancesResponse)1 ServerConnectorConfigImpl (com.tencent.polaris.factory.config.global.ServerConnectorConfigImpl)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1