org.zodiac.actuate.nacos.confcenter.NacosConfCenterHealthIndicator Maven / Gradle / Ivy
The newest version!
package org.zodiac.actuate.nacos.confcenter;
import java.util.Properties;
import java.util.function.Function;
import com.alibaba.nacos.api.config.ConfigService;
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 NacosConfCenterHealthIndicator extends AbstractHealthIndicator {
private static final String UP_STATUS = AppInstanceStatus.UP.getText().toLowerCase();
public NacosConfCenterHealthIndicator() {
super();
}
public NacosConfCenterHealthIndicator(Function healthCheckFailedMessage) {
super(healthCheckFailedMessage);
}
public NacosConfCenterHealthIndicator(String healthCheckFailedMessage) {
super(healthCheckFailedMessage);
}
@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(NacosUtil.extractSafeProperties(properties)),
configService.getServerStatus());
}
if (!configService.getServerStatus().toLowerCase().equals(UP_STATUS)) {
builder.down();
}
}
}
}