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;
}
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;
}
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());
}
}
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;
}
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;
}
Aggregations