Search in sources :

Example 1 with ClientBeatProcessorV2

use of com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2 in project nacos by alibaba.

the class InstanceOperatorClientImpl method handleBeat.

@Override
public int handleBeat(String namespaceId, String serviceName, String ip, int port, String cluster, RsInfo clientBeat, BeatInfoInstanceBuilder builder) throws NacosException {
    Service service = getService(namespaceId, serviceName, true);
    String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, true);
    IpPortBasedClient client = (IpPortBasedClient) clientManager.getClient(clientId);
    if (null == client || !client.getAllPublishedService().contains(service)) {
        if (null == clientBeat) {
            return NamingResponseCode.RESOURCE_NOT_FOUND;
        }
        Instance instance = builder.setBeatInfo(clientBeat).setServiceName(serviceName).build();
        registerInstance(namespaceId, serviceName, instance);
        client = (IpPortBasedClient) clientManager.getClient(clientId);
    }
    if (!ServiceManager.getInstance().containSingleton(service)) {
        throw new NacosException(NacosException.SERVER_ERROR, "service not found: " + serviceName + "@" + namespaceId);
    }
    if (null == clientBeat) {
        clientBeat = new RsInfo();
        clientBeat.setIp(ip);
        clientBeat.setPort(port);
        clientBeat.setCluster(cluster);
        clientBeat.setServiceName(serviceName);
    }
    ClientBeatProcessorV2 beatProcessor = new ClientBeatProcessorV2(namespaceId, clientBeat, client);
    HealthCheckReactor.scheduleNow(beatProcessor);
    client.setLastUpdatedTime();
    return NamingResponseCode.OK;
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) 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) RsInfo(com.alibaba.nacos.naming.healthcheck.RsInfo) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) NacosException(com.alibaba.nacos.api.exception.NacosException) ClientBeatProcessorV2(com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2)

Aggregations

NacosException (com.alibaba.nacos.api.exception.NacosException)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)1 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)1 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)1 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)1 RsInfo (com.alibaba.nacos.naming.healthcheck.RsInfo)1 ClientBeatProcessorV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2)1 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)1