Search in sources :

Example 1 with OTableFormatter

use of com.orientechnologies.orient.console.OTableFormatter 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();
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OTableFormatter(com.orientechnologies.orient.console.OTableFormatter) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OTableFormatter

use of com.orientechnologies.orient.console.OTableFormatter 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();
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OTableFormatter(com.orientechnologies.orient.console.OTableFormatter) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OTableFormatter

use of com.orientechnologies.orient.console.OTableFormatter 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();
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OTableFormatter(com.orientechnologies.orient.console.OTableFormatter) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OTableFormatter

use of com.orientechnologies.orient.console.OTableFormatter 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();
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OTableFormatter(com.orientechnologies.orient.console.OTableFormatter) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OTableFormatter

use of com.orientechnologies.orient.console.OTableFormatter in project orientdb by orientechnologies.

the class ODistributedOutput method formatServerStatus.

public static String formatServerStatus(final ODistributedServerManager manager, final ODocument distribCfg) {
    final List<OIdentifiable> rows = new ArrayList<OIdentifiable>();
    final Collection<ODocument> members = distribCfg.field("members");
    if (members != null)
        for (ODocument m : members) {
            if (m == null)
                continue;
            final ODocument serverRow = new ODocument();
            final String serverName = m.field("name");
            serverRow.field("Name", serverName + (manager.getLocalNodeName().equals(serverName) ? "*" : ""));
            serverRow.field("Status", m.field("status"));
            serverRow.field("Databases", (String) null);
            serverRow.field("Conns", m.field("connections"));
            final Date date = m.field("startedOn");
            if (date != null) {
                final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
                if (sdf.format(date).equals(sdf.format(new Date())))
                    // TODAY, PUT ONLY THE HOUR
                    serverRow.field("StartedOn", new SimpleDateFormat("HH:mm:ss").format(date));
                else
                    // ANY OTHER DAY, PUT FULL DATE
                    serverRow.field("StartedOn", date);
            }
            final Collection<Map> listeners = m.field("listeners");
            if (listeners != null) {
                for (Map l : listeners) {
                    final String protocol = (String) l.get("protocol");
                    if (protocol.equals("ONetworkProtocolBinary")) {
                        serverRow.field("Binary", l.get("listen"));
                    } else if (protocol.equals("ONetworkProtocolHttpDb")) {
                        serverRow.field("HTTP", l.get("listen"));
                    }
                }
            }
            final Long usedMem = m.field("usedMemory");
            if (usedMem != null) {
                final long maxMem = m.field("maxMemory");
                serverRow.field("UsedMemory", String.format("%s/%s (%.2f%%)", OFileUtils.getSizeAsString(usedMem), OFileUtils.getSizeAsString(maxMem), ((float) usedMem / (float) maxMem) * 100));
            }
            rows.add(serverRow);
            final Collection<String> databases = m.field("databases");
            if (databases != null) {
                int serverNum = 0;
                for (String dbName : databases) {
                    final StringBuilder buffer = new StringBuilder();
                    final ODistributedConfiguration dbCfg = manager.getDatabaseConfiguration(dbName, false);
                    if (dbCfg == null)
                        continue;
                    buffer.append(dbName);
                    buffer.append("=");
                    buffer.append(manager.getDatabaseStatus(serverName, dbName));
                    buffer.append(" (");
                    buffer.append(dbCfg.getServerRole(serverName));
                    buffer.append(")");
                    if (serverNum++ == 0)
                        // ADD THE 1ST DB IT IN THE SERVER ROW
                        serverRow.field("Databases", buffer.toString());
                    else
                        // ADD IN A SEPARATE ROW
                        rows.add(new ODocument().field("Databases", buffer.toString()));
                }
            }
        }
    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));
        }
    });
    table.setColumnHidden("#");
    table.writeRecords(rows, -1);
    buffer.append("\n");
    return buffer.toString();
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OTableFormatter(com.orientechnologies.orient.console.OTableFormatter) ODistributedConfiguration(com.orientechnologies.orient.server.distributed.ODistributedConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OTableFormatter (com.orientechnologies.orient.console.OTableFormatter)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODistributedConfiguration (com.orientechnologies.orient.server.distributed.ODistributedConfiguration)1 SimpleDateFormat (java.text.SimpleDateFormat)1