use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODistributedOutput method formatLatency.
public static String formatLatency(final OHazelcastPlugin manager, final ODocument distribCfg) {
final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
final List<ODocument> members = distribCfg.field("members");
final StringBuilder buffer = new StringBuilder();
buffer.append("\nREPLICATION LATENCY AVERAGE (in milliseconds)");
final OTableFormatter table = new OTableFormatter(new OTableFormatter.OTableOutput() {
@Override
public void onMessage(final String text, final Object... args) {
buffer.append(String.format(text, args));
}
});
table.setColumnHidden("#");
if (members != null) {
// BUILD A SORTED SERVER LIST
final List<String> orderedServers = new ArrayList<String>(members.size());
for (ODocument fromMember : members) {
if (fromMember != null) {
String serverName = fromMember.field("name");
orderedServers.add(serverName);
table.setColumnAlignment(formatServerName(manager, serverName), OTableFormatter.ALIGNMENT.RIGHT);
}
}
Collections.sort(orderedServers);
for (String fromServer : orderedServers) {
// SEARCH FOR THE MEMBER
ODocument fromMember = null;
for (ODocument m : members) {
if (fromServer.equals(m.field("name"))) {
fromMember = m;
break;
}
}
if (fromMember == null)
// SKIP IT
continue;
final ODocument row = new ODocument();
rows.add(row);
row.field("Servers", formatServerName(manager, fromServer));
final ODocument latencies = fromMember.field("latencies");
if (latencies == null)
continue;
for (String toServer : orderedServers) {
String value = "";
if (toServer != null && !toServer.equals(fromServer)) {
final ODocument latency = latencies.field(toServer);
if (latency != null) {
value = String.format("%.2f", ((Float) latency.field("average") / 1000000f));
}
}
row.field(formatServerName(manager, toServer), value);
}
}
}
table.writeRecords(rows, -1);
buffer.append("\n");
return buffer.toString();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODistributedOutput method formatMessageBetweenServers.
public static String formatMessageBetweenServers(final OHazelcastPlugin manager, final ODocument distribCfg) {
final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
final List<ODocument> members = distribCfg.field("members");
final StringBuilder buffer = new StringBuilder();
buffer.append("\nREPLICATION MESSAGE COUNTERS (servers: source on the row and destination on the column)");
final OTableFormatter table = new OTableFormatter(new OTableFormatter.OTableOutput() {
@Override
public void onMessage(final String text, final Object... args) {
buffer.append(String.format(text, args));
}
});
table.setColumnHidden("#");
if (members != null) {
// BUILD A SORTED SERVER LIST
final List<String> orderedServers = new ArrayList<String>(members.size());
for (ODocument fromMember : members) {
if (fromMember != null) {
String serverName = fromMember.field("name");
orderedServers.add(serverName);
table.setColumnAlignment(formatServerName(manager, serverName), OTableFormatter.ALIGNMENT.RIGHT);
}
}
Collections.sort(orderedServers);
final ODocument rowTotals = new ODocument();
for (String fromServer : orderedServers) {
// SEARCH FOR THE MEMBER
ODocument fromMember = null;
for (ODocument m : members) {
if (fromServer.equals(m.field("name"))) {
fromMember = m;
break;
}
}
if (fromMember == null)
// SKIP IT
continue;
final ODocument row = new ODocument();
rows.add(row);
row.field("Servers", formatServerName(manager, fromServer));
final ODocument latencies = fromMember.field("latencies");
if (latencies == null)
continue;
long total = 0;
for (String toServer : orderedServers) {
final String serverLabel = formatServerName(manager, toServer);
if (toServer != null && !toServer.equals(fromServer)) {
final ODocument latency = latencies.field(toServer);
if (latency != null) {
final Long entries = (Long) latency.field("entries");
total += entries;
row.field(serverLabel, String.format("%,d", entries));
// AGGREGATE IN TOTALS
sumTotal(rowTotals, serverLabel, total);
continue;
}
}
row.field(serverLabel, "");
}
row.field("TOTAL", String.format("%,d", total));
sumTotal(rowTotals, "TOTAL", total);
}
// FOOTER WITH THE TOTAL OF ALL THE ROWS
table.setFooter(rowTotals);
rowTotals.field("Servers", "TOTAL");
for (String fromServer : orderedServers) {
fromServer = formatServerName(manager, fromServer);
rowTotals.field(fromServer, String.format("%,d", rowTotals.field(fromServer)));
}
rowTotals.field("TOTAL", String.format("%,d", rowTotals.field("TOTAL")));
table.setColumnAlignment("TOTAL", OTableFormatter.ALIGNMENT.RIGHT);
}
table.writeRecords(rows, -1);
buffer.append("\n");
return buffer.toString();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODistributedOutput method formatClusterTable.
public static String formatClusterTable(final ODistributedServerManager manager, final String databaseName, final ODistributedConfiguration cfg, final int availableNodes) {
final StringBuilder buffer = new StringBuilder();
if (cfg.hasDataCenterConfiguration()) {
buffer.append("\n\nDATA CENTER CONFIGURATION");
final OTableFormatter table = new OTableFormatter(new OTableFormatter.OTableOutput() {
@Override
public void onMessage(final String text, final Object... args) {
buffer.append(String.format(text, args));
}
});
table.setColumnSorting("NAME", true);
table.setColumnHidden("#");
table.setColumnAlignment("SERVERS", OTableFormatter.ALIGNMENT.LEFT);
table.setColumnAlignment("writeQuorum", OTableFormatter.ALIGNMENT.CENTER);
final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
for (String dcName : cfg.getDataCenters()) {
final ODocument row = new ODocument();
rows.add(row);
final String dcServers = cfg.getDataCenterServers(dcName).toString();
row.field("NAME", dcName);
row.field("SERVERS", dcServers.substring(1, dcServers.length() - 1));
row.field("writeQuorum", cfg.getDataCenterWriteQuorum(dcName));
}
table.writeRecords(rows, -1);
}
buffer.append("\n\nCLUSTER CONFIGURATION (LEGEND: X = Owner, o = Copy)");
final OTableFormatter table = new OTableFormatter(new OTableFormatter.OTableOutput() {
@Override
public void onMessage(final String text, final Object... args) {
buffer.append(String.format(text, args));
}
});
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null && db.isClosed())
db = null;
table.setColumnSorting("CLUSTER", true);
table.setColumnHidden("#");
if (db != null)
table.setColumnAlignment("id", OTableFormatter.ALIGNMENT.RIGHT);
table.setColumnAlignment("writeQuorum", OTableFormatter.ALIGNMENT.CENTER);
table.setColumnAlignment("readQuorum", OTableFormatter.ALIGNMENT.CENTER);
final String localNodeName = manager.getLocalNodeName();
// READ DEFAULT CFG (CLUSTER=*)
final String defaultWQ = cfg.isLocalDataCenterWriteQuorum() ? ODistributedConfiguration.QUORUM_LOCAL_DC : "" + cfg.getWriteQuorum(ODistributedConfiguration.ALL_WILDCARD, availableNodes, localNodeName);
final int defaultRQ = cfg.getReadQuorum(ODistributedConfiguration.ALL_WILDCARD, availableNodes, localNodeName);
final String defaultOwner = "" + cfg.getClusterOwner(ODistributedConfiguration.ALL_WILDCARD);
final List<String> defaultServers = cfg.getConfiguredServers(ODistributedConfiguration.ALL_WILDCARD);
final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
final Set<String> allServers = new HashSet<String>();
for (String cluster : cfg.getClusterNames()) {
final String wQ = cfg.isLocalDataCenterWriteQuorum() ? ODistributedConfiguration.QUORUM_LOCAL_DC : "" + cfg.getWriteQuorum(cluster, availableNodes, localNodeName);
final int rQ = cfg.getReadQuorum(cluster, availableNodes, localNodeName);
final String owner = cfg.getClusterOwner(cluster);
final List<String> servers = cfg.getConfiguredServers(cluster);
if (!cluster.equals(ODistributedConfiguration.ALL_WILDCARD) && defaultWQ.equals(wQ) && defaultRQ == rQ && defaultOwner.equals(owner) && defaultServers.size() == servers.size() && defaultServers.containsAll(servers))
// SAME CFG AS THE DEFAULT: DON'T DISPLAY IT
continue;
final ODocument row = new ODocument();
rows.add(row);
row.field("CLUSTER", cluster);
if (db != null) {
final int clId = db.getClusterIdByName(cluster);
row.field("id", clId > -1 ? clId : "");
}
row.field("writeQuorum", wQ);
row.field("readQuorum", rQ);
if (servers != null)
for (String server : servers) {
if (server.equalsIgnoreCase("<NEW_NODE>"))
continue;
allServers.add(server);
row.field(server, OAnsiCode.format(server.equals(owner) ? "X" : "o"));
table.setColumnAlignment(server, OTableFormatter.ALIGNMENT.CENTER);
}
}
final Set<String> registeredServers = cfg.getRegisteredServers();
for (String server : allServers) {
table.setColumnMetadata(server, "CFG", registeredServers.contains(server) ? "static" : "dynamic");
table.setColumnMetadata(server, "ROLE", cfg.getServerRole(server).toString());
table.setColumnMetadata(server, "STATUS", manager.getDatabaseStatus(server, databaseName).toString());
if (cfg.hasDataCenterConfiguration())
table.setColumnMetadata(server, "DC", "DC(" + cfg.getDataCenterOfServer(server) + ")");
}
table.writeRecords(rows, -1);
buffer.append("\n");
return buffer.toString();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class ODistributedOutput method formatClasses.
public static String formatClasses(final ODistributedConfiguration cfg, final ODatabaseDocument db) {
final StringBuilder buffer = new StringBuilder();
final OTableFormatter table = new OTableFormatter(new OTableFormatter.OTableOutput() {
@Override
public void onMessage(final String text, final Object... args) {
buffer.append(String.format(text, args));
}
});
final Set<String> allServers = cfg.getAllConfiguredServers();
final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
for (OClass cls : db.getMetadata().getSchema().getClasses()) {
final ODocument row = new ODocument();
rows.add(row);
row.field("CLASS", cls.getName());
final StringBuilder serverBuffer = new StringBuilder();
for (String server : allServers) {
final Set<String> clustersOnServer = cfg.getClustersOnServer(server);
for (String clusterName : clustersOnServer) {
if (serverBuffer.length() > 0)
serverBuffer.append(',');
serverBuffer.append(clusterName);
serverBuffer.append('(');
serverBuffer.append(db.getClusterIdByName(clusterName));
serverBuffer.append(')');
}
row.field(server, serverBuffer.toString());
}
}
table.writeRecords(rows, -1);
return buffer.toString();
}
use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.
the class TestDirtyTrackingTreeRidBagRemote method test.
@Test
public void test() {
final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
try {
graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
graph.createEdgeType("Edge");
OIdentifiable oneVertex = null;
Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
for (int i = 0; i < max; i++) {
Vertex v = graph.addVertex("class:V");
v.setProperty("key", "foo" + i);
graph.commit();
vertices.put(v.getProperty("key"), v);
if (i == max / 2 + 1)
oneVertex = ((OrientVertex) v).getIdentity();
}
graph.commit();
// Add the edges
for (int i = 0; i < max; i++) {
String codeUCD1 = "foo" + i;
// Take the first vertex
Vertex med1 = (Vertex) vertices.get(codeUCD1);
// For the 2nd term
for (int j = 0; j < max; j++) {
String key = "foo" + j;
// Take the second vertex
Vertex med2 = (Vertex) vertices.get(key);
// ((OrientVertex)med2).getRecord().reload();
OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
}
// COMMIT
graph.commit();
}
graph.getRawGraph().getLocalCache().clear();
OrientVertex vertex = graph.getVertex(oneVertex);
assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
} finally {
graph.shutdown();
}
}
Aggregations