diff --git a/js/actions/api-cluster.js b/js/actions/api-cluster.js index 4fbd54713d..4db9c55463 100644 --- a/js/actions/api-cluster.js +++ b/js/actions/api-cluster.js @@ -60,6 +60,68 @@ var _ = require('lodash'); // / @brief was docuBlock JSF_cluster_test_HEAD // ////////////////////////////////////////////////////////////////////////////// +actions.defineHttp({ + url: '_admin/cluster/removeServer', + allowUseDatabase: true, + prefix: false, + + callback: function (req, res) { + if (req.requestType !== actions.POST || + !require('@arangodb/cluster').isCoordinator()) { + actions.resultError(req, res, actions.HTTP_FORBIDDEN, 0, + 'only DELETE requests are allowed and only to coordinators'); + return; + } + + let serverId; + try { + serverId = JSON.parse(req.requestBody); + } catch (e) { + } + + if (typeof serverId !== 'string') { + actions.resultError(req, res, actions.HTTP_BAD, + 'required parameter ServerID was not given'); + return; + } + + let agency = ArangoAgency.get('', false, true).arango; + + if (agency.Current.DBServers[serverId] !== undefined) { + actions.resultError(req, res, actions.HTTP_BAD, + 'removing dbservers not yet supported'); + return; + } + + let operations = {}; + operations['/arango/Coordinators/' + serverId] = {'op': 'delete'}; + operations['/arango/DBServers/' + serverId] = {'op': 'delete'}; + operations['/arango/ServersRegistered/' + serverId] = {'op': 'delete'}; + operations['/arango/Supervision/Health/' + serverId] = {'op': 'delete'}; + operations['/arango/MapUniqueToShortID/' + serverId] = {'op': 'delete'}; + + let preconditions = {}; + preconditions['/arango/Supervision/Health/' + serverId + '/Status'] = {'old': 'FAILED'}; + + try { + global.ArangoAgency.write([[operations, preconditions]]); + } catch (e) { + if (e.code === 412) { + actions.resultError(req, res, actions.HTTP_PRECONDITION_FAILED, + 'you can only remove failed servers'); + return; + } + throw e; + } + + actions.resultOk(req, res, actions.HTTP_OK, true); + /*DBOnly: + + Current/Databases/YYY/XXX + */ + } +}); + actions.defineHttp({ url: '_admin/cluster-test', prefix: true,