diff --git a/resource/readers/resource_reader_jgf.cpp b/resource/readers/resource_reader_jgf.cpp index 2ac450c52..9ebebe8b6 100644 --- a/resource/readers/resource_reader_jgf.cpp +++ b/resource/readers/resource_reader_jgf.cpp @@ -17,6 +17,7 @@ extern "C" { #include #include #include +#include #include #include "resource/readers/resource_reader_jgf.hpp" #include "resource/store/resource_graph_store.hpp" @@ -353,8 +354,25 @@ int resource_reader_jgf_t::apply_defaults (fetch_helper_t &f, const char *name) return -1; } } - 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; + } + } + } + } if (f.exclusive == -1) f.exclusive = 0; if (f.size == -1) diff --git a/src/python/fluxion/resourcegraph/V1.py b/src/python/fluxion/resourcegraph/V1.py index 31e3c9392..972336dbb 100644 --- a/src/python/fluxion/resourcegraph/V1.py +++ b/src/python/fluxion/resourcegraph/V1.py @@ -7,7 +7,6 @@ # # SPDX-License-Identifier: LGPL-3.0 ############################################################## -import re from flux.idset import IDset from flux.hostlist import Hostlist @@ -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}" @@ -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, )