Commit d7bf6725 authored by Steffen Lackner's avatar Steffen Lackner
Browse files

[code] refactor with helper methods on job states

parent a002068e
......@@ -329,3 +329,51 @@ Job * Job::from_json(const std::string & json_str,
return Job::from_json(doc, workload, error_prefix);
}
string job_state_to_string(JobState state)
{
string job_state("UNKNOWN");
switch (state) {
case JobState::JOB_STATE_NOT_SUBMITTED:
job_state = "NOT_SUBMITTED";
break;
case JobState::JOB_STATE_SUBMITTED:
job_state = "SUBMITTED";
break;
case JobState::JOB_STATE_RUNNING:
job_state = "RUNNING";
break;
case JobState::JOB_STATE_COMPLETED_SUCCESSFULLY:
job_state = "COMPLETED_SUCCESSFULLY";
break;
case JobState::JOB_STATE_COMPLETED_KILLED:
job_state = "COMPLETED_KILLED";
break;
case JobState::JOB_STATE_REJECTED:
job_state = "REJECTED";
break;
}
return job_state;
}
JobState job_state_from_string(string state)
{
JobState new_state;
if (state == "NOT_SUBMITTED") {
new_state = JobState::JOB_STATE_NOT_SUBMITTED;
} else if (state == "SUBMITTED") {
new_state = JobState::JOB_STATE_SUBMITTED;
} else if (state == "RUNNING") {
new_state = JobState::JOB_STATE_RUNNING;
} else if (state == "COMPLETED_SUCCESSFULLY") {
new_state = JobState::JOB_STATE_COMPLETED_SUCCESSFULLY;
} else if (state == "COMPLETED_KILLED") {
new_state = JobState::JOB_STATE_COMPLETED_KILLED;
} else if (state == "REJECTED") {
new_state = JobState::JOB_STATE_REJECTED;
} else {
xbt_assert(false, "Invalid job state");
}
return new_state;
}
......@@ -212,3 +212,17 @@ private:
Profiles * _profiles = nullptr; //!< The profiles associated with the jobs
Workload * _workload = nullptr; //!< The Workload the jobs belong to
};
/**
* @brief Returns a std::string corresponding to a given JobState
* @param[in] state The JobState
* @return A std::string corresponding to a given JobState
*/
std::string job_state_to_string(JobState state);
/**
* @brief Returns a JobState corresponding to a given std::string
* @param[in] state The std::string
* @return A JobState corresponding to a given std::string
*/
JobState job_state_from_string(std::string state);
......@@ -212,30 +212,9 @@ void server_on_job_completed(ServerData * data,
status = "TIMEOUT";
}
string job_state;
switch (job->state) {
case JobState::JOB_STATE_NOT_SUBMITTED:
job_state = "NOT_SUBMITTED";
break;
case JobState::JOB_STATE_SUBMITTED:
job_state = "SUBMITTED";
break;
case JobState::JOB_STATE_RUNNING:
job_state = "RUNNING";
break;
case JobState::JOB_STATE_COMPLETED_SUCCESSFULLY:
job_state = "COMPLETED_SUCCESSFULLY";
break;
case JobState::JOB_STATE_COMPLETED_KILLED:
job_state = "COMPLETED_KILLED";
break;
case JobState::JOB_STATE_REJECTED:
job_state = "REJECTED";
break;
}
data->context->proto_writer->append_job_completed(message->job_id.to_string(),
status, job_state, job->kill_reason,
status, job_state_to_string(job->state),
job->kill_reason,
MSG_get_clock());
check_submitted_and_completed(data);
......@@ -643,22 +622,7 @@ void server_on_change_job_state(ServerData * data,
job->number, job->workload->name.c_str(),
message->job_state.c_str(), message->kill_reason.c_str());
JobState new_state;
if (message->job_state == "NOT_SUBMITTED") {
new_state = JobState::JOB_STATE_NOT_SUBMITTED;
} else if (message->job_state == "SUBMITTED") {
new_state = JobState::JOB_STATE_SUBMITTED;
} else if (message->job_state == "RUNNING") {
new_state = JobState::JOB_STATE_RUNNING;
} else if (message->job_state == "COMPLETED_SUCCESSFULLY") {
new_state = JobState::JOB_STATE_COMPLETED_SUCCESSFULLY;
} else if (message->job_state == "COMPLETED_KILLED") {
new_state = JobState::JOB_STATE_COMPLETED_KILLED;
} else if (message->job_state == "REJECTED") {
new_state = JobState::JOB_STATE_REJECTED;
} else {
xbt_assert(false, "Invalid new job state");
}
JobState new_state = job_state_from_string(message->job_state);
switch (job->state) {
case JobState::JOB_STATE_SUBMITTED:
......
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