mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 17:00:13 +02:00
Merge pull request #2514 from birarda/kill-node-button
add a button on DS admin page to kill all nodes
This commit is contained in:
commit
9d8089a7d1
5 changed files with 49 additions and 25 deletions
|
@ -1,5 +1,9 @@
|
||||||
<!--#include file="header.html"-->
|
<!--#include file="header.html"-->
|
||||||
<div id="nodes-lead" class="table-lead"><h3>Nodes</h3><div class="lead-line"></div></div>
|
<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">
|
<table id="nodes-table" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -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.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -657,6 +657,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
const QString URI_ASSIGNMENT = "/assignment";
|
const QString URI_ASSIGNMENT = "/assignment";
|
||||||
const QString URI_NODES = "/nodes";
|
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 (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
||||||
if (url.path() == "/assignments.json") {
|
if (url.path() == "/assignments.json") {
|
||||||
// user is asking for json list of assignments
|
// user is asking for json list of assignments
|
||||||
|
@ -726,9 +728,8 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const QString NODE_REGEX_STRING =
|
const QString NODE_JSON_REGEX_STRING = QString("\\%1\\/(%2).json\\/?$").arg(URI_NODES).arg(UUID_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_JSON_REGEX_STRING);
|
||||||
QRegExp nodeShowRegex(NODE_REGEX_STRING);
|
|
||||||
|
|
||||||
if (nodeShowRegex.indexIn(url.path()) != -1) {
|
if (nodeShowRegex.indexIn(url.path()) != -1) {
|
||||||
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
|
QUuid matchingUUID = QUuid(nodeShowRegex.cap(1));
|
||||||
|
@ -801,29 +802,35 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
|
} else if (connection->requestOperation() == QNetworkAccessManager::DeleteOperation) {
|
||||||
if (url.path().startsWith(URI_NODES)) {
|
const QString ALL_NODE_DELETE_REGEX_STRING = QString("\\%1\\/?$").arg(URI_NODES);
|
||||||
// this is a request to DELETE a node by UUID
|
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
|
// pull the captured string, if it exists
|
||||||
QUuid deleteUUID = QUuid(url.path().mid(URI_NODES.size() + sizeof('/')));
|
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) {
|
// we have a valid UUID and node - kill the node that has this assignment
|
||||||
// start with a 200 response
|
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
|
||||||
connection->respond(HTTPConnection::StatusCode200);
|
|
||||||
|
// successfully processed request
|
||||||
// we have a valid UUID and node - kill the node that has this assignment
|
return true;
|
||||||
QMetaObject::invokeMethod(NodeList::getInstance(), "killNodeWithUUID", Q_ARG(const QUuid&, deleteUUID));
|
|
||||||
|
|
||||||
// successfully processed request
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bad request, couldn't pull a node ID
|
return true;
|
||||||
connection->respond(HTTPConnection::StatusCode400);
|
} else if (allNodesDeleteRegex.indexIn(url.path()) != -1) {
|
||||||
|
qDebug() << "Received request to kill all nodes.";
|
||||||
|
NodeList::getInstance()->eraseAllNodes();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,7 +359,7 @@ NodeHash NodeList::getNodeHash() {
|
||||||
return NodeHash(_nodeHash);
|
return NodeHash(_nodeHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::clear() {
|
void NodeList::eraseAllNodes() {
|
||||||
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
|
qDebug() << "Clearing the NodeList. Deleting all nodes in list.";
|
||||||
|
|
||||||
QMutexLocker locker(&_nodeHashMutex);
|
QMutexLocker locker(&_nodeHashMutex);
|
||||||
|
@ -373,7 +373,7 @@ void NodeList::clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeList::reset() {
|
void NodeList::reset() {
|
||||||
clear();
|
eraseAllNodes();
|
||||||
_numNoReplyDomainCheckIns = 0;
|
_numNoReplyDomainCheckIns = 0;
|
||||||
|
|
||||||
// refresh the owner UUID to the NULL UUID
|
// refresh the owner UUID to the NULL UUID
|
||||||
|
|
|
@ -128,6 +128,7 @@ public:
|
||||||
void saveData(QSettings* settings);
|
void saveData(QSettings* settings);
|
||||||
public slots:
|
public slots:
|
||||||
void reset();
|
void reset();
|
||||||
|
void eraseAllNodes();
|
||||||
|
|
||||||
void sendDomainServerCheckIn();
|
void sendDomainServerCheckIn();
|
||||||
void pingInactiveNodes();
|
void pingInactiveNodes();
|
||||||
|
@ -154,8 +155,6 @@ private:
|
||||||
const QUuid& connectionSecret);
|
const QUuid& connectionSecret);
|
||||||
|
|
||||||
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
NodeHash::iterator killNodeAtHashIterator(NodeHash::iterator& nodeItemToKill);
|
||||||
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
void processDomainServerAuthRequest(const QByteArray& packet);
|
void processDomainServerAuthRequest(const QByteArray& packet);
|
||||||
void requestAuthForDomainServer();
|
void requestAuthForDomainServer();
|
||||||
|
|
Loading…
Reference in a new issue