|
|
|
@ -51,7 +51,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|
|
|
|
*/
|
|
|
|
|
public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(PolarisServiceRegistry.class);
|
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(PolarisServiceRegistry.class);
|
|
|
|
|
|
|
|
|
|
private static final int ttl = 5;
|
|
|
|
|
|
|
|
|
@ -82,7 +82,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
@Override
|
|
|
|
|
public void register(Registration registration) {
|
|
|
|
|
if (StringUtils.isEmpty(registration.getServiceId())) {
|
|
|
|
|
log.warn("No service to register for polaris client...");
|
|
|
|
|
LOG.warn("No service to register for polaris client...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Register instance.
|
|
|
|
@ -105,7 +105,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
try {
|
|
|
|
|
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
|
|
|
|
|
providerClient.register(instanceRegisterRequest);
|
|
|
|
|
log.info("polaris registry, {} {} {}:{} {} register finished",
|
|
|
|
|
LOG.info("polaris registry, {} {} {}:{} {} register finished",
|
|
|
|
|
polarisDiscoveryProperties.getNamespace(),
|
|
|
|
|
registration.getServiceId(), registration.getHost(),
|
|
|
|
|
registration.getPort(), staticMetadataManager.getMergedStaticMetadata());
|
|
|
|
@ -118,17 +118,17 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
log.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
|
|
|
|
|
LOG.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
|
|
|
|
|
rethrowRuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deregister(Registration registration) {
|
|
|
|
|
log.info("De-registering from Polaris Server now...");
|
|
|
|
|
LOG.info("De-registering from Polaris Server now...");
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(registration.getServiceId())) {
|
|
|
|
|
log.warn("No dom to de-register for polaris client...");
|
|
|
|
|
LOG.warn("No dom to de-register for polaris client...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -144,14 +144,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
providerClient.deRegister(deRegisterRequest);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
log.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration, e);
|
|
|
|
|
LOG.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration, e);
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
if (null != heartbeatExecutor) {
|
|
|
|
|
heartbeatExecutor.shutdown();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("De-registration finished.");
|
|
|
|
|
LOG.info("De-registration finished.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -204,7 +204,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
heartbeatRequest.getHost(), heartbeatRequest.getPort(), healthCheckEndpoint);
|
|
|
|
|
|
|
|
|
|
if (!OkHttpUtil.get(healthCheckUrl, null)) {
|
|
|
|
|
log.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint);
|
|
|
|
|
LOG.error("backend service health check failed. health check endpoint = {}", healthCheckEndpoint);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -212,10 +212,10 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
|
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
|
|
|
|
|
}
|
|
|
|
|
catch (PolarisException e) {
|
|
|
|
|
log.error("polaris heartbeat[{}]", e.getCode(), e);
|
|
|
|
|
LOG.error("polaris heartbeat[{}]", e.getCode(), e);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
log.error("polaris heartbeat runtime error", e);
|
|
|
|
|
LOG.error("polaris heartbeat runtime error", e);
|
|
|
|
|
}
|
|
|
|
|
}, ttl, ttl, TimeUnit.SECONDS);
|
|
|
|
|
}
|
|
|
|
|