use of org.apache.dubbo.common.status.Status in project dubbo by alibaba.
the class SpringStatusCheckerTest method testWithLifeCycleRunning.
@Test
public void testWithLifeCycleRunning() {
SpringExtensionFactory.clearContexts();
ApplicationLifeCycle applicationLifeCycle = mock(ApplicationLifeCycle.class);
new ServiceBean<Object>().setApplicationContext(applicationLifeCycle);
given(applicationLifeCycle.getConfigLocations()).willReturn(new String[] { "test1", "test2" });
given(applicationLifeCycle.isRunning()).willReturn(true);
Status status = springStatusChecker.check();
assertThat(status.getLevel(), is(Status.Level.OK));
assertThat(status.getMessage(), is("test1,test2"));
}
use of org.apache.dubbo.common.status.Status 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());
}
Aggregations