Repository: trafficserver
Updated Branches:
refs/heads/master 95f45d4a7 -> 0e703e1e3
TS-3800: HostDB UI: support json output, improve srv records, add hostnames
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0e703e1e
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0e703e1e
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0e703e1e
Branch: refs/heads/master
Commit: 0e703e1e3b7198f5c4b0648971fd35d56421e4fd
Parents: 95f45d4
Author: Brian Geffon
Authored: Mon Jul 27 22:14:09 2015 -0700
Committer: Brian Geffon
Committed: Mon Jul 27 22:14:09 2015 -0700
--
iocore/hostdb/HostDB.cc | 169 ++---
iocore/hostdb/I_HostDBProcessor.h | 3 +
proxy/Show.h | 16 +++-
3 files changed, 153 insertions(+), 35 deletions(-)
--
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0e703e1e/iocore/hostdb/HostDB.cc
--
diff --git a/iocore/hostdb/HostDB.cc b/iocore/hostdb/HostDB.cc
index 9d5ece3..5a9c85a 100644
--- a/iocore/hostdb/HostDB.cc
+++ b/iocore/hostdb/HostDB.cc
@@ -1364,6 +1364,12 @@ HostDBContinuation::lookup_done(IpAddr const &ip, char
const *aname, bool around
}
}
}
+
+ const size_t s_size = strlen(aname) + 1;
+ void *host_dest = hostDB.alloc(&i->hostname_offset, s_size);
+ ink_strlcpy((char *)host_dest, aname, s_size);
+ *((char *)host_dest + s_size) = '\0';
+
if (from_cont)
do_put_response(from, i, from_cont);
ink_assert(!i->round_robin || !i->reverse_dns);
@@ -2311,6 +2317,17 @@ HostDBInfo::hostname()
return (char *)hostDB.ptr(&data.hostname_offset,
hostDB.ptr_to_partition((char *)this));
}
+/*
+ * The perm_hostname exists for all records not just reverse dns records.
+ */
+char *
+HostDBInfo::perm_hostname()
+{
+ if (hostname_offset == 0)
+return NULL;
+
+ return (char *)hostDB.ptr(&hostname_offset, hostDB.ptr_to_partition((char
*)this));
+}
HostDBRoundRobin *
HostDBInfo::rr()
@@ -2373,6 +2390,8 @@ struct ShowHostDB : public ShowCont {
uint16_t port;
IpEndpoint ip;
bool force;
+ bool output_json;
+ int records_seen;
int
showMain(int event, Event *e)
@@ -2412,8 +2431,12 @@ struct ShowHostDB : public ShowCont {
int
showAll(int event, Event *e)
{
-CHECK_SHOW(begin("HostDB All Records"));
-CHECK_SHOW(show(""));
+if (!output_json) {
+ CHECK_SHOW(begin("HostDB All Records"));
+ CHECK_SHOW(show(""));
+} else {
+ CHECK_SHOW(show("["));
+}
SET_HANDLER(&ShowHostDB::showAllEvent);
hostDBProcessor.iterate(this);
return EVENT_CONT;
@@ -2424,22 +2447,54 @@ struct ShowHostDB : public ShowCont {
{
if (event == EVENT_INTERVAL) {
HostDBInfo *r = reinterpret_cast(e);
+ if (output_json && records_seen++ > 0) {
+CHECK_SHOW(show(",")); // we need to seperate records
+ }
showOne(r, false, event, e);
if (r->round_robin) {
HostDBRoundRobin *rr_data = r->rr();
if (rr_data) {
- CHECK_SHOW(show("\n"));
- CHECK_SHOW(show("%s%d\n", "Total",
rr_data->rrcount));
- CHECK_SHOW(show("%s%d\n", "Good",
rr_data->good));
- CHECK_SHOW(show("%s%d\n", "Current",
rr_data->current));
- CHECK_SHOW(show("\n"));
+ if (!output_json) {
+CHECK_SHOW(show("\n"));
+CHECK_SHOW(show("%s%d\n", "Total",
rr_data->rrcount));
+CHECK_SHOW(show("%s%d\n", "Good",
rr_data->good));
+CHECK_SHOW(show("%s%d\n", "Current",
rr_data->current));
+CHECK_SHOW(show("\n"));
+ } else {
+CHECK_SHOW(show(",\"%s\":\"%d\",", "rr_total", rr_data->rrcount));
+CHECK_SHOW(show("\"%s\":\"%d\",", "rr_good", rr_data->good));
+CHECK_SHOW(show("\"%s\":\"%d\",", "rr_current", rr_data->current));
+CHECK_SHOW(show("\"rr_records\":["));
+ }
- for (int i = 0; i < rr_data->rrcount; i++)
-showOne(&rr_data->info[i], true, event, e);
+ for (int i = 0; i < rr_data->rrcount; i++) {
+showOne(&rr_data->info[i], true, event, e, rr_data);
+if (output_json) {
+ CHECK_SHOW(show("}")); // we need to seperate records
+ if (i < (rr_data->rrcount - 1))
+CHECK_SHOW(show(","));
+}
+ }
+
+ if (!output_json) {
+CHECK_SHOW(show("\n\n"));
+ } else {
+CHECK_SHOW(show("]"));
+ }
}
}
+
+ if (output_json) {
+CHECK_SHOW(show("}"));
+ }
+
} else if (event == EVENT_DONE) {
- return complete(event, e);
+ if (output_json) {
+CHECK_SHOW(show("]"));
+