Look up the port that has been requested for this task in `server_def_`.
| 115 | |
| 116 | // Look up the port that has been requested for this task in `server_def_`. |
| 117 | Status GrpcServer::GetPort(int* port) const { |
| 118 | *port = -1; |
| 119 | for (const auto& job : server_def_.cluster().job()) { |
| 120 | if (job.name() == server_def_.job_name()) { |
| 121 | auto iter = job.tasks().find(server_def_.task_index()); |
| 122 | if (iter == job.tasks().end()) { |
| 123 | return errors::InvalidArgument("Task ", server_def_.task_index(), |
| 124 | " was not defined in job \"", |
| 125 | server_def_.job_name(), "\""); |
| 126 | } |
| 127 | auto colon_index = iter->second.find_last_of(':'); |
| 128 | if (!strings::safe_strto32(iter->second.substr(colon_index + 1), port)) { |
| 129 | return errors::InvalidArgument( |
| 130 | "Could not parse port for local server from \"", iter->second, |
| 131 | "\"."); |
| 132 | } |
| 133 | break; |
| 134 | } |
| 135 | } |
| 136 | if (*port == -1) { |
| 137 | return errors::Internal("Job \"", server_def_.job_name(), |
| 138 | "\" was not defined in cluster"); |
| 139 | } |
| 140 | |
| 141 | return Status::OK(); |
| 142 | } |
| 143 | |
| 144 | Status GrpcServer::Init(const GrpcServerOptions& opts) { |
| 145 | mutex_lock l(mu_); |
nothing calls this directly
no test coverage detected