org.zodiac.actuate.eureka.EurekaReadinessHealthCheckHandler Maven / Gradle / Ivy
The newest version!
package org.zodiac.actuate.eureka;
import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.zodiac.actuate.health.checker.ReadinessHealthCheckerProcessor;
import org.zodiac.sdk.toolkit.util.collection.CollUtil;
import java.util.Map;
public class EurekaReadinessHealthCheckHandler implements HealthCheckHandler {
private static final Map STATUS_MAPPING = CollUtil.map();
static{
STATUS_MAPPING.put(Status.UNKNOWN, InstanceInfo.InstanceStatus.UNKNOWN);
STATUS_MAPPING.put(Status.OUT_OF_SERVICE, InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
STATUS_MAPPING.put(Status.DOWN, InstanceInfo.InstanceStatus.DOWN);
STATUS_MAPPING.put(Status.UP, InstanceInfo.InstanceStatus.UP);
}
ReadinessHealthCheckerProcessor readinessHealthCheckerProcessor;
public EurekaReadinessHealthCheckHandler(ReadinessHealthCheckerProcessor readinessHealthCheckProcessor) {
this.readinessHealthCheckerProcessor = readinessHealthCheckProcessor;
}
@Override
public InstanceInfo.InstanceStatus getStatus(InstanceInfo.InstanceStatus currentStatus) {
Health health = this.readinessHealthCheckerProcessor.healthCheck();
return mapToInstanceStatus(health.getStatus());
}
protected InstanceInfo.InstanceStatus mapToInstanceStatus(Status status) {
return STATUS_MAPPING.getOrDefault(status, InstanceInfo.InstanceStatus.UNKNOWN);
}
}