|
|
@ -18,12 +18,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.polaris.registry;
|
|
|
|
package com.tencent.cloud.polaris.registry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
|
|
|
|
import com.tencent.cloud.common.metadata.config.MetadataLocalProperties;
|
|
|
|
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
|
|
|
|
import com.tencent.cloud.polaris.PolarisDiscoveryProperties;
|
|
|
|
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
|
|
|
|
import com.tencent.cloud.polaris.discovery.PolarisDiscoveryHandler;
|
|
|
|
import com.tencent.cloud.polaris.registry.filter.DefaultRegisterFilterHandler;
|
|
|
|
import com.tencent.cloud.polaris.registry.filter.DefaultRegisterFilterHandler;
|
|
|
|
import com.tencent.cloud.polaris.registry.filter.RegisterFilterHandler;
|
|
|
|
import com.tencent.cloud.polaris.registry.filter.RegisterFilterHandler;
|
|
|
|
import com.tencent.cloud.polaris.registry.filter.RegisterFilterHandlerContext;
|
|
|
|
|
|
|
|
import com.tencent.cloud.polaris.util.OkHttpUtil;
|
|
|
|
import com.tencent.cloud.polaris.util.OkHttpUtil;
|
|
|
|
import com.tencent.polaris.api.core.ProviderAPI;
|
|
|
|
import com.tencent.polaris.api.core.ProviderAPI;
|
|
|
|
import com.tencent.polaris.api.exception.PolarisException;
|
|
|
|
import com.tencent.polaris.api.exception.PolarisException;
|
|
|
@ -36,16 +41,11 @@ import com.tencent.polaris.client.util.NamedThreadFactory;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.cloud.client.serviceregistry.Registration;
|
|
|
|
import org.springframework.cloud.client.serviceregistry.Registration;
|
|
|
|
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
|
|
|
import org.springframework.cloud.client.serviceregistry.ServiceRegistry;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|
|
|
import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -86,12 +86,13 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
this.metadataLocalProperties = metadataLocalProperties;
|
|
|
|
this.metadataLocalProperties = metadataLocalProperties;
|
|
|
|
|
|
|
|
|
|
|
|
this.registerFilterHandler = new LinkedList<>();
|
|
|
|
this.registerFilterHandler = new LinkedList<>();
|
|
|
|
this.addRegisterFilterHandler(new DefaultRegisterFilterHandler());
|
|
|
|
this.registerFilterHandler.add(new DefaultRegisterFilterHandler());
|
|
|
|
|
|
|
|
|
|
|
|
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
|
|
|
|
if (polarisDiscoveryProperties.isHeartbeatEnabled()) {
|
|
|
|
this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(
|
|
|
|
this.heartbeatExecutor = Executors.newSingleThreadScheduledExecutor(
|
|
|
|
new NamedThreadFactory("spring-cloud-heartbeat"));
|
|
|
|
new NamedThreadFactory("spring-cloud-heartbeat"));
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
this.heartbeatExecutor = null;
|
|
|
|
this.heartbeatExecutor = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -122,8 +123,9 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
List<RegisterFilterHandler> registerFilterHandlerInstances = registerFilterHandlerInstances();
|
|
|
|
List<RegisterFilterHandler> registerFilterHandlerInstances = registerFilterHandlerInstances();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
registerFilterHandlerInstances.forEach(registerFilterHandler -> {
|
|
|
|
registerFilterHandlerInstances.forEach(registerFilterHandler -> {
|
|
|
|
if (!registerFilterHandler.beforeInvoke(new RegisterFilterHandlerContext(instanceRegisterRequest))) {
|
|
|
|
if (!registerFilterHandler.beforeInvoke(instanceRegisterRequest)) {
|
|
|
|
log.error("the registerFilterHandler return false on before invoke");
|
|
|
|
log.error("{} the registerFilterHandler return false on before invoke", registerFilterHandler.getClass()
|
|
|
|
|
|
|
|
.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -140,14 +142,17 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
// Start the heartbeat thread after the registration is successful.
|
|
|
|
// Start the heartbeat thread after the registration is successful.
|
|
|
|
heartbeat(heartbeatRequest);
|
|
|
|
heartbeat(heartbeatRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
log.error("polaris registry, {} register failed...{},",
|
|
|
|
log.error("polaris registry, {} register failed...{},",
|
|
|
|
registration.getServiceId(), registration, e);
|
|
|
|
registration.getServiceId(), registration, e);
|
|
|
|
rethrowRuntimeException(e);
|
|
|
|
rethrowRuntimeException(e);
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
registerFilterHandlerInstances.forEach(registerFilterHandler -> {
|
|
|
|
registerFilterHandlerInstances.forEach(registerFilterHandler -> {
|
|
|
|
if (!registerFilterHandler.afterInvoke(new RegisterFilterHandlerContext(instanceRegisterRequest))) {
|
|
|
|
if (!registerFilterHandler.afterInvoke(instanceRegisterRequest)) {
|
|
|
|
log.error("the registerFilterHandler return false on after invoke");
|
|
|
|
log.error("{} registerFilterHandler return false on after invoke", registerFilterHandler.getClass()
|
|
|
|
|
|
|
|
.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -173,10 +178,12 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
|
|
|
|
ProviderAPI providerClient = polarisDiscoveryHandler.getProviderAPI();
|
|
|
|
providerClient.deRegister(deRegisterRequest);
|
|
|
|
providerClient.deRegister(deRegisterRequest);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
log.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration,
|
|
|
|
log.error("ERR_POLARIS_DEREGISTER, de-register failed...{},", registration,
|
|
|
|
e);
|
|
|
|
e);
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
|
|
|
|
finally {
|
|
|
|
if (null != heartbeatExecutor) {
|
|
|
|
if (null != heartbeatExecutor) {
|
|
|
|
heartbeatExecutor.shutdown();
|
|
|
|
heartbeatExecutor.shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -245,9 +252,11 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
|
|
|
|
polarisDiscoveryHandler.getProviderAPI().heartbeat(heartbeatRequest);
|
|
|
|
} catch (PolarisException e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (PolarisException e) {
|
|
|
|
log.error("polaris heartbeat[{}]", e.getCode(), e);
|
|
|
|
log.error("polaris heartbeat[{}]", e.getCode(), e);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
log.error("polaris heartbeat runtime error", e);
|
|
|
|
log.error("polaris heartbeat runtime error", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, ttl, ttl, TimeUnit.SECONDS);
|
|
|
|
}, ttl, ttl, TimeUnit.SECONDS);
|
|
|
@ -259,12 +268,14 @@ public class PolarisServiceRegistry implements ServiceRegistry<Registration> {
|
|
|
|
log.info("register filterHandler name[{}]", instance.getClass().getName());
|
|
|
|
log.info("register filterHandler name[{}]", instance.getClass().getName());
|
|
|
|
if (instance instanceof RegisterFilterHandler) {
|
|
|
|
if (instance instanceof RegisterFilterHandler) {
|
|
|
|
registerFilterHandlerInstances.add((RegisterFilterHandler) instance);
|
|
|
|
registerFilterHandlerInstances.add((RegisterFilterHandler) instance);
|
|
|
|
} else if (instance instanceof Class<?>) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (instance instanceof Class<?>) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Class<?> cl = (Class<?>) instance;
|
|
|
|
Class<?> cl = (Class<?>) instance;
|
|
|
|
RegisterFilterHandler filter = (RegisterFilterHandler) cl.newInstance();
|
|
|
|
RegisterFilterHandler filter = (RegisterFilterHandler) cl.newInstance();
|
|
|
|
registerFilterHandlerInstances.add(filter);
|
|
|
|
registerFilterHandlerInstances.add(filter);
|
|
|
|
} catch (Exception e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
log.error("register filterHandler name[{}] error{}", instance.getClass().getName(), e);
|
|
|
|
log.error("register filterHandler name[{}] error{}", instance.getClass().getName(), e);
|
|
|
|
rethrowRuntimeException(e);
|
|
|
|
rethrowRuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|