diff --git a/resource/planner/c++/planner.cpp b/resource/planner/c++/planner.cpp index 0f55c0dc5..94dadbf62 100644 --- a/resource/planner/c++/planner.cpp +++ b/resource/planner/c++/planner.cpp @@ -229,6 +229,26 @@ int planner::restore_track_points () return rc; } +int planner::update (uint64_t resource_total) +{ + int64_t delta = resource_total - m_total_resources; + m_total_resources = static_cast (resource_total); + scheduled_point_t *point = nullptr; + if (delta == 0) + return 0; + point = m_sched_point_tree.get_state (m_plan_start); + while (point) { + // Allow remaining to be negative. This should only happen for + // reservations, which will be removed and rescheduled during the + // next cycle. Planner C interface checks should catch negative + // remaining while adding spans. Return code is int rather than + // void as we may need checks in the future. + point->remaining = point->remaining + delta; + point = m_sched_point_tree.next (point); + } + return 0; +} + int64_t planner::get_total_resources () const { return m_total_resources; diff --git a/resource/planner/c++/planner.hpp b/resource/planner/c++/planner.hpp index 05fc39f75..4499eadf2 100644 --- a/resource/planner/c++/planner.hpp +++ b/resource/planner/c++/planner.hpp @@ -51,6 +51,7 @@ class planner { int erase (); int reinitialize (int64_t base_time, uint64_t duration); int restore_track_points (); + int update (uint64_t resource_total); // Resources and duration int64_t get_total_resources () const; diff --git a/resource/planner/c/planner.h b/resource/planner/c/planner.h index 0f777973f..25cf66876 100644 --- a/resource/planner/c/planner.h +++ b/resource/planner/c/planner.h @@ -229,6 +229,21 @@ int64_t planner_span_resource_count (planner_t *ctx, int64_t span_id); */ bool planners_equal (planner_t *lhs, planner_t *rhs); +/*! Update the counts and resource types to support elasticity. + * + * \param resource_total + * 64-bit unsigned integer of + * the total count of available resources + * of the resource type. + * \param resource_type + * string containing + * the planner resource type. + * \return 0 on success; -1 on an error with errno set as follows: + * EINVAL: invalid argument. + */ +int planner_update (planner_t *ctx, + uint64_t resource_total); + #ifdef __cplusplus } #endif diff --git a/resource/planner/c/planner_c_interface.cpp b/resource/planner/c/planner_c_interface.cpp index e0f154f9c..ff65fc5b3 100644 --- a/resource/planner/c/planner_c_interface.cpp +++ b/resource/planner/c/planner_c_interface.cpp @@ -698,6 +698,12 @@ extern "C" bool planners_equal (planner_t *lhs, planner_t *rhs) return (*(lhs->plan) == *(rhs->plan)); } +extern "C" int planner_update (planner_t *ctx, + uint64_t resource_total) +{ + return ctx->plan->update (resource_total); +} + /* * vi: ts=4 sw=4 expandtab */