Skip to content

Commit

Permalink
readers: infer node id from hostname suffix
Browse files Browse the repository at this point in the history
Problem: the JGF writer supplies the ID of nodes based on the
hostname suffix (assuming it exists), which determines which nodes
are matched first under policies like high and low. However, the
JGF reader could just as easily supply the ID itself, thereby
reducing the size of JGF.

Make the reader supply the ID instead of the writer.
  • Loading branch information
jameshcorbett committed Sep 30, 2024
1 parent dbe9971 commit 6785369
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
20 changes: 19 additions & 1 deletion resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
#include <map>
#include <unordered_set>
#include <unistd.h>
#include <regex>
#include <jansson.h>
#include "resource/readers/resource_reader_jgf.hpp"
#include "resource/store/resource_graph_store.hpp"
Expand Down Expand Up @@ -353,8 +354,25 @@ int resource_reader_jgf_t::apply_defaults (fetch_helper_t &f, const char *name)
return -1;

Check warning on line 354 in resource/readers/resource_reader_jgf.cpp

View check run for this annotation

Codecov / codecov/patch

resource/readers/resource_reader_jgf.cpp#L350-L354

Added lines #L350 - L354 were not covered by tests
}
}
if (f.id == -1)
if (f.id == -1) {
f.id = f.uniq_id;
// for nodes, see if there is an integer suffix on the hostname and use it if so
if (f.type == std::string{"node"} && name != NULL) {
std::string sname{name};
std::regex nodesuffix ("(\\d+$)");
std::smatch r;
if (std::regex_search (sname, r, nodesuffix)) {
try {
f.id = std::stoll (r.str (0));
} catch (std::invalid_argument const &ex) {
m_err_msg += __FUNCTION__;
m_err_msg += ": could not extract ID from hostname ";
m_err_msg += sname;
return -1;

Check warning on line 371 in resource/readers/resource_reader_jgf.cpp

View check run for this annotation

Codecov / codecov/patch

resource/readers/resource_reader_jgf.cpp#L367-L371

Added lines #L367 - L371 were not covered by tests
}
}
}
}
if (f.exclusive == -1)
f.exclusive = 0;
if (f.size == -1)
Expand Down
9 changes: 0 additions & 9 deletions src/python/fluxion/resourcegraph/V1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#
# SPDX-License-Identifier: LGPL-3.0
##############################################################
import re

from flux.idset import IDset
from flux.hostlist import Hostlist
Expand Down Expand Up @@ -125,13 +124,6 @@ def _contains_any(self, prop_str, charset):
return True
return False

def _extract_id_from_hn(self, hostName):
postfix = re.findall(r"(\d+$)", hostName)
rc = self._uniqId
if len(postfix) == 1:
rc = int(postfix[0])
return rc

def _encode_child(self, ppid, path, rank, resType, i):
vtx = FluxionResourcePoolV1(
self._uniqId, resType, iden=i, rank=rank, path=f"{path}/{resType}{i}"
Expand All @@ -146,7 +138,6 @@ def _encode_rank(self, ppid, path, rank, children, hostname, properties):
"node",
name=hostname,
rank=rank,
iden=self._extract_id_from_hn(hostname),
properties=properties,
path=path,
)
Expand Down

0 comments on commit 6785369

Please sign in to comment.