summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2019-08-26 16:54:38 -0300
committerEric Avdey <eiri@eiri.ca>2019-08-26 16:55:41 -0300
commit376c24e3337d3939d4970dcfd9dcf5d6f76caa2d (patch)
treeed9870f201daac98e74a01c1e4030510d0388c00
parentfddc7eec2debf5f3195095d73f86543bf88e6312 (diff)
downloadcouchdb-prototype/readiness-end-point.tar.gz
Add new _ready end-pointprototype/readiness-end-point
Add new _ready end-point similar to _up, but with a check for fdb availability.
-rw-r--r--src/chttpd/src/chttpd_auth_request.erl2
-rw-r--r--src/chttpd/src/chttpd_httpd_handlers.erl1
-rw-r--r--src/chttpd/src/chttpd_misc.erl14
3 files changed, 17 insertions, 0 deletions
diff --git a/src/chttpd/src/chttpd_auth_request.erl b/src/chttpd/src/chttpd_auth_request.erl
index 7210905f0..9dec218c4 100644
--- a/src/chttpd/src/chttpd_auth_request.erl
+++ b/src/chttpd/src/chttpd_auth_request.erl
@@ -84,6 +84,8 @@ authorize_request_int(#httpd{path_parts=[_DbName|_]}=Req) ->
server_authorization_check(#httpd{path_parts=[<<"_up">>]}=Req) ->
Req;
+server_authorization_check(#httpd{path_parts=[<<"_ready">>]}=Req) ->
+ Req;
server_authorization_check(#httpd{path_parts=[<<"_uuids">>]}=Req) ->
Req;
server_authorization_check(#httpd{path_parts=[<<"_session">>]}=Req) ->
diff --git a/src/chttpd/src/chttpd_httpd_handlers.erl b/src/chttpd/src/chttpd_httpd_handlers.erl
index 000f29b2f..5cec5079f 100644
--- a/src/chttpd/src/chttpd_httpd_handlers.erl
+++ b/src/chttpd/src/chttpd_httpd_handlers.erl
@@ -27,6 +27,7 @@ url_handler(<<"_replicate">>) -> fun chttpd_misc:handle_replicate_req/1;
url_handler(<<"_uuids">>) -> fun chttpd_misc:handle_uuids_req/1;
url_handler(<<"_session">>) -> fun chttpd_auth:handle_session_req/1;
url_handler(<<"_up">>) -> fun chttpd_misc:handle_up_req/1;
+url_handler(<<"_ready">>) -> fun chttpd_misc:handle_ready_req/1;
url_handler(_) -> no_match.
db_handler(<<"_view_cleanup">>) -> fun chttpd_db:handle_view_cleanup_req/2;
diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl
index 11d2c5b72..57a15f00d 100644
--- a/src/chttpd/src/chttpd_misc.erl
+++ b/src/chttpd/src/chttpd_misc.erl
@@ -23,6 +23,7 @@
handle_system_req/1,
handle_task_status_req/1,
handle_up_req/1,
+ handle_ready_req/1,
handle_utils_dir_req/1,
handle_utils_dir_req/2,
handle_uuids_req/1,
@@ -510,6 +511,19 @@ handle_up_req(#httpd{method='GET'} = Req) ->
handle_up_req(Req) ->
send_method_not_allowed(Req, "GET,HEAD").
+
+handle_ready_req(#httpd{method='GET'} = Req) ->
+ try
+ fabric2_db:list_dbs([{limit, 0}]),
+ send_json(Req, 200, {[{status, ready}]})
+ catch error:{timeout, _} ->
+ send_json(Req, 404, {[{status, unavailable}]})
+ end;
+
+handle_ready_req(Req) ->
+ send_method_not_allowed(Req, "GET,HEAD").
+
+
message_queues(Registered) ->
lists:map(fun(Name) ->
Type = message_queue_len,