Skip to content

Commit

Permalink
rgw: add support for the healthcheck feature of Swift API.
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
  • Loading branch information
rzarzynski committed Jul 14, 2016
1 parent d34b1ee commit a3c0406
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common/config_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ OPTION(rgw_keystone_revocation_interval, OPT_INT, 15 * 60) // seconds between t
OPTION(rgw_keystone_verify_ssl, OPT_BOOL, true) // should we try to verify keystone's ssl
OPTION(rgw_keystone_implicit_tenants, OPT_BOOL, false) // create new users in their own tenants of the same name
OPTION(rgw_cross_domain_policy, OPT_STR, "<allow-access-from domain=\"*\" secure=\"false\" />")
OPTION(rgw_healthcheck_disabling_path, OPT_STR, "") // path that existence causes the healthcheck to respond 503
OPTION(rgw_s3_auth_use_rados, OPT_BOOL, true) // should we try to use the internal credentials for s3?
OPTION(rgw_s3_auth_use_keystone, OPT_BOOL, false) // should we try to use keystone for s3?

Expand Down
1 change: 1 addition & 0 deletions src/rgw/rgw_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ enum RGWOpType {
RGW_OP_BULK_DELETE,
RGW_OP_SET_ATTRS,
RGW_OP_GET_CROSS_DOMAIN_POLICY,
RGW_OP_GET_HEALTH_CHECK,

/* rgw specific */
RGW_OP_ADMIN_SET_METADATA
Expand Down
3 changes: 3 additions & 0 deletions src/rgw/rgw_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ int main(int argc, const char **argv)
set_logging(new RGWRESTMgr_SWIFT_CrossDomain));
}

swift_resource->register_resource("healthcheck",
set_logging(new RGWRESTMgr_SWIFT_HealthCheck));

if (! swift_at_root) {
rest.register_resource(g_conf->rgw_swift_url_prefix,
set_logging(swift_resource));
Expand Down
11 changes: 11 additions & 0 deletions src/rgw/rgw_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <errno.h>
#include <stdlib.h>
#include <unistd.h>

#include <sstream>

Expand Down Expand Up @@ -4568,6 +4569,16 @@ void RGWListBucketMultiparts::execute()
}
}

void RGWGetHealthCheck::execute()
{
if (! g_conf->rgw_healthcheck_disabling_path.empty() &&
::access(g_conf->rgw_healthcheck_disabling_path.c_str(), F_OK )) {
op_ret = -ERR_SERVICE_UNAVAILABLE;
} else {
op_ret = 0; /* 200 OK */
}
}

int RGWDeleteMultiObj::verify_permission()
{
if (!verify_bucket_permission(s, RGW_PERM_WRITE))
Expand Down
25 changes: 25 additions & 0 deletions src/rgw/rgw_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,31 @@ class RGWGetCrossDomainPolicy : public RGWOp {
};


class RGWGetHealthCheck : public RGWOp {
public:
RGWGetHealthCheck() = default;
~RGWGetHealthCheck() = default;

int verify_permission() override {
return 0;
}

void execute() override;

const string name() override {
return "get_health_check";
}

RGWOpType get_type() override {
return RGW_OP_GET_HEALTH_CHECK;
}

uint32_t op_mask() override {
return RGW_OP_TYPE_READ;
}
};


class RGWDeleteMultiObj : public RGWOp {
protected:
int max_to_delete;
Expand Down
6 changes: 6 additions & 0 deletions src/rgw/rgw_rest.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ class RGWGetCrossDomainPolicy_ObjStore : public RGWGetCrossDomainPolicy {
~RGWGetCrossDomainPolicy_ObjStore() = default;
};

class RGWGetHealthCheck_ObjStore : public RGWGetHealthCheck {
public:
RGWGetHealthCheck_ObjStore() = default;
~RGWGetHealthCheck_ObjStore() = default;
};

class RGWCopyObj_ObjStore : public RGWCopyObj {
public:
RGWCopyObj_ObjStore() {}
Expand Down
12 changes: 11 additions & 1 deletion src/rgw/rgw_rest_swift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,6 @@ void RGWBulkDelete_ObjStore_SWIFT::send_response()
rgw_flush_formatter_and_reset(s, s->formatter);
}


void RGWGetCrossDomainPolicy_ObjStore_SWIFT::send_response()
{
set_req_state_err(s, op_ret);
Expand All @@ -1367,6 +1366,17 @@ void RGWGetCrossDomainPolicy_ObjStore_SWIFT::send_response()
STREAM_IO(s)->write(ss.str().c_str(), ss.str().length());
}

void RGWGetHealthCheck_ObjStore_SWIFT::send_response()
{
set_req_state_err(s, op_ret);
dump_errno(s);
end_header(s, this, "application/xml");

if (op_ret) {
STREAM_IO(s)->print("DISABLED BY FILE");
}
}

RGWOp *RGWHandler_REST_Service_SWIFT::op_get()
{
return new RGWListBuckets_ObjStore_SWIFT;
Expand Down
62 changes: 62 additions & 0 deletions src/rgw/rgw_rest_swift.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,15 @@ class RGWGetCrossDomainPolicy_ObjStore_SWIFT
void send_response() override;
};

class RGWGetHealthCheck_ObjStore_SWIFT
: public RGWGetHealthCheck_ObjStore {
public:
RGWGetHealthCheck_ObjStore_SWIFT() = default;
~RGWGetHealthCheck_ObjStore_SWIFT() = default;

void send_response() override;
};

class RGWHandler_SWIFT_CrossDomain : public RGWHandler_REST {
public:
RGWHandler_SWIFT_CrossDomain() = default;
Expand Down Expand Up @@ -333,4 +342,57 @@ class RGWRESTMgr_SWIFT_CrossDomain : public RGWRESTMgr {
};


class RGWHandler_SWIFT_HealthCheck : public RGWHandler_REST {
public:
RGWHandler_SWIFT_HealthCheck() = default;
~RGWHandler_SWIFT_HealthCheck() = default;

RGWOp *op_get() override {
return new RGWGetHealthCheck_ObjStore_SWIFT();
}

int init(RGWRados* const store,
struct req_state* const state,
RGWClientIO* const cio) override {
state->dialect = "swift";
state->formatter = new JSONFormatter;
state->format = RGW_FORMAT_JSON;

return RGWHandler::init(store, state, cio);
}

int authorize() override {
return 0;
}

int postauth_init() override {
return 0;
}

int read_permissions(RGWOp *) override {
return 0;
}

virtual RGWAccessControlPolicy *alloc_policy() { return nullptr; }
virtual void free_policy(RGWAccessControlPolicy *policy) {}
};

class RGWRESTMgr_SWIFT_HealthCheck : public RGWRESTMgr {
public:
RGWRESTMgr_SWIFT_HealthCheck() = default;
~RGWRESTMgr_SWIFT_HealthCheck() = default;

RGWRESTMgr *get_resource_mgr(struct req_state* const s,
const std::string& uri,
std::string* const out_uri) override {
return this;
}

RGWHandler_REST* get_handler(struct req_state* const s) override {
s->prot_flags |= RGW_REST_SWIFT;
return new RGWHandler_SWIFT_HealthCheck;
}
};


#endif

0 comments on commit a3c0406

Please sign in to comment.