Skip to content

Commit cb617c9

Browse files
committed
add a button on DS admin page to kill all nodes
1 parent 0d0784e commit cb617c9

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

Diff for: domain-server/resources/web/index.shtml

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<!--#include file="header.html"-->
22
<div id="nodes-lead" class="table-lead"><h3>Nodes</h3><div class="lead-line"></div></div>
3+
<div style="clear:both;"></div>
4+
<button type="button" class="btn btn-danger" id="kill-all-btn">
5+
<span class="glyphicon glyphicon-fire"></span> Kill all Nodes
6+
</button>
37
<table id="nodes-table" class="table table-striped">
48
<thead>
59
<tr>

Diff for: domain-server/resources/web/js/tables.js

+14
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,18 @@ $(document).ready(function(){
4949
}
5050
});
5151
});
52+
53+
$(document.body).on('click', '#kill-all-btn', function() {
54+
var confirmed_kill = confirm("Are you sure?");
55+
56+
if (confirmed_kill == true) {
57+
$.ajax({
58+
url: "/nodes/",
59+
type: 'DELETE',
60+
success: function(result) {
61+
console.log("Successful request to delete all nodes.");
62+
}
63+
});
64+
}
65+
});
5266
});

Diff for: domain-server/src/DomainServer.cpp

+28-21
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
657657
const QString URI_ASSIGNMENT = "/assignment";
658658
const QString URI_NODES = "/nodes";
659659

660+
const QString UUID_REGEX_STRING = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
661+
660662
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
661663
if (url.path() == "/assignments.json") {
662664
// user is asking for json list of assignments
@@ -726,9 +728,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
726728

727729
return true;
728730
} else {
729-
const QString NODE_REGEX_STRING =
730-
QString("\\%1\\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).json\\/?$").arg(URI_NODES);
731-
QRegExp nodeShowRegex(NODE_REGEX_STRING);
731+
const QString NODE_JSON_REGEX_STRING = QString("\\%1\\/(%2).json\\/?$").arg(URI_NODES).arg(UUID_REGEX_STRING);
732+
QRegExp nodeShowRegex(NODE_JSON_REGEX_STRING);
732733

733734
if (nodeShowRegex.indexIn(url.path()) != -1) {
734735
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
@@ -801,29 +802,35 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
801802
return true;
802803
}
803804
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
804-
if (url.path().startsWith(URI_NODES)) {
805-
// this is a request to DELETE a node by UUID
805+
const QString ALL_NODE_DELETE_REGEX_STRING = QString("\\%1\\/?$").arg(URI_NODES);
806+
const QString NODE_DELETE_REGEX_STRING = QString("\\%1\\/(%2)\\/$").arg(URI_NODES).arg(UUID_REGEX_STRING);
807+
808+
QRegExp allNodesDeleteRegex(ALL_NODE_DELETE_REGEX_STRING);
809+
QRegExp nodeDeleteRegex(NODE_DELETE_REGEX_STRING);
810+
811+
if (nodeDeleteRegex.indexIn(url.path()) != -1) {
812+
// this is a request to DELETE one node by UUID
813+
814+
// pull the captured string, if it exists
815+
QUuid deleteUUID = QUuid(nodeDeleteRegex.cap(1));
806816

807-
// pull the UUID from the url
808-
QUuid deleteUUID = QUuid(url.path().mid(URI_NODES.size() + sizeof('/')));
817+
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
809818

810-
if (!deleteUUID.isNull()) {
811-
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
819+
if (nodeToKill) {
820+
// start with a 200 response
821+
connection->respond(HTTPConnection::StatusCode200);
812822

813-
if (nodeToKill) {
814-
// start with a 200 response
815-
connection->respond(HTTPConnection::StatusCode200);
816-
817-
// we have a valid UUID and node - kill the node that has this assignment
818-
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
819-
820-
// successfully processed request
821-
return true;
822-
}
823+
// we have a valid UUID and node - kill the node that has this assignment
824+
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
825+
826+
// successfully processed request
827+
return true;
823828
}
824829

825-
// bad request, couldn't pull a node ID
826-
connection->respond(HTTPConnection::StatusCode400);
830+
return true;
831+
} else if (allNodesDeleteRegex.indexIn(url.path()) != -1) {
832+
qDebug() << "Received request to kill all nodes.";
833+
NodeList::getInstance()->eraseAllNodes();
827834

828835
return true;
829836
}

Diff for: libraries/shared/src/NodeList.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ NodeHash NodeList::getNodeHash() {
359359
return NodeHash(_nodeHash);
360360
}
361361

362-
void NodeList::clear() {
362+
void NodeList::eraseAllNodes() {
363363
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
364364

365365
QMutexLocker locker(&_nodeHashMutex);
@@ -373,7 +373,7 @@ void NodeList::clear() {
373373
}
374374

375375
void NodeList::reset() {
376-
clear();
376+
eraseAllNodes();
377377
_numNoReplyDomainCheckIns = 0;
378378

379379
// refresh the owner UUID to the NULL UUID

Diff for: libraries/shared/src/NodeList.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class NodeList : public QObject {
128128
void saveData(QSettings* settings);
129129
public slots:
130130
void reset();
131+
void eraseAllNodes();
131132

132133
void sendDomainServerCheckIn();
133134
void pingInactiveNodes();
@@ -154,8 +155,6 @@ private slots:
154155
const QUuid& connectionSecret);
155156

156157
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
157-
158-
void clear();
159158

160159
void processDomainServerAuthRequest(const QByteArray& packet);
161160
void requestAuthForDomainServer();

0 commit comments

Comments
 (0)