use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.
the class OServerCommandGetDatabase method exec.
protected void exec(final OHttpRequest iRequest, final OHttpResponse iResponse, final String[] urlParts) throws InterruptedException, IOException {
ODatabaseDocumentInternal db = null;
try {
if (urlParts.length > 2) {
db = server.getDatabasePoolFactory().get(urlParts[1], urlParts[2], urlParts[3]).acquire();
} 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 (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().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());
// exportSecurityInfo(db, json);
}
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().getProperties() != null)
for (OStorageEntryConfiguration entry : db.getStorage().getConfiguration().getProperties()) {
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();
}
}
use of com.orientechnologies.orient.core.storage.OCluster in project orientdb by orientechnologies.
the class ClusterMetadataTest method testMetadataStore.
public void testMetadataStore() throws Exception {
final int clusterId = database.addCluster("clusterTest");
OCluster cluster = database.getStorage().getClusterById(clusterId);
Assert.assertEquals(cluster.recordGrowFactor(), 1.2f);
Assert.assertEquals(cluster.recordOverflowGrowFactor(), 1.2f);
Assert.assertEquals(cluster.compression(), OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValueAsString());
database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor 2")).execute();
database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor 2")).execute();
database.command(new OCommandSQL("alter cluster clusterTest compression nothing")).execute();
Assert.assertEquals(cluster.recordGrowFactor(), 2f);
Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
Assert.assertEquals(cluster.compression(), "nothing");
OStorage storage = database.getStorage();
database.close();
storage.close(true, false);
database.activateOnCurrentThread();
database.resetInitialization();
database.open("admin", "admin");
cluster = database.getStorage().getClusterById(clusterId);
Assert.assertEquals(cluster.recordGrowFactor(), 2f);
Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
Assert.assertEquals(cluster.compression(), "nothing");
try {
database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor 0.5")).execute();
Assert.fail();
} catch (OException e) {
}
try {
database.command(new OCommandSQL("alter cluster clusterTest record_grow_factor fff")).execute();
Assert.fail();
} catch (OException e) {
}
try {
database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor 0.5")).execute();
Assert.fail();
} catch (OException e) {
}
try {
database.command(new OCommandSQL("alter cluster clusterTest record_overflow_grow_factor fff")).execute();
Assert.fail();
} catch (OException e) {
}
try {
database.command(new OCommandSQL("alter cluster clusterTest compression dsgfgd")).execute();
Assert.fail();
} catch (OException e) {
}
Assert.assertEquals(cluster.recordGrowFactor(), 2f);
Assert.assertEquals(cluster.recordOverflowGrowFactor(), 2f);
Assert.assertEquals(cluster.compression(), "nothing");
}
Aggregations