Commit 1663206f authored by Millian Poquet's avatar Millian Poquet
Browse files

[code] cosmetics

parent 1ca474b2
......@@ -311,7 +311,9 @@ int execute_profile(BatsimContext *context,
send_message("server", IPMessageType::FROM_JOB_MSG, (void*)message);
if (delay_job(data->sleeptime, remaining_time) == -1)
{
return -1;
}
return profile->return_code;
}
......@@ -323,46 +325,62 @@ int execute_profile(BatsimContext *context,
bool has_messages = false;
XBT_INFO("Trying to receive message from scheduler");
if (job->incoming_message_buffer.empty()) {
if (data->on_timeout == "") {
if (job->incoming_message_buffer.empty())
{
if (data->on_timeout == "")
{
XBT_INFO("Waiting for message from scheduler");
while (true) {
while (true)
{
if (delay_job(data->polltime, remaining_time) == -1)
{
return -1;
}
if (!job->incoming_message_buffer.empty()) {
if (!job->incoming_message_buffer.empty())
{
XBT_INFO("Finally got message from scheduler");
has_messages = true;
break;
}
}
} else {
}
else
{
XBT_INFO("Timeout on waiting for message from scheduler");
profile_to_execute = data->on_timeout;
}
} else {
}
else
{
has_messages = true;
}
if (has_messages) {
if (has_messages)
{
string first_message = job->incoming_message_buffer.front();
job->incoming_message_buffer.pop_front();
regex msg_regex(data->regex);
if (regex_match(first_message, msg_regex)) {
if (regex_match(first_message, msg_regex))
{
XBT_INFO("Message from scheduler matches");
profile_to_execute = data->on_success;
} else {
}
else
{
XBT_INFO("Message from scheduler does not match");
profile_to_execute = data->on_failure;
}
}
if (profile_to_execute != "") {
if (profile_to_execute != "")
{
XBT_INFO("Execute profile: %s", profile_to_execute.c_str());
int ret_last_profile = execute_profile(context, profile_to_execute, allocation,
cleanup_data, remaining_time);
if (ret_last_profile != 0) {
if (ret_last_profile != 0)
{
return ret_last_profile;
}
}
......
......@@ -240,7 +240,8 @@ Profile *Profile::from_json(const std::string & profile_name,
string profile_type = json_desc["type"].GetString();
int return_code = 0;
if (json_desc.HasMember("ret")) {
if (json_desc.HasMember("ret"))
{
return_code = json_desc["ret"].GetInt();
}
profile->return_code = return_code;
......@@ -336,8 +337,9 @@ Profile *Profile::from_json(const std::string & profile_name,
profile->type = ProfileType::SEQUENCE;
SequenceProfileData * data = new SequenceProfileData;
int repeat = 1;
if (json_desc.HasMember("nb")) {
int repeat = 1;
if (json_desc.HasMember("nb"))
{
xbt_assert(json_desc["nb"].IsInt(), "%s: profile '%s' has a non-integral 'nb' field",
error_prefix.c_str(), profile_name.c_str());
repeat = json_desc["nb"].GetInt();
......@@ -463,7 +465,7 @@ Profile *Profile::from_json(const std::string & profile_name,
}
profile->data = data;
}
}
else if (profile_type == "send")
{
profile->type = ProfileType::SCHEDULER_SEND;
......@@ -476,13 +478,18 @@ Profile *Profile::from_json(const std::string & profile_name,
data->message.CopyFrom(json_desc["msg"], data->message.GetAllocator());
if (json_desc.HasMember("sleeptime")) {
xbt_assert(json_desc["sleeptime"].IsNumber(), "%s: profile '%s' has a non-number 'sleeptime' field",
if (json_desc.HasMember("sleeptime"))
{
xbt_assert(json_desc["sleeptime"].IsNumber(),
"%s: profile '%s' has a non-number 'sleeptime' field",
error_prefix.c_str(), profile_name.c_str());
data->sleeptime = json_desc["sleeptime"].GetDouble();
xbt_assert(data->sleeptime > 0, "%s: profile '%s' has a non-positive 'sleeptime' field (%g)",
xbt_assert(data->sleeptime > 0,
"%s: profile '%s' has a non-positive 'sleeptime' field (%g)",
error_prefix.c_str(), profile_name.c_str(), data->sleeptime);
} else {
}
else
{
data->sleeptime = 0.0000001;
}
profile->data = data;
......@@ -493,32 +500,41 @@ Profile *Profile::from_json(const std::string & profile_name,
SchedulerRecvProfileData * data = new SchedulerRecvProfileData;
data->regex = string(".*");
if (json_desc.HasMember("regex")) {
if (json_desc.HasMember("regex"))
{
data->regex = json_desc["regex"].GetString();
}
data->on_success = string("");
if (json_desc.HasMember("success")) {
if (json_desc.HasMember("success"))
{
data->on_success = json_desc["success"].GetString();
}
data->on_failure = string("");
if (json_desc.HasMember("failure")) {
if (json_desc.HasMember("failure"))
{
data->on_failure = json_desc["failure"].GetString();
}
data->on_timeout = string("");
if (json_desc.HasMember("timeout")) {
if (json_desc.HasMember("timeout"))
{
data->on_timeout = json_desc["timeout"].GetString();
}
if (json_desc.HasMember("polltime")) {
xbt_assert(json_desc["polltime"].IsNumber(), "%s: profile '%s' has a non-number 'polltime' field",
if (json_desc.HasMember("polltime"))
{
xbt_assert(json_desc["polltime"].IsNumber(),
"%s: profile '%s' has a non-number 'polltime' field",
error_prefix.c_str(), profile_name.c_str());
data->polltime = json_desc["polltime"].GetDouble();
xbt_assert(data->polltime > 0, "%s: profile '%s' has a non-positive 'polltime' field (%g)",
xbt_assert(data->polltime > 0,
"%s: profile '%s' has a non-positive 'polltime' field (%g)",
error_prefix.c_str(), profile_name.c_str(), data->polltime);
} else {
}
else
{
data->polltime = 0.005;
}
profile->data = data;
......
......@@ -651,7 +651,9 @@ void server_on_change_job_state(ServerData * data,
xbt_assert(data->nb_completed_jobs + data->nb_running_jobs <= data->nb_submitted_jobs);
break;
default:
xbt_assert(false, "Can only change the state of a submitted job to running or rejected. State was %s", job_state_to_string(job->state).c_str());
xbt_assert(false,
"Can only change the state of a submitted job to running or rejected. "
"State was %s", job_state_to_string(job->state).c_str());
}
break;
case JobState::JOB_STATE_RUNNING:
......@@ -667,11 +669,16 @@ void server_on_change_job_state(ServerData * data,
xbt_assert(data->nb_completed_jobs + data->nb_running_jobs <= data->nb_submitted_jobs);
break;
default:
xbt_assert(false, "Can only change the state of a running job to completed (successfully, failed, and killed). State was %s", job_state_to_string(job->state).c_str());
xbt_assert(false,
"Can only change the state of a running job to completed "
"(successfully, failed, and killed). State was %s",
job_state_to_string(job->state).c_str());
}
break;
default:
xbt_assert(false, "Can only change the state of a submitted or running job. State was %s", job_state_to_string(job->state).c_str());
xbt_assert(false,
"Can only change the state of a submitted or running job. State was %s",
job_state_to_string(job->state).c_str());
}
job->state = new_state;
......@@ -692,8 +699,8 @@ void server_on_to_job_msg(ServerData * data,
Job * job = data->context->workloads.job_at(message->job_id);
XBT_INFO("Send message to job: Job %d (workload=%s) message=%s",
job->number, job->workload->name.c_str(),
message->message.c_str());
job->number, job->workload->name.c_str(),
message->message.c_str());
job->incoming_message_buffer.push_back(message->message);
......@@ -709,11 +716,11 @@ void server_on_from_job_msg(ServerData * data,
Job * job = data->context->workloads.job_at(message->job_id);
XBT_INFO("Send message to scheduler: Job %d (workload=%s)",
job->number, job->workload->name.c_str());
job->number, job->workload->name.c_str());
data->context->proto_writer->append_from_job_message(message->job_id.to_string(),
message->message,
MSG_get_clock());
message->message,
MSG_get_clock());
check_submitted_and_completed(data);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment