Search in sources :

Example 1 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class HttpHealthCheckProcessor method process.

@Override
public void process(HealthCheckTaskV2 task, Service service, ClusterMetadata metadata) {
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
    if (null == instance) {
        return;
    }
    try {
        // TODO handle marked(white list) logic like v1.x.
        if (!instance.tryStartCheck()) {
            SRV_LOG.warn("http check started before last one finished, service: {} : {} : {}:{}", service.getGroupedServiceName(), instance.getCluster(), instance.getIp(), instance.getPort());
            healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getHttpHealthParams());
            return;
        }
        Http healthChecker = (Http) metadata.getHealthChecker();
        int ckPort = metadata.isUseInstancePortForCheck() ? instance.getPort() : metadata.getHealthyCheckPort();
        URL host = new URL(HTTP_PREFIX + instance.getIp() + ":" + ckPort);
        URL target = new URL(host, healthChecker.getPath());
        Map<String, String> customHeaders = healthChecker.getCustomHeaders();
        Header header = Header.newInstance();
        header.addAll(customHeaders);
        ASYNC_REST_TEMPLATE.get(target.toString(), header, Query.EMPTY, String.class, new HttpHealthCheckCallback(instance, task, service));
        MetricsMonitor.getHttpHealthCheckMonitor().incrementAndGet();
    } catch (Throwable e) {
        instance.setCheckRt(switchDomain.getHttpHealthParams().getMax());
        healthCheckCommon.checkFail(task, service, "http:error:" + e.getMessage());
        healthCheckCommon.reEvaluateCheckRT(switchDomain.getHttpHealthParams().getMax(), task, switchDomain.getHttpHealthParams());
    }
}
Also used : Header(com.alibaba.nacos.common.http.param.Header) Http(com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) URL(java.net.URL)

Example 2 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class ClientBeatCheckTaskV2 method doHealthCheck.

@Override
public void doHealthCheck() {
    try {
        Collection<Service> services = client.getAllPublishedService();
        for (Service each : services) {
            HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(each);
            interceptorChain.doInterceptor(new InstanceBeatCheckTask(client, each, instance));
        }
    } catch (Exception e) {
        Loggers.SRV_LOG.warn("Exception while processing client beat time out.", e);
    }
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)

Example 3 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class ClientBeatProcessorV2 method run.

@Override
public void run() {
    if (Loggers.EVT_LOG.isDebugEnabled()) {
        Loggers.EVT_LOG.debug("[CLIENT-BEAT] processing beat: {}", rsInfo.toString());
    }
    String ip = rsInfo.getIp();
    int port = rsInfo.getPort();
    String serviceName = NamingUtils.getServiceName(rsInfo.getServiceName());
    String groupName = NamingUtils.getGroupName(rsInfo.getServiceName());
    Service service = Service.newService(namespace, groupName, serviceName, rsInfo.isEphemeral());
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) client.getInstancePublishInfo(service);
    if (instance.getIp().equals(ip) && instance.getPort() == port) {
        if (Loggers.EVT_LOG.isDebugEnabled()) {
            Loggers.EVT_LOG.debug("[CLIENT-BEAT] refresh beat: {}", rsInfo);
        }
        instance.setLastHeartBeatTime(System.currentTimeMillis());
        if (!instance.isHealthy()) {
            instance.setHealthy(true);
            Loggers.EVT_LOG.info("service: {} {POS} {IP-ENABLED} valid: {}:{}@{}, region: {}, msg: client beat ok", rsInfo.getServiceName(), ip, port, rsInfo.getCluster(), UtilsAndCommons.LOCALHOST_SITE);
            NotifyCenter.publishEvent(new ServiceEvent.ServiceChangedEvent(service));
            NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(client));
        }
    }
}
Also used : ServiceEvent(com.alibaba.nacos.naming.core.v2.event.service.ServiceEvent) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

Example 4 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class InstanceEnableBeatCheckInterceptor method intercept.

@Override
public boolean intercept(InstanceBeatCheckTask object) {
    NamingMetadataManager metadataManager = ApplicationUtils.getBean(NamingMetadataManager.class);
    HealthCheckInstancePublishInfo instance = object.getInstancePublishInfo();
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(object.getService(), instance.getMetadataId());
    if (metadata.isPresent() && metadata.get().getExtendData().containsKey(UtilsAndCommons.ENABLE_CLIENT_BEAT)) {
        return ConvertUtils.toBoolean(metadata.get().getExtendData().get(UtilsAndCommons.ENABLE_CLIENT_BEAT).toString());
    }
    if (instance.getExtendDatum().containsKey(UtilsAndCommons.ENABLE_CLIENT_BEAT)) {
        return ConvertUtils.toBoolean(instance.getExtendDatum().get(UtilsAndCommons.ENABLE_CLIENT_BEAT).toString());
    }
    return false;
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) NamingMetadataManager(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)

Example 5 with HealthCheckInstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo in project nacos by alibaba.

the class IpPortBasedClient method parseToHealthCheckInstance.

private HealthCheckInstancePublishInfo parseToHealthCheckInstance(InstancePublishInfo instancePublishInfo) {
    HealthCheckInstancePublishInfo result;
    if (instancePublishInfo instanceof HealthCheckInstancePublishInfo) {
        result = (HealthCheckInstancePublishInfo) instancePublishInfo;
    } else {
        result = new HealthCheckInstancePublishInfo();
        result.setIp(instancePublishInfo.getIp());
        result.setPort(instancePublishInfo.getPort());
        result.setHealthy(instancePublishInfo.isHealthy());
        result.setCluster(instancePublishInfo.getCluster());
        result.setExtendDatum(instancePublishInfo.getExtendDatum());
    }
    if (!ephemeral) {
        result.initHealthCheck();
    }
    return result;
}
Also used : 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