Search in sources :

Example 1 with NacosServiceFactory

use of com.alibaba.nacos.spring.factory.NacosServiceFactory in project nacos-spring-boot-project by nacos-group.

the class NacosConfigHealthIndicator method doHealthCheck.

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    builder.up();
    NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
    for (ConfigService configService : nacosServiceFactory.getConfigServices()) {
        if (configService instanceof NacosServiceMetaData) {
            NacosServiceMetaData nacosServiceMetaData = (NacosServiceMetaData) configService;
            Properties properties = nacosServiceMetaData.getProperties();
            builder.withDetail(JacksonUtils.toJson(PropertiesUtils.extractSafeProperties(properties)), configService.getServerStatus());
        }
        if (!configService.getServerStatus().toLowerCase().equals(UP_STATUS)) {
            builder.down();
        }
    }
}
Also used : ConfigService(com.alibaba.nacos.api.config.ConfigService) NacosServiceMetaData(com.alibaba.nacos.spring.metadata.NacosServiceMetaData) CacheableEventPublishingNacosServiceFactory(com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory) NacosServiceFactory(com.alibaba.nacos.spring.factory.NacosServiceFactory) Properties(java.util.Properties)

Example 2 with NacosServiceFactory

use of com.alibaba.nacos.spring.factory.NacosServiceFactory in project nacos-spring-boot-project by nacos-group.

the class NacosDiscoveryEndpoint method invoke.

@ReadOperation
public Map<String, Object> invoke() {
    Map<String, Object> result = new HashMap<>(8);
    result.put("nacosDiscoveryGlobalProperties", PropertiesUtils.extractSafeProperties(applicationContext.getBean(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() + ": " + NacosUtils.SEPARATOR + e.getMessage());
        }
    }
    result.put("namingServersStatus", array);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) NamingService(com.alibaba.nacos.api.naming.NamingService) NacosServiceFactory(com.alibaba.nacos.spring.factory.NacosServiceFactory) CacheableEventPublishingNacosServiceFactory(com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 3 with NacosServiceFactory

use of com.alibaba.nacos.spring.factory.NacosServiceFactory in project nacos-spring-boot-project by nacos-group.

the class NacosDiscoveryHealthIndicator method doHealthCheck.

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
    builder.up();
    NacosServiceFactory nacosServiceFactory = CacheableEventPublishingNacosServiceFactory.getSingleton();
    for (NamingService namingService : nacosServiceFactory.getNamingServices()) {
        if (namingService instanceof NacosServiceMetaData) {
            NacosServiceMetaData nacosServiceMetaData = (NacosServiceMetaData) namingService;
            Properties properties = nacosServiceMetaData.getProperties();
            builder.withDetail(JacksonUtils.toJson(PropertiesUtils.extractSafeProperties(properties)), namingService.getServerStatus());
        }
        if (!namingService.getServerStatus().equalsIgnoreCase(UP_STATUS)) {
            builder.down();
        }
    }
}
Also used : NacosServiceMetaData(com.alibaba.nacos.spring.metadata.NacosServiceMetaData) NamingService(com.alibaba.nacos.api.naming.NamingService) CacheableEventPublishingNacosServiceFactory(com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory) NacosServiceFactory(com.alibaba.nacos.spring.factory.NacosServiceFactory) Properties(java.util.Properties)

Aggregations

CacheableEventPublishingNacosServiceFactory (com.alibaba.nacos.spring.factory.CacheableEventPublishingNacosServiceFactory)3 NacosServiceFactory (com.alibaba.nacos.spring.factory.NacosServiceFactory)3 NamingService (com.alibaba.nacos.api.naming.NamingService)2 NacosServiceMetaData (com.alibaba.nacos.spring.metadata.NacosServiceMetaData)2 Properties (java.util.Properties)2 ConfigService (com.alibaba.nacos.api.config.ConfigService)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 ReadOperation (org.springframework.boot.actuate.endpoint.annotation.ReadOperation)1