]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rest_opstate.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
14 #include "common/ceph_json.h"
15 #include "common/strtol.h"
18 #include "rgw_rest_s3.h"
19 #include "rgw_rest_opstate.h"
20 #include "rgw_client_io.h"
21 #include "common/errno.h"
22 #include "include/assert.h"
24 #define dout_context g_ceph_context
25 #define OPSTATE_LIST_MAX_ENTRIES 1000
26 #define dout_subsys ceph_subsys_rgw
28 void RGWOp_Opstate_List::execute() {
29 string client_id
= s
->info
.args
.get("client-id"),
30 op_id
= s
->info
.args
.get("op-id"),
31 object
= s
->info
.args
.get("object"),
32 max_entries_str
= s
->info
.args
.get("max-entries");
33 unsigned max_entries
= OPSTATE_LIST_MAX_ENTRIES
;
35 if (!max_entries_str
.empty()) {
37 max_entries
= (unsigned)strict_strtol(max_entries_str
.c_str(), 10, &err
);
39 dout(5) << "Error parsing max-entries " << max_entries_str
<< dendl
;
45 RGWOpState oc
= RGWOpState(store
);
48 list
<cls_statelog_entry
> entries
;
50 oc
.init_list_entries(client_id
, op_id
, object
, &handle
);
55 int ret
= oc
.list_entries(handle
, max_entries
, entries
, &done
);
58 dout(5) << "oc.list_entries failed with error " << ret
<< dendl
;
60 oc
.finish_list_entries(handle
);
64 if (!max_entries_str
.empty())
65 max_entries
-= entries
.size();
67 send_response(entries
);
68 } while (!done
&& max_entries
> 0);
70 oc
.finish_list_entries(handle
);
74 void RGWOp_Opstate_List::send_response() {
78 set_req_state_err(s
, http_ret
);
87 s
->formatter
->open_array_section("entries");
90 void RGWOp_Opstate_List::send_response(list
<cls_statelog_entry
> entries
) {
92 for (list
<cls_statelog_entry
>::iterator it
= entries
.begin();
93 it
!= entries
.end(); ++it
) {
94 oc
.dump_entry(*it
, s
->formatter
);
99 void RGWOp_Opstate_List::send_response_end() {
100 s
->formatter
->close_section();
104 void RGWOp_Opstate_Set::execute() {
105 string client_id
= s
->info
.args
.get("client-id"),
106 op_id
= s
->info
.args
.get("op-id"),
107 object
= s
->info
.args
.get("object"),
108 state_str
= s
->info
.args
.get("state");
110 if (client_id
.empty() ||
114 dout(5) << "Error - invalid parameter list" << dendl
;
119 RGWOpState
oc(store
);
120 RGWOpState::OpState state
;
122 http_ret
= oc
.state_from_str(state_str
, &state
);
124 dout(5) << "Error - invalid state" << dendl
;
128 http_ret
= oc
.set_state(client_id
, op_id
, object
, state
);
130 dout(5) << "Error - Unable to set state" << dendl
;
135 void RGWOp_Opstate_Renew::execute() {
136 string client_id
= s
->info
.args
.get("client-id"),
137 op_id
= s
->info
.args
.get("op-id"),
138 object
= s
->info
.args
.get("object"),
139 state_str
= s
->info
.args
.get("state");
141 if (client_id
.empty() ||
145 dout(5) << "Error - invalid parameter list" << dendl
;
149 RGWOpState
oc(store
);
150 RGWOpState::OpState state
;
152 http_ret
= oc
.state_from_str(state_str
, &state
);
154 dout(5) << "Error - invalid state" << dendl
;
158 http_ret
= oc
.renew_state(client_id
, op_id
, object
, state
);
160 dout(5) << "Error - Unable to renew state" << dendl
;
165 void RGWOp_Opstate_Delete::execute() {
166 string client_id
= s
->info
.args
.get("client-id"),
167 op_id
= s
->info
.args
.get("op-id"),
168 object
= s
->info
.args
.get("object");
170 if (client_id
.empty() ||
173 dout(5) << "Error - invalid parameter list" << dendl
;
178 RGWOpState
oc(store
);
180 http_ret
= oc
.remove_entry(client_id
, op_id
, object
);
182 dout(5) << "Error - Unable to remove entry" << dendl
;
186 RGWOp
*RGWHandler_Opstate::op_post() {
187 if (s
->info
.args
.exists("renew")) {
188 return new RGWOp_Opstate_Renew
;
190 return new RGWOp_Opstate_Set
;