"...composable_kernel_rocm.git" did not exist on "72b7ae251aa9060b59e08897e1a5ac724bad43ed"
Unverified Commit a5232a7f authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

symphony/client: add UMA support to base client

parent 26efc226
...@@ -64,67 +64,76 @@ class BaseClient: ...@@ -64,67 +64,76 @@ class BaseClient:
await session.close() await session.close()
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def post( async def request(
self, self, meth: str, url: str, data: typing.Any = None, retry: bool = True,
url: str, **kwargs: typing.Any
data: typing.Any = None,
**kwargs: typing.Any,
) -> typing.AsyncIterator[aiohttp.ClientResponse]: ) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.session() as session: async with self.session() as session:
async with session.post( async with session.request(
url=self.build_url(url), data=data, **kwargs method=meth, url=self.build_url(url), data=data, **kwargs
) as resp: # TODO: handel connection error ) as resp: # TODO: handel connection error
# print(await resp.text()) if resp.status == 401 and 'WWW-Authenticate' in resp.headers \
resp.raise_for_status() # TODO: handel gracefully and retry:
yield resp wwa = resp.headers['WWW-Authenticate']
parts = wwa.split(',')
ticket = None
for p in parts:
p = p.strip()
if p.startswith("ticket=\""):
ticket = p[8:-1]
if ticket:
await self._token_provider.resource_token(ticket)
async with self.request(
meth, url, data, False, **kwargs
) as resp:
yield resp
else:
resp.raise_for_status() # TODO: handel gracefully
yield resp
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def put( async def get(
self, self, url: str, data: typing.Any = None, **kwargs: typing.Any,
url: str,
overwrite_headers: dict[str, typing.Any] | None = None,
data: typing.Any = None,
**kwargs: typing.Any,
) -> typing.AsyncIterator[aiohttp.ClientResponse]: ) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.session(overwrite_headers=overwrite_headers) as session: async with self.request(
async with session.put( meth=aiohttp.hdrs.METH_GET, url=url, data=data, **kwargs
url=self.build_url(url), data=data, **kwargs ) as resp:
) as resp: # TODO: handel connection error yield resp
# print(await resp.text())
resp.raise_for_status() # TODO: handel gracefully
yield resp
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def patch( async def post(
self, url: str, data: typing.Any = None, **kwargs: typing.Any self, url: str, data: typing.Any = None, **kwargs: typing.Any,
) -> typing.AsyncIterator[aiohttp.ClientResponse]: ) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.session() as session: async with self.request(
async with session.patch( meth=aiohttp.hdrs.METH_POST, url=url, data=data, **kwargs
url=self.build_url(url), data=data, **kwargs ) as resp:
) as resp: # TODO: handel connection error yield resp
# print(await resp.text())
resp.raise_for_status() # TODO: handel gracefully
yield resp
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def get( async def put(
self, url: str, data: typing.Any = None, **kwargs: typing.Any,
) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.request(
meth=aiohttp.hdrs.METH_PUT, url=url, data=data, **kwargs
) as resp:
yield resp
@contextlib.asynccontextmanager
async def patch(
self, url: str, data: typing.Any = None, **kwargs: typing.Any self, url: str, data: typing.Any = None, **kwargs: typing.Any
) -> typing.AsyncIterator[aiohttp.ClientResponse]: ) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.session() as session: async with self.request(
async with session.get( meth=aiohttp.hdrs.METH_PATCH, url=url, data=data, **kwargs
url=self.build_url(url), data=data, **kwargs ) as resp:
) as resp: # TODO: handel connection error yield resp
# print(await resp.text())
resp.raise_for_status() # TODO: handel gracefully
yield resp
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def delete(self, url: str, **kwargs: typing.Any) -> typing.AsyncIterator[aiohttp.ClientResponse]: async def delete(self, url: str, **kwargs: typing.Any) -> typing.AsyncIterator[aiohttp.ClientResponse]:
async with self.session() as session: async with self.request(
async with session.delete(url=self.build_url(url), **kwargs) as resp: # TODO: handel connection error meth=aiohttp.hdrs.METH_DELETE, url=url, **kwargs
# print(await resp.text()) ) as resp:
resp.raise_for_status() # TODO: handel gracefully yield resp
yield resp
async def info(self): async def info(self):
async with self.get(url="/info") as resp: async with self.get(url="/info") as resp:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment