Object used to stream I/O between a running Mesos task and the local terminal. :param task: task ID :type task: str :param cmd: a command to launch inside the task's container :type cmd: str :param args: Additional arguments for the command :type args: str :para
| 138 | return data[key] |
| 139 | |
| 140 | class TaskIO(): |
| 141 | """ |
| 142 | Object used to stream I/O between a |
| 143 | running Mesos task and the local terminal. |
| 144 | |
| 145 | :param task: task ID |
| 146 | :type task: str |
| 147 | :param cmd: a command to launch inside the task's container |
| 148 | :type cmd: str |
| 149 | :param args: Additional arguments for the command |
| 150 | :type args: str |
| 151 | :param interactive: whether to attach STDIN of the current |
| 152 | terminal to the new command being launched |
| 153 | :type interactive: bool |
| 154 | :param tty: whether to allocate a tty for this command and attach |
| 155 | the local terminal to it |
| 156 | :type tty: bool |
| 157 | """ |
| 158 | # pylint: disable=too-many-instance-attributes |
| 159 | |
| 160 | # The interval to send heartbeat messages to |
| 161 | # keep persistent connections alive. |
| 162 | HEARTBEAT_INTERVAL = 30 |
| 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": |