Search in sources :

Example 11 with ClusterMetadata

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

use of com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata 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)

Example 13 with ClusterMetadata

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

the class MysqlHealthCheckProcessor method process.

@Override
public void process(HealthCheckTaskV2 task, Service service, ClusterMetadata metadata) {
    HealthCheckInstancePublishInfo instance = (HealthCheckInstancePublishInfo) task.getClient().getInstancePublishInfo(service);
    if (null == instance) {
        return;
    }
    SRV_LOG.debug("mysql check, ip:" + instance);
    try {
        // TODO handle marked(white list) logic like v1.x.
        if (!instance.tryStartCheck()) {
            SRV_LOG.warn("mysql check started before last one finished, service: {} : {} : {}:{}", service.getGroupedServiceName(), instance.getCluster(), instance.getIp(), instance.getPort());
            healthCheckCommon.reEvaluateCheckRT(task.getCheckRtNormalized() * 2, task, switchDomain.getMysqlHealthParams());
            return;
        }
        GlobalExecutor.executeMysqlCheckTask(new MysqlCheckTask(task, service, instance, metadata));
        MetricsMonitor.getMysqlHealthCheckMonitor().incrementAndGet();
    } catch (Exception e) {
        instance.setCheckRt(switchDomain.getMysqlHealthParams().getMax());
        healthCheckCommon.checkFail(task, service, "mysql:error:" + e.getMessage());
        healthCheckCommon.reEvaluateCheckRT(switchDomain.getMysqlHealthParams().getMax(), task, switchDomain.getMysqlHealthParams());
    }
}
Also used : HealthCheckInstancePublishInfo(com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 14 with ClusterMetadata

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

the class DefaultServiceMetadataUpgradeHelper method toV1Service.

@Override
public Service toV1Service(Service v1, com.alibaba.nacos.naming.core.v2.pojo.Service v2, ServiceMetadata v2meta) {
    if (null == v1) {
        v1 = new Service(v2.getGroupedServiceName());
        v1.setGroupName(v2.getGroup());
        v1.setNamespaceId(v2.getNamespace());
    }
    v1.setSelector(v2meta.getSelector());
    v1.setProtectThreshold(v2meta.getProtectThreshold());
    v1.setMetadata(v2meta.getExtendData());
    for (Map.Entry<String, ClusterMetadata> entry : v2meta.getClusters().entrySet()) {
        if (!v1.getClusterMap().containsKey(entry.getKey())) {
            v1.addCluster(toV1Cluster(new Cluster(entry.getKey(), v1), entry.getValue()));
        } else {
            toV1Cluster(v1.getClusterMap().get(entry.getKey()), entry.getValue());
        }
    }
    return v1;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata) Service(com.alibaba.nacos.naming.core.Service) Cluster(com.alibaba.nacos.naming.core.Cluster) Map(java.util.Map)

Example 15 with ClusterMetadata

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

the class DefaultServiceMetadataUpgradeHelper method toV2ClusterMetadata.

@Override
public ClusterMetadata toV2ClusterMetadata(Cluster v1) {
    ClusterMetadata result = new ClusterMetadata();
    result.setHealthyCheckPort(v1.getDefCkport());
    result.setUseInstancePortForCheck(v1.isUseIPPort4Check());
    result.setExtendData(v1.getMetadata());
    result.setHealthChecker(v1.getHealthChecker());
    result.setHealthyCheckType(v1.getHealthChecker().getType());
    return result;
}
Also used : ClusterMetadata(com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)

Aggregations

ClusterMetadata (com.alibaba.nacos.naming.core.v2.metadata.ClusterMetadata)12 ServiceMetadata (com.alibaba.nacos.naming.core.v2.metadata.ServiceMetadata)7 Service (com.alibaba.nacos.naming.core.v2.pojo.Service)6 NacosException (com.alibaba.nacos.api.exception.NacosException)4 NamingMetadataOperateService (com.alibaba.nacos.naming.core.v2.metadata.NamingMetadataOperateService)3 HealthCheckInstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.HealthCheckInstancePublishInfo)3 InstancePublishInfo (com.alibaba.nacos.naming.core.v2.pojo.InstancePublishInfo)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 IpPortBasedClient (com.alibaba.nacos.naming.core.v2.client.impl.IpPortBasedClient)2 Cluster (com.alibaba.nacos.api.naming.pojo.Cluster)1 Instance (com.alibaba.nacos.api.naming.pojo.Instance)1 AbstractHealthChecker (com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker)1 Http (com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http)1 Secured (com.alibaba.nacos.auth.annotation.Secured)1 Header (com.alibaba.nacos.common.http.param.Header)1 Cluster (com.alibaba.nacos.naming.core.Cluster)1 Service (com.alibaba.nacos.naming.core.Service)1 Client (com.alibaba.nacos.naming.core.v2.client.Client)1