From 59f73b73b630bf9a5ae56bce8bc346110b6d8d9a Mon Sep 17 00:00:00 2001 From: Millian Poquet Date: Sat, 7 Oct 2017 20:27:30 +0200 Subject: [PATCH] [code] support SUBMIT_PROFILE + submit algo param --- src/algo/submitter.cpp | 15 +++++++++++++- src/algo/submitter.hpp | 2 ++ src/decision.cpp | 11 +++++++++++ src/decision.hpp | 5 +++++ src/protocol.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++ src/protocol.hpp | 10 ++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) diff --git a/src/algo/submitter.cpp b/src/algo/submitter.cpp index ae33daa..a98c062 100644 --- a/src/algo/submitter.cpp +++ b/src/algo/submitter.cpp @@ -33,9 +33,17 @@ Submitter::Submitter(Workload *workload, SchedulingDecision *decision, Queue *qu send_profile_if_already_sent = (*variant_options)["send_profile_if_already_sent"].GetBool(); } + if (variant_options->HasMember("send_profiles_in_separate_event")) + { + PPK_ASSERT_ERROR((*variant_options)["send_profiles_in_separate_event"].IsBool(), + "Bad algo options: send_profiles_in_separate_event is not a boolean"); + send_profiles_in_separate_event = (*variant_options)["send_profiles_in_separate_event"].GetBool(); + } + printf("nb_jobs_to_submit: %d\n", nb_jobs_to_submit); printf("increase_jobs_duration: %d\n", increase_jobs_duration); printf("send_profile_if_already_sent: %d\n", send_profile_if_already_sent); + printf("send_profiles_in_separate_event: %d\n", send_profiles_in_separate_event); } Submitter::~Submitter() @@ -175,9 +183,14 @@ void Submitter::submit_delay_job(double delay, double date) bool already_sent_profile = profiles_already_sent.count(profile) == 1; + bool send_profile = !already_sent_profile || send_profile_if_already_sent; + + if (send_profile && send_profiles_in_separate_event) + _decision->add_submit_profile(workload_name, profile, buf_profile, date); + _decision->add_submit_job(workload_name, job_id, profile, buf_job, buf_profile, date, - !already_sent_profile || send_profile_if_already_sent); + send_profile && !send_profiles_in_separate_event); profiles_already_sent.insert(profile); diff --git a/src/algo/submitter.hpp b/src/algo/submitter.hpp index b0dd7fb..b2c3b6e 100644 --- a/src/algo/submitter.hpp +++ b/src/algo/submitter.hpp @@ -40,6 +40,8 @@ private: int nb_jobs_to_submit = 10; //!< The number of jobs to submit bool increase_jobs_duration = true; //!< Whether the duration of the submitted jobs increases or not. If false, the same profile will be used by all the submitted jobs. bool send_profile_if_already_sent = true; //!< Whether already transmitted profiles should be sent again to Batsim or not. + bool send_profiles_in_separate_event = false; //!< Whether profiles should be sent in a separate message or not + bool dyn_submit_ack; bool redis_enabled; bool finished_submitting_sent = false; diff --git a/src/decision.cpp b/src/decision.cpp index 08594fc..3ea234e 100644 --- a/src/decision.cpp +++ b/src/decision.cpp @@ -65,6 +65,17 @@ void SchedulingDecision::add_submit_job(const string & workload_name, send_profile); } +void SchedulingDecision::add_submit_profile(const string &workload_name, + const string &profile_name, + const string &profile_json_description, + double date) +{ + _proto_writer->append_submit_profile(workload_name, + profile_name, + profile_json_description, + date); +} + void SchedulingDecision::add_set_resource_state(MachineRange machines, int new_state, double date) { _proto_writer->append_set_resource_state(machines, std::to_string(new_state), date); diff --git a/src/decision.hpp b/src/decision.hpp index 0e843ff..b7d0044 100644 --- a/src/decision.hpp +++ b/src/decision.hpp @@ -36,6 +36,11 @@ public: double date, bool send_profile = true); + void add_submit_profile(const std::string & workload_name, + const std::string & profile_name, + const std::string & profile_json_description, + double date); + void add_set_resource_state(MachineRange machines, int new_state, double date); void add_call_me_later(double future_date, double date); diff --git a/src/protocol.cpp b/src/protocol.cpp index 67012ad..906708a 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -94,6 +94,50 @@ void JsonProtocolWriter::append_submit_job(const string &job_id, _events.PushBack(event, _alloc); } +void JsonProtocolWriter::append_submit_profile(const string &workload_name, + const string &profile_name, + const string &profile_description, + double date) +{ + /* { + "timestamp": 10.0, + "type": "SUBMIT_PROFILE", + "data": { + "workload_name": "dyn_wl1", + "profile_name": "delay_10s", + "profile": { + "type": "delay", + "delay": 10 + } + } + } */ + + PPK_ASSERT(date >= _last_date, "Date inconsistency"); + _last_date = date; + _is_empty = false; + + Value data(rapidjson::kObjectType); + data.AddMember("workload_name", Value().SetString(workload_name.c_str(), _alloc), _alloc); + data.AddMember("profile_name", Value().SetString(profile_name.c_str(), _alloc), _alloc); + + PPK_ASSERT_ERROR(!profile_description.empty()); + { + Document profile_doc; + profile_doc.Parse(profile_description.c_str()); + PPK_ASSERT_ERROR(!profile_doc.HasParseError(), "Invalid JSON profile ###%s###", + profile_description.c_str()); + + data.AddMember("profile", Value().CopyFrom(profile_doc, _alloc), _alloc); + } + + Value event(rapidjson::kObjectType); + event.AddMember("timestamp", Value().SetDouble(date), _alloc); + event.AddMember("type", Value().SetString("SUBMIT_PROFILE"), _alloc); + event.AddMember("data", data, _alloc); + + _events.PushBack(event, _alloc); +} + void JsonProtocolWriter::append_execute_job(const string &job_id, const MachineRange &allocated_resources, double date, diff --git a/src/protocol.hpp b/src/protocol.hpp index 96da851..3ca35bc 100644 --- a/src/protocol.hpp +++ b/src/protocol.hpp @@ -47,6 +47,11 @@ public: const std::string & profile_description = "", bool send_profile = true) = 0; + virtual void append_submit_profile(const std::string & workload_name, + const std::string & profile_name, + const std::string & profile_description, + double date) = 0; + /** * @brief Appends an EXECUTE_JOB event. * @param[in] job_id The job identifier. It must be known by Batsim. @@ -244,6 +249,11 @@ public: const std::string & profile_description = "", bool send_profile = true); + void append_submit_profile(const std::string & workload_name, + const std::string & profile_name, + const std::string & profile_description, + double date); + /** * @brief Appends an EXECUTE_JOB event. * @param[in] job_id The job identifier. It must be known by Batsim. -- 2.18.1