use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.
the class CatalogServiceV2Impl method patternServices.
private Collection<Service> patternServices(String namespaceId, String group, String serviceName) {
boolean noFilter = StringUtils.isBlank(serviceName) && StringUtils.isBlank(group);
if (noFilter) {
return ServiceManager.getInstance().getSingletons(namespaceId);
}
Collection<Service> result = new LinkedList<>();
StringJoiner regex = new StringJoiner(Constants.SERVICE_INFO_SPLITER);
regex.add(getRegexString(group));
regex.add(getRegexString(serviceName));
String regexString = regex.toString();
for (Service each : ServiceManager.getInstance().getSingletons(namespaceId)) {
if (each.getGroupedServiceName().matches(regexString)) {
result.add(each);
}
}
return result;
}
use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.
the class DistroClientDataProcessor method upgradeClient.
private void upgradeClient(Client client, ClientSyncData clientSyncData) {
List<String> namespaces = clientSyncData.getNamespaces();
List<String> groupNames = clientSyncData.getGroupNames();
List<String> serviceNames = clientSyncData.getServiceNames();
List<InstancePublishInfo> instances = clientSyncData.getInstancePublishInfos();
Set<Service> syncedService = new HashSet<>();
for (int i = 0; i < namespaces.size(); i++) {
Service service = Service.newService(namespaces.get(i), groupNames.get(i), serviceNames.get(i));
Service singleton = ServiceManager.getInstance().getSingleton(service);
syncedService.add(singleton);
InstancePublishInfo instancePublishInfo = instances.get(i);
if (!instancePublishInfo.equals(client.getInstancePublishInfo(singleton))) {
client.addServiceInstance(singleton, instancePublishInfo);
NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, client.getClientId()));
}
}
for (Service each : client.getAllPublishedService()) {
if (!syncedService.contains(each)) {
client.removeServiceInstance(each);
NotifyCenter.publishEvent(new ClientOperationEvent.ClientDeregisterServiceEvent(each, client.getClientId()));
}
}
}
use of com.alibaba.nacos.naming.core.v2.pojo.Service in project nacos by alibaba.
the class EphemeralClientOperationServiceImpl method registerInstance.
@Override
public void registerInstance(Service service, Instance instance, String clientId) {
Service singleton = ServiceManager.getInstance().getSingleton(service);
if (!singleton.isEphemeral()) {
throw new NacosRuntimeException(NacosException.INVALID_PARAM, String.format("Current service %s is persistent service, can't register ephemeral instance.", singleton.getGroupedServiceName()));
}
Client client = clientManager.getClient(clientId);
if (!clientIsLegal(client, clientId)) {
return;
}
InstancePublishInfo instanceInfo = getPublishInfo(instance);
client.addServiceInstance(singleton, instanceInfo);
client.setLastUpdatedTime();
NotifyCenter.publishEvent(new ClientOperationEvent.ClientRegisterServiceEvent(singleton, clientId));
NotifyCenter.publishEvent(new MetadataEvent.InstanceMetadataEvent(singleton, instanceInfo.getMetadataId(), false));
}
use of com.alibaba.nacos.naming.core.v2.pojo.Service 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.Service in project nacos by alibaba.
the class PersistentClientOperationServiceImpl method onInstanceDeregister.
private void onInstanceDeregister(Service service, String clientId) {
Service singleton = ServiceManager.getInstance().getSingleton(service);
Client client = clientManager.getClient(clientId);
client.removeServiceInstance(singleton);
client.setLastUpdatedTime();
if (client.getAllPublishedService().isEmpty()) {
clientManager.clientDisconnected(clientId);
}
NotifyCenter.publishEvent(new ClientOperationEvent.ClientDeregisterServiceEvent(singleton, clientId));
}
Aggregations