MCPcopy Create free account
hub / github.com/apache/mesos / __init__

Method __init__

src/python/cli_new/lib/cli/mesos.py:165–262  ·  view source on GitHub ↗
(self, master, task_id)

Source from the content-addressed store, hash-verified

163 HEARTBEAT_INTERVAL_NANOSECONDS = HEARTBEAT_INTERVAL * 1000000000
164
165 def __init__(self, master, task_id):
166 # Get the task and make sure its container was launched by the UCR.
167 # Since task's containers are launched by the UCR by default, we want
168 # to allow most tasks to pass through unchecked. The only exception is
169 # when a task has an explicit container specified and it is not of type
170 # "MESOS". Having a type of "MESOS" implies that it was launched by the
171 # UCR -- all other types imply it was not.
172 try:
173 tasks = get_tasks(master, query={'task_id': task_id})
174 except Exception as exception:
175 raise CLIException("Unable to get task with ID {task_id}"
176 " from leading master '{master}': {error}"
177 .format(task_id=task_id, master=master,
178 error=exception))
179
180 running_tasks = [t for t in tasks if t["state"] == "TASK_RUNNING"]
181 matching_tasks = [t for t in running_tasks if t["id"] == task_id]
182
183 if not matching_tasks:
184 raise CLIException("Unable to find running task '{task_id}'"
185 " from leading master '{master}'"
186 .format(task_id=task_id, master=master))
187
188 if len(matching_tasks) > 1:
189 raise CLIException("More than one task matching id '{id}'"
190 .format(id=task_id))
191
192
193 task_obj = matching_tasks[0]
194
195 if "container" in task_obj:
196 if "type" in task_obj["container"]:
197 if task_obj["container"]["type"] != "MESOS":
198 raise CLIException(
199 "This command is only supported for tasks"
200 " launched by the Universal Container Runtime (UCR).")
201
202 # Get the URL to the agent running the task.
203 agent_addr = util.sanitize_address(
204 get_agent_address(task_obj["slave_id"], master))
205 self.agent_url = mesos.http.simple_urljoin(agent_addr, "api/v1")
206
207 # Get the agent's task path by checking the `state` endpoint.
208 try:
209 self.container_id = get_container_id(task_obj)
210 except CLIException as exception:
211 raise CLIException("Could not get container ID of task '{id}'"
212 " from agent '{addr}': {error}"
213 .format(id=task_id, addr=agent_addr,
214 error=exception))
215
216 # Set up a recordio encoder and decoder
217 # for any incoming and outgoing messages.
218 self.encoder = recordio.Encoder(
219 lambda s: bytes(json.dumps(s, ensure_ascii=False), "UTF-8"))
220 self.decoder = recordio.Decoder(
221 lambda s: json.loads(s.decode("UTF-8")))
222

Callers

nothing calls this directly

Calls 10

CLIExceptionClass · 0.90
QueueClass · 0.90
get_tasksFunction · 0.85
get_agent_addressFunction · 0.85
get_container_idFunction · 0.85
EncoderMethod · 0.80
DecoderMethod · 0.80
EventMethod · 0.80
decodeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected