use of org.apache.dubbo.common.status.StatusChecker in project dubbo by alibaba.
the class DubboHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
ExtensionLoader<StatusChecker> extensionLoader = getExtensionLoader(StatusChecker.class);
Map<String, String> statusCheckerNamesMap = resolveStatusCheckerNamesMap();
boolean hasError = false;
boolean hasUnknown = false;
// Up first
builder.up();
for (Map.Entry<String, String> entry : statusCheckerNamesMap.entrySet()) {
String statusCheckerName = entry.getKey();
String source = entry.getValue();
StatusChecker checker = extensionLoader.getExtension(statusCheckerName);
org.apache.dubbo.common.status.Status status = checker.check();
org.apache.dubbo.common.status.Status.Level level = status.getLevel();
if (!hasError && level.equals(org.apache.dubbo.common.status.Status.Level.ERROR)) {
hasError = true;
builder.down();
}
if (!hasError && !hasUnknown && level.equals(org.apache.dubbo.common.status.Status.Level.UNKNOWN)) {
hasUnknown = true;
builder.unknown();
}
Map<String, Object> detail = new LinkedHashMap<>();
detail.put("source", source);
detail.put("status", status);
builder.withDetail(statusCheckerName, detail);
}
}
use of org.apache.dubbo.common.status.StatusChecker in project dubbo by alibaba.
the class ServerStatusCheckerTest method testServerStatusChecker.
@Test
public void testServerStatusChecker() throws Exception {
int port = NetUtils.getAvailablePort(7000);
URL url = URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName());
DemoService service = new DemoServiceImpl();
DubboProtocol.getDubboProtocol().export(proxy.getInvoker(service, DemoService.class, url));
StatusChecker server = ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension("server");
Assertions.assertEquals(ServerStatusChecker.class, server.getClass());
Status status = server.check();
Assertions.assertEquals(Status.Level.OK, status.getLevel());
ProtocolUtils.closeAll();
}
use of org.apache.dubbo.common.status.StatusChecker in project dubbo by alibaba.
the class StatusTelnetHandler method telnet.
@Override
public String telnet(Channel channel, String message) {
if ("-l".equals(message)) {
List<StatusChecker> checkers = extensionLoader.getActivateExtension(channel.getUrl(), STATUS_KEY);
String[] header = new String[] { "resource", "status", "message" };
List<List<String>> table = new ArrayList<List<String>>();
Map<String, Status> statuses = new HashMap<String, Status>();
if (CollectionUtils.isNotEmpty(checkers)) {
for (StatusChecker checker : checkers) {
String name = extensionLoader.getExtensionName(checker);
Status stat;
try {
stat = checker.check();
} catch (Throwable t) {
stat = new Status(Status.Level.ERROR, t.getMessage());
}
statuses.put(name, stat);
if (stat.getLevel() != null && stat.getLevel() != Status.Level.UNKNOWN) {
List<String> row = new ArrayList<String>();
row.add(name);
row.add(String.valueOf(stat.getLevel()));
row.add(stat.getMessage() == null ? "" : stat.getMessage());
table.add(row);
}
}
}
Status stat = StatusUtils.getSummaryStatus(statuses);
List<String> row = new ArrayList<String>();
row.add("summary");
row.add(String.valueOf(stat.getLevel()));
row.add(stat.getMessage());
table.add(row);
return TelnetUtils.toTable(header, table);
} else if (message.length() > 0) {
return "Unsupported parameter " + message + " for status.";
}
String status = channel.getUrl().getParameter(STATUS_KEY);
Map<String, Status> statuses = new HashMap<String, Status>();
if (StringUtils.isNotEmpty(status)) {
String[] ss = COMMA_SPLIT_PATTERN.split(status);
for (String s : ss) {
StatusChecker handler = extensionLoader.getExtension(s);
Status stat;
try {
stat = handler.check();
} catch (Throwable t) {
stat = new Status(Status.Level.ERROR, t.getMessage());
}
statuses.put(s, stat);
}
}
Status stat = StatusUtils.getSummaryStatus(statuses);
return String.valueOf(stat.getLevel());
}
use of org.apache.dubbo.common.status.StatusChecker in project incubator-dubbo-spring-boot-project by apache.
the class DubboHealthIndicator method doHealthCheck.
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
ExtensionLoader<StatusChecker> extensionLoader = getExtensionLoader(StatusChecker.class);
Map<String, String> statusCheckerNamesMap = resolveStatusCheckerNamesMap();
boolean hasError = false;
boolean hasUnknown = false;
// Up first
builder.up();
for (Map.Entry<String, String> entry : statusCheckerNamesMap.entrySet()) {
String statusCheckerName = entry.getKey();
String source = entry.getValue();
StatusChecker checker = extensionLoader.getExtension(statusCheckerName);
org.apache.dubbo.common.status.Status status = checker.check();
org.apache.dubbo.common.status.Status.Level level = status.getLevel();
if (!hasError && level.equals(org.apache.dubbo.common.status.Status.Level.ERROR)) {
hasError = true;
builder.down();
}
if (!hasError && !hasUnknown && level.equals(org.apache.dubbo.common.status.Status.Level.UNKNOWN)) {
hasUnknown = true;
builder.unknown();
}
Map<String, Object> detail = new LinkedHashMap<>();
detail.put("source", source);
detail.put("status", status);
builder.withDetail(statusCheckerName, detail);
}
}
Aggregations