Search in sources :

Example 11 with HealthCheckInstancePublishInfo

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);
    }
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 12 with HealthCheckInstancePublishInfo

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);
    }
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 13 with HealthCheckInstancePublishInfo

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;
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Aggregations

HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)13 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)4 Http (com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http)1 Header (com.alibaba.nacos.common.http.param.Header)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1 ServiceEvent (com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent)1 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)1 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 URL (java.net.URL)1 SQLException (java.sql.SQLException)1 TimeoutException (java.util.concurrent.TimeoutException)1