Skip to content

Commit

Permalink
dispatcher: new option for rpc list command to print more attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Apr 7, 2022
1 parent 2eac6a0 commit 68901fc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/modules/dispatcher/dispatcher.c
Expand Up @@ -1587,6 +1587,7 @@ static const char *dispatcher_rpc_list_doc[2] = {

#define DS_RPC_PRINT_NORMAL 1
#define DS_RPC_PRINT_SHORT 2
#define DS_RPC_PRINT_FULL 3

/**
*
Expand All @@ -1604,6 +1605,7 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle,
int j;
char c[3];
str data = STR_NULL;
char ipbuf[IP_ADDR_MAX_STRZ_SIZE];

if(!node)
return 0;
Expand Down Expand Up @@ -1644,11 +1646,26 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle,
else
c[1] = 'X';

if(rpc->struct_add(vh, "Ssd", "URI", &node->dlist[j].uri, "FLAGS",
c, "PRIORITY", node->dlist[j].priority)
< 0) {
rpc->fault(ctx, 500, "Internal error creating dest struct");
return -1;
}

if(mode == DS_RPC_PRINT_FULL) {
ipbuf[0] = '\0';
ip_addr2sbufz(&node->dlist[j].ip_address, ipbuf, IP_ADDR_MAX_STRZ_SIZE);
if(rpc->struct_add(vh, "Ssdd", "HOST", &node->dlist[j].host,
"IPADDR", ipbuf, "PORT", (int)node->dlist[j].port,
"PROTOID", (int)node->dlist[j].proto) < 0) {
rpc->fault(ctx, 500, "Internal error creating dest struct");
return -1;
}
}

if(mode != DS_RPC_PRINT_SHORT && node->dlist[j].attrs.body.s!=NULL) {
if(rpc->struct_add(vh, "Ssd{", "URI", &node->dlist[j].uri,
"FLAGS", c,
"PRIORITY", node->dlist[j].priority,
"ATTRS", &wh) < 0) {
if(rpc->struct_add(vh, "{", "ATTRS", &wh) < 0) {
rpc->fault(ctx, 500, "Internal error creating dest struct");
return -1;
}
Expand All @@ -1669,13 +1686,6 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle,
rpc->fault(ctx, 500, "Internal error creating attrs struct");
return -1;
}
} else {
if(rpc->struct_add(vh, "Ssd", "URI", &node->dlist[j].uri, "FLAGS",
c, "PRIORITY", node->dlist[j].priority)
< 0) {
rpc->fault(ctx, 500, "Internal error creating dest struct");
return -1;
}
}
if (ds_ping_latency_stats) {
if(rpc->struct_add(vh, "{", "LATENCY", &lh) < 0) {
Expand Down Expand Up @@ -1722,6 +1732,8 @@ static void dispatcher_rpc_list(rpc_t *rpc, void *ctx)
if(n == 1) {
if(smode.len==5 && strncasecmp(smode.s, "short", 5)==0) {
vmode = DS_RPC_PRINT_SHORT;
} else if(smode.len==4 && strncasecmp(smode.s, "full", 4)==0) {
vmode = DS_RPC_PRINT_FULL;
}
}

Expand Down

0 comments on commit 68901fc

Please sign in to comment.