Search in sources :

Example 26 with ServiceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.

the class CatalogServiceV2Impl method pageListService.

@Override
public Object pageListService(String namespaceId, String groupName, String serviceName, int pageNo, int pageSize, String instancePattern, boolean ignoreEmptyService) throws NacosException {
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    List<ServiceView> serviceViews = new LinkedList<>();
    Collection<Service> services = patternServices(namespaceId, groupName, serviceName);
    if (ignoreEmptyService) {
        services = services.stream().filter(each -> 0 != serviceStorage.getData(each).ipCount()).collect(Collectors.toList());
    }
    result.put(FieldsConstants.COUNT, services.size());
    services = doPage(services, pageNo - 1, pageSize);
    for (Service each : services) {
        ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(each).orElseGet(ServiceMetadata::new);
        ServiceView serviceView = new ServiceView();
        serviceView.setName(each.getName());
        serviceView.setGroupName(each.getGroup());
        serviceView.setClusterCount(serviceStorage.getClusters(each).size());
        serviceView.setIpCount(serviceStorage.getData(each).ipCount());
        serviceView.setHealthyInstanceCount(countHealthyInstance(serviceStorage.getData(each)));
        serviceView.setTriggerFlag(isProtectThreshold(serviceView, serviceMetadata) ? "true" : "false");
        serviceViews.add(serviceView);
    }
    result.set(FieldsConstants.SERVICE_LIST, JacksonUtils.transferToJsonNode(serviceViews));
    return result;
}
Also used : ServiceView(com.alibaba.nacos.naming.pojo.ServiceView) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) LinkedList(java.util.LinkedList) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 27 with ServiceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata 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 28 with ServiceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.

the class ServiceMetadataProcessor method addClusterMetadataToService.

private void addClusterMetadataToService(MetadataOperation<ServiceMetadata> op) {
    Service service = Service.newService(op.getNamespace(), op.getGroup(), op.getServiceName(), op.getMetadata().isEphemeral());
    Optional<ServiceMetadata> currentMetadata = namingMetadataManager.getServiceMetadata(service);
    if (currentMetadata.isPresent()) {
        currentMetadata.get().getClusters().putAll(op.getMetadata().getClusters());
    } else {
        Service singleton = ServiceManager.getInstance().getSingleton(service);
        namingMetadataManager.updateServiceMetadata(singleton, op.getMetadata());
    }
    doubleWriteMetadata(service, false);
}
Also used : Service(com.alibaba.nacos.naming.core.v2.pojo.Service)

Example 29 with ServiceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.

the class ServiceOperatorV2Impl method queryService.

@Override
public ObjectNode queryService(String namespaceId, String serviceName) throws NacosException {
    Service service = getServiceFromGroupedServiceName(namespaceId, serviceName, true);
    if (!ServiceManager.getInstance().containSingleton(service)) {
        throw new NacosException(NacosException.INVALID_PARAM, "service not found, namespace: " + namespaceId + ", serviceName: " + serviceName);
    }
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(service).orElse(new ServiceMetadata());
    setServiceMetadata(result, serviceMetadata, service);
    ArrayNode clusters = JacksonUtils.createEmptyArrayNode();
    for (String each : serviceStorage.getClusters(service)) {
        ClusterMetadata clusterMetadata = serviceMetadata.getClusters().containsKey(each) ? serviceMetadata.getClusters().get(each) : new ClusterMetadata();
        clusters.add(newClusterNode(each, clusterMetadata));
    }
    result.set(FieldsConstants.CLUSTERS, clusters);
    return result;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NacosException(com.alibaba.nacos.api.exception.NacosException) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Example 30 with ServiceMetadata

use of com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata in project nacos by alibaba.

the class ServiceOperatorV2Impl method queryService.

/**
 * Query service detail.
 *
 * @param service service
 * @return service detail with cluster info
 * @throws NacosException nacos exception during query
 */
public ServiceDetailInfo queryService(Service service) throws NacosException {
    if (!ServiceManager.getInstance().containSingleton(service)) {
        throw new NacosException(NacosException.INVALID_PARAM, "service not found, namespace: " + service.getNamespace() + ", serviceName: " + service.getGroupedServiceName());
    }
    Service singleton = ServiceManager.getInstance().getSingleton(service);
    ServiceDetailInfo result = new ServiceDetailInfo();
    ServiceMetadata serviceMetadata = metadataManager.getServiceMetadata(singleton).orElse(new ServiceMetadata());
    setServiceMetadata(result, serviceMetadata, singleton);
    Map<String, ClusterInfo> clusters = new HashMap<>(2);
    for (String each : serviceStorage.getClusters(singleton)) {
        ClusterMetadata clusterMetadata = serviceMetadata.getClusters().containsKey(each) ? serviceMetadata.getClusters().get(each) : new ClusterMetadata();
        clusters.put(each, newClusterNodeV2(each, clusterMetadata));
    }
    result.setClusterMap(clusters);
    result.setEphemeral(singleton.isEphemeral());
    return result;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) ClusterInfo(com.alibaba.nacos.naming.pojo.ClusterInfo) HashMap(java.util.HashMap) ServiceDetailInfo(com.alibaba.nacos.naming.pojo.ServiceDetailInfo) NamingMetadataOperateService(com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService) Service(com.alibaba.nacos.naming.core.v2.pojo.Service) NacosException(com.alibaba.nacos.api.exception.NacosException) ServiceMetadata(com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)

Aggregations

ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)33 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)18 Test (org.junit.Test)13 ServiceInfo (com.alibaba.nacos.api.naming.pojo.ServiceInfo)11 ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)8 NacosException (com.alibaba.nacos.api.exception.NacosException)7 Secured (com.alibaba.nacos.auth.annotation.Secured)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Instance (com.alibaba.nacos.api.naming.pojo.Instance)5 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)4 PushDataWrapper (com.alibaba.nacos.naming.push.v2.PushDataWrapper)4 Before (org.junit.Before)4 ServiceDetailInfo (com.alibaba.nacos.naming.pojo.ServiceDetailInfo)3 HashMap (java.util.HashMap)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 RequestMeta (com.alibaba.nacos.api.remote.request.RequestMeta)2 Serializer (com.alibaba.nacos.consistency.Serializer)2 Cluster (com.alibaba.nacos.naming.core.Cluster)2 NamingMetadataManager (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataManager)2 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)2