From 2e3026db91f30af7c153e2a2dd9c8d333fc8a6e3 Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Wed, 8 Feb 2017 10:25:10 +0100 Subject: [PATCH 1/2] Make it possible to remove failed coordinators --- js/actions/api-cluster.js | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/js/actions/api-cluster.js b/js/actions/api-cluster.js index 4fbd54713d..b0d3854f8b 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, From ad1c7e7c13e6fdfcdff091c6d11747fab1a8680d Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Wed, 8 Feb 2017 10:49:36 +0100 Subject: [PATCH 2/2] oh jslint --- js/actions/api-cluster.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/actions/api-cluster.js b/js/actions/api-cluster.js index b0d3854f8b..4db9c55463 100644 --- a/js/actions/api-cluster.js +++ b/js/actions/api-cluster.js @@ -94,11 +94,11 @@ actions.defineHttp({ } 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'}; + 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'}; @@ -106,7 +106,7 @@ actions.defineHttp({ try { global.ArangoAgency.write([[operations, preconditions]]); } catch (e) { - if (e.code == 412) { + if (e.code === 412) { actions.resultError(req, res, actions.HTTP_PRECONDITION_FAILED, 'you can only remove failed servers'); return;