Skip to content

Commit

Permalink
Merge pull request #2807 from chu11/issue2796
Browse files Browse the repository at this point in the history
cmd/flux-kvs: Remove legacy --json options and json output
  • Loading branch information
mergify[bot] committed Mar 9, 2020
2 parents 2dda84a + 522ba5e commit 175b5ed
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 351 deletions.
40 changes: 19 additions & 21 deletions doc/man1/flux-kvs.adoc
Expand Up @@ -59,39 +59,37 @@ Remove a kvs namespace.
*namespace list*::
List all current namespaces and info on each namespace.

*get* [-N ns] [-j|-r|-t] [-a treeobj] [-l] [-W] [-w] [-u] [-A] [-f] [-c count] 'key' ['key...']::
*get* [-N ns] [-r|-t] [-a treeobj] [-l] [-W] [-w] [-u] [-A] [-f] [-c count] 'key' ['key...']::
Retrieve the value stored under 'key'. If nothing has been stored
under 'key', display an error message. Specify an alternate namespace
to retrieve 'key' from via '-N'. If no options, value is displayed
with a newline appended (if value length is nonzero). If '-l', a
'key=' prefix is added. If '-j', value is interpreted as encoded JSON
and formatted accordingly. If '-r', value is displayed without a
newline. If '-t', the RFC 11 object is displayed. '-a treeobj'
causes the lookup to be relative to an RFC 11 snapshot reference. If
'-W' is specified and a key does not exist, wait until the key has
been created. If '-w', after the initial value, display the new value
each time the key is written to until interrupted, or if '-c count' is
'key=' prefix is added. If '-r', value is displayed without a newline.
If '-t', the RFC 11 object is displayed. '-a treeobj' causes the
lookup to be relative to an RFC 11 snapshot reference. If '-W' is
specified and a key does not exist, wait until the key has been
created. If '-w', after the initial value, display the new value each
time the key is written to until interrupted, or if '-c count' is
specified, until 'count' values have been displayed. If '-u' is
specified, only writes that change the key value will be displayed.
If '-A' is specified, only display appends that occur on a key.
By default, only a direct write to a key is monitored, which may miss
If '-A' is specified, only display appends that occur on a key. By
default, only a direct write to a key is monitored, which may miss
several unique situations, such as the replacement of an entire parent
directory. The '-f' option can be specified to monitor for many of
these special situations.

*put* [-N ns] [-O|-s] [-j|-r|-t] [-n] [-A] 'key=value' ['key=value...']::
*put* [-N ns] [-O|-s] [-r|-t] [-n] [-A] 'key=value' ['key=value...']::
Store 'value' under 'key' and commit it. Specify an alternate
namespace to commit value(s) via '-N'. If it already has a value,
overwrite it. If no options, value is stored directly. If '-j', it
is first encoded as JSON, then stored. If '-r' or '-t', the value may
optionally be read from standard input if specified as "-". If '-r',
the value may include embedded NULL bytes. If '-t', value is stored
as a RFC 11 object. '-n' prevents the commit from being merged with
with other contemporaneous commits. '-A' appends the value to a key
instead of overwriting the value. Append is incompatible with the -j
option. After a successful put, '-O' or '-s' can be specified to
output the RFC11 treeobj or root sequence number of the root
containing the put(s).
overwrite it. If no options, value is stored directly. If '-r' or
'-t', the value may optionally be read from standard input if
specified as "-". If '-r', the value may include embedded NULL bytes.
If '-t', value is stored as a RFC 11 object. '-n' prevents the commit
from being merged with with other contemporaneous commits. '-A'
appends the value to a key instead of overwriting the value. Append
is incompatible with the -j option. After a successful put, '-O' or
'-s' can be specified to output the RFC11 treeobj or root sequence
number of the root containing the put(s).

*ls* [-N ns] [-R] [-d] [-F] [-w COLS] [-1] ['key' ...]::
Display directory referred to by _key_, or "." (root) if unspecified.
Expand Down
94 changes: 4 additions & 90 deletions src/cmd/flux-kvs.c
Expand Up @@ -68,9 +68,6 @@ static struct optparse_option get_opts[] = {
{ .name = "namespace", .key = 'N', .has_arg = 1,
.usage = "Specify KVS namespace to use.",
},
{ .name = "json", .key = 'j', .has_arg = 0,
.usage = "Interpret value(s) as encoded JSON",
},
{ .name = "raw", .key = 'r', .has_arg = 0,
.usage = "Interpret value(s) as raw data",
},
Expand Down Expand Up @@ -114,9 +111,6 @@ static struct optparse_option put_opts[] = {
{ .name = "sequence", .key = 's', .has_arg = 0,
.usage = "Output root sequence of root containing puts",
},
{ .name = "json", .key = 'j', .has_arg = 0,
.usage = "Store value(s) as encoded JSON",
},
{ .name = "raw", .key = 'r', .has_arg = 0,
.usage = "Store value(s) as-is without adding NULL termination",
},
Expand Down Expand Up @@ -267,15 +261,15 @@ static struct optparse_subcommand subcommands[] = {
NULL,
},
{ "get",
"[-N ns] [-j|-r|-t] [-a treeobj] [-l] [-W] [-w] [-u] [-A] [-f] "
"[-N ns] [-r|-t] [-a treeobj] [-l] [-W] [-w] [-u] [-A] [-f] "
"[-c COUNT] key [key...]",
"Get value stored under key",
cmd_get,
0,
get_opts
},
{ "put",
"[-N ns] [-O|-s] [-j|-r|-t] [-n] [-A] key=value [key=value...]",
"[-N ns] [-O|-s] [-r|-t] [-n] [-A] key=value [key=value...]",
"Store value under key",
cmd_put,
0,
Expand Down Expand Up @@ -640,56 +634,6 @@ static void kv_printf (const char *key, int maxcol, const char *fmt, ...)
free (kv);
}

static void output_key_json_object (const char *key, json_t *o, int maxcol)
{
char *s;

switch (json_typeof (o)) {
case JSON_NULL:
kv_printf (key, maxcol, "nil");
break;
case JSON_TRUE:
kv_printf (key, maxcol, "true");
break;
case JSON_FALSE:
kv_printf (key, maxcol, "false");
break;
case JSON_REAL:
kv_printf (key, maxcol, "%f", json_real_value (o));
break;
case JSON_INTEGER:
kv_printf (key, maxcol, "%lld", (long long)json_integer_value (o));
break;
case JSON_STRING:
kv_printf (key, maxcol, "%s", json_string_value (o));
break;
case JSON_ARRAY:
case JSON_OBJECT:
default:
if (!(s = json_dumps (o, JSON_SORT_KEYS)))
log_msg_exit ("json_dumps failed");
kv_printf (key, maxcol, "%s", s);
free (s);
break;
}
}

static void output_key_json_str (const char *key,
const char *json_str,
const char *arg)
{
json_t *o;
json_error_t error;

if (!json_str)
json_str = "null";
if (!(o = json_loads (json_str, JSON_DECODE_ANY, &error)))
log_msg_exit ("%s: %s (line %d column %d)",
arg, error.text, error.line, error.column);
output_key_json_object (key, o, 0);
json_decref (o);
}

struct lookup_ctx {
optparse_t *p;
int maxcount;
Expand Down Expand Up @@ -717,16 +661,6 @@ void lookup_continuation (flux_future_t *f, void *arg)
printf ("%s=", key);
printf ("%s\n", treeobj);
}
else if (optparse_hasopt (ctx->p, "json")) {
const char *json_str;
if (flux_kvs_lookup_get (f, &json_str) < 0)
log_err_exit ("%s", key);
if (!json_str)
log_msg_exit ("%s: zero-length value", key);
if (optparse_hasopt (ctx->p, "label"))
printf ("%s=", key);
output_key_json_str (NULL, json_str, key);
}
else if (optparse_hasopt (ctx->p, "raw")) {
const void *data;
int len;
Expand Down Expand Up @@ -885,18 +819,6 @@ int cmd_put (optparse_t *p, int argc, char **argv)
log_err_exit ("%s", key);
free (buf);
}
else if (optparse_hasopt (p, "json")) {
json_t *obj;
if ((obj = json_loads (val, JSON_DECODE_ANY, NULL))) {
if (flux_kvs_txn_put (txn, 0, key, val) < 0)
log_err_exit ("%s", key);
json_decref (obj);
}
else { // encode as JSON string if not already valid encoded JSON
if (flux_kvs_txn_pack (txn, 0, key, "s", val) < 0)
log_err_exit ("%s", key);
}
}
else if (optparse_hasopt (p, "raw")) {
int len;
uint8_t *buf = NULL;
Expand Down Expand Up @@ -1218,18 +1140,10 @@ static char *process_key (const char *key)

static void dump_kvs_val (const char *key, int maxcol, const char *value)
{
json_t *o;

if (!value) {
if (!value)
kv_printf (key, maxcol, "");
}
else if ((o = json_loads (value, JSON_DECODE_ANY, NULL))) {
output_key_json_object (key, o, maxcol);
json_decref (o);
}
else {
else
kv_printf (key, maxcol, value);
}
}

static void dump_kvs_dir (const flux_kvsdir_t *dir, int maxcol,
Expand Down
2 changes: 1 addition & 1 deletion src/test/sched-bench.sh
Expand Up @@ -69,7 +69,7 @@ log "broker.pid=$(flux getattr broker.pid)\n"

# Reload scheduler so we can insert a fake resource set:
flux module remove sched-simple
flux kvs put --json \
flux kvs put \
resource.hwloc.by_rank="{\"[0-$(($NNODES-1))]\":{\"Core\":$CPN}}"
flux mini run --dry-run --setattr=system.exec.test.run_duration=.001s hostname \
> job.json
Expand Down
6 changes: 3 additions & 3 deletions t/issues/t0441-kvs-put-get.sh
Expand Up @@ -3,8 +3,8 @@

TEST=issue441

flux kvs put --json ${TEST}.x=foo
flux kvs put ${TEST}.x=foo

flux kvs get --json ${TEST}.x.y && test $? -eq 1
flux kvs get ${TEST}.x.y && test $? -eq 1

flux kvs get --json ${TEST}.x # fails if broker died
flux kvs get ${TEST}.x # fails if broker died
6 changes: 3 additions & 3 deletions t/issues/t0821-kvs-segfault.sh
Expand Up @@ -2,6 +2,6 @@
# kvs put test="large string", get test.x fails without panic

TEST=issue0821
flux kvs put --json ${TEST}="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
flux kvs get --json ${TEST}.x && test $? -eq 1
flux kvs get --json ${TEST} # fails if broker died
flux kvs put ${TEST}="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
flux kvs get ${TEST}.x && test $? -eq 1
flux kvs get ${TEST} # fails if broker died
4 changes: 2 additions & 2 deletions t/kvs/kvs-helper.sh
Expand Up @@ -20,7 +20,7 @@ loophandlereturn() {
# arg1 - key to retrieve
# arg2 - expected value
test_kvs_key() {
flux kvs get --json "$1" >output
flux kvs get "$1" >output
echo "$2" >expected
test_cmp expected output
}
Expand All @@ -29,7 +29,7 @@ test_kvs_key() {
# arg2 - key to retrieve
# arg3 - expected value
test_kvs_key_namespace() {
flux kvs get --namespace="$1" --json "$2" >output
flux kvs get --namespace="$1" "$2" >output
echo "$3" >expected
test_cmp expected output
}
Expand Down
2 changes: 1 addition & 1 deletion t/sharness.d/flux-sharness.sh
Expand Up @@ -158,7 +158,7 @@ TEST_NAME=$SHARNESS_TEST_NAME
export TEST_NAME

# Test requirements for testsuite
if ! run_timeout 1.0 lua -e 'require "posix"'; then
if ! run_timeout 10.0 lua -e 'require "posix"'; then
error "failed to find lua posix module in path"
fi

Expand Down
6 changes: 3 additions & 3 deletions t/t0017-security.t
Expand Up @@ -293,7 +293,7 @@ test_expect_success 'connector delivers kvs.namespace-primary-setroot event to o
$SHARNESS_TEST_SRCDIR/scripts/event-trace-bypass.lua \
kvs kvs.test.end \
"flux event pub kvs.test.a; \
flux kvs put --json ev9=42; \
flux kvs put ev9=42; \
flux event pub kvs.test.end" >ev9.out &&
grep -q kvs.namespace-primary-setroot ev9.out
'
Expand All @@ -303,7 +303,7 @@ test_expect_success 'dispatcher delivers kvs.namespace-primary-setroot event to
$SHARNESS_TEST_SRCDIR/scripts/event-trace.lua \
kvs kvs.test.end \
"flux event pub kvs.test.a; \
flux kvs put --json ev10=42; \
flux kvs put ev10=42; \
flux event pub kvs.test.end" >ev10.out &&
grep -q kvs.namespace-primary-setroot ev10.out
'
Expand All @@ -314,7 +314,7 @@ test_expect_success 'connector suppresses kvs.namespace-primary-setroot event to
$SHARNESS_TEST_SRCDIR/scripts/event-trace-bypass.lua \
kvs kvs.test.end \
"flux event pub kvs.test.a; \
flux kvs put --json ev11=42; \
flux kvs put ev11=42; \
flux event pub kvs.test.end" >ev11.out &&
! grep -q kvs.namespace-primary-setroot ev11.out
'
Expand Down

0 comments on commit 175b5ed

Please sign in to comment.