Merge pull request #1114 from birarda/master

fixes for admin interface with multiple nodes of same type
This commit is contained in:
Philip Rosedale 2013-10-24 17:14:28 -07:00
commit 41ff88f0b5
2 changed files with 36 additions and 23 deletions

View file

@ -4,14 +4,14 @@ $(document).ready(function(){
$.getJSON("nodes.json", function(json){
nodesTableBody = "";
$.each(json.nodes, function (type, data) {
$.each(json.nodes, function (uuid, data) {
nodesTableBody += "<tr>";
nodesTableBody += "<td>" + type + "</td>";
nodesTableBody += "<td>" + data.UUID + "</td>";
nodesTableBody += "<td>" + data.type + "</td>";
nodesTableBody += "<td>" + uuid + "</td>";
nodesTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
nodesTableBody += "<td>" + data.public.ip + "<span class='port'>:" + data.public.port + "</span></td>";
nodesTableBody += "<td>" + data.local.ip + "<span class='port'>:" + data.local.port + "</span></td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + data.UUID + "></span></td>";
nodesTableBody += "<td><span class='glyphicon glyphicon-remove' data-uuid=" + uuid + "></span></td>";
nodesTableBody += "</tr>";
});
@ -21,10 +21,10 @@ $(document).ready(function(){
$.getJSON("assignments.json", function(json){
queuedTableBody = "";
$.each(json.queued, function (type, data) {
$.each(json.queued, function (uuid, data) {
queuedTableBody += "<tr>";
queuedTableBody += "<td>" + type + "</td>";
queuedTableBody += "<td>" + data.UUID + "</td>";
queuedTableBody += "<td>" + uuid + "</td>";
queuedTableBody += "<td>" + data.type + "</td>";
queuedTableBody += "<td>" + (data.pool ? data.pool : "") + "</td>";
queuedTableBody += "</tr>";
});

View file

@ -42,28 +42,32 @@ QJsonObject jsonForSocket(sockaddr* 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";
const char JSON_KEY_POOL[] = "pool";
void addNodeToJsonObject(Node* node, QJsonObject& jsonObject) {
QJsonObject jsonObjectForNode(Node* node) {
QJsonObject nodeJson;
// add the UUID
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
nodeJson[JSON_KEY_UUID] = uuidString;
// add the node socket information
nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket());
nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket());
// re-format the type name so it matches the target name
QString nodeTypeName(node->getTypeName());
nodeTypeName = nodeTypeName.toLower();
nodeTypeName.replace(' ', '-');
jsonObject[nodeTypeName] = nodeJson;
// add the node type
nodeJson[JSON_KEY_TYPE] = nodeTypeName;
// add the node socket information
nodeJson[JSON_KEY_PUBLIC_SOCKET] = jsonForSocket(node->getPublicSocket());
nodeJson[JSON_KEY_LOCAL_SOCKET] = jsonForSocket(node->getLocalSocket());
// if the node has pool information, add it
if (node->getLinkedData() && ((Assignment*) node->getLinkedData())->hasPool()) {
nodeJson[JSON_KEY_POOL] = QString(((Assignment*) node->getLinkedData())->getPool());
}
return nodeJson;
}
int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
@ -91,7 +95,9 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
if (node->getLinkedData()) {
addNodeToJsonObject(&(*node), assignedNodesJSON);
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
assignedNodesJSON[uuidString] = jsonObjectForNode(&(*node));
}
}
@ -106,10 +112,15 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
QJsonObject queuedAssignmentJSON;
QString uuidString = uuidStringWithoutCurlyBraces((*assignment)->getUUID());
queuedAssignmentJSON[JSON_KEY_UUID] = uuidString;
queuedAssignmentJSON[JSON_KEY_TYPE] = QString((*assignment)->getTypeName());
// if the assignment has a pool, add it
if ((*assignment)->hasPool()) {
queuedAssignmentJSON[JSON_KEY_POOL] = QString((*assignment)->getPool());
}
// add this queued assignment to the JSON
queuedAssignmentsJSON[(*assignment)->getTypeName()] = queuedAssignmentJSON;
queuedAssignmentsJSON[uuidString] = queuedAssignmentJSON;
// push forward the iterator to check the next assignment
assignment++;
@ -135,7 +146,9 @@ int DomainServer::civetwebRequestHandler(struct mg_connection *connection) {
NodeList* nodeList = NodeList::getInstance();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {
addNodeToJsonObject(&(*node), nodesJSON);
// add the node using the UUID as the key
QString uuidString = uuidStringWithoutCurlyBraces(node->getUUID());
nodesJSON[uuidString] = jsonObjectForNode(&(*node));
}
rootJSON["nodes"] = nodesJSON;