osd = OSDS[0]
# retrieve all objects from all PGs
- cmd = (CFSD_PREFIX + "--op list").format(osd=osd)
+ cmd = (CFSD_PREFIX + "--op list --pretty-format=false").format(osd=osd)
logging.debug(cmd);
tmpfd = open(TMPFILE, "a")
logging.debug(cmd)
(pgid, jsondict) = json.loads(JSONOBJ[0])[0]
# retrieve all objects in a given PG
- cmd = (CFSD_PREFIX + "--op list --pgid {pg}").format(osd=osd, pg=pgid)
+ cmd = (CFSD_PREFIX + "--op list --pgid {pg} --pretty-format=false").format(osd=osd, pg=pgid)
logging.debug(cmd);
tmpfd = open(OTHERFILE, "a")
logging.debug(cmd)
ERRORS += 1
# retrieve all objects with a given name in a given PG
- cmd = (CFSD_PREFIX + "--op list --pgid {pg} {object}").format(osd=osd, pg=pgid, object=jsondict['oid'])
+ cmd = (CFSD_PREFIX + "--op list --pgid {pg} {object} --pretty-format=false").format(osd=osd, pg=pgid, object=jsondict['oid'])
logging.debug(cmd);
tmpfd = open(OTHERFILE, "a")
logging.debug(cmd)
"from the first line of --op list --pgid {pg} {object}".format(pg=pgid, object=jsondict['oid']))
ERRORS += 1
- print "Test --op list by generating json for all objects"
+ print "Test --op list by generating json for all objects using default format"
for pg in ALLPGS:
OSDS = get_osds(pg, OSDDIR)
for osd in OSDS:
lines = get_lines(TMPFILE)
JSONOBJ = sorted(set(lines))
for JSON in JSONOBJ:
- for (pgid, jsondict) in json.loads(JSON):
- db[jsondict['namespace']][jsondict['oid']]['json'] = json.dumps((pgid, jsondict))
- if string.find(jsondict['oid'], EC_NAME) == 0 and 'shard_id' not in jsondict:
- logging.error("Malformed JSON {json}".format(json=JSON))
- ERRORS += 1
+ (pgid, jsondict) = json.loads(JSON)
+ db[jsondict['namespace']][jsondict['oid']]['json'] = json.dumps((pgid, jsondict))
+ # print db[jsondict['namespace']][jsondict['oid']]['json']
+ if string.find(jsondict['oid'], EC_NAME) == 0 and 'shard_id' not in jsondict:
+ logging.error("Malformed JSON {json}".format(json=JSON))
+ ERRORS += 1
# Test get-bytes
print "Test get-bytes and set-bytes"
_objects.push_back(make_pair(coll, ghobj));
}
- void dump(Formatter *f) const {
- bool terminal = isatty(STDOUT_FILENO);
- if (!terminal)
+ void dump(Formatter *f, bool human_readable) const {
+ if (!human_readable)
f->open_array_section("pgid_objects");
for (list<pair<coll_t, ghobject_t> >::const_iterator i = _objects.begin();
i != _objects.end();
i++) {
- if (i != _objects.begin() && terminal) {
+ if (i != _objects.begin() && human_readable) {
f->flush(cout);
cout << std::endl;
}
f->close_section();
f->close_section();
}
- if (!terminal)
+ if (!human_readable)
f->close_section();
}
};
return front;
}
- void dump(Formatter *f) const {
- _objects.dump(f);
+ void dump(Formatter *f, bool human_readable) const {
+ _objects.dump(f, human_readable);
}
};
return 0;
}
-int do_list(ObjectStore *store, string pgidstr, string object, Formatter *formatter, bool debug)
+int do_list(ObjectStore *store, string pgidstr, string object, Formatter *formatter, bool debug, bool human_readable)
{
int r;
lookup_ghobject lookup(object);
}
if (r)
return r;
- lookup.dump(formatter);
+ lookup.dump(formatter, human_readable);
formatter->flush(cout);
cout << std::endl;
return 0;
int main(int argc, char **argv)
{
- string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type;
+ string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format;
spg_t pgid;
ghobject_t ghobj;
+ bool pretty_format, human_readable;
po::options_description desc("Allowed options");
desc.add_options()
"Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects]")
("file", po::value<string>(&file),
"path of file to export or import")
+ ("pretty-format", po::value<bool>(&pretty_format)->default_value(true),
+ "Make json or xml output more readable")
+ ("format", po::value<string>(&format)->default_value("json"),
+ "Output format which may be xml or json")
("debug", "Enable diagnostic output to stderr")
("skip-journal-replay", "Disable journal replay")
("skip-mount-omap", "Disable mounting of omap")
goto out;
}
+ // Special list handling. Treating pretty_format as human readable,
+ // with one object per line and not an enclosing array.
+ human_readable = pretty_format;
if (op == "list") {
- Formatter *formatter = new JSONFormatter(false);
- r = do_list(fs, pgidstr, object, formatter, debug);
+ pretty_format = false;
+ }
+
+ Formatter *formatter;
+ if (format == "xml") {
+ formatter = new XMLFormatter(pretty_format);
+ } else if (format == "json") {
+ formatter = new JSONFormatter(pretty_format);
+ } else {
+ cerr << "unrecognized format: " << format << std::endl;
+ ret = 1;
+ goto out;
+ }
+
+ if (op == "list") {
+ r = do_list(fs, pgidstr, object, formatter, debug, human_readable);
if (r) {
cerr << "do_list failed with " << r << std::endl;
ret = 1;
usage(desc);
}
- Formatter *formatter = new JSONFormatter(true);
bufferlist bl;
map_epoch = PG::peek_map_epoch(fs, coll, infos_oid, &bl);
if (debug)