You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2020/01/21 11:05:02 UTC

[couchdb] branch master updated: Add POST /_node//_config/_reload

This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ac0673  Add POST /_node/<node>/_config/_reload
2ac0673 is described below

commit 2ac0673824dff1606e04741d83cd14964fb60481
Author: Will Holley <wi...@gmail.com>
AuthorDate: Mon Jan 20 17:02:36 2020 +0000

    Add POST /_node/<node>/_config/_reload
    
    Using the backend port 5986 it was possible to reload config from disk
    using the _config/_reload endpoint. This ports it to the _node API
    on the frontend cluster port.
---
 src/chttpd/src/chttpd_node.erl   | 10 ++++++++++
 test/elixir/test/config_test.exs |  7 +++++++
 2 files changed, 17 insertions(+)

diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 2020702..acd5aff 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -46,6 +46,16 @@ handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_config">>]}=Req) -
     send_json(Req, 200, {KVs});
 handle_node_req(#httpd{path_parts=[_, _Node, <<"_config">>]}=Req) ->
     send_method_not_allowed(Req, "GET");
+% POST /_node/$node/_config/_reload - Flushes unpersisted config values from RAM
+handle_node_req(#httpd{method='POST', path_parts=[_, Node, <<"_config">>, <<"_reload">>]}=Req) ->
+    case call_node(Node, config, reload, []) of
+        ok ->
+            send_json(Req, 200, {[{ok, true}]});
+        {error, Reason} ->
+            chttpd:send_error(Req, {bad_request, Reason})
+    end;
+handle_node_req(#httpd{path_parts=[_, _Node, <<"_config">>, <<"_reload">>]}=Req) ->
+    send_method_not_allowed(Req, "POST");
 % GET /_node/$node/_config/Section
 handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_config">>, Section]}=Req) ->
     KVs = [{list_to_binary(Key), list_to_binary(Value)}
diff --git a/test/elixir/test/config_test.exs b/test/elixir/test/config_test.exs
index 2b2d714..53c5bc8 100644
--- a/test/elixir/test/config_test.exs
+++ b/test/elixir/test/config_test.exs
@@ -174,4 +174,11 @@ defmodule ConfigTest do
       set_config(context, section, "wohali", "rules", 403)
     end)
   end
+
+  test "Reload config", context do
+    url = "#{context[:config_url]}/_reload"
+    resp = Couch.post(url)
+
+    assert resp.status_code == 200
+  end
 end