Skip to content

Commit

Permalink
Merge pull request #665 from milroy/resource-status
Browse files Browse the repository at this point in the history
Resource status
  • Loading branch information
mergify[bot] authored Jul 10, 2020
2 parents 39e263f + 44cf965 commit 4b54941
Show file tree
Hide file tree
Showing 28 changed files with 327 additions and 3 deletions.
1 change: 1 addition & 0 deletions resource/readers/resource_reader_hwloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ vtx_t resource_reader_hwloc_t::add_new_vertex (resource_graph_t &g,
g[v].name = basename + istr;
g[v].paths[subsys] = prefix + "/" + g[v].name;
g[v].idata.member_of[subsys] = "*";
g[v].status = resource_pool_t::status_t::UP;

// Indexing for fast look-up
m.by_path[g[v].paths[subsys]] = v;
Expand Down
6 changes: 4 additions & 2 deletions resource/readers/resource_reader_jgf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct fetch_helper_t {
int64_t size = 0;
int64_t uniq_id = 0;
int exclusive = 0;
resource_pool_t::status_t status = resource_pool_t::status_t::UP;
const char *type = NULL;
const char *name = NULL;
const char *unit = NULL;
Expand Down Expand Up @@ -186,11 +187,11 @@ int resource_reader_jgf_t::unpack_vtx (json_t *element, fetch_helper_t &f)
m_err_msg += std::string (f.vertex_id) + ".\n";
goto done;
}
if ( (json_unpack (metadata, "{ s:s s:s s:s s:I s:I s:I s:b s:s s:I }",
if ( (json_unpack (metadata, "{ s:s s:s s:s s:I s:I s:I s?:i s:b s:s s:I }",
"type", &f.type, "basename", &f.basename,
"name", &f.name, "id", &f.id,
"uniq_id", &f.uniq_id, "rank", &f.rank,
"exclusive", &f.exclusive,
"status", &f.status, "exclusive", &f.exclusive,
"unit", &f.unit, "size", &f.size)) < 0) {
errno = EPROTO;
m_err_msg += __FUNCTION__;
Expand Down Expand Up @@ -245,6 +246,7 @@ vtx_t resource_reader_jgf_t::create_vtx (resource_graph_t &g,
g[v].size = fetcher.size;
g[v].uniq_id = fetcher.uniq_id;
g[v].rank = fetcher.rank;
g[v].status = fetcher.status;
g[v].id = fetcher.id;
g[v].name = fetcher.name;
g[v].properties = fetcher.properties;
Expand Down
4 changes: 4 additions & 0 deletions resource/schema/resource_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ resource_relation_t::~resource_relation_t ()

}

const resource_pool_t::string_to_status resource_pool_t::str_to_status =
{ { "up", resource_pool_t::status_t::UP },
{ "down", resource_pool_t::status_t::DOWN } };


} // Flux::resource_model
} // Flux
Expand Down
10 changes: 10 additions & 0 deletions resource/schema/resource_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include "resource/schema/color.hpp"
#include "resource/schema/data_std.hpp"
Expand All @@ -44,6 +45,14 @@ struct resource_pool_t {
resource_pool_t &operator= (const resource_pool_t &o);
~resource_pool_t ();

enum class status_t : int {
UP = 0,
DOWN = 1
};

typedef std::unordered_map<std::string, status_t> string_to_status;
static const string_to_status str_to_status;

// Resource pool data
std::string type;
std::map<std::string, std::string> paths;
Expand All @@ -58,6 +67,7 @@ struct resource_pool_t {

schedule_t schedule; //!< schedule data
pool_infra_t idata; //!< scheduling infrastructure data
status_t status = status_t::UP;
};

/*! Resource relationship type.
Expand Down
14 changes: 13 additions & 1 deletion resource/traversers/dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,22 @@ int dfu_traverser_t::remove (int64_t jobid)
return -1;
}

vtx_t root = get_graph_db ()->metadata.roots.at(dom);
vtx_t root = get_graph_db ()->metadata.roots.at (dom);
return detail::dfu_impl_t::remove (root, jobid);
}

int dfu_traverser_t::mark (const std::string &root_path,
resource_pool_t::status_t status)
{
return detail::dfu_impl_t::mark (root_path, status);
}

int dfu_traverser_t::mark (std::set<int64_t> &ranks,
resource_pool_t::status_t status)
{
return detail::dfu_impl_t::mark (ranks, status);
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
18 changes: 18 additions & 0 deletions resource/traversers/dfu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ class dfu_traverser_t : protected detail::dfu_impl_t
*/
int remove (int64_t jobid);

/*! Mark the resource status up|down|etc starting at subtree_root.
*
* \param root_path path to the root of the subtree to update.
* \param status new status value
* \return 0 on success; -1 on error.
* EINVAL: roots or by_path not found.
*/
int mark (const std::string &root_path, resource_pool_t::status_t status);

/*! Mark the resource status up|down|etc for subgraph represented by ranks.
*
* \param ranks set of ranks representing the subgraph to update.
* \param status new status value
* \return 0 on success; -1 on error.
* EINVAL: roots or by_path not found.
*/
int mark (std::set<int64_t> &ranks, resource_pool_t::status_t status);

private:
int schedule (Jobspec::Jobspec &jobspec, detail::jobmeta_t &meta,
bool x, match_op_t op, vtx_t root,
Expand Down
19 changes: 19 additions & 0 deletions resource/traversers/dfu_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,25 @@ class dfu_impl_t {
*/
int remove (vtx_t root, int64_t jobid);

/*! Update the resource status to up|down|etc starting at subtree_root.
*
* \param root_path path to the root of the subtree to update.
* \param status new status value
* \return 0 on success; -1 on error.
* EINVAL: graph, roots or match callback not set.
*/
int mark (const std::string &root_path, resource_pool_t::status_t status);

/*! Update the resource status to up|down|etc for subgraph
* represented by ranks.
*
* \param ranks set of ranks representing the subgraphs to update.
* \param status new status value
* \return 0 on success; -1 on error.
* EINVAL: roots or by_path not found.
*/
int mark (std::set<int64_t> &ranks, resource_pool_t::status_t status);

private:

/************************************************************************
Expand Down
53 changes: 53 additions & 0 deletions resource/traversers/dfu_impl_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,59 @@ int dfu_impl_t::remove (vtx_t root, int64_t jobid)
return (root_has_jtag)? rem_dfv (root, jobid) : rem_exv (jobid);
}

int dfu_impl_t::mark (const std::string &root_path,
resource_pool_t::status_t status)
{
std::map<std::string, vtx_t>::const_iterator vit_root =
m_graph_db->metadata.by_path.find (root_path);

if (vit_root == m_graph_db->metadata.by_path.end ()) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": could not find subtree path ("
+ root_path + ") in resource graph.\n";
return -1;
}
(*m_graph)[vit_root->second].status = status;

return 0;
}

int dfu_impl_t::mark (std::set<int64_t> &ranks,
resource_pool_t::status_t status)
{
std::map<int64_t, std::vector <vtx_t>>::iterator vit;
std::string subtree_path = "", tmp_path = "";
const std::string &dom = m_match->dom_subsystem ();
vtx_t subtree_root;

for (auto &rank : ranks) {
// Now iterate through subgraphs keyed by rank and
// set status appropriately
vit = m_graph_db->metadata.by_rank.find (rank);
if (vit == m_graph_db->metadata.by_rank.end ()) {
errno = EINVAL;
m_err_msg += __FUNCTION__;
m_err_msg += ": could not find rank path in by_rank map.\n";
return -1;
}

subtree_root = vit->second.front ();
subtree_path = (*m_graph)[subtree_root].paths.at (dom);
for (vtx_t v : vit->second) {
// The shortest path string is the subtree root.
tmp_path = (*m_graph)[v].paths.at (dom);
if (tmp_path.length () < subtree_path.length ()) {
subtree_path = tmp_path;
subtree_root = v;
}
}
(*m_graph)[subtree_root].status = status;
}

return 0;
}

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
69 changes: 69 additions & 0 deletions resource/utilities/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ command_t commands[] = {
"resource-query> set-property resource PROPERTY=VALUE" },
{ "get-property", "g", cmd_get_property, "Get all properties of a resource: "
"resource-query> get-property resource" },
{ "set-status", "t", cmd_set_status, "Set resource status on vertex: "
"resource-query> set-status PATH_TO_VERTEX {up|down}" },
{ "get-status", "e", cmd_get_status, "Get the graph resource vertex status: "
"resource-query> get-status PATH_TO_VERTEX" },
{ "list", "l", cmd_list, "List all jobs: resource-query> list" },
{ "info", "i", cmd_info,
"Print info on a jobid: resource-query> info jobid" },
Expand Down Expand Up @@ -421,6 +425,71 @@ int cmd_get_property (std::shared_ptr<resource_context_t> &ctx,
return 0;
}

int cmd_set_status (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
if (args.size () != 3) {
std::cerr << "ERROR: malformed command" << std::endl;
return 0;
}
std::string vtx_path = args[1];
std::string status = args[2];
std::map<std::string, vtx_t>::const_iterator it =
ctx->db->metadata.by_path.find (vtx_path);
resource_pool_t::string_to_status sts = resource_pool_t::str_to_status;

if (it == ctx->db->metadata.by_path.end ()) {
std::cout << "Could not find path " << vtx_path
<< " in resource graph." << std::endl;
return 0;
}

auto status_it = sts.find (status);
if (status_it == sts.end ()) {
std::cerr << "ERROR: unrecognized status" << std::endl;
return 0;
}

return ctx->traverser->mark (vtx_path, status_it->second);
}

int cmd_get_status (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
if (args.size () != 2) {
std::cerr << "ERROR: malformed command" << std::endl;
return 0;
}
std::string vtx_path = args[1];
std::map<std::string, vtx_t>::const_iterator it =
ctx->db->metadata.by_path.find (vtx_path);
resource_pool_t::string_to_status sts = resource_pool_t::str_to_status;
std::string status = "";

if (it == ctx->db->metadata.by_path.end ()) {
std::cout << "Could not find path " << vtx_path
<< " in resource graph." << std::endl;
return 0;
}

for (auto &status_it : sts) {
if (status_it.second == ctx->db->resource_graph[it->second].status) {
status = status_it.first;
break;
}
}

if (status == "") {
std::cerr << "ERROR: vertex " << vtx_path
<< " has unknown status." << std::endl;
return 0;
}

std::cout << vtx_path << " is " << status << std::endl;

return 0;
}

int cmd_list (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args)
{
Expand Down
4 changes: 4 additions & 0 deletions resource/utilities/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ int cmd_set_property (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_get_property (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_set_status (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_get_status (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_list (std::shared_ptr<resource_context_t> &ctx,
std::vector<std::string> &args);
int cmd_info (std::shared_ptr<resource_context_t> &ctx,
Expand Down
1 change: 1 addition & 0 deletions t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ TESTS = \
t3021-resource-mtl3.t \
t3022-resource-update.t \
t3023-resource-update2.t \
t3024-resource-status.t \
t4000-match-params.t \
t4001-match-allocate.t \
t4002-match-reserve.t \
Expand Down
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds01
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get-status
quit
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds02
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get-status /dne
quit
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds03
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get-status /tiny0/rack0/node0
quit
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds04
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set-status
quit
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds05
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set-status /dne down
quit
2 changes: 2 additions & 0 deletions t/data/resource/commands/status/cmds06
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set-status /tiny0/rack0/node0 dwn
quit
5 changes: 5 additions & 0 deletions t/data/resource/commands/status/cmds07
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set-status /tiny0/rack0/node0 down
get-status /tiny0/rack0/node0
set-status /tiny0/rack0/node0 up
get-status /tiny0/rack0/node0
quit
6 changes: 6 additions & 0 deletions t/data/resource/commands/status/cmds08
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
get-status /cz0/pfs0/bandwidth0
set-status /cz0/pfs0/bandwidth0 down
get-status /cz0/pfs0/bandwidth0
set-status /cz0/pfs0/bandwidth0 up
get-status /cz0/pfs0/bandwidth0
quit
1 change: 1 addition & 0 deletions t/data/resource/expected/status/001.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: malformed command
4 changes: 4 additions & 0 deletions t/data/resource/expected/status/002.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INFO: Loading a matcher: CA
resource-query> get-status /dne
Could not find path /dne in resource graph.
resource-query> quit
4 changes: 4 additions & 0 deletions t/data/resource/expected/status/003.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INFO: Loading a matcher: CA
resource-query> get-status /tiny0/rack0/node0
/tiny0/rack0/node0 is up
resource-query> quit
1 change: 1 addition & 0 deletions t/data/resource/expected/status/004.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: malformed command
4 changes: 4 additions & 0 deletions t/data/resource/expected/status/005.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INFO: Loading a matcher: CA
resource-query> set-status /dne down
Could not find path /dne in resource graph.
resource-query> quit
1 change: 1 addition & 0 deletions t/data/resource/expected/status/006.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ERROR: unrecognized status
8 changes: 8 additions & 0 deletions t/data/resource/expected/status/007.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
INFO: Loading a matcher: CA
resource-query> set-status /tiny0/rack0/node0 down
resource-query> get-status /tiny0/rack0/node0
/tiny0/rack0/node0 is down
resource-query> set-status /tiny0/rack0/node0 up
resource-query> get-status /tiny0/rack0/node0
/tiny0/rack0/node0 is up
resource-query> quit
10 changes: 10 additions & 0 deletions t/data/resource/expected/status/008.R.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
INFO: Loading a matcher: CA
resource-query> get-status /cz0/pfs0/bandwidth0
/cz0/pfs0/bandwidth0 is up
resource-query> set-status /cz0/pfs0/bandwidth0 down
resource-query> get-status /cz0/pfs0/bandwidth0
/cz0/pfs0/bandwidth0 is down
resource-query> set-status /cz0/pfs0/bandwidth0 up
resource-query> get-status /cz0/pfs0/bandwidth0
/cz0/pfs0/bandwidth0 is up
resource-query> quit
Loading

0 comments on commit 4b54941

Please sign in to comment.