use of org.apache.servicecomb.config.kie.client.model.ConfigurationsResponse in project java-chassis by ServiceComb.
the class KieClient method queryConfigurations.
@Override
public ConfigurationsResponse queryConfigurations(ConfigurationsRequest request) {
String address = addressManager.address();
String url = buildUrl(request, address);
try {
if (kieConfiguration.isEnableLongPolling()) {
url += "&wait=" + kieConfiguration.getPollingWaitInSeconds() + "s";
}
HttpRequest httpRequest = new HttpRequest(url, null, null, HttpRequest.GET);
HttpResponse httpResponse = httpTransport.doRequest(httpRequest);
ConfigurationsResponse configurationsResponse = new ConfigurationsResponse();
if (httpResponse.getStatusCode() == HttpStatus.SC_OK) {
revision = httpResponse.getHeader("X-Kie-Revision");
KVResponse allConfigList = HttpUtils.deserialize(httpResponse.getContent(), KVResponse.class);
Map<String, Object> configurations = getConfigByLabel(allConfigList);
configurationsResponse.setConfigurations(configurations);
configurationsResponse.setChanged(true);
configurationsResponse.setRevision(revision);
addressManager.recordSuccessState(address);
return configurationsResponse;
}
if (httpResponse.getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
throw new OperationException("Bad request for query configurations.");
}
if (httpResponse.getStatusCode() == HttpStatus.SC_NOT_MODIFIED) {
configurationsResponse.setChanged(false);
addressManager.recordSuccessState(address);
return configurationsResponse;
}
addressManager.recordFailState(address);
throw new OperationException("read response failed. status:" + httpResponse.getStatusCode() + "; message:" + httpResponse.getMessage() + "; content:" + httpResponse.getContent());
} catch (Exception e) {
LOGGER.error("query configuration from {} failed, message={}", url, e.getMessage());
throw new OperationException("read response failed. ", e);
}
}
use of org.apache.servicecomb.config.kie.client.model.ConfigurationsResponse in project java-chassis by ServiceComb.
the class KieConfigManager method firstPull.
public void firstPull() {
try {
Map<String, Object> data = new HashMap<>();
this.configurationsRequests.forEach(r -> {
r.setRevision(ConfigurationsRequest.INITIAL_REVISION);
ConfigurationsResponse response = configKieClient.queryConfigurations(r);
if (response.isChanged()) {
r.setRevision(response.getRevision());
r.setLastRawData(response.getConfigurations());
data.putAll(response.getConfigurations());
}
});
this.configConverter.updateData(data);
} catch (RuntimeException e) {
if (this.kieConfiguration.isFirstPullRequired()) {
throw e;
} else {
LOGGER.warn("first pull failed, and ignore {}", e.getMessage());
}
}
}
Aggregations