org.zodiac.actuate.nacos.naming.NacosNamingHealthIndicator Maven / Gradle / Ivy
package org.zodiac.actuate.nacos.naming;
import java.util.Properties;
import java.util.function.Function;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.common.utils.JacksonUtils;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.zodiac.core.application.AppInstanceStatus;
import org.zodiac.nacos.base.factory.CacheableEventPublishingNacosServiceFactory;
import org.zodiac.nacos.base.factory.NacosServiceFactory;
import org.zodiac.nacos.base.metadata.NacosServiceMetaData;
import org.zodiac.nacos.base.util.NacosUtil;
public class NacosNamingHealthIndicator extends AbstractHealthIndicator {
private static final String UP_STATUS = AppInstanceStatus.UP.getText().toLowerCase();
public NacosNamingHealthIndicator() {
super();
}
public NacosNamingHealthIndicator(Function healthCheckFailedMessage) {
super(healthCheckFailedMessage);
}
public NacosNamingHealthIndicator(String healthCheckFailedMessage) {
super(healthCheckFailedMessage);
}
@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(NacosUtil.extractSafeProperties(properties)),
namingService.getServerStatus());
}
if (!namingService.getServerStatus().equalsIgnoreCase(UP_STATUS)) {
builder.down();
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy