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));
}
}
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));
}
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);
}
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);
}
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;
}
Aggregations