Search in sources :

Example 11 with InstancePublishInfo

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

the class EphemeralClientOperationServiceImpl method deregisterInstance.

@Override
public void deregisterInstance(Service service, Instance instance, String clientId) {
    if (!ServiceManager.getInstance().containSingleton(service)) {
        Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", service);
        return;
    }
    Service singleton = ServiceManager.getInstance().getSingleton(service);
    Client client = clientManager.getClient(clientId);
    if (!clientIsLegal(client, clientId)) {
        return;
    }
    InstancePublishInfo removedInstance = client.removeServiceInstance(singleton);
    client.setLastUpdatedTime();
    if (null != removedInstance) {
        NotifyCenter.publishEvent(new ClientOperationEvent.ClientDeregisterServiceEvent(singleton, clientId));
        NotifyCenter.publishEvent(new MetadataEvent.InstanceMetadataEvent(singleton, removedInstance.getMetadataId(), true));
    }
}
Also used : ClientOperationEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent) MetadataEvent(com.alibaba.nacos.naming.core.v2.event.metadata.MetadataEvent) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) Client(com.alibaba.nacos.naming.core.v2.client.Client)

Example 12 with InstancePublishInfo

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

the class PersistentClientOperationServiceImpl method onInstanceRegister.

private void onInstanceRegister(Service service, Instance instance, String clientId) {
    Service singleton = ServiceManager.getInstance().getSingleton(service);
    if (!clientManager.contains(clientId)) {
        clientManager.clientConnected(clientId, new ClientAttributes());
    }
    Client client = clientManager.getClient(clientId);
    InstancePublishInfo instancePublishInfo = getPublishInfo(instance);
    client.addServiceInstance(singleton, instancePublishInfo);
    client.setLastUpdatedTime();
    NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, clientId));
}
Also used : ClientOperationEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientOperationEvent) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Client(com.alibaba.nacos.naming.core.v2.client.Client) ClientAttributes(com.alibaba.nacos.naming.core.v2.client.ClientAttributes)

Example 13 with InstancePublishInfo

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

the class ServiceStorage method getAllInstancesFromIndex.

private List<Instance> getAllInstancesFromIndex(Service service) {
    Set<Instance> result = new HashSet<>();
    Set<String> clusters = new HashSet<>();
    for (String each : serviceIndexesManager.getAllClientsRegisteredService(service)) {
        Optional<InstancePublishInfo> instancePublishInfo = getInstanceInfo(each, service);
        if (instancePublishInfo.isPresent()) {
            Instance instance = parseInstance(service, instancePublishInfo.get());
            result.add(instance);
            clusters.add(instance.getClusterName());
        }
    }
    // cache clusters of this service
    serviceClusterIndex.put(service, clusters);
    return new LinkedList<>(result);
}
Also used : Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 14 with InstancePublishInfo

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

the class HealthOperatorV2Impl method updateHealthStatusForPersistentInstance.

@Override
public void updateHealthStatusForPersistentInstance(String namespace, String fullServiceName, String clusterName, String ip, int port, boolean healthy) throws NacosException {
    String groupName = NamingUtils.getGroupName(fullServiceName);
    String serviceName = NamingUtils.getServiceName(fullServiceName);
    Service service = Service.newService(namespace, groupName, serviceName);
    Optional<ServiceMetadata> serviceMetadata = metadataManager.getServiceMetadata(service);
    if (!serviceMetadata.isPresent() || !serviceMetadata.get().getClusters().containsKey(clusterName)) {
        throwHealthCheckerException(fullServiceName, clusterName);
    }
    ClusterMetadata clusterMetadata = serviceMetadata.get().getClusters().get(clusterName);
    if (!HealthCheckType.NONE.name().equals(clusterMetadata.getHealthyCheckType())) {
        throwHealthCheckerException(fullServiceName, clusterName);
    }
    String clientId = IpPortBasedClient.getClientId(ip + InternetAddressUtil.IP_PORT_SPLITER + port, false);
    Client client = clientManager.getClient(clientId);
    if (null == client) {
        return;
    }
    InstancePublishInfo oldInstance = client.getInstancePublishInfo(service);
    if (null == oldInstance) {
        return;
    }
    Instance newInstance = InstanceUtil.parseToApiInstance(service, oldInstance);
    newInstance.setHealthy(healthy);
    clientOperationService.registerInstance(service, newInstance, clientId);
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ClientOperationService(com.alibaba.nacos.naming.core.v2.service.ClientOperationService) IpPortBasedClient(com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient) Client(com.alibaba.nacos.naming.core.v2.client.Client) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 15 with InstancePublishInfo

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

the class AbstractClient method removeServiceInstance.

@Override
public InstancePublishInfo removeServiceInstance(Service service) {
    InstancePublishInfo result = publishers.remove(service);
    if (null != result) {
        MetricsMonitor.decrementInstanceCount();
        NotifyCenter.publishEvent(new ClientEvent.ClientChangedEvent(this));
    }
    Loggers.SRV_LOG.info("Client remove for service {}, {}", service, getClientId());
    return result;
}
Also used : InstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo) ClientEvent(com.alibaba.nacos.naming.core.v2.event.client.ClientEvent)

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