|
|
@ -117,12 +117,14 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void reportResult(URI url, ClientHttpResponse response) {
|
|
|
|
private void reportResult(URI url, ClientHttpResponse response) {
|
|
|
|
ServiceCallResult resultRequest = createServiceCallResult(url);
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
ServiceCallResult resultRequest = createServiceCallResult(url, response);
|
|
|
|
Map<String, String> loadBalancerContext = MetadataContextHolder.get().getLoadbalancerMetadata();
|
|
|
|
Map<String, String> loadBalancerContext = MetadataContextHolder.get().getLoadbalancerMetadata();
|
|
|
|
|
|
|
|
|
|
|
|
String targetHost = loadBalancerContext.get("host");
|
|
|
|
String targetHost = loadBalancerContext.get("host");
|
|
|
|
String targetPort = loadBalancerContext.get("port");
|
|
|
|
String targetPort = loadBalancerContext.get("port");
|
|
|
|
|
|
|
|
String startMillis = loadBalancerContext.get("startMillis");
|
|
|
|
|
|
|
|
long delay = System.currentTimeMillis() - Long.parseLong(startMillis);
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(targetHost) || StringUtils.isBlank(targetPort)) {
|
|
|
|
if (StringUtils.isBlank(targetHost) || StringUtils.isBlank(targetPort)) {
|
|
|
|
LOGGER.warn("Can not get target host or port from metadata context. host = {}, port = {}", targetHost, targetPort);
|
|
|
|
LOGGER.warn("Can not get target host or port from metadata context. host = {}, port = {}", targetHost, targetPort);
|
|
|
@ -131,6 +133,7 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
|
|
|
|
|
|
|
|
resultRequest.setHost(targetHost);
|
|
|
|
resultRequest.setHost(targetHost);
|
|
|
|
resultRequest.setPort(Integer.parseInt(targetPort));
|
|
|
|
resultRequest.setPort(Integer.parseInt(targetPort));
|
|
|
|
|
|
|
|
resultRequest.setDelay(delay);
|
|
|
|
|
|
|
|
|
|
|
|
// checking response http status code
|
|
|
|
// checking response http status code
|
|
|
|
if (apply(response.getStatusCode())) {
|
|
|
|
if (apply(response.getStatusCode())) {
|
|
|
@ -150,8 +153,8 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// processing report with consumerAPI .
|
|
|
|
// processing report with consumerAPI .
|
|
|
|
LOGGER.debug("Will report result of {}. URL=[{}]. Response=[{}].", resultRequest.getRetStatus().name(),
|
|
|
|
LOGGER.debug("Will report result of {}. Request=[{}]. Response=[{}]. Delay=[{}]ms.", resultRequest.getRetStatus()
|
|
|
|
url, response);
|
|
|
|
.name(), url, response.getStatusCode().value(), delay);
|
|
|
|
consumerAPI.updateServiceCallResult(resultRequest);
|
|
|
|
consumerAPI.updateServiceCallResult(resultRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
catch (Exception e) {
|
|
|
@ -193,12 +196,13 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
response.getHeaders().remove(HEADER_HAS_ERROR);
|
|
|
|
response.getHeaders().remove(HEADER_HAS_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ServiceCallResult createServiceCallResult(URI uri) {
|
|
|
|
private ServiceCallResult createServiceCallResult(URI uri, ClientHttpResponse response) throws IOException {
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
String serviceName = uri.getHost();
|
|
|
|
String serviceName = uri.getHost();
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
|
|
|
|
resultRequest.setRetCode(response.getStatusCode().value());
|
|
|
|
resultRequest.setRetStatus(RetStatus.RetSuccess);
|
|
|
|
resultRequest.setRetStatus(RetStatus.RetSuccess);
|
|
|
|
String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
|
|
|
|
String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
|
|
|
|
String sourceService = MetadataContext.LOCAL_SERVICE;
|
|
|
|
String sourceService = MetadataContext.LOCAL_SERVICE;
|
|
|
|