Skip to content

Commit

Permalink
readers: make most JGF vertex metadata optional
Browse files Browse the repository at this point in the history
Problem: as described in flux-framework#1255, JGF is too large and unwieldy,
with lots of redundant and repeated data.

To begin to cut back, make most vertex metadata optional.
  • Loading branch information
jameshcorbett committed Sep 24, 2024
1 parent ff0505e commit ffd548a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
55 changes: 42 additions & 13 deletions resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct fetch_helper_t : public fetch_remap_support_t {
int exclusive = -1;
resource_pool_t::status_t status = resource_pool_t::status_t::UP;
const char *type = NULL;
const char *name = NULL;
std::string name;
const char *unit = NULL;
const char *basename = NULL;
const char *vertex_id = NULL;
Expand Down Expand Up @@ -119,7 +119,7 @@ void fetch_remap_support_t::clear ()

const char *fetch_helper_t::get_proper_name () const
{
return (is_name_remapped ()) ? get_remapped_name ().c_str () : name;
return (is_name_remapped ()) ? get_remapped_name ().c_str () : name.c_str ();
}

int64_t fetch_helper_t::get_proper_id () const
Expand All @@ -141,7 +141,7 @@ void fetch_helper_t::scrub ()
exclusive = -1;
status = resource_pool_t::status_t::UP;
type = NULL;
name = NULL;
name.clear ();
unit = NULL;
basename = NULL;
vertex_id = NULL;
Expand Down Expand Up @@ -341,35 +341,66 @@ int resource_reader_jgf_t::remap_aware_unpack_vtx (fetch_helper_t &f,
return 0;
}

int resource_reader_jgf_t::apply_defaults (fetch_helper_t &f, const char *name)
{
if (f.uniq_id == -1) {
try {
f.uniq_id = static_cast<int64_t> (std::stoll (std::string{f.vertex_id}));
} catch (std::invalid_argument const &ex) {
m_err_msg += __FUNCTION__;
m_err_msg += ": value for key (uniq_id) could not be inferred from outer ";
m_err_msg += "'id' field " + std::string (f.vertex_id) + ".\n";
return -1;
}
}
if (f.id == -1)
f.id = f.uniq_id;
if (f.exclusive == -1)
f.exclusive = 0;
if (f.size == -1)
f.size = 1;
if (f.basename == NULL)
f.basename = f.type;
if (name == NULL) {
f.name = f.basename;
f.name.append (std::to_string (f.id));
} else {
f.name = name;
}
if (f.unit == NULL)
f.unit = "";
return 0;
}

int resource_reader_jgf_t::fill_fetcher (json_t *element,
fetch_helper_t &f,
json_t **paths,
json_t **properties)
{
int rc = -1;
json_t *metadata = NULL;
const char *name = NULL;

if ((json_unpack (element, "{ s:s }", "id", &f.vertex_id) < 0)) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": JGF vertex id key is not found in a node.\n";
goto done;
return -1;
}
if ((metadata = json_object_get (element, "metadata")) == NULL) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": key (metadata) is not found in an JGF node for ";
m_err_msg += std::string (f.vertex_id) + ".\n";
goto done;
return -1;
}
if ((json_unpack (metadata,
"{ s:s s:s s:s s:I s:I s:I s?:i s:b s:s s:I s:o s?o }",
"{ s:s s?s s?s s?I s?I s?I s?i s?b s?s s?I s:o s?o }",
"type",
&f.type,
"basename",
&f.basename,
"name",
&f.name,
&name,
"id",
&f.id,
"uniq_id",
Expand All @@ -393,18 +424,16 @@ int resource_reader_jgf_t::fill_fetcher (json_t *element,
m_err_msg += __FUNCTION__;
m_err_msg += ": malformed metadata in an JGF node for ";
m_err_msg += std::string (f.vertex_id) + "\n";
goto done;
return -1;
}
if (*properties && !json_is_object (*properties)) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": key (properties) must be an object or null for ";
m_err_msg += std::string (f.vertex_id) + ".\n";
goto done;
return -1;
}
rc = 0;
done:
return rc;
return apply_defaults (f, name);
}

int resource_reader_jgf_t::unpack_vtx (json_t *element, fetch_helper_t &f)
Expand Down
1 change: 1 addition & 0 deletions resource/readers/resource_reader_jgf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class resource_reader_jgf_t : public resource_reader_base_t {
int fetch_jgf (const std::string &str, json_t **jgf_p, json_t **nodes_p, json_t **edges_p);
int unpack_and_remap_vtx (fetch_helper_t &f, json_t *paths, json_t *properties);
int remap_aware_unpack_vtx (fetch_helper_t &f, json_t *paths, json_t *properties);
int apply_defaults (fetch_helper_t &f, const char *name);
int fill_fetcher (json_t *element, fetch_helper_t &f, json_t **path, json_t **properties);
int unpack_vtx (json_t *element, fetch_helper_t &f);
vtx_t create_vtx (resource_graph_t &g, const fetch_helper_t &fetcher);
Expand Down

0 comments on commit ffd548a

Please sign in to comment.