Skip to content

Commit

Permalink
Add internal_hostname_named to JobDescription (#1675)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Skurikhin <[email protected]>
  • Loading branch information
romasku and Roman Skurikhin authored Aug 13, 2020
1 parent f379cce commit a71033f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.D/1675.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `internal_hostname_named` to `JobDescription` and to output of `neuro job status`.
5 changes: 5 additions & 0 deletions docs/jobs_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,11 @@ JobDescription

DNS name to access the running job from other jobs.

.. attribute:: internal_hostname_named

DNS name to access the running job from other jobs based on jobs name instead of
jobs id. Produces same value for jobs with ``name`` and ``owner`` in same cluster.


JobStatus
=========
Expand Down
3 changes: 3 additions & 0 deletions neuromation/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class JobDescription:
http_url: URL = URL()
ssh_server: URL = URL()
internal_hostname: Optional[str] = None
internal_hostname_named: Optional[str] = None
restart_policy: JobRestartPolicy = JobRestartPolicy.NEVER
life_span: Optional[float] = None

Expand Down Expand Up @@ -721,6 +722,7 @@ def _job_description_from_api(res: Dict[str, Any], parse: Parser) -> JobDescript
http_url_named = URL(res.get("http_url_named", ""))
ssh_server = URL(res.get("ssh_server", ""))
internal_hostname = res.get("internal_hostname", None)
internal_hostname_named = res.get("internal_hostname_named", None)
restart_policy = JobRestartPolicy(res.get("restart_policy", JobRestartPolicy.NEVER))
max_run_time_minutes = res.get("max_run_time_minutes")
life_span = (
Expand All @@ -740,6 +742,7 @@ def _job_description_from_api(res: Dict[str, Any], parse: Parser) -> JobDescript
http_url=http_url_named or http_url,
ssh_server=ssh_server,
internal_hostname=internal_hostname,
internal_hostname_named=internal_hostname_named,
uri=URL(res["uri"]),
restart_policy=restart_policy,
life_span=life_span,
Expand Down
2 changes: 2 additions & 0 deletions neuromation/cli/formatters/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def add(descr: str, value: str) -> None:

if job_status.internal_hostname:
add("Internal Hostname", job_status.internal_hostname)
if job_status.internal_hostname_named:
add("Internal Hostname Named", job_status.internal_hostname_named)
if job_status.http_url:
add("Http URL", str(job_status.http_url))
if job_status.container.http:
Expand Down
51 changes: 51 additions & 0 deletions tests/cli/formatters/test_jobs_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,57 @@ def test_running_job(self) -> None:
"Started: 2018-09-25T12:28:24.759433+00:00"
)

def test_running_named_job(self) -> None:
description = JobDescription(
status=JobStatus.RUNNING,
owner="test-user",
name="test-job",
cluster_name="default",
id="test-job",
uri=URL("job://default/test-user/test-job"),
description="test job description",
history=JobStatusHistory(
status=JobStatus.RUNNING,
reason="ContainerRunning",
description="",
created_at=isoparse("2018-09-25T12:28:21.298672+00:00"),
started_at=isoparse("2018-09-25T12:28:24.759433+00:00"),
finished_at=None,
),
http_url=URL("http://local.host.test/"),
container=Container(
command="test-command",
image=RemoteImage.new_external_image(name="test-image"),
resources=Resources(16, 0.1, 0, None, False, None, None),
),
ssh_server=URL("ssh-auth"),
is_preemptible=False,
internal_hostname="host.local",
internal_hostname_named="test-job--test-owner.local",
)

uri_fmtr = uri_formatter(username="test-user", cluster_name="test-cluster")
status = click.unstyle(JobStatusFormatter(uri_formatter=uri_fmtr)(description))
resource_formatter = ResourcesFormatter()
resource = click.unstyle(resource_formatter(description.container.resources))
assert (
status == "Job: test-job\n"
"Name: test-job\n"
"Owner: test-user\n"
"Cluster: default\n"
"Description: test job description\n"
"Status: running\n"
"Image: test-image\n"
"Command: test-command\n"
f"{resource}\n"
"TTY: False\n"
"Internal Hostname: host.local\n"
"Internal Hostname Named: test-job--test-owner.local\n"
"Http URL: http://local.host.test/\n"
"Created: 2018-09-25T12:28:21.298672+00:00\n"
"Started: 2018-09-25T12:28:24.759433+00:00"
)

def test_job_with_entrypoint(self) -> None:
description = JobDescription(
status=JobStatus.RUNNING,
Expand Down
1 change: 1 addition & 0 deletions tests/cli/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def _job_entry(job_id: str) -> Dict[str, Any]:
"is_preemptible": True,
"name": "job-name",
"internal_hostname": "job-id.default",
"internal_hostname_named": "job-name--job-owner.default",
}


Expand Down

0 comments on commit a71033f

Please sign in to comment.