Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ public Health isHealthy() {
Health.Builder builder = new Health.Builder();
for (ComponentInfo componentInfo : sofaRuntimeContext.getComponentManager().getComponents()) {
HealthResult healthy = componentInfo.isHealthy();
if (healthy.isHealthy()) {
builder.withDetail(healthy.getHealthName(), "passed");
} else {
builder.withDetail(healthy.getHealthName(), healthy.getHealthReport());
builder.withDetail(healthy.getHealthName(), healthy.getHealthReport());
if (!healthy.isHealthy()) {
allPassed = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
*/
package com.alipay.sofa.rpc.boot.test.xsd;

import com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding;
import com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding;
import com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingType;
import com.alipay.sofa.runtime.api.component.ComponentName;
import com.alipay.sofa.runtime.service.component.Reference;
import com.alipay.sofa.runtime.service.component.ReferenceComponent;
import com.alipay.sofa.runtime.service.component.ServiceComponent;
import com.alipay.sofa.runtime.spi.component.ComponentInfo;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -34,8 +31,6 @@
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Collection;

/**
* @author <a href="mailto:[email protected]">guaner.zzx</a>
* Created on 2019/12/18
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class JvmBinding extends AbstractBinding {

private JvmBindingParam jvmBindingParam = new JvmBindingParam();

private HealthResult healthResult = new HealthResult(getName());

public JvmBinding() {
}

Expand Down Expand Up @@ -92,7 +94,6 @@ public int getBindingHashCode() {

@Override
public HealthResult healthCheck() {
HealthResult healthResult = new HealthResult(getName());
healthResult.setHealthy(isHealthy);
return healthResult;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public Object doInvoke(MethodInvocation invocation) throws Throwable {
}
}

if ((targetObj == null || ((targetObj instanceof Proxy) && binding.hasBackupProxy()))) {
if (targetObj == null || ((targetObj instanceof Proxy) && binding.hasBackupProxy())) {
targetObj = binding.getBackupProxy();
SofaLogger.debug("<<{0}.{1} backup proxy invoke.", getInterfaceName().getName(),
invocation.getMethod().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ public Map<String, Property> getProperties() {

@Override
public HealthResult isHealthy() {
if (!isActivated()) {
return super.isHealthy();
}

HealthResult result = new HealthResult(componentName.getRawName());
List<HealthResult> bindingHealth = new ArrayList<>();

Expand Down Expand Up @@ -122,14 +118,9 @@ public HealthResult isHealthy() {
if (failedBindingHealth.size() == 0) {
result.setHealthy(true);
} else {
StringBuilder healthReport = new StringBuilder("|");
for (HealthResult healthResult : failedBindingHealth) {
healthReport.append(healthResult.getHealthName()).append("#")
.append(healthResult.getHealthReport());
}
result.setHealthReport(healthReport.substring(1, healthReport.length()));
result.setHealthy(false);
}
result.setHealthReport(aggregateBindingHealth(reference.getBindings()));

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private void activateBinding() {
getContext());
} catch (Throwable t) {
allPassed = false;
binding.setHealthy(false);
SofaLogger.error(t, " <<Out binding [{0}] for [{1}] occur exception.",
binding.getBindingType(), service);
continue;
Expand Down Expand Up @@ -306,17 +307,14 @@ public Service getService() {

@Override
public HealthResult isHealthy() {
if (!isActivated()) {
return super.isHealthy();
}

HealthResult healthResult = new HealthResult(componentName.getRawName());
if (this.e == null) {
healthResult.setHealthy(true);
} else {
healthResult.setHealthy(false);
healthResult.setHealthReport(e.getMessage());
}
healthResult.setHealthReport(aggregateBindingHealth(service.getBindings()));

return healthResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@
import com.alipay.sofa.runtime.api.component.ComponentLifeCycle;
import com.alipay.sofa.runtime.api.component.ComponentName;
import com.alipay.sofa.runtime.model.ComponentStatus;
import com.alipay.sofa.runtime.spi.binding.Binding;
import com.alipay.sofa.runtime.spi.health.HealthResult;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* abstract component implementation
*
Expand Down Expand Up @@ -170,6 +175,20 @@ public HealthResult isHealthy() {
return healthResult;
}

protected String aggregateBindingHealth(Collection<Binding> bindings) {
List<String> healthResult = new ArrayList<>();
for (Binding binding : bindings) {
HealthResult result = binding.healthCheck();
String report = "["
+ result.getHealthName()
+ ","
+ (result.getHealthReport() == null ? (result.isHealthy() ? "passed"
: "failed") : result.getHealthReport()) + "]";
healthResult.add(report);
}
return String.join(" ", healthResult);
}

@Override
public boolean canBeDuplicate() {
return true;
Expand Down