add a button on DS admin page to kill all nodes

This commit is contained in:
Stephen Birarda 2014-03-26 11:37:30 -07:00
parent 0d0784ef4b
commit cb617c9e17
5 changed files with 49 additions and 25 deletions

View file

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

View file

@ -49,4 +49,18 @@ $(document).ready(function(){
}
});
});
$(document.body).on('click', '#kill-all-btn', function() {
var confirmed_kill = confirm("Are you sure?");
if (confirmed_kill == true) {
$.ajax({
url: "/nodes/",
type: 'DELETE',
success: function(result) {
console.log("Successful request to delete all nodes.");
}
});
}
});
});

View file

@ -657,6 +657,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
const QString URI_ASSIGNMENT = "/assignment";
const QString URI_NODES = "/nodes";
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}";
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
if (url.path() == "/assignments.json") {
// user is asking for json list of assignments
@ -726,9 +728,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
return true;
} else {
const QString NODE_REGEX_STRING =
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);
QRegExp nodeShowRegex(NODE_REGEX_STRING);
const QString NODE_JSON_REGEX_STRING = QString("\\%1\\/(%2).json\\/?$").arg(URI_NODES).arg(UUID_REGEX_STRING);
QRegExp nodeShowRegex(NODE_JSON_REGEX_STRING);
if (nodeShowRegex.indexIn(url.path()) != -1) {
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
@ -801,29 +802,35 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
return true;
}
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
if (url.path().startsWith(URI_NODES)) {
// this is a request to DELETE a node by UUID
const QString ALL_NODE_DELETE_REGEX_STRING = QString("\\%1\\/?$").arg(URI_NODES);
const QString NODE_DELETE_REGEX_STRING = QString("\\%1\\/(%2)\\/$").arg(URI_NODES).arg(UUID_REGEX_STRING);
QRegExp allNodesDeleteRegex(ALL_NODE_DELETE_REGEX_STRING);
QRegExp nodeDeleteRegex(NODE_DELETE_REGEX_STRING);
if (nodeDeleteRegex.indexIn(url.path()) != -1) {
// this is a request to DELETE one node by UUID
// pull the UUID from the url
QUuid deleteUUID = QUuid(url.path().mid(URI_NODES.size() + sizeof('/')));
// pull the captured string, if it exists
QUuid deleteUUID = QUuid(nodeDeleteRegex.cap(1));
if (!deleteUUID.isNull()) {
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
SharedNodePointer nodeToKill = NodeList::getInstance()->nodeWithUUID(deleteUUID);
if (nodeToKill) {
// start with a 200 response
connection->respond(HTTPConnection::StatusCode200);
if (nodeToKill) {
// start with a 200 response
connection->respond(HTTPConnection::StatusCode200);
// we have a valid UUID and node - kill the node that has this assignment
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
// successfully processed request
return true;
}
// we have a valid UUID and node - kill the node that has this assignment
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
// successfully processed request
return true;
}
// bad request, couldn't pull a node ID
connection->respond(HTTPConnection::StatusCode400);
return true;
} else if (allNodesDeleteRegex.indexIn(url.path()) != -1) {
qDebug() << "Received request to kill all nodes.";
NodeList::getInstance()->eraseAllNodes();
return true;
}

View file

@ -359,7 +359,7 @@ NodeHash NodeList::getNodeHash() {
return NodeHash(_nodeHash);
}
void NodeList::clear() {
void NodeList::eraseAllNodes() {
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
QMutexLocker locker(&_nodeHashMutex);
@ -373,7 +373,7 @@ void NodeList::clear() {
}
void NodeList::reset() {
clear();
eraseAllNodes();
_numNoReplyDomainCheckIns = 0;
// refresh the owner UUID to the NULL UUID

View file

@ -128,6 +128,7 @@ public:
void saveData(QSettings* settings);
public slots:
void reset();
void eraseAllNodes();
void sendDomainServerCheckIn();
void pingInactiveNodes();
@ -154,8 +155,6 @@ private:
const QUuid& connectionSecret);
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
void clear();
void processDomainServerAuthRequest(const QByteArray& packet);
void requestAuthForDomainServer();