Search in sources :

Example 1 with HealthResult

use of com.alipay.sofa.runtime.spi.health.HealthResult in project sofa-boot by alipay.

the class JvmBinding method healthCheck.

@Override
public HealthResult healthCheck() {
    HealthResult healthResult = new HealthResult(getName());
    healthResult.setHealthy(isHealthy);
    return healthResult;
}
Also used : HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Example 2 with HealthResult

use of com.alipay.sofa.runtime.spi.health.HealthResult in project sofa-boot by alipay.

the class ComponentHealthChecker method isHealthy.

@Override
public Health isHealthy() {
    boolean allPassed = true;
    Health.Builder builder = new Health.Builder();
    for (ComponentInfo componentInfo : SofaFrameworkHolder.getSofaFramework().getSofaRuntimeContext(Slite2Configuration.getAppName()).getComponentManager().getComponents()) {
        HealthResult healthy = componentInfo.isHealthy();
        if (healthy.isHealthy()) {
            builder.withDetail(healthy.getHealthName(), "passed");
        } else {
            builder.withDetail(healthy.getHealthName(), healthy.getHealthReport());
            allPassed = false;
        }
    }
    if (allPassed) {
        return builder.status(Status.UP).build();
    } else {
        return builder.status(Status.DOWN).build();
    }
}
Also used : Health(org.springframework.boot.actuate.health.Health) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Example 3 with HealthResult

use of com.alipay.sofa.runtime.spi.health.HealthResult in project sofa-boot by alipay.

the class ReferenceComponent method isHealthy.

@Override
public HealthResult isHealthy() {
    if (!isActivated()) {
        return super.isHealthy();
    }
    HealthResult result = new HealthResult(componentName.getRawName());
    List<HealthResult> bindingHealth = new ArrayList<HealthResult>();
    JvmBinding jvmBinding = null;
    HealthResult jvmBindingHealthResult = null;
    if (reference.hasBinding()) {
        for (Binding binding : reference.getBindings()) {
            bindingHealth.add(binding.healthCheck());
            if (JvmBinding.JVM_BINDING_TYPE.equals(binding.getBindingType())) {
                jvmBinding = (JvmBinding) binding;
                jvmBindingHealthResult = bindingHealth.get(bindingHealth.size() - 1);
            }
        }
    }
    // check reference has a corresponding service
    if (!skipJVMReferenceHealth() && jvmBinding != null) {
        Object serviceTarget = getServiceTarget();
        if (serviceTarget == null && !jvmBinding.hasBackupProxy()) {
            jvmBindingHealthResult.setHealthy(false);
            jvmBindingHealthResult.setHealthReport("can not find corresponding jvm service");
        }
    }
    List<HealthResult> failedBindingHealth = new ArrayList<HealthResult>();
    for (HealthResult healthResult : bindingHealth) {
        if (healthResult != null && !healthResult.isHealthy()) {
            failedBindingHealth.add(healthResult);
        }
    }
    if (failedBindingHealth.size() == 0) {
        result.setHealthy(true);
    } else {
        String healthReport = "|";
        for (HealthResult healthResult : failedBindingHealth) {
            healthReport = healthReport + healthResult.getHealthName() + "#" + healthResult.getHealthReport();
        }
        result.setHealthReport(healthReport.substring(1, healthReport.length()));
        result.setHealthy(false);
    }
    return result;
}
Also used : JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) ArrayList(java.util.ArrayList) HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding)

Example 4 with HealthResult

use of com.alipay.sofa.runtime.spi.health.HealthResult in project sofa-boot by alipay.

the class ServiceComponent method isHealthy.

@Override
public HealthResult isHealthy() {
    HealthResult healthResult = new HealthResult(componentName.getRawName());
    healthResult.setHealthy(true);
    return healthResult;
}
Also used : HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Example 5 with HealthResult

use of com.alipay.sofa.runtime.spi.health.HealthResult in project sofa-boot by alipay.

the class AbstractComponent method isHealthy.

@Override
public HealthResult isHealthy() {
    HealthResult healthResult = new HealthResult(componentName.getRawName());
    if (!isActivated()) {
        healthResult.setHealthy(false);
        healthResult.setHealthReport("Status: " + this.getState().toString());
    } else {
        healthResult.setHealthy(true);
    }
    return healthResult;
}
Also used : HealthResult(com.alipay.sofa.runtime.spi.health.HealthResult)

Aggregations

HealthResult (com.alipay.sofa.runtime.spi.health.HealthResult)5 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)1 Binding (com.alipay.sofa.runtime.spi.binding.Binding)1 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)1 ArrayList (java.util.ArrayList)1 Health (org.springframework.boot.actuate.health.Health)1