use of com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus.HealthIndicatorDetail in project sofa-boot by alipay.
the class SpringContextStartUpHealthCheckStatusCheckInfo method invoke.
@Override
public Health invoke() {
// spring
boolean springContextStatus = StartUpHealthCheckStatus.getSpringContextStatus();
// component
boolean componentStatus = StartUpHealthCheckStatus.getComponentStatus();
Map<String, Health> componentDetail = StartUpHealthCheckStatus.getComponentDetail();
// HealthIndicator
boolean healthIndicatorStatus = StartUpHealthCheckStatus.getHealthIndicatorStatus();
List<HealthIndicatorDetail> healthIndicatorDetails = StartUpHealthCheckStatus.getHealthIndicatorDetails();
// AfterHealthCheckCallback
boolean afterHealthCheckCallbackStatus = StartUpHealthCheckStatus.getAfterHealthCheckCallbackStatus();
Map<String, Health> afterHealthCheckCallbackDetails = StartUpHealthCheckStatus.getAfterHealthCheckCallbackDetails();
Map<String, Health> healths = new HashMap<String, Health>();
// spring
if (springContextStatus) {
healths.put("springContextHealthCheckInfo", Health.up().build());
} else {
healths.put("springContextHealthCheckInfo", Health.down().build());
}
// component and callback
Builder builder = null;
if (componentStatus && healthIndicatorStatus && afterHealthCheckCallbackStatus) {
builder = Health.up();
} else {
builder = Health.down();
}
if (!CollectionUtils.isEmpty(componentDetail)) {
builder = builder.withDetail("Middleware-start-period", componentDetail);
}
if (!CollectionUtils.isEmpty(afterHealthCheckCallbackDetails)) {
builder = builder.withDetail("Middleware-operation-period", afterHealthCheckCallbackDetails);
}
healths.put("sofaBootComponentHealthCheckInfo", builder.build());
// HealthIndicator
for (HealthIndicatorDetail healthIndicatorDetail : healthIndicatorDetails) {
String name = healthIndicatorDetail.getName();
Health health = healthIndicatorDetail.getHealth();
healths.put(name, health);
}
return this.healthAggregator.aggregate(healths);
}
use of com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus.HealthIndicatorDetail in project sofa-boot by alipay.
the class HealthIndicatorCheckProcessor method checkIndicator.
public boolean checkIndicator() {
if (skipHealthIndicator()) {
logger.info("Skip startup healthIndicator check.");
return true;
}
logger.info("Begin startup healthIndicator check.");
List<HealthIndicator> healthIndicators = HealthCheckManager.getHealthIndicator();
if (healthIndicators == null) {
return true;
}
boolean result = true;
for (HealthIndicator healthIndicator : healthIndicators) {
try {
Health health = healthIndicator.health();
Status status = health.getStatus();
if (!status.equals(Status.UP)) {
result = false;
logger.error("healthIndicator (" + healthIndicator.getClass() + ")check fail. And the status is[" + status + "]; the detail is: " + JSON.toJSONString(health.getDetails()));
} else {
logger.info("healthIndicator (" + healthIndicator.getClass() + ")check success.");
}
StartUpHealthCheckStatus.addHealthIndicatorDetail(new HealthIndicatorDetail(getKey(healthIndicator), health));
} catch (Exception e) {
result = false;
logger.error("Error occurred while doing healthIndicator health check(" + healthIndicator.getClass() + ")", e);
}
}
if (result) {
logger.info("Startup healthIndicator check result: success.");
} else {
logger.error("Startup healthIndicator check result: fail.");
}
StartUpHealthCheckStatus.setHealthIndicatorStatus(result);
return result;
}
Aggregations