summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_rest_opstate.cc
diff options
context:
space:
mode:
authorBabu Shanmugam <anbu@enovance.com>2013-06-24 15:24:32 +0200
committerBabu Shanmugam <anbu@enovance.com>2013-06-24 15:24:32 +0200
commit626d9eed649846af265c35e99a76e136621da4b4 (patch)
tree2e4316da452ff681374370e83bef14f2172429bc /src/rgw/rgw_rest_opstate.cc
parentradosgw-admin: interface to control ops state (diff)
downloadceph-626d9eed649846af265c35e99a76e136621da4b4.tar.xz
ceph-626d9eed649846af265c35e99a76e136621da4b4.zip
opstate RESTful API implementation with unit test application
Signed-off-by: Babu Shanmugam <anbu@enovance.com>
Diffstat (limited to 'src/rgw/rgw_rest_opstate.cc')
-rw-r--r--src/rgw/rgw_rest_opstate.cc171
1 files changed, 171 insertions, 0 deletions
diff --git a/src/rgw/rgw_rest_opstate.cc b/src/rgw/rgw_rest_opstate.cc
new file mode 100644
index 00000000000..f9af580c9e9
--- /dev/null
+++ b/src/rgw/rgw_rest_opstate.cc
@@ -0,0 +1,171 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation. See file COPYING.
+ *
+ */
+#include "common/ceph_json.h"
+#include "common/strtol.h"
+#include "rgw_rest.h"
+#include "rgw_op.h"
+#include "rgw_rest_s3.h"
+#include "rgw_rest_opstate.h"
+#include "rgw_client_io.h"
+#include "common/errno.h"
+
+#define OPSTATE_LIST_MAX_ENTRIES 1000
+#define dout_subsys ceph_subsys_rgw
+
+void RGWOp_Opstate_List::execute() {
+ string client_id = s->info.args.get("client_id"),
+ op_id = s->info.args.get("op_id"),
+ object = s->info.args.get("object"),
+ max_entries_str = s->info.args.get("max-entries");
+ unsigned max_entries = OPSTATE_LIST_MAX_ENTRIES;
+
+ if (!max_entries_str.empty()) {
+ string err;
+ max_entries = (unsigned)strict_strtol(max_entries_str.c_str(), 10, &err);
+ if (!err.empty()) {
+ dout(5) << "Error parsing max-entries " << max_entries_str << dendl;
+ http_ret = -EINVAL;
+ return;
+ }
+ }
+
+ RGWOpState oc = RGWOpState(store);
+ void *handle;
+ bool done;
+
+ oc.init_list_entries(client_id, op_id, object, &handle);
+
+ do {
+ int ret = oc.list_entries(handle, max_entries, entries, &done);
+
+ if (ret < 0) {
+ dout(5) << "oc.list_entries failed with error " << ret << dendl;
+ http_ret = ret;
+ oc.finish_list_entries(handle);
+ return;
+ }
+
+ if (!max_entries_str.empty())
+ max_entries -= entries.size();
+
+ } while (!done && max_entries > 0);
+
+ oc.finish_list_entries(handle);
+ http_ret = 0;
+}
+
+void RGWOp_Opstate_List::send_response() {
+ set_req_state_err(s, http_ret);
+ dump_errno(s);
+ end_header(s);
+
+ s->formatter->open_array_section("entries");
+ RGWOpState oc(store);
+ for (list<cls_statelog_entry>::iterator it = entries.begin();
+ it != entries.end(); it++) {
+ oc.dump_entry(*it, s->formatter);
+ flusher.flush();
+ }
+ s->formatter->close_section();
+ flusher.flush();
+}
+
+void RGWOp_Opstate_Set::execute() {
+ string client_id = s->info.args.get("client_id"),
+ op_id = s->info.args.get("op_id"),
+ object = s->info.args.get("object"),
+ state_str = s->info.args.get("state");
+
+ if (client_id.empty() ||
+ op_id.empty() ||
+ object.empty() ||
+ state_str.empty()) {
+ dout(5) << "Error - invalid parameter list" << dendl;
+ http_ret = -EINVAL;
+ return;
+ }
+
+ RGWOpState oc(store);
+ RGWOpState::OpState state;
+
+ http_ret = oc.state_from_str(state_str, &state);
+ if (http_ret < 0) {
+ dout(5) << "Error - invalid state" << dendl;
+ return;
+ }
+
+ http_ret = oc.set_state(client_id, op_id, object, state);
+ if (http_ret < 0) {
+ dout(5) << "Error - Unable to set state" << dendl;
+ return;
+ }
+}
+
+void RGWOp_Opstate_Renew::execute() {
+ string client_id = s->info.args.get("client_id"),
+ op_id = s->info.args.get("op_id"),
+ object = s->info.args.get("object"),
+ state_str = s->info.args.get("state");
+
+ if (client_id.empty() ||
+ op_id.empty() ||
+ object.empty() ||
+ state_str.empty()) {
+ dout(5) << "Error - invalid parameter list" << dendl;
+ http_ret = -EINVAL;
+ return;
+ }
+ RGWOpState oc(store);
+ RGWOpState::OpState state;
+
+ http_ret = oc.state_from_str(state_str, &state);
+ if (http_ret < 0) {
+ dout(5) << "Error - invalid state" << dendl;
+ return;
+ }
+
+ http_ret = oc.renew_state(client_id, op_id, object, state);
+ if (http_ret < 0) {
+ dout(5) << "Error - Unable to renew state" << dendl;
+ return;
+ }
+}
+
+void RGWOp_Opstate_Delete::execute() {
+ string client_id = s->info.args.get("client_id"),
+ op_id = s->info.args.get("op_id"),
+ object = s->info.args.get("object");
+
+ if (client_id.empty() ||
+ op_id.empty() ||
+ object.empty()) {
+ dout(5) << "Error - invalid parameter list" << dendl;
+ http_ret = -EINVAL;
+ return;
+ }
+
+ RGWOpState oc(store);
+
+ http_ret = oc.remove_entry(client_id, op_id, object);
+ if (http_ret < 0) {
+ dout(5) << "Error - Unable to remove entry" << dendl;
+ }
+}
+
+RGWOp *RGWHandler_Opstate::op_post() {
+ if (s->info.args.exists("renew")) {
+ return new RGWOp_Opstate_Renew;
+ }
+ return new RGWOp_Opstate_Set;
+}