Search in sources :

Example 1 with InstancePublishInfo

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

the class ServiceStorage method parseInstance.

private Instance parseInstance(Service service, InstancePublishInfo instanceInfo) {
    Instance result = InstanceUtil.parseToApiInstance(service, instanceInfo);
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(service, instanceInfo.getMetadataId());
    metadata.ifPresent(instanceMetadata -> InstanceUtil.updateInstanceMetadata(result, instanceMetadata));
    return result;
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)

Example 2 with InstancePublishInfo

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

the class HealthCheckTaskV2 method doHealthCheck.

@Override
public void doHealthCheck() {
    try {
        for (Service each : client.getAllPublishedService()) {
            if (switchDomain.isHealthCheckEnabled(each.getGroupedServiceName())) {
                InstancePublishInfo instancePublishInfo = client.getInstancePublishInfo(each);
                ClusterMetadata metadata = getClusterMetadata(each, instancePublishInfo);
                ApplicationUtils.getBean(HealthCheckProcessorV2Delegate.class).process(this, each, metadata);
                if (Loggers.EVT_LOG.isDebugEnabled()) {
                    Loggers.EVT_LOG.debug("[HEALTH-CHECK-V2] schedule health check task: {}", client.getClientId());
                }
            }
        }
    } catch (Throwable e) {
        Loggers.SRV_LOG.error("[HEALTH-CHECK-V2] error while process health check for {}", client.getClientId(), e);
    } finally {
        if (!cancelled) {
            HealthCheckReactor.scheduleCheck(this);
            // worst == 0 means never checked
            if (this.getCheckRtWorst() > 0) {
                // TLog doesn't support float so we must convert it into long
                long checkRtLastLast = getCheckRtLastLast();
                this.setCheckRtLastLast(this.getCheckRtLast());
                if (checkRtLastLast > 0) {
                    long diff = ((this.getCheckRtLast() - this.getCheckRtLastLast()) * 10000) / checkRtLastLast;
                    if (Loggers.CHECK_RT.isDebugEnabled()) {
                        Loggers.CHECK_RT.debug("{}->normalized: {}, worst: {}, best: {}, last: {}, diff: {}", client.getClientId(), this.getCheckRtNormalized(), this.getCheckRtWorst(), this.getCheckRtBest(), this.getCheckRtLast(), diff);
                    }
                }
            }
        }
    }
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) HealthCheckProcessorV2Delegate(com.alibaba.nacos.naming.healthcheck.v2.processor.HealthCheckProcessorV2Delegate)

Example 3 with InstancePublishInfo

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

the class HealthCheckTaskV2 method getClusterMetadata.

private ClusterMetadata getClusterMetadata(Service service, InstancePublishInfo instancePublishInfo) {
    Optional<ServiceMetadata> serviceMetadata = metadataManager.getServiceMetadata(service);
    if (!serviceMetadata.isPresent()) {
        return new ClusterMetadata();
    }
    String cluster = instancePublishInfo.getCluster();
    ClusterMetadata result = serviceMetadata.get().getClusters().get(cluster);
    return null == result ? new ClusterMetadata() : result;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 4 with InstancePublishInfo

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

the class InstanceOperatorClientImpl method getHeartBeatInterval.

@Override
public long getHeartBeatInterval(String namespaceId, String serviceName, String ip, int port, String cluster) {
    Service service = getService(namespaceId, serviceName, true);
    String metadataId = InstancePublishInfo.genMetadataId(ip, port, cluster);
    Optional<InstanceMetadata> metadata = metadataManager.getInstanceMetadata(service, metadataId);
    if (metadata.isPresent() && metadata.get().getExtendData().containsKey(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) {
        return ConvertUtils.toLong(metadata.get().getExtendData().get(PreservedMetadataKeys.HEART_BEAT_INTERVAL));
    }
    String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, true);
    Client client = clientManager.getClient(clientId);
    InstancePublishInfo instance = null != client ? client.getInstancePublishInfo(service) : null;
    if (null != instance && instance.getExtendDatum().containsKey(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) {
        return ConvertUtils.toLong(instance.getExtendDatum().get(PreservedMetadataKeys.HEART_BEAT_INTERVAL));
    }
    return switchDomain.getClientBeatInterval();
}
Also used : InstanceMetadata(com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) UdpPushService(com.alibaba.nacos.naming.push.UdpPushService) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Client(com.alibaba.nacos.naming.core.v2.client.Client)

Example 5 with InstancePublishInfo

use of com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo 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

InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)17 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)9 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 Client (com.alibaba.nacos.naming.core.v2.client.Client)5 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)5 Test (org.junit.Test)5 ClientOperationEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent)4 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)4 InstanceMetadata (com.alibaba.nacos.naming.core.v2.metadata.InstanceMetadata)4 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)3 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)3 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)3 MetadataEvent (com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent)2 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 NacosRuntimeException (com.alibaba.nacos.api.exception.runtime.NacosRuntimeException)1 ClientAttributes (com.alibaba.nacos.naming.core.v2.client.ClientAttributes)1 ConnectionBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.ConnectionBasedClient)1 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)1