use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceInfoHolder method processServiceInfo.
/**
* Process service json.
*
* @param json service json
* @return service info
*/
public ServiceInfo processServiceInfo(String json) {
ServiceInfo serviceInfo = JacksonUtils.toObj(json, ServiceInfo.class);
serviceInfo.setJsonFromServer(json);
return processServiceInfo(serviceInfo);
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class UpgradeOpsController method getMetrics.
private ObjectNode getMetrics() throws NacosException {
ObjectNode result = JacksonUtils.createEmptyJsonNode();
Set<String> serviceNamesV2 = new HashSet<>();
Set<String> persistentServiceNamesV2 = new HashSet<>();
Set<String> ephemeralServiceNamesV2 = new HashSet<>();
int persistentInstanceCountV2 = 0;
int ephemeralInstanceCountV2 = 0;
Set<String> allNamespaces = com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getAllNamespaces();
for (String ns : allNamespaces) {
Set<com.alibaba.nacos.naming.core.v2.pojo.Service> services = com.alibaba.nacos.naming.core.v2.ServiceManager.getInstance().getSingletons(ns);
for (com.alibaba.nacos.naming.core.v2.pojo.Service service : services) {
String nameWithNs = service.getNamespace() + NAMESPACE_SERVICE_CONNECTOR + service.getGroupedServiceName();
serviceNamesV2.add(nameWithNs);
if (service.isEphemeral()) {
ephemeralServiceNamesV2.add(nameWithNs);
} else {
persistentServiceNamesV2.add(nameWithNs);
}
ServiceInfo data = serviceStorage.getPushData(service);
for (com.alibaba.nacos.api.naming.pojo.Instance instance : data.getHosts()) {
if (instance.isEphemeral()) {
ephemeralInstanceCountV2 += 1;
} else {
persistentInstanceCountV2 += 1;
}
}
}
}
result.put("upgraded", upgradeJudgement.isUseGrpcFeatures());
result.put("isAll20XVersion", upgradeJudgement.isAll20XVersion());
result.put("isDoubleWriteEnabled", switchDomain.isDoubleWriteEnabled());
result.put("doubleWriteDelayTaskCount", doubleWriteDelayTaskEngine.size());
result.put("serviceCountV1", serviceManager.getServiceCount());
result.put("instanceCountV1", serviceManager.getInstanceCount());
result.put("serviceCountV2", MetricsMonitor.getDomCountMonitor().get());
result.put("instanceCountV2", MetricsMonitor.getIpCountMonitor().get());
result.put("subscribeCountV2", MetricsMonitor.getSubscriberCount().get());
result.put("responsibleServiceCountV1", serviceManager.getResponsibleServiceCount());
result.put("responsibleInstanceCountV1", serviceManager.getResponsibleInstanceCount());
result.put("ephemeralServiceCountV2", ephemeralServiceNamesV2.size());
result.put("persistentServiceCountV2", persistentServiceNamesV2.size());
result.put("ephemeralInstanceCountV2", ephemeralInstanceCountV2);
result.put("persistentInstanceCountV2", persistentInstanceCountV2);
Set<String> serviceNamesV1 = serviceManager.getAllServiceNames().entrySet().stream().flatMap(e -> e.getValue().stream().map(name -> {
if (!name.contains(SERVICE_INFO_SPLITER)) {
name = NamingUtils.getGroupedName(name, DEFAULT_GROUP);
}
return e.getKey() + NAMESPACE_SERVICE_CONNECTOR + name;
})).collect(Collectors.toSet());
result.put("service.V1.not.in.V2", String.join("\n", (Collection<String>) CollectionUtils.subtract(serviceNamesV1, serviceNamesV2)));
result.put("service.V2.not.in.V1", String.join("\n", (Collection<String>) CollectionUtils.subtract(serviceNamesV2, serviceNamesV1)));
return result;
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceStorage method emptyServiceInfo.
private ServiceInfo emptyServiceInfo(Service service) {
ServiceInfo result = new ServiceInfo();
result.setName(service.getName());
result.setGroupName(service.getGroup());
result.setLastRefTime(System.currentTimeMillis());
result.setCacheMillis(switchDomain.getDefaultPushCacheMillis());
return result;
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class ServiceStorage method getPushData.
public ServiceInfo getPushData(Service service) {
ServiceInfo result = emptyServiceInfo(service);
if (!ServiceManager.getInstance().containSingleton(service)) {
return result;
}
result.setHosts(getAllInstancesFromIndex(service));
serviceDataIndexes.put(service, result);
return result;
}
use of com.alibaba.nacos.api.naming.pojo.ServiceInfo in project nacos by alibaba.
the class AsyncServicesCheckTask method checkService.
private void checkService(String namespace, String fullServiceName, Service serviceV1, ServiceStorage serviceStorage) {
if (upgradeJudgement.isUseGrpcFeatures()) {
return;
}
String groupName = NamingUtils.getGroupName(serviceV1.getName());
String serviceName = NamingUtils.getServiceName(fullServiceName);
com.alibaba.nacos.naming.core.v2.pojo.Service serviceV2 = com.alibaba.nacos.naming.core.v2.pojo.Service.newService(namespace, groupName, serviceName);
ServiceInfo serviceInfo = serviceStorage.getData(serviceV2);
if (serviceV1.allIPs().size() != serviceInfo.getHosts().size()) {
boolean isEphemeral = serviceV1.allIPs(false).isEmpty();
String key = ServiceChangeV1Task.getKey(namespace, fullServiceName, isEphemeral);
ServiceChangeV1Task task = new ServiceChangeV1Task(namespace, fullServiceName, isEphemeral, DoubleWriteContent.INSTANCE);
doubleWriteDelayTaskEngine.addTask(key, task);
}
}
Aggregations