Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job tags listing #1396

Merged
merged 8 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.D/1396.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support job tags listing: `neuro job tags`.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* [neuro job submit](#neuro-job-submit)
* [neuro job ls](#neuro-job-ls)
* [neuro job status](#neuro-job-status)
* [neuro job tags](#neuro-job-tags)
* [neuro job exec](#neuro-job-exec)
* [neuro job port-forward](#neuro-job-port-forward)
* [neuro job logs](#neuro-job-logs)
Expand Down Expand Up @@ -377,6 +378,7 @@ Name | Description|
| _[neuro job submit](#neuro-job-submit)_| Submit an image to run on the cluster |
| _[neuro job ls](#neuro-job-ls)_| List all jobs |
| _[neuro job status](#neuro-job-status)_| Display status of a job |
| _[neuro job tags](#neuro-job-tags)_| List all tags submitted by the user |
| _[neuro job exec](#neuro-job-exec)_| Execute command in a running job |
| _[neuro job port-forward](#neuro-job-port-forward)_| Forward port\(s) of a running job to local port\(s) |
| _[neuro job logs](#neuro-job-logs)_| Print the logs for a container |
Expand Down Expand Up @@ -518,7 +520,7 @@ neuro ps -a --owner=user-1 --owner=user-2
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description=my favourite job
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2
neuro ps -t tag1 -t tag2

```

Expand Down Expand Up @@ -559,6 +561,25 @@ Name | Description|



### neuro job tags

List all tags submitted by the user.

**Usage:**

```bash
neuro job tags [OPTIONS]
```

**Options:**

Name | Description|
|----|------------|
|_--help_|Show this message and exit.|




### neuro job exec

Execute command in a running job.<br/>
Expand Down Expand Up @@ -1768,7 +1789,7 @@ neuro ps -a --owner=user-1 --owner=user-2
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description=my favourite job
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2
neuro ps -t tag1 -t tag2

```

Expand Down
6 changes: 6 additions & 0 deletions docs/jobs_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ Jobs

:return: :class:`JobDescription` instance with job status details.

.. comethod:: tags() -> List[str]

Get the list of all tags submitted by the user.

:return: :class:`List[str]` list of tags.

.. comethod:: top(id: str) -> AsyncIterator[JobTelemetry]
:async-for:

Expand Down
7 changes: 7 additions & 0 deletions neuromation/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ async def status(self, id: str) -> JobDescription:
ret = await resp.json()
return _job_description_from_api(ret, self._parse)

async def tags(self) -> List[str]:
url = self._config.api_url / "tags"
auth = await self._config._api_auth()
async with self._core.request("GET", url, auth=auth) as resp:
ret = await resp.json()
return ret["tags"]

async def top(self, id: str) -> AsyncIterator[JobTelemetry]:
url = self._config.monitoring_url / id / "top"
auth = await self._config._api_auth()
Expand Down
12 changes: 11 additions & 1 deletion neuromation/cli/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ async def ls(
neuro ps --name my-experiments-v1 -s failed -s succeeded
neuro ps --description="my favourite job"
neuro ps -s failed -s succeeded -q
neuro ps --tag tag1 -t tag2
neuro ps -t tag1 -t tag2
"""

format = await calc_columns(root.client, format)
Expand Down Expand Up @@ -625,6 +625,15 @@ async def status(root: Root, job: str) -> None:
click.echo(JobStatusFormatter()(res))


@command()
async def tags(root: Root) -> None:
"""
List all tags submitted by the user.
"""
res = await root.client.jobs.tags()
pager_maybe(res, root.tty, root.terminal_size)


@command()
@click.argument("job")
async def browse(root: Root, job: str) -> None:
Expand Down Expand Up @@ -941,6 +950,7 @@ async def run(
job.add_command(submit)
job.add_command(ls)
job.add_command(status)
job.add_command(tags)
job.add_command(exec)
job.add_command(port_forward)
job.add_command(logs)
Expand Down
4 changes: 4 additions & 0 deletions tests/e2e/test_e2e_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ def test_job_tags(helper: Helper) -> None:
jobs = [x.split(" ")[0] for x in store_out_list]
assert job_id in jobs

captured = helper.run_cli(["job", "tags"])
tags_listed = captured.out.split("\n")
assert set(tags) <= set(tags_listed)


@pytest.mark.e2e
def test_job_kill_non_existing(helper: Helper) -> None:
Expand Down