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

update jobs capacity api #1872

Merged
merged 3 commits into from
Dec 1, 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/1872.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change jobs capacity API endpoint.
4 changes: 1 addition & 3 deletions docs/jobs_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Jobs
:return: Asynchronous context manager which can be used to access
stdin/stdout/stderr, see :class:`StdStream` for details.

.. comethod:: get_capacity(presets: Mapping[str, Preset]) -> Mapping[str, int]
.. comethod:: get_capacity() -> Mapping[str, int]

Get counts of available job for current cluster for each available preset.

Expand All @@ -98,8 +98,6 @@ Jobs
The returned capacity is an approximation, the real value can differ if already
running jobs are finished or another user starts own jobs at the same time.

:param presets: presets mapping, as :attr:`Config.presets` attribute.

:return: A mapping of *preset_name* to *count*, where *count* is a number of
concurrent jobs that can be executed using *preset_name*.

Expand Down
16 changes: 3 additions & 13 deletions neuromation/api/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
)
from .parser import DiskVolume, Parser, SecretFile, Volume
from .parsing_utils import LocalImage, RemoteImage, _as_repo_str, _is_in_neuro_registry
from .server_cfg import Preset
from .url_utils import (
normalize_disk_uri,
normalize_secret_uri,
Expand Down Expand Up @@ -674,19 +673,10 @@ async def send_signal(self, id: str, signal: Union[str, int]) -> None:
async with self._core.request("POST", url, auth=auth) as resp:
resp

async def get_capacity(self, presets: Mapping[str, Preset]) -> Mapping[str, int]:
url = self._config.monitoring_url / "available"
async def get_capacity(self) -> Mapping[str, int]:
url = self._config.monitoring_url / "capacity"
auth = await self._config._api_auth()
payload: Dict[str, Any] = {}
for name, preset in presets.items():
payload[name] = {
"cpu": preset.cpu,
"memory_mb": preset.memory_mb,
"gpu": preset.gpu or 0,
"gpu_model": preset.gpu_model or "",
"is_preemptible": preset.is_preemptible,
}
async with self._core.request("POST", url, auth=auth, json=payload) as resp:
async with self._core.request("GET", url, auth=auth) as resp:
return await resp.json()


Expand Down
2 changes: 1 addition & 1 deletion neuromation/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def show(root: Root) -> None:
"""
fmt = ConfigFormatter()
try:
jobs_capacity = await root.client.jobs.get_capacity(root.client.config.presets)
jobs_capacity = await root.client.jobs.get_capacity()
except ClientConnectionError:
jobs_capacity = {}
root.print(fmt(root.client.config, jobs_capacity))
Expand Down
25 changes: 2 additions & 23 deletions tests/api/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
_job_description_from_api,
)
from neuromation.api.parser import SecretFile
from neuromation.api.server_cfg import Preset
from tests import _TestServerFactory


Expand Down Expand Up @@ -2422,33 +2421,13 @@ async def test_get_capacity(
aiohttp_server: _TestServerFactory, make_client: _MakeClient
) -> None:
async def handler(request: web.Request) -> web.Response:
payload = await request.json()
assert payload == {
"gpu-p": {
"cpu": 0.1,
"memory_mb": 100,
"gpu": 1,
"gpu_model": "nvidia-tesla-k80",
"is_preemptible": True,
}
}
return web.json_response({"cpu-micro": 10})

app = web.Application()
app.router.add_post("/jobs/available", handler)
app.router.add_get("/jobs/capacity", handler)

srv = await aiohttp_server(app)

async with make_client(srv.make_url("/")) as client:
result = await client.jobs.get_capacity(
{
"gpu-p": Preset(
cpu=0.1,
memory_mb=100,
gpu=1,
gpu_model="nvidia-tesla-k80",
is_preemptible=True,
)
}
)
result = await client.jobs.get_capacity()
assert result == {"cpu-micro": 10}