2 #include "cls/rgw/cls_rgw_types.h"
3 #include "common/ceph_json.h"
4 #include "include/utime.h"
7 void rgw_bucket_pending_info::generate_test_instances(list<rgw_bucket_pending_info*>& o)
9 rgw_bucket_pending_info *i = new rgw_bucket_pending_info;
10 i->state = CLS_RGW_STATE_COMPLETE;
11 i->op = CLS_RGW_OP_DEL;
13 o.push_back(new rgw_bucket_pending_info);
16 void rgw_bucket_pending_info::dump(Formatter *f) const
18 encode_json("state", (int)state, f);
19 utime_t ut(timestamp);
20 encode_json("timestamp", ut, f);
21 encode_json("op", (int)op, f);
24 void rgw_bucket_pending_info::decode_json(JSONObj *obj) {
26 JSONDecoder::decode_json("state", val, obj);
27 state = (RGWPendingState)val;
28 utime_t ut(timestamp);
29 JSONDecoder::decode_json("timestamp", ut, obj);
30 JSONDecoder::decode_json("op", val, obj);
34 void cls_rgw_obj_key::decode_json(JSONObj *obj) {
35 JSONDecoder::decode_json("name", name, obj);
36 JSONDecoder::decode_json("instance", instance, obj);
39 void rgw_bucket_dir_entry_meta::generate_test_instances(list<rgw_bucket_dir_entry_meta*>& o)
41 rgw_bucket_dir_entry_meta *m = new rgw_bucket_dir_entry_meta;
46 m->owner_display_name = "display name";
47 m->content_type = "content/type";
49 o.push_back(new rgw_bucket_dir_entry_meta);
52 void rgw_bucket_dir_entry_meta::dump(Formatter *f) const
54 encode_json("category", (int)category, f);
55 encode_json("size", size, f);
57 encode_json("mtime", ut, f);
58 encode_json("etag", etag, f);
59 encode_json("owner", owner, f);
60 encode_json("owner_display_name", owner_display_name, f);
61 encode_json("content_type", content_type, f);
62 encode_json("accounted_size", accounted_size, f);
63 encode_json("user_data", user_data, f);
66 void rgw_bucket_dir_entry_meta::decode_json(JSONObj *obj) {
68 JSONDecoder::decode_json("category", val, obj);
69 category = (uint8_t)val;
70 JSONDecoder::decode_json("size", size, obj);
72 JSONDecoder::decode_json("mtime", ut, obj);
73 JSONDecoder::decode_json("etag", etag, obj);
74 JSONDecoder::decode_json("owner", owner, obj);
75 JSONDecoder::decode_json("owner_display_name", owner_display_name, obj);
76 JSONDecoder::decode_json("content_type", content_type, obj);
77 JSONDecoder::decode_json("accounted_size", accounted_size, obj);
78 JSONDecoder::decode_json("user_data", user_data, obj);
81 void rgw_bucket_dir_entry::generate_test_instances(list<rgw_bucket_dir_entry*>& o)
83 list<rgw_bucket_dir_entry_meta *> l;
84 rgw_bucket_dir_entry_meta::generate_test_instances(l);
86 list<rgw_bucket_dir_entry_meta *>::iterator iter;
87 for (iter = l.begin(); iter != l.end(); ++iter) {
88 rgw_bucket_dir_entry_meta *m = *iter;
89 rgw_bucket_dir_entry *e = new rgw_bucket_dir_entry;
93 e->locator = "locator";
102 o.push_back(new rgw_bucket_dir_entry);
105 void rgw_bucket_entry_ver::dump(Formatter *f) const
107 encode_json("pool", pool, f);
108 encode_json("epoch", epoch, f);
111 void rgw_bucket_entry_ver::decode_json(JSONObj *obj) {
112 JSONDecoder::decode_json("pool", pool, obj);
113 JSONDecoder::decode_json("epoch", epoch, obj);
116 void rgw_bucket_entry_ver::generate_test_instances(list<rgw_bucket_entry_ver*>& ls)
118 ls.push_back(new rgw_bucket_entry_ver);
119 ls.push_back(new rgw_bucket_entry_ver);
120 ls.back()->pool = 123;
121 ls.back()->epoch = 12322;
125 void rgw_bucket_dir_entry::dump(Formatter *f) const
127 encode_json("name", key.name, f);
128 encode_json("instance", key.instance , f);
129 encode_json("ver", ver , f);
130 encode_json("locator", locator , f);
131 encode_json("exists", exists , f);
132 encode_json("meta", meta , f);
133 encode_json("tag", tag , f);
134 encode_json("flags", (int)flags , f);
135 encode_json("pending_map", pending_map, f);
136 encode_json("versioned_epoch", versioned_epoch , f);
139 void rgw_bucket_dir_entry::decode_json(JSONObj *obj) {
140 JSONDecoder::decode_json("name", key.name, obj);
141 JSONDecoder::decode_json("instance", key.instance , obj);
142 JSONDecoder::decode_json("ver", ver , obj);
143 JSONDecoder::decode_json("locator", locator , obj);
144 JSONDecoder::decode_json("exists", exists , obj);
145 JSONDecoder::decode_json("meta", meta , obj);
146 JSONDecoder::decode_json("tag", tag , obj);
148 JSONDecoder::decode_json("flags", val , obj);
149 flags = (uint16_t)val;
150 JSONDecoder::decode_json("pending_map", pending_map, obj);
151 JSONDecoder::decode_json("versioned_epoch", versioned_epoch, obj);
154 static void dump_bi_entry(bufferlist bl, BIIndexType index_type, Formatter *formatter)
156 bufferlist::iterator iter = bl.begin();
157 switch (index_type) {
161 rgw_bucket_dir_entry entry;
162 ::decode(entry, iter);
163 encode_json("entry", entry, formatter);
168 rgw_bucket_olh_entry entry;
169 ::decode(entry, iter);
170 encode_json("entry", entry, formatter);
178 void rgw_cls_bi_entry::decode_json(JSONObj *obj, cls_rgw_obj_key *effective_key) {
179 JSONDecoder::decode_json("idx", idx, obj);
181 JSONDecoder::decode_json("type", s, obj);
184 } else if (s == "instance") {
186 } else if (s == "olh") {
195 rgw_bucket_dir_entry entry;
196 JSONDecoder::decode_json("entry", entry, obj);
197 ::encode(entry, data);
200 *effective_key = entry.key;
206 rgw_bucket_olh_entry entry;
207 JSONDecoder::decode_json("entry", entry, obj);
208 ::encode(entry, data);
211 *effective_key = entry.key;
220 void rgw_cls_bi_entry::dump(Formatter *f) const
228 type_str = "instance";
234 type_str = "invalid";
236 encode_json("type", type_str, f);
237 encode_json("idx", idx, f);
238 dump_bi_entry(data, type, f);
241 bool rgw_cls_bi_entry::get_info(cls_rgw_obj_key *key, uint8_t *category, rgw_bucket_category_stats *accounted_stats)
243 bool account = false;
244 bufferlist::iterator iter = data.begin();
249 rgw_bucket_dir_entry entry;
250 ::decode(entry, iter);
252 *category = entry.meta.category;
253 accounted_stats->num_entries++;
254 accounted_stats->total_size += entry.meta.accounted_size;
255 accounted_stats->total_size_rounded += cls_rgw_get_rounded_size(entry.meta.accounted_size);
261 rgw_bucket_olh_entry entry;
262 ::decode(entry, iter);
273 void rgw_bucket_olh_entry::dump(Formatter *f) const
275 encode_json("key", key, f);
276 encode_json("delete_marker", delete_marker, f);
277 encode_json("epoch", epoch, f);
278 encode_json("pending_log", pending_log, f);
279 encode_json("tag", tag, f);
280 encode_json("exists", exists, f);
281 encode_json("pending_removal", pending_removal, f);
284 void rgw_bucket_olh_entry::decode_json(JSONObj *obj)
286 JSONDecoder::decode_json("key", key, obj);
287 JSONDecoder::decode_json("delete_marker", delete_marker, obj);
288 JSONDecoder::decode_json("epoch", epoch, obj);
289 JSONDecoder::decode_json("pending_log", pending_log, obj);
290 JSONDecoder::decode_json("tag", tag, obj);
291 JSONDecoder::decode_json("exists", exists, obj);
292 JSONDecoder::decode_json("pending_removal", pending_removal, obj);
295 void rgw_bucket_olh_log_entry::generate_test_instances(list<rgw_bucket_olh_log_entry*>& o)
297 rgw_bucket_olh_log_entry *entry = new rgw_bucket_olh_log_entry;
299 entry->op = CLS_RGW_OLH_OP_LINK_OLH;
300 entry->op_tag = "op_tag";
301 entry->key.name = "key.name";
302 entry->key.instance = "key.instance";
303 entry->delete_marker = true;
305 o.push_back(new rgw_bucket_olh_log_entry);
308 void rgw_bucket_olh_log_entry::dump(Formatter *f) const
310 encode_json("epoch", epoch, f);
313 case CLS_RGW_OLH_OP_LINK_OLH:
316 case CLS_RGW_OLH_OP_UNLINK_OLH:
317 op_str = "unlink_olh";
319 case CLS_RGW_OLH_OP_REMOVE_INSTANCE:
320 op_str = "remove_instance";
325 encode_json("op", op_str, f);
326 encode_json("op_tag", op_tag, f);
327 encode_json("key", key, f);
328 encode_json("delete_marker", delete_marker, f);
331 void rgw_bucket_olh_log_entry::decode_json(JSONObj *obj)
333 JSONDecoder::decode_json("epoch", epoch, obj);
335 JSONDecoder::decode_json("op", op_str, obj);
336 if (op_str == "link_olh") {
337 op = CLS_RGW_OLH_OP_LINK_OLH;
338 } else if (op_str == "unlink_olh") {
339 op = CLS_RGW_OLH_OP_UNLINK_OLH;
340 } else if (op_str == "remove_instance") {
341 op = CLS_RGW_OLH_OP_REMOVE_INSTANCE;
343 op = CLS_RGW_OLH_OP_UNKNOWN;
345 JSONDecoder::decode_json("op_tag", op_tag, obj);
346 JSONDecoder::decode_json("key", key, obj);
347 JSONDecoder::decode_json("delete_marker", delete_marker, obj);
349 void rgw_bi_log_entry::decode_json(JSONObj *obj)
351 JSONDecoder::decode_json("op_id", id, obj);
352 JSONDecoder::decode_json("op_tag", tag, obj);
354 JSONDecoder::decode_json("op", op_str, obj);
355 if (op_str == "write") {
357 } else if (op_str == "del") {
359 } else if (op_str == "cancel") {
360 op = CLS_RGW_OP_CANCEL;
361 } else if (op_str == "unknown") {
362 op = CLS_RGW_OP_UNKNOWN;
363 } else if (op_str == "link_olh") {
364 op = CLS_RGW_OP_LINK_OLH;
365 } else if (op_str == "link_olh_del") {
366 op = CLS_RGW_OP_LINK_OLH_DM;
367 } else if (op_str == "unlink_instance") {
368 op = CLS_RGW_OP_UNLINK_INSTANCE;
369 } else if (op_str == "syncstop") {
370 op = CLS_RGW_OP_SYNCSTOP;
371 } else if (op_str == "resync") {
372 op = CLS_RGW_OP_RESYNC;
374 op = CLS_RGW_OP_UNKNOWN;
376 JSONDecoder::decode_json("object", object, obj);
377 JSONDecoder::decode_json("instance", instance, obj);
379 JSONDecoder::decode_json("state", state_str, obj);
380 if (state_str == "pending") {
381 state = CLS_RGW_STATE_PENDING_MODIFY;
382 } else if (state_str == "complete") {
383 state = CLS_RGW_STATE_COMPLETE;
385 state = CLS_RGW_STATE_UNKNOWN;
387 JSONDecoder::decode_json("index_ver", index_ver, obj);
389 JSONDecoder::decode_json("timestamp", ut, obj);
390 timestamp = ut.to_real_time();
392 JSONDecoder::decode_json("bilog_flags", f, obj);
393 JSONDecoder::decode_json("ver", ver, obj);
394 bilog_flags = (uint16_t)f;
395 JSONDecoder::decode_json("owner", owner, obj);
396 JSONDecoder::decode_json("owner_display_name", owner_display_name, obj);
397 JSONDecoder::decode_json("zones_trace", zones_trace, obj);
400 void rgw_bi_log_entry::dump(Formatter *f) const
402 f->dump_string("op_id", id);
403 f->dump_string("op_tag", tag);
406 f->dump_string("op", "write");
409 f->dump_string("op", "del");
411 case CLS_RGW_OP_CANCEL:
412 f->dump_string("op", "cancel");
414 case CLS_RGW_OP_UNKNOWN:
415 f->dump_string("op", "unknown");
417 case CLS_RGW_OP_LINK_OLH:
418 f->dump_string("op", "link_olh");
420 case CLS_RGW_OP_LINK_OLH_DM:
421 f->dump_string("op", "link_olh_del");
423 case CLS_RGW_OP_UNLINK_INSTANCE:
424 f->dump_string("op", "unlink_instance");
426 case CLS_RGW_OP_SYNCSTOP:
427 f->dump_string("op", "syncstop");
429 case CLS_RGW_OP_RESYNC:
430 f->dump_string("op", "resync");
433 f->dump_string("op", "invalid");
437 f->dump_string("object", object);
438 f->dump_string("instance", instance);
441 case CLS_RGW_STATE_PENDING_MODIFY:
442 f->dump_string("state", "pending");
444 case CLS_RGW_STATE_COMPLETE:
445 f->dump_string("state", "complete");
448 f->dump_string("state", "invalid");
452 f->dump_int("index_ver", index_ver);
453 utime_t ut(timestamp);
454 ut.gmtime_nsec(f->dump_stream("timestamp"));
455 f->open_object_section("ver");
458 f->dump_int("bilog_flags", bilog_flags);
459 f->dump_bool("versioned", (bilog_flags & RGW_BILOG_FLAG_VERSIONED_OP) != 0);
460 f->dump_string("owner", owner);
461 f->dump_string("owner_display_name", owner_display_name);
462 encode_json("zones_trace", zones_trace, f);
465 void rgw_bi_log_entry::generate_test_instances(list<rgw_bi_log_entry*>& ls)
467 ls.push_back(new rgw_bi_log_entry);
468 ls.push_back(new rgw_bi_log_entry);
469 ls.back()->id = "midf";
470 ls.back()->object = "obj";
471 ls.back()->timestamp = ceph::real_clock::from_ceph_timespec({2, 3});
472 ls.back()->index_ver = 4323;
473 ls.back()->tag = "tagasdfds";
474 ls.back()->op = CLS_RGW_OP_DEL;
475 ls.back()->state = CLS_RGW_STATE_PENDING_MODIFY;
478 void rgw_bucket_category_stats::generate_test_instances(list<rgw_bucket_category_stats*>& o)
480 rgw_bucket_category_stats *s = new rgw_bucket_category_stats;
481 s->total_size = 1024;
482 s->total_size_rounded = 4096;
484 s->actual_size = 1024;
486 o.push_back(new rgw_bucket_category_stats);
489 void rgw_bucket_category_stats::dump(Formatter *f) const
491 f->dump_unsigned("total_size", total_size);
492 f->dump_unsigned("total_size_rounded", total_size_rounded);
493 f->dump_unsigned("num_entries", num_entries);
494 f->dump_unsigned("actual_size", actual_size);
497 void rgw_bucket_dir_header::generate_test_instances(list<rgw_bucket_dir_header*>& o)
499 list<rgw_bucket_category_stats *> l;
500 list<rgw_bucket_category_stats *>::iterator iter;
501 rgw_bucket_category_stats::generate_test_instances(l);
504 for (i = 0, iter = l.begin(); iter != l.end(); ++iter, ++i) {
505 rgw_bucket_dir_header *h = new rgw_bucket_dir_header;
506 rgw_bucket_category_stats *s = *iter;
514 o.push_back(new rgw_bucket_dir_header);
517 void rgw_bucket_dir_header::dump(Formatter *f) const
519 f->dump_int("ver", ver);
520 f->dump_int("master_ver", master_ver);
521 map<uint8_t, struct rgw_bucket_category_stats>::const_iterator iter = stats.begin();
522 f->open_array_section("stats");
523 for (; iter != stats.end(); ++iter) {
524 f->dump_int("category", (int)iter->first);
525 f->open_object_section("category_stats");
526 iter->second.dump(f);
529 ::encode_json("new_instance", new_instance, f);
533 void rgw_bucket_dir::generate_test_instances(list<rgw_bucket_dir*>& o)
535 list<rgw_bucket_dir_header *> l;
536 list<rgw_bucket_dir_header *>::iterator iter;
537 rgw_bucket_dir_header::generate_test_instances(l);
540 for (i = 0, iter = l.begin(); iter != l.end(); ++iter, ++i) {
541 rgw_bucket_dir *d = new rgw_bucket_dir;
542 rgw_bucket_dir_header *h = *iter;
545 list<rgw_bucket_dir_entry *> el;
546 list<rgw_bucket_dir_entry *>::iterator eiter;
547 for (eiter = el.begin(); eiter != el.end(); ++eiter) {
548 rgw_bucket_dir_entry *e = *eiter;
549 d->m[e->key.name] = *e;
559 o.push_back(new rgw_bucket_dir);
562 void rgw_bucket_dir::dump(Formatter *f) const
564 f->open_object_section("header");
567 map<string, struct rgw_bucket_dir_entry>::const_iterator iter = m.begin();
568 f->open_array_section("map");
569 for (; iter != m.end(); ++iter) {
570 f->dump_string("key", iter->first);
571 f->open_object_section("dir_entry");
572 iter->second.dump(f);
578 void cls_rgw_reshard_entry::generate_key(const string& tenant, const string& bucket_name, string *key)
580 *key = tenant + ":" + bucket_name;
583 void cls_rgw_reshard_entry::get_key(string *key) const
585 generate_key(tenant, bucket_name, key);
588 void cls_rgw_reshard_entry::dump(Formatter *f) const
591 encode_json("time",ut, f);
592 encode_json("tenant", tenant, f);
593 encode_json("bucket_name", bucket_name, f);
594 encode_json("bucket_id", bucket_id, f);
595 encode_json("new_instance_id", new_instance_id, f);
596 encode_json("old_num_shards", old_num_shards, f);
597 encode_json("new_num_shards", new_num_shards, f);
601 void cls_rgw_reshard_entry::generate_test_instances(list<cls_rgw_reshard_entry*>& ls)
603 ls.push_back(new cls_rgw_reshard_entry);
604 ls.push_back(new cls_rgw_reshard_entry);
605 ls.back()->time = ceph::real_clock::from_ceph_timespec({2, 3});
606 ls.back()->tenant = "tenant";
607 ls.back()->bucket_name = "bucket1""";
608 ls.back()->bucket_id = "bucket_id";
609 ls.back()->new_instance_id = "new_instance_id";
610 ls.back()->old_num_shards = 8;
611 ls.back()->new_num_shards = 64;
614 void cls_rgw_bucket_instance_entry::dump(Formatter *f) const
616 encode_json("reshard_status", (int)reshard_status, f);
617 encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
618 encode_json("num_shards", num_shards, f);
622 void cls_rgw_bucket_instance_entry::generate_test_instances(list<cls_rgw_bucket_instance_entry*>& ls)
624 ls.push_back(new cls_rgw_bucket_instance_entry);
625 ls.push_back(new cls_rgw_bucket_instance_entry);
626 ls.back()->reshard_status = CLS_RGW_RESHARD_IN_PROGRESS;
627 ls.back()->new_bucket_instance_id = "new_instance_id";