db = server.getDatabasePool().acquire(urlParts[1], urlParts[2], urlParts[3]);
} else
db = getProfiledDatabaseInstance(iRequest);
final StringWriter buffer = new StringWriter();
final OJSONWriter json = new OJSONWriter(buffer);
json.beginObject();
json.beginObject("server");
json.writeAttribute("version", OConstants.ORIENT_VERSION);
if (OConstants.getBuildNumber() != null)
json.writeAttribute("build", OConstants.getBuildNumber());
json.writeAttribute("osName", System.getProperty("os.name"));
json.writeAttribute("osVersion", System.getProperty("os.version"));
json.writeAttribute("osArch", System.getProperty("os.arch"));
json.writeAttribute("javaVendor", System.getProperty("java.vm.vendor"));
json.writeAttribute("javaVersion", System.getProperty("java.vm.version"));
json.endObject();
if (db.getMetadata().getSchema().getClasses() != null) {
json.beginCollection("classes");
List<String> classNames = new ArrayList<String>();
for (OClass cls : db.getMetadata().getSchema().getClasses())
classNames.add(cls.getName());
Collections.sort(classNames);
for (String className : classNames) {
final OClass cls = db.getMetadata().getSchema().getClass(className);
try {
exportClass(db, json, cls);
} catch (Exception e) {
OLogManager.instance().error(this, "Error on exporting class '" + cls + "'", e);
}
}
json.endCollection();
}
if (db.getClusterNames() != null) {
json.beginCollection("clusters");
OCluster cluster;
for (String clusterName : db.getClusterNames()) {
try {
cluster = db.getStorage().getClusterById(db.getClusterIdByName(clusterName));
} catch (IllegalArgumentException e) {
OLogManager.instance().error(this, "Cluster '%s' does not exist in database", clusterName);
continue;
}
try {
final String conflictStrategy = cluster.getRecordConflictStrategy() != null ? cluster.getRecordConflictStrategy().getName() : null;
json.beginObject();
json.writeAttribute("id", cluster.getId());
json.writeAttribute("name", clusterName);
json.writeAttribute("records", cluster.getEntries() - cluster.getTombstonesCount());
json.writeAttribute("conflictStrategy", conflictStrategy);
json.writeAttribute("size", "-");
json.writeAttribute("filled", "-");
json.writeAttribute("maxSize", "-");
json.writeAttribute("files", "-");
} catch (Exception e) {
json.writeAttribute("records", "? (Unauthorized)");
}
json.endObject();
}
json.endCollection();
}
if (db.getUser() != null) {
json.writeAttribute("currentUser", db.getUser().getName());
json.beginCollection("users");
// for (ODocument doc : db.getMetadata().getSecurity().getAllUsers()) {
// OUser user = new OUser(doc);
// json.beginObject();
// json.writeAttribute("name", user.getName());
// json.writeAttribute("roles", user.getRoles() != null ? Arrays.toString(user.getRoles().toArray()) : "null");
// json.endObject();
// }
json.endCollection();
json.beginCollection("roles");
// ORole role;
// for (ODocument doc : db.getMetadata().getSecurity().getAllRoles()) {
// role = new ORole(doc);
// json.beginObject();
// json.writeAttribute("name", role.getName());
// json.writeAttribute("mode", role.getMode().toString());
//
// json.beginCollection("rules");
// if (role.getRules() != null) {
// for (Entry<String, Byte> rule : role.getRules().entrySet()) {
// json.beginObject();
// json.writeAttribute("name", rule.getKey());
// json.writeAttribute("create", role.allow(rule.getKey(), ORole.PERMISSION_CREATE));
// json.writeAttribute("read", role.allow(rule.getKey(), ORole.PERMISSION_READ));
// json.writeAttribute("update", role.allow(rule.getKey(), ORole.PERMISSION_UPDATE));
// json.writeAttribute("delete", role.allow(rule.getKey(), ORole.PERMISSION_DELETE));
// json.endObject();
// }
// }
// json.endCollection();
//
// json.endObject();
// }
json.endCollection();
}
final OIndexManagerProxy idxManager = db.getMetadata().getIndexManager();
json.beginCollection("indexes");
for (OIndex<?> index : idxManager.getIndexes()) {
json.beginObject();
try {
json.writeAttribute("name", index.getName());
json.writeAttribute("configuration", index.getConfiguration());
// Exclude index size because it's too costly
// json.writeAttribute("size", index.getSize());
} catch (Exception e) {
OLogManager.instance().error(this, "Cannot serialize index configuration", e);
}
json.endObject();
}
json.endCollection();
json.beginObject("config");
json.beginCollection("values");
json.writeObjects(null, new Object[] { "name", "dateFormat", "value", db.getStorage().getConfiguration().dateFormat },
new Object[] { "name", "dateTimeFormat", "value", db.getStorage().getConfiguration().dateTimeFormat }, new Object[] {
"name", "localeCountry", "value", db.getStorage().getConfiguration().getLocaleCountry() }, new Object[] { "name",
"localeLanguage", "value", db.getStorage().getConfiguration().getLocaleLanguage() }, new Object[] { "name",
"charSet", "value", db.getStorage().getConfiguration().getCharset() }, new Object[] { "name", "timezone", "value",
db.getStorage().getConfiguration().getTimeZone().getID() }, new Object[] { "name", "definitionVersion", "value",
db.getStorage().getConfiguration().version }, new Object[] { "name", "clusterSelection", "value",
db.getStorage().getConfiguration().getClusterSelection() }, new Object[] { "name", "minimumClusters", "value",
db.getStorage().getConfiguration().getMinimumClusters() }, new Object[] { "name", "conflictStrategy", "value",
db.getStorage().getConfiguration().getConflictStrategy() });
json.endCollection();
json.beginCollection("properties");
if (db.getStorage().getConfiguration().properties != null)
for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().properties) {
if (entry != null) {
json.beginObject();
json.writeAttribute("name", entry.name);
json.writeAttribute("value", entry.value);
json.endObject();
}
}
json.endCollection();
json.endObject();
json.endObject();
json.flush();
iResponse.send(OHttpUtils.STATUS_OK_CODE, "OK", OHttpUtils.CONTENT_JSON, buffer.toString(), null);
} finally {
if (db != null)
db.close();