|
|
@ -68,7 +68,7 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
this.polarisDiscoveryHandler = polarisDiscoveryHandler;
|
|
|
|
this.polarisDiscoveryHandler = polarisDiscoveryHandler;
|
|
|
|
this.staticMetadataManager = staticMetadataManager;
|
|
|
|
this.staticMetadataManager = staticMetadataManager;
|
|
|
|
|
|
|
|
|
|
|
|
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
|
|
|
|
if (StringUtils.isNotBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
|
|
|
|
this.heartbeatExecutor = Executors
|
|
|
|
this.heartbeatExecutor = Executors
|
|
|
|
.newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat"));
|
|
|
|
.newSingleThreadScheduledExecutor(new NamedThreadFactory("polaris-heartbeat"));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -95,26 +95,27 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
instanceRegisterRequest.setRegion(staticMetadataManager.getRegion());
|
|
|
|
instanceRegisterRequest.setRegion(staticMetadataManager.getRegion());
|
|
|
|
instanceRegisterRequest.setZone(staticMetadataManager.getZone());
|
|
|
|
instanceRegisterRequest.setZone(staticMetadataManager.getZone());
|
|
|
|
instanceRegisterRequest.setCampus(staticMetadataManager.getCampus());
|
|
|
|
instanceRegisterRequest.setCampus(staticMetadataManager.getCampus());
|
|
|
|
if (null != heartbeatExecutor) {
|
|
|
|
|
|
|
|
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
|
|
|
|
instanceRegisterRequest.setTtl(polarisDiscoveryProperties.getHeartbeatInterval());
|
|
|
|
}
|
|
|
|
|
|
|
|
instanceRegisterRequest.setMetadata(registration.getMetadata());
|
|
|
|
instanceRegisterRequest.setMetadata(registration.getMetadata());
|
|
|
|
instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
|
|
|
|
instanceRegisterRequest.setProtocol(polarisDiscoveryProperties.getProtocol());
|
|
|
|
instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
|
|
|
|
instanceRegisterRequest.setVersion(polarisDiscoveryProperties.getVersion());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
|
|
|
|
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
|
|
|
|
InstanceRegisterResponse instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
|
|
|
|
InstanceRegisterResponse instanceRegisterResponse;
|
|
|
|
registration.setInstanceId(instanceRegisterResponse.getInstanceId());
|
|
|
|
if (StringUtils.isBlank(polarisDiscoveryProperties.getHealthCheckUrl())) {
|
|
|
|
LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(),
|
|
|
|
instanceRegisterResponse = providerClient.registerInstance(instanceRegisterRequest);
|
|
|
|
registration.getServiceId(), registration.getHost(), registration.getPort(),
|
|
|
|
}
|
|
|
|
staticMetadataManager.getMergedStaticMetadata());
|
|
|
|
else {
|
|
|
|
|
|
|
|
instanceRegisterResponse = providerClient.register(instanceRegisterRequest);
|
|
|
|
if (null != heartbeatExecutor) {
|
|
|
|
|
|
|
|
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
|
|
|
|
InstanceHeartbeatRequest heartbeatRequest = new InstanceHeartbeatRequest();
|
|
|
|
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
|
|
|
|
BeanUtils.copyProperties(instanceRegisterRequest, heartbeatRequest);
|
|
|
|
// Start the heartbeat thread after the registration is successful.
|
|
|
|
// Start the heartbeat thread after the registration is successful.
|
|
|
|
heartbeat(heartbeatRequest);
|
|
|
|
heartbeat(heartbeatRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
registration.setInstanceId(instanceRegisterResponse.getInstanceId());
|
|
|
|
|
|
|
|
LOGGER.info("polaris registry, {} {} {}:{} {} register finished", polarisDiscoveryProperties.getNamespace(),
|
|
|
|
|
|
|
|
registration.getServiceId(), registration.getHost(), registration.getPort(),
|
|
|
|
|
|
|
|
staticMetadataManager.getMergedStaticMetadata());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
catch (Exception e) {
|
|
|
|
LOGGER.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
|
|
|
|
LOGGER.error("polaris registry, {} register failed...{},", registration.getServiceId(), registration, e);
|
|
|
@ -188,12 +189,8 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
heartbeatExecutor.scheduleWithFixedDelay(() -> {
|
|
|
|
heartbeatExecutor.scheduleWithFixedDelay(() -> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String healthCheckEndpoint = polarisDiscoveryProperties.getHealthCheckUrl();
|
|
|
|
String healthCheckEndpoint = polarisDiscoveryProperties.getHealthCheckUrl();
|
|
|
|
// First determine whether health-check-url is configured.
|
|
|
|
|
|
|
|
// If configured, the service instance health check needs to be executed
|
|
|
|
|
|
|
|
// first.
|
|
|
|
|
|
|
|
// If the health check passes, the heartbeat will be reported.
|
|
|
|
// If the health check passes, the heartbeat will be reported.
|
|
|
|
// If it does not pass, the heartbeat will not be reported.
|
|
|
|
// If it does not pass, the heartbeat will not be reported.
|
|
|
|
if (StringUtils.isNotBlank(healthCheckEndpoint)) {
|
|
|
|
|
|
|
|
if (!healthCheckEndpoint.startsWith("/")) {
|
|
|
|
if (!healthCheckEndpoint.startsWith("/")) {
|
|
|
|
healthCheckEndpoint = "/" + healthCheckEndpoint;
|
|
|
|
healthCheckEndpoint = "/" + healthCheckEndpoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -206,7 +203,6 @@ public class PolarisServiceRegistry implements ServiceRegistry<PolarisRegistrati
|
|
|
|
healthCheckEndpoint);
|
|
|
|
healthCheckEndpoint);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
|
|
|
|
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
|
|
|
|
LOGGER.trace("Polaris heartbeat is sent");
|
|
|
|
LOGGER.trace("Polaris heartbeat is sent");
|
|
|
|