From 44860a5f5a5acb1951c3ced95224dbf36a053981 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 28 Mar 2014 12:01:37 -0700 Subject: [PATCH 1/2] put servers alphabetically first in node list --- domain-server/resources/web/js/tables.js | 25 +++++++++++++++++++++--- domain-server/src/DomainServer.cpp | 11 +++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/domain-server/resources/web/js/tables.js b/domain-server/resources/web/js/tables.js index 18e67ac6e7..3f7b2b7b28 100644 --- a/domain-server/resources/web/js/tables.js +++ b/domain-server/resources/web/js/tables.js @@ -2,16 +2,35 @@ $(document).ready(function(){ // setup a function to grab the assignments function getNodesAndAssignments() { $.getJSON("nodes.json", function(json){ + + json.nodes.sort(function(a, b){ + if (a.type === b.type) { + return 0; + } + + if (a.type === "agent" && b.type !== "agent") { + return 1; + } + + if (a.type > b.type) { + return 1; + } + + if (a.type < b.type) { + return -1; + } + }); + nodesTableBody = ""; - $.each(json.nodes, function (uuid, data) { + $.each(json.nodes, function(index, data) { nodesTableBody += ""; nodesTableBody += "" + data.type + ""; - nodesTableBody += "" + uuid + ""; + nodesTableBody += "" + data.uuid + ""; nodesTableBody += "" + (data.pool ? data.pool : "") + ""; nodesTableBody += "" + data.public.ip + ":" + data.public.port + ""; nodesTableBody += "" + data.local.ip + ":" + data.local.port + ""; - nodesTableBody += ""; + nodesTableBody += ""; nodesTableBody += ""; }); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 035e6c9a20..d18f12ec7f 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -622,6 +622,7 @@ QJsonObject DomainServer::jsonForSocket(const HifiSockAddr& socket) { return socketJSON; } +const char JSON_KEY_UUID[] = "uuid"; const char JSON_KEY_TYPE[] = "type"; const char JSON_KEY_PUBLIC_SOCKET[] = "public"; const char JSON_KEY_LOCAL_SOCKET[] = "local"; @@ -635,6 +636,9 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) { nodeTypeName = nodeTypeName.toLower(); nodeTypeName.replace(' ', '-'); + // add the node UUID + nodeJson[JSON_KEY_UUID] = uuidStringWithoutCurlyBraces(node->getUUID()); + // add the node type nodeJson[JSON_KEY_TYPE] = nodeTypeName; @@ -707,18 +711,17 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url } else if (url.path() == QString("%1.json").arg(URI_NODES)) { // setup the JSON QJsonObject rootJSON; - QJsonObject nodesJSON; + QJsonArray nodesJSONArray; // enumerate the NodeList to find the assigned nodes NodeList* nodeList = NodeList::getInstance(); foreach (const SharedNodePointer& node, nodeList->getNodeHash()) { // add the node using the UUID as the key - QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID()); - nodesJSON[uuidString] = jsonObjectForNode(node); + nodesJSONArray.append(jsonObjectForNode(node)); } - rootJSON["nodes"] = nodesJSON; + rootJSON["nodes"] = nodesJSONArray; // print out the created JSON QJsonDocument nodesDocument(rootJSON); From 5adcf6875241fd7c58ec309f026e8b866fd87a8a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 7 Apr 2014 09:08:51 -0700 Subject: [PATCH 2/2] sort nodes on DS page by their uptime --- domain-server/resources/web/index.shtml | 1 + domain-server/resources/web/js/tables.js | 16 ++++++++++++++-- domain-server/src/DomainServer.cpp | 4 ++++ libraries/shared/src/Node.cpp | 3 ++- libraries/shared/src/Node.h | 6 +++--- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/domain-server/resources/web/index.shtml b/domain-server/resources/web/index.shtml index bba4dc4d22..afd0af1679 100644 --- a/domain-server/resources/web/index.shtml +++ b/domain-server/resources/web/index.shtml @@ -12,6 +12,7 @@ Pool Public Local + Uptime (s) Kill? diff --git a/domain-server/resources/web/js/tables.js b/domain-server/resources/web/js/tables.js index 3f7b2b7b28..a4884486c3 100644 --- a/domain-server/resources/web/js/tables.js +++ b/domain-server/resources/web/js/tables.js @@ -5,13 +5,21 @@ $(document).ready(function(){ json.nodes.sort(function(a, b){ if (a.type === b.type) { - return 0; + if (a.wake_timestamp < b.wake_timestamp) { + return 1; + } else if (a.wake_timestamp > b.wake_timestamp) { + return -1; + } else { + return 0; + } } if (a.type === "agent" && b.type !== "agent") { return 1; + } else if (b.type === "agent" && a.type !== "agent") { + return -1; } - + if (a.type > b.type) { return 1; } @@ -30,6 +38,10 @@ $(document).ready(function(){ nodesTableBody += "" + (data.pool ? data.pool : "") + ""; nodesTableBody += "" + data.public.ip + ":" + data.public.port + ""; nodesTableBody += "" + data.local.ip + ":" + data.local.port + ""; + + var uptimeSeconds = (Date.now() - data.wake_timestamp) / 1000; + nodesTableBody += "" + uptimeSeconds.toLocaleString() + ""; + nodesTableBody += ""; nodesTableBody += ""; }); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index d18f12ec7f..8d1ee9d3dd 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -627,6 +627,7 @@ const char JSON_KEY_TYPE[] = "type"; const char JSON_KEY_PUBLIC_SOCKET[] = "public"; const char JSON_KEY_LOCAL_SOCKET[] = "local"; const char JSON_KEY_POOL[] = "pool"; +const char JSON_KEY_WAKE_TIMESTAMP[] = "wake_timestamp"; QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) { QJsonObject nodeJson; @@ -646,6 +647,9 @@ QJsonObject DomainServer::jsonObjectForNode(const SharedNodePointer& node) { nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket()); nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket()); + // add the node uptime in our list + nodeJson[JSON_KEY_WAKE_TIMESTAMP] = QString::number(node->getWakeTimestamp()); + // if the node has pool information, add it SharedAssignmentPointer matchingAssignment = _staticAssignmentHash.value(node->getUUID()); if (matchingAssignment) { diff --git a/libraries/shared/src/Node.cpp b/libraries/shared/src/Node.cpp index a4491fb707..1e78bc3feb 100644 --- a/libraries/shared/src/Node.cpp +++ b/libraries/shared/src/Node.cpp @@ -19,6 +19,7 @@ #include "SharedUtil.h" #include +#include #include const QString UNKNOWN_NodeType_t_NAME = "Unknown"; @@ -47,7 +48,7 @@ const QString& NodeType::getNodeTypeName(NodeType_t nodeType) { Node::Node(const QUuid& uuid, char type, const HifiSockAddr& publicSocket, const HifiSockAddr& localSocket) : _type(type), _uuid(uuid), - _wakeMicrostamp(usecTimestampNow()), + _wakeTimestamp(QDateTime::currentMSecsSinceEpoch()), _lastHeardMicrostamp(usecTimestampNow()), _publicSocket(publicSocket), _localSocket(localSocket), diff --git a/libraries/shared/src/Node.h b/libraries/shared/src/Node.h index 79d75629a6..5d30d6f7b0 100644 --- a/libraries/shared/src/Node.h +++ b/libraries/shared/src/Node.h @@ -60,8 +60,8 @@ public: const QUuid& getUUID() const { return _uuid; } void setUUID(const QUuid& uuid) { _uuid = uuid; } - quint64 getWakeMicrostamp() const { return _wakeMicrostamp; } - void setWakeMicrostamp(quint64 wakeMicrostamp) { _wakeMicrostamp = wakeMicrostamp; } + quint64 getWakeTimestamp() const { return _wakeTimestamp; } + void setWakeTimestamp(quint64 wakeTimestamp) { _wakeTimestamp = wakeTimestamp; } quint64 getLastHeardMicrostamp() const { return _lastHeardMicrostamp; } void setLastHeardMicrostamp(quint64 lastHeardMicrostamp) { _lastHeardMicrostamp = lastHeardMicrostamp; } @@ -109,7 +109,7 @@ private: NodeType_t _type; QUuid _uuid; - quint64 _wakeMicrostamp; + quint64 _wakeTimestamp; quint64 _lastHeardMicrostamp; HifiSockAddr _publicSocket; HifiSockAddr _localSocket;