Search in sources :

Example 1 with QueryConfigurationsRequest

use of org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest in project java-chassis by ServiceComb.

the class ConfigCenterConfigurationSourceImpl method createQueryConfigurationsRequest.

private QueryConfigurationsRequest createQueryConfigurationsRequest() {
    QueryConfigurationsRequest request = new QueryConfigurationsRequest();
    request.setApplication(ConfigCenterConfig.INSTANCE.getAppName());
    request.setServiceName(ConfigCenterConfig.INSTANCE.getServiceName());
    request.setVersion(ConfigCenterConfig.INSTANCE.getServiceVersion());
    request.setEnvironment(ConfigCenterConfig.INSTANCE.getEnvironment());
    // 需要设置为 null, 并且 query 参数为 revision=null 才会返回 revision 信息。 revision = 是不行的。
    request.setRevision(null);
    return request;
}
Also used : QueryConfigurationsRequest(org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest)

Example 2 with QueryConfigurationsRequest

use of org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest in project incubator-servicecomb-java-chassis by apache.

the class ConfigCenterConfigurationSourceImpl method init.

@Override
public void init(Configuration localConfiguration) {
    configConverter = new ConfigConverter(ConfigCenterConfig.INSTANCE.getFileSources());
    AddressManager kieAddressManager = configKieAddressManager();
    HttpTransport httpTransport = createHttpTransport(kieAddressManager, HttpTransportFactory.defaultRequestConfig().build(), localConfiguration);
    ConfigCenterClient configCenterClient = new ConfigCenterClient(kieAddressManager, httpTransport);
    EventManager.register(this);
    QueryConfigurationsRequest queryConfigurationsRequest = firstPull(configCenterClient);
    configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(), configConverter);
    configCenterManager.setQueryConfigurationsRequest(queryConfigurationsRequest);
    configCenterManager.startConfigCenterManager();
}
Also used : ConfigConverter(org.apache.servicecomb.config.common.ConfigConverter) HttpTransport(org.apache.servicecomb.http.client.common.HttpTransport) AddressManager(org.apache.servicecomb.config.center.client.AddressManager) ConfigCenterManager(org.apache.servicecomb.config.center.client.ConfigCenterManager) QueryConfigurationsRequest(org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest) ConfigCenterClient(org.apache.servicecomb.config.center.client.ConfigCenterClient)

Example 3 with QueryConfigurationsRequest

use of org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest in project incubator-servicecomb-java-chassis by apache.

the class ConfigCenterConfigurationSourceImpl method firstPull.

private QueryConfigurationsRequest firstPull(ConfigCenterClient configCenterClient) {
    QueryConfigurationsRequest queryConfigurationsRequest = createQueryConfigurationsRequest();
    try {
        QueryConfigurationsResponse response = configCenterClient.queryConfigurations(queryConfigurationsRequest);
        if (response.isChanged()) {
            configConverter.updateData(response.getConfigurations());
            updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null));
            queryConfigurationsRequest.setRevision(response.getRevision());
        }
    } catch (Exception e) {
        if (ConfigCenterConfig.INSTANCE.firstPullRequired()) {
            throw e;
        }
        LOGGER.warn("first pull failed, and ignore {}", e.getMessage());
    }
    return queryConfigurationsRequest;
}
Also used : QueryConfigurationsResponse(org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse) QueryConfigurationsRequest(org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest)

Example 4 with QueryConfigurationsRequest

use of org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest in project java-chassis by ServiceComb.

the class ConfigCenterConfigurationSourceImpl method init.

@Override
public void init(Configuration localConfiguration) {
    configConverter = new ConfigConverter(ConfigCenterConfig.INSTANCE.getFileSources());
    AddressManager kieAddressManager = configKieAddressManager();
    HttpTransport httpTransport = createHttpTransport(kieAddressManager, HttpTransportFactory.defaultRequestConfig().build(), localConfiguration);
    ConfigCenterClient configCenterClient = new ConfigCenterClient(kieAddressManager, httpTransport);
    EventManager.register(this);
    QueryConfigurationsRequest queryConfigurationsRequest = firstPull(configCenterClient);
    configCenterManager = new ConfigCenterManager(configCenterClient, EventManager.getEventBus(), configConverter);
    configCenterManager.setQueryConfigurationsRequest(queryConfigurationsRequest);
    configCenterManager.startConfigCenterManager();
}
Also used : ConfigConverter(org.apache.servicecomb.config.common.ConfigConverter) HttpTransport(org.apache.servicecomb.http.client.common.HttpTransport) AddressManager(org.apache.servicecomb.config.center.client.AddressManager) ConfigCenterManager(org.apache.servicecomb.config.center.client.ConfigCenterManager) QueryConfigurationsRequest(org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest) ConfigCenterClient(org.apache.servicecomb.config.center.client.ConfigCenterClient)

Example 5 with QueryConfigurationsRequest

use of org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest in project java-chassis by ServiceComb.

the class ConfigCenterConfigurationSourceImpl method firstPull.

private QueryConfigurationsRequest firstPull(ConfigCenterClient configCenterClient) {
    QueryConfigurationsRequest queryConfigurationsRequest = createQueryConfigurationsRequest();
    try {
        QueryConfigurationsResponse response = configCenterClient.queryConfigurations(queryConfigurationsRequest);
        if (response.isChanged()) {
            configConverter.updateData(response.getConfigurations());
            updateConfiguration(WatchedUpdateResult.createIncremental(configConverter.getCurrentData(), null, null));
            queryConfigurationsRequest.setRevision(response.getRevision());
        }
    } catch (Exception e) {
        if (ConfigCenterConfig.INSTANCE.firstPullRequired()) {
            throw e;
        }
        LOGGER.warn("first pull failed, and ignore {}", e.getMessage());
    }
    return queryConfigurationsRequest;
}
Also used : QueryConfigurationsResponse(org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse) QueryConfigurationsRequest(org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest)

Aggregations

QueryConfigurationsRequest (org.apache.servicecomb.config.center.client.model.QueryConfigurationsRequest)6 AddressManager (org.apache.servicecomb.config.center.client.AddressManager)2 ConfigCenterClient (org.apache.servicecomb.config.center.client.ConfigCenterClient)2 ConfigCenterManager (org.apache.servicecomb.config.center.client.ConfigCenterManager)2 QueryConfigurationsResponse (org.apache.servicecomb.config.center.client.model.QueryConfigurationsResponse)2 ConfigConverter (org.apache.servicecomb.config.common.ConfigConverter)2 HttpTransport (org.apache.servicecomb.http.client.common.HttpTransport)2