Search in sources :

Example 1 with IpPortBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.

the class EphemeralIpPortClientManager method clientDisconnected.

@Override
public boolean clientDisconnected(String clientId) {
    Loggers.SRV_LOG.info("Client connection {} disconnect, remove instances and subscribers", clientId);
    IpPortBasedClient client = clients.remove(clientId);
    if (null == client) {
        return true;
    }
    NotifyCenter.publishEvent(new ClientEvent.ClientDisconnectEvent(client));
    client.release();
    return true;
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

Example 2 with IpPortBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.

the class PersistentIpPortClientManager method clientConnected.

@Override
public boolean clientConnected(final Client client) {
    clients.computeIfAbsent(client.getClientId(), s -> {
        Loggers.SRV_LOG.info("Client connection {} connect", client.getClientId());
        IpPortBasedClient ipPortBasedClient = (IpPortBasedClient) client;
        ipPortBasedClient.init();
        return ipPortBasedClient;
    });
    return true;
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)

Example 3 with IpPortBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.

the class PersistentIpPortClientManager method clientDisconnected.

@Override
public boolean clientDisconnected(String clientId) {
    Loggers.SRV_LOG.info("Persistent client connection {} disconnect", clientId);
    IpPortBasedClient client = clients.remove(clientId);
    if (null == client) {
        return true;
    }
    NotifyCenter.publishEvent(new ClientEvent.ClientDisconnectEvent(client));
    client.release();
    return true;
}
Also used : IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

Example 4 with IpPortBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient 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)

Example 5 with IpPortBasedClient

use of com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient in project nacos by alibaba.

the class HealthCheckTaskInterceptWrapperTest method setUp.

@Before
public void setUp() throws Exception {
    when(applicationContext.getBean(NamingMetadataManager.class)).thenReturn(namingMetadataManager);
    when(applicationContext.getBean(GlobalConfig.class)).thenReturn(globalConfig);
    when(applicationContext.getBean(SwitchDomain.class)).thenReturn(switchDomain);
    when(applicationContext.getBean(DistroMapper.class)).thenReturn(distroMapper);
    when(applicationContext.getBean(UpgradeJudgement.class)).thenReturn(upgradeJudgement);
    ApplicationUtils.injectContext(applicationContext);
    client = new IpPortBasedClient(CLIENT_ID, true);
    when(switchDomain.isHealthCheckEnabled()).thenReturn(true);
    when(distroMapper.responsible(client.getResponsibleId())).thenReturn(true);
    when(upgradeJudgement.isUseGrpcFeatures()).thenReturn(true);
    ClientBeatCheckTaskV2 beatCheckTask = new ClientBeatCheckTaskV2(client);
    taskWrapper = new HealthCheckTaskInterceptWrapper(beatCheckTask);
}
Also used : ClientBeatCheckTaskV2(com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatCheckTaskV2) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Before(org.junit.Before)

Aggregations

IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)11 Before (org.junit.Before)5 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)3 Test (org.junit.Test)3 Instance (com.alibaba.nacos.api.naming.pojo.Instance)2 ClientEvent (com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)2 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)2 ClientOperationService (com.alibaba.nacos.naming.core.v2.service.ClientOperationService)2 RsInfo (com.alibaba.nacos.naming.healthcheck.RsInfo)2 UdpPushService (com.alibaba.nacos.naming.push.UdpPushService)2 NacosException (com.alibaba.nacos.api.exception.NacosException)1 Response (com.alibaba.nacos.consistency.entity.Response)1 WriteRequest (com.alibaba.nacos.consistency.entity.WriteRequest)1 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)1 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)1 ClientBeatCheckTaskV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatCheckTaskV2)1 ClientBeatProcessorV2 (com.alibaba.nacos.naming.healthcheck.heartbeat.ClientBeatProcessorV2)1 SwitchDomain (com.alibaba.nacos.naming.misc.SwitchDomain)1