* Returns an {@link com.splout.db.dnode.beans.DNodeSystemStatus} filled with the appropriated data.
*/
@Override
public String status() throws DNodeException {
try {
DNodeSystemStatus status = new DNodeSystemStatus();
if(lastException == null) {
status.setSystemStatus("UP");
status.setLastExceptionTime(-1);
} else {
status.setSystemStatus("Last exception: " + lastException);
status.setLastExceptionTime(lastExceptionTime);
}
status.setUpSince(upSince);
status.setFailedQueries(failedQueries.get());
status.setnQueries(performanceTool.getNQueries());
status.setAverage(performanceTool.getAverage());
status.setSlowQueries(slowQueries);
status.setDeployInProgress(deployInProgress.get() > 0);
status.setHttpExchangerAddress(httpExchangerAddress());
status.setBalanceActionsStateMap(balanceActionsStateMap);
File folder = new File(config.getString(DNodeProperties.DATA_FOLDER));
if(folder.exists()) {
status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb(folder.toString()));
status.setOccupiedSpaceInDisk(FileUtils.sizeOfDirectory(folder));
Collection<File> files = FileUtils.listFilesAndDirs(folder, TrueFileFilter.INSTANCE,
TrueFileFilter.INSTANCE);
status.setFiles(new ArrayList<String>(Lists.transform(Lists.newArrayList(files),
new Function<File, String>() {
@Override
public String apply(File file) {
return file.getAbsolutePath() + " (" + FileUtils.sizeOf(file) + " bytes)";
}
})));
Collections.sort(status.getFiles());
} else {
status.setOccupiedSpaceInDisk(0);
status.setFreeSpaceInDisk(FileSystemUtils.freeSpaceKb("."));
status.setFiles(new ArrayList<String>());
}
return JSONSerDe.ser(status);
} catch(Throwable t) {
unexpectedException(t);
throw new DNodeException(EXCEPTION_UNEXPECTED, t.getMessage());