use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.
the class HealthCheckCommonV2 method checkFail.
/**
* Health check fail, when instance check failed count more than max failed time, set unhealthy.
*
* @param task health check task
* @param service service
* @param msg message
*/
public void checkFail(HealthCheckTaskV2 task, Service service, String msg) {
try {
HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
if (instance == null) {
return;
}
try {
if (instance.isHealthy()) {
String serviceName = service.getGroupedServiceName();
String clusterName = instance.getCluster();
if (instance.getFailCount().incrementAndGet() >= switchDomain.getCheckTimes()) {
if (switchDomain.isHealthCheckEnabled(serviceName) && !task.isCancelled() && distroMapper.responsible(task.getClient().getResponsibleId())) {
healthStatusSynchronizer.instanceHealthStatusChange(false, task.getClient(), service, instance);
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-DISABLED} invalid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg);
}
} else {
Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-DISABLED} pre-invalid: {}:{}@{} in {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, instance.getFailCount(), msg);
}
}
} finally {
instance.resetOkCount();
instance.finishCheck();
}
} catch (Throwable t) {
Loggers.SRV_LOG.error("[CHECK-FAIL] error when close check task.", t);
}
}
use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.
the class HealthCheckCommonV2 method checkOk.
/**
* Health check pass.
*
* @param task health check task
* @param service service
* @param msg message
*/
public void checkOk(HealthCheckTaskV2 task, Service service, String msg) {
try {
HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
if (instance == null) {
return;
}
try {
if (!instance.isHealthy()) {
String serviceName = service.getGroupedServiceName();
String clusterName = instance.getCluster();
if (instance.getOkCount().incrementAndGet() >= switchDomain.getCheckTimes()) {
if (switchDomain.isHealthCheckEnabled(serviceName) && !task.isCancelled() && distroMapper.responsible(task.getClient().getResponsibleId())) {
healthStatusSynchronizer.instanceHealthStatusChange(true, task.getClient(), service, instance);
Loggers.EVT_LOG.info("serviceName: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, UtilsAndCommons.LOCALHOST_SITE, msg);
}
} else {
Loggers.EVT_LOG.info("serviceName: {} {OTHER} {IP-ENABLED} pre-valid: {}:{}@{} in {}, msg: {}", serviceName, instance.getIp(), instance.getPort(), clusterName, instance.getOkCount(), msg);
}
}
} finally {
instance.resetFailCount();
instance.finishCheck();
}
} catch (Throwable t) {
Loggers.SRV_LOG.error("[CHECK-OK] error when close check task.", t);
}
}
use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.
the class ClientBeatCheckTaskV2Test method injectInstance.
private HealthCheckInstancePublishInfo injectInstance(boolean healthy, long heartbeatTime) {
HealthCheckInstancePublishInfo instance = new HealthCheckInstancePublishInfo(IP, PORT);
instance.setHealthy(healthy);
instance.setLastHeartBeatTime(heartbeatTime);
instance.setCluster(UtilsAndCommons.DEFAULT_CLUSTER_NAME);
Service service = Service.newService(NAMESPACE, GROUP_NAME, SERVICE_NAME);
client.addServiceInstance(service, instance);
return instance;
}
Aggregations