org.zodiac.actuate.nacos.naming.NacosNamingEndpoint Maven / Gradle / Ivy
package org.zodiac.actuate.nacos.naming;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.context.ApplicationContext;
import org.zodiac.nacos.base.constants.NacosBeanConstants;
import org.zodiac.nacos.base.factory.CacheableEventPublishingNacosServiceFactory;
import org.zodiac.nacos.base.factory.NacosServiceFactory;
import org.zodiac.nacos.base.util.NacosUtil;
import org.zodiac.nacos.client.constants.NacosNamingConstants;
@Endpoint(id = NacosNamingConstants.ENDPOINT_PREFIX)
public class NacosNamingEndpoint {
@Autowired
private ApplicationContext applicationContext;
private static final Integer PAGE_SIZE = 100;
@ReadOperation
public Map invoke() {
Map result = new HashMap<>(8);
result.put("nacosDiscoveryGlobalProperties", NacosUtil.extractSafeProperties(
applicationContext.getBean(NacosBeanConstants.DISCOVERY_GLOBAL_NACOS_PROPERTIES_BEAN_NAME, Properties.class)));
NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
ArrayNode array = JacksonUtils.createEmptyArrayNode();
for (NamingService namingService : nacosServiceFactory.getNamingServices()) {
ObjectNode jsonObject = JacksonUtils.createEmptyJsonNode();
try {
jsonObject.putPOJO("servicesOfServer", namingService.getServicesOfServer(0, PAGE_SIZE));
jsonObject.putPOJO("subscribeServices", namingService.getSubscribeServices());
array.add(jsonObject);
} catch (Exception e) {
jsonObject.put("serverStatus",
namingService.getServerStatus() + ": " + NacosUtil.SEPARATOR + e.getMessage());
}
}
result.put("namingServersStatus", array);
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy