Search in sources :

Example 51 with ServiceInfo

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);
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Example 52 with 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;
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) CommonParams(com.alibaba.nacos.api.naming.CommonParams) WebUtils(com.alibaba.nacos.core.utils.WebUtils) URLDecoder(java.net.URLDecoder) HttpRequestInstanceBuilder(com.alibaba.nacos.naming.pojo.instance.HttpRequestInstanceBuilder) Autowired(org.springframework.beans.factory.annotation.Autowired) CanDistro(com.alibaba.nacos.naming.web.CanDistro) NAMESPACE_SERVICE_CONNECTOR(com.alibaba.nacos.naming.misc.UtilsAndCommons.NAMESPACE_SERVICE_CONNECTOR) Selector(com.alibaba.nacos.api.selector.Selector) PutMapping(org.springframework.web.bind.annotation.PutMapping) Instance(com.alibaba.nacos.api.naming.pojo.Instance) InstanceOperatorServiceImpl(com.alibaba.nacos.naming.core.InstanceOperatorServiceImpl) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Subscriber(com.alibaba.nacos.naming.pojo.Subscriber) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) MetricsMonitor(com.alibaba.nacos.naming.monitor.MetricsMonitor) JacksonUtils(com.alibaba.nacos.common.utils.JacksonUtils) PostMapping(org.springframework.web.bind.annotation.PostMapping) SelectorManager(com.alibaba.nacos.naming.selector.SelectorManager) DoubleWriteDelayTaskEngine(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.DoubleWriteDelayTaskEngine) Collection(java.util.Collection) Set(java.util.Set) InstanceOperatorClientImpl(com.alibaba.nacos.naming.core.InstanceOperatorClientImpl) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) UtilsAndCommons(com.alibaba.nacos.naming.misc.UtilsAndCommons) Constants(com.alibaba.nacos.api.common.Constants) StringUtils(com.alibaba.nacos.common.utils.StringUtils) ActionTypes(com.alibaba.nacos.plugin.auth.constant.ActionTypes) Optional(java.util.Optional) Secured(com.alibaba.nacos.auth.annotation.Secured) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ServiceManager(com.alibaba.nacos.naming.core.ServiceManager) ServiceOperator(com.alibaba.nacos.naming.core.ServiceOperator) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashSet(java.util.HashSet) NumberUtils(com.alibaba.nacos.common.utils.NumberUtils) DEFAULT_GROUP(com.alibaba.nacos.api.common.Constants.DEFAULT_GROUP) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServiceUtil(com.alibaba.nacos.naming.utils.ServiceUtil) CollectionUtils(org.apache.commons.collections.CollectionUtils) SwitchDomain(com.alibaba.nacos.naming.misc.SwitchDomain) NacosException(com.alibaba.nacos.api.exception.NacosException) GetMapping(org.springframework.web.bind.annotation.GetMapping) SERVICE_INFO_SPLITER(com.alibaba.nacos.api.common.Constants.SERVICE_INFO_SPLITER) ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ConvertUtils(com.alibaba.nacos.common.utils.ConvertUtils) Iterator(java.util.Iterator) ServiceOperatorV2Impl(com.alibaba.nacos.naming.core.ServiceOperatorV2Impl) UpgradeJudgement(com.alibaba.nacos.naming.core.v2.upgrade.UpgradeJudgement) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata) InstanceOperator(com.alibaba.nacos.naming.core.InstanceOperator) NamingUtils(com.alibaba.nacos.api.naming.utils.NamingUtils) ServiceOperatorV1Impl(com.alibaba.nacos.naming.core.ServiceOperatorV1Impl) NoneSelector(com.alibaba.nacos.naming.selector.NoneSelector) ServiceStorage(com.alibaba.nacos.naming.core.v2.index.ServiceStorage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) Instance(com.alibaba.nacos.api.naming.pojo.Instance) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 53 with ServiceInfo

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;
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Example 54 with ServiceInfo

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;
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo)

Example 55 with ServiceInfo

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);
    }
}
Also used : ServiceInfo(com.alibaba.nacos.api.naming.pojo.ServiceInfo) ServiceChangeV1Task(com.alibaba.nacos.naming.core.v2.upgrade.doublewrite.delay.ServiceChangeV1Task)

Aggregations

ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)74 Test (org.junit.Test)44 Instance (com.alibaba.nacos.api.naming.pojo.Instance)29 ArrayList (java.util.ArrayList)17 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)12 Properties (java.util.Properties)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 NacosException (com.alibaba.nacos.api.exception.NacosException)8 ServiceInfoHolder (com.alibaba.nacos.client.naming.cache.ServiceInfoHolder)8 Before (org.junit.Before)8 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)7 Field (java.lang.reflect.Field)6 HashSet (java.util.HashSet)5 EventListener (com.alibaba.nacos.api.naming.listener.EventListener)4 SubscribeServiceResponse (com.alibaba.nacos.api.naming.remote.response.SubscribeServiceResponse)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 HashMap (java.util.HashMap)4 QueryServiceResponse (com.alibaba.nacos.api.naming.remote.response.QueryServiceResponse)3 Secured (com.alibaba.nacos.auth.annotation.Secured)3 InstancesChangeNotifier (com.alibaba.nacos.client.naming.event.InstancesChangeNotifier)3