SINGA-38 Support concurrent jobs clean code format for * include/utils/cluster_rt.h * src/utils/cluster_rt.cc * src/utils/tool.cc
Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/29de8633 Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/29de8633 Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/29de8633 Branch: refs/heads/master Commit: 29de863379fcdbdc3cd41e510877a3ba2e31e39f Parents: 1fa5d5f Author: wang sheng <[email protected]> Authored: Tue Jul 21 22:43:33 2015 +0800 Committer: wang sheng <[email protected]> Committed: Tue Jul 21 22:43:33 2015 +0800 ---------------------------------------------------------------------- include/utils/cluster_rt.h | 6 +++--- src/utils/cluster_rt.cc | 12 ++++++------ src/utils/tool.cc | 22 ++++++++-------------- 3 files changed, 17 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/29de8633/include/utils/cluster_rt.h ---------------------------------------------------------------------- diff --git a/include/utils/cluster_rt.h b/include/utils/cluster_rt.h index ab95adf..5738ae3 100644 --- a/include/utils/cluster_rt.h +++ b/include/utils/cluster_rt.h @@ -63,7 +63,7 @@ const std::string kZKPathJobPLock = "/proc-lock"; inline std::string GetZKJobWorkspace(int job_id) { char buf[kZKBufSize]; - sprintf(buf, "%010d", job_id); + snprintf(buf, kZKBufSize, "%010d", job_id); return kZKPathJob + buf; } @@ -122,14 +122,14 @@ class ZKClusterRT : public ClusterRuntime { inline std::string workerPath(int gid, int wid) { return "/g" + std::to_string(gid) + "_w" + std::to_string(wid); } - + int timeout_ = 30000; std::string host_ = ""; ZKService zk_; std::string workspace_ = ""; std::string group_path_ = ""; std::string proc_path_ = ""; - std::string proc_lock_path_ = ""; + std::string proc_lock_path_ = ""; std::vector<RTCallback*> cb_vec_; }; http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/29de8633/src/utils/cluster_rt.cc ---------------------------------------------------------------------- diff --git a/src/utils/cluster_rt.cc b/src/utils/cluster_rt.cc index c722a73..0458b12 100644 --- a/src/utils/cluster_rt.cc +++ b/src/utils/cluster_rt.cc @@ -167,7 +167,8 @@ void ZKService::WatcherGlobal(zhandle_t * zh, int type, int state, } } -ZKClusterRT::ZKClusterRT(const string& host, int job_id) : ZKClusterRT(host, job_id, 30000) {} +ZKClusterRT::ZKClusterRT(const string& host, int job_id) + : ZKClusterRT(host, job_id, 30000) {} ZKClusterRT::ZKClusterRT(const string& host, int job_id, int timeout) { host_ = host; @@ -321,16 +322,15 @@ bool JobManager::ListJobProcs(int job, vector<string>* procs) { return false; } char buf[singa::kZKBufSize]; - for (string pname : vt){ + for (string pname : vt) { pname = proc_path + "/" + pname; if (!zk_.GetNode(pname.c_str(), buf)) continue; std::string proc = ""; for (int i = 0; buf[i] != '\0'; ++i) { if (buf[i] == ':') { buf[i] = '\0'; - proc += buf; - } - else if (buf[i] == '|') { + proc += buf; + } else if (buf[i] == '|') { proc += buf + i; } } @@ -358,7 +358,7 @@ bool JobManager::ListJobs(vector<JobInfo>* jobs) { job.id = atoi(jid.c_str()); job.procs = procs.size(); jobs->push_back(job); - //may need to delete it + // may need to delete it if (!job.procs && (i + kJobsNotRemoved < size)) CleanPath(kZKPathApp + "/" + vt[i], true); } http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/29de8633/src/utils/tool.cc ---------------------------------------------------------------------- diff --git a/src/utils/tool.cc b/src/utils/tool.cc index fc9f618..267d266 100644 --- a/src/utils/tool.cc +++ b/src/utils/tool.cc @@ -33,12 +33,11 @@ int main(int argc, char **argv) { LOG(ERROR) << usage; return 1; } - if (!mng.Init()) return 1; + if (!mng.Init()) return 1; if (!strcmp(argv[1], "create")) { int id = mng.GenerateJobID(); printf("%d\n", id); - } - else if (!strcmp(argv[1], "list")) { + } else if (!strcmp(argv[1], "list")) { std::vector<singa::JobInfo> jobs; if (!mng.ListJobs(&jobs)) return 1; printf("JOB ID |NUM PROCS \n"); @@ -47,8 +46,7 @@ int main(int argc, char **argv) { if (!job.procs) continue; printf("job-%-6d|%-10d\n", job.id, job.procs); } - } - else if (!strcmp(argv[1], "listall")) { + } else if (!strcmp(argv[1], "listall")) { std::vector<singa::JobInfo> jobs; if (!mng.ListJobs(&jobs)) return 1; printf("JOB ID |NUM PROCS \n"); @@ -56,8 +54,7 @@ int main(int argc, char **argv) { for (singa::JobInfo job : jobs) { printf("job-%-6d|%-10d\n", job.id, job.procs); } - } - else if (!strcmp(argv[1], "view")) { + } else if (!strcmp(argv[1], "view")) { if (argc <= 2) { LOG(ERROR) << usage; return 1; @@ -68,22 +65,19 @@ int main(int argc, char **argv) { for (std::string s : procs) { printf("%s\n", s.c_str()); } - } - else if (!strcmp(argv[1], "clean")) { + } else if (!strcmp(argv[1], "clean")) { if (argc <= 2) { LOG(ERROR) << usage; return 1; } int id = atoi(argv[2]); if (!mng.Clean(id)) return 1; - } - else if (!strcmp(argv[1], "cleanup")) { + } else if (!strcmp(argv[1], "cleanup")) { if (!mng.Cleanup()) return 1; - } - else{ + } else { LOG(ERROR) << usage; return 1; } - + return 0; }
