use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class RetryableRestTemplate method exchangeGet.
private <T> ResponseEntity<T> exchangeGet(Env env, String path, ParameterizedTypeReference<T> reference, Object... uriVariables) {
if (path.startsWith("/")) {
path = path.substring(1);
}
String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
Transaction ct = Tracer.newTransaction("AdminAPI", uri);
ct.addData("Env", env);
List<ServiceDTO> services = getAdminServices(env, ct);
HttpEntity<Void> entity = new HttpEntity<>(assembleExtraHeaders(env));
for (ServiceDTO serviceDTO : services) {
try {
ResponseEntity<T> result = restTemplate.exchange(parseHost(serviceDTO) + path, HttpMethod.GET, entity, reference, uriVariables);
ct.setStatus(Transaction.SUCCESS);
ct.complete();
return result;
} catch (Throwable t) {
logger.error("Http request failed, uri: {}, method: {}", uri, HttpMethod.GET, t);
Tracer.logError(t);
if (canRetry(t, HttpMethod.GET)) {
Tracer.logEvent(TracerEventType.API_RETRY, uri);
} else {
// biz exception rethrow
ct.setStatus(t);
ct.complete();
throw t;
}
}
}
// all admin server down
ServiceException e = new ServiceException(String.format("Admin servers are unresponsive. meta server address: %s, admin servers: %s", portalMetaDomainService.getDomain(env), services));
ct.setStatus(e);
ct.complete();
throw e;
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class RetryableRestTemplate method getAdminServices.
private List<ServiceDTO> getAdminServices(Env env, Transaction ct) {
List<ServiceDTO> services = adminServiceAddressLocator.getServiceList(env);
if (CollectionUtils.isEmpty(services)) {
ServiceException e = new ServiceException(String.format("No available admin server." + " Maybe because of meta server down or all admin server down. " + "Meta server address: %s", portalMetaDomainService.getDomain(env)));
ct.setStatus(e);
ct.complete();
throw e;
}
return services;
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class ConfigServiceLocator method updateConfigServices.
private synchronized void updateConfigServices() {
String url = assembleMetaServiceUrl();
HttpRequest request = new HttpRequest(url);
int maxRetries = 2;
Throwable exception = null;
for (int i = 0; i < maxRetries; i++) {
Transaction transaction = Tracer.newTransaction("Apollo.MetaService", "getConfigService");
transaction.addData("Url", url);
try {
HttpResponse<List<ServiceDTO>> response = m_httpClient.doGet(request, m_responseType);
transaction.setStatus(Transaction.SUCCESS);
List<ServiceDTO> services = response.getBody();
if (services == null || services.isEmpty()) {
logConfigService("Empty response!");
continue;
}
setConfigServices(services);
return;
} catch (Throwable ex) {
Tracer.logEvent("ApolloConfigException", ExceptionUtil.getDetailMessage(ex));
transaction.setStatus(ex);
exception = ex;
} finally {
transaction.complete();
}
try {
m_configUtil.getOnErrorRetryIntervalTimeUnit().sleep(m_configUtil.getOnErrorRetryInterval());
} catch (InterruptedException ex) {
// ignore
}
}
throw new ApolloConfigException(String.format("Get config services failed from %s", url), exception);
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class NacosDiscoveryService method toServiceDTO.
private ServiceDTO toServiceDTO(Instance instance, String appName) {
ServiceDTO service = new ServiceDTO();
service.setAppName(appName);
service.setInstanceId(instance.getInstanceId());
String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort() + "/";
service.setHomepageUrl(homePageUrl);
return service;
}
use of com.ctrip.framework.apollo.core.dto.ServiceDTO in project apollo by ctripcorp.
the class KubernetesDiscoveryService method assembleServiceDTO.
private List<ServiceDTO> assembleServiceDTO(String serviceId, String directUrl) {
if (Strings.isNullOrEmpty(directUrl)) {
return Collections.emptyList();
}
List<ServiceDTO> serviceDTOList = Lists.newLinkedList();
COMMA_SPLITTER.split(directUrl).forEach(url -> {
ServiceDTO service = new ServiceDTO();
service.setAppName(serviceId);
service.setInstanceId(String.format("%s:%s", serviceId, url));
service.setHomepageUrl(url);
serviceDTOList.add(service);
});
return serviceDTOList;
}
Aggregations