From e79a1f672e0c63c15c99ae01ab61b848d5476139 Mon Sep 17 00:00:00 2001 From: aldbr Date: Fri, 29 Nov 2024 16:42:44 +0100 Subject: [PATCH] feat(jobs): move the submission endpoint from '/' to '/jdl' --- diracx-cli/src/diracx/cli/jobs.py | 2 +- .../generated/aio/operations/_operations.py | 22 ++++++++--------- .../generated/operations/_operations.py | 24 +++++++++---------- .../diracx/routers/job_manager/__init__.py | 4 ++-- diracx-routers/tests/jobs/test_sandboxes.py | 6 ++--- diracx-routers/tests/test_job_manager.py | 24 +++++++++---------- docs/CLIENT.md | 2 +- docs/SERVICES.md | 2 +- .../tests/test_gubbins_job_manager.py | 2 +- 9 files changed, 44 insertions(+), 44 deletions(-) diff --git a/diracx-cli/src/diracx/cli/jobs.py b/diracx-cli/src/diracx/cli/jobs.py index e4430b88..87fdc99b 100644 --- a/diracx-cli/src/diracx/cli/jobs.py +++ b/diracx-cli/src/diracx/cli/jobs.py @@ -152,7 +152,7 @@ def display_rich(data, content_range: ContentRange) -> None: async def submit(jdl: list[FileText]): async with DiracClient() as api: # api.valid(enforce_https=False) - jobs = await api.jobs.submit_bulk_jobs([x.read() for x in jdl]) + jobs = await api.jobs.submit_bulk_jdl_jobs([x.read() for x in jdl]) print( f"Inserted {len(jobs)} jobs with ids: {','.join(map(str, (job.job_id for job in jobs)))}" ) diff --git a/diracx-client/src/diracx/client/generated/aio/operations/_operations.py b/diracx-client/src/diracx/client/generated/aio/operations/_operations.py index 72211529..5bb099dd 100644 --- a/diracx-client/src/diracx/client/generated/aio/operations/_operations.py +++ b/diracx-client/src/diracx/client/generated/aio/operations/_operations.py @@ -57,7 +57,7 @@ build_jobs_set_job_status_bulk_request, build_jobs_set_single_job_properties_request, build_jobs_set_single_job_status_request, - build_jobs_submit_bulk_jobs_request, + build_jobs_submit_bulk_jdl_jobs_request, build_jobs_summary_request, build_jobs_unassign_bulk_jobs_sandboxes_request, build_jobs_unassign_job_sandboxes_request, @@ -1423,12 +1423,12 @@ async def assign_sandbox_to_job(self, job_id: int, body: str, **kwargs: Any) -> return deserialized # type: ignore @overload - async def submit_bulk_jobs( + async def submit_bulk_jdl_jobs( self, body: List[str], *, content_type: str = "application/json", **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Required. :type body: list[str] @@ -1441,12 +1441,12 @@ async def submit_bulk_jobs( """ @overload - async def submit_bulk_jobs( + async def submit_bulk_jdl_jobs( self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Required. :type body: IO[bytes] @@ -1459,12 +1459,12 @@ async def submit_bulk_jobs( """ @distributed_trace_async - async def submit_bulk_jobs( + async def submit_bulk_jdl_jobs( self, body: Union[List[str], IO[bytes]], **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Is either a [str] type or a IO[bytes] type. Required. :type body: list[str] or IO[bytes] @@ -1496,7 +1496,7 @@ async def submit_bulk_jobs( else: _json = self._serialize.body(body, "[str]") - _request = build_jobs_submit_bulk_jobs_request( + _request = build_jobs_submit_bulk_jdl_jobs_request( content_type=content_type, json=_json, content=_content, diff --git a/diracx-client/src/diracx/client/generated/operations/_operations.py b/diracx-client/src/diracx/client/generated/operations/_operations.py index 98eb97f4..1d04f2e7 100644 --- a/diracx-client/src/diracx/client/generated/operations/_operations.py +++ b/diracx-client/src/diracx/client/generated/operations/_operations.py @@ -458,7 +458,7 @@ def build_jobs_assign_sandbox_to_job_request( ) -def build_jobs_submit_bulk_jobs_request(**kwargs: Any) -> HttpRequest: +def build_jobs_submit_bulk_jdl_jobs_request(**kwargs: Any) -> HttpRequest: _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) content_type: Optional[str] = kwargs.pop( @@ -467,7 +467,7 @@ def build_jobs_submit_bulk_jobs_request(**kwargs: Any) -> HttpRequest: accept = _headers.pop("Accept", "application/json") # Construct URL - _url = "/api/jobs/" + _url = "/api/jobs/jdl" # Construct headers if content_type is not None: @@ -2245,12 +2245,12 @@ def assign_sandbox_to_job(self, job_id: int, body: str, **kwargs: Any) -> Any: return deserialized # type: ignore @overload - def submit_bulk_jobs( + def submit_bulk_jdl_jobs( self, body: List[str], *, content_type: str = "application/json", **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Required. :type body: list[str] @@ -2263,12 +2263,12 @@ def submit_bulk_jobs( """ @overload - def submit_bulk_jobs( + def submit_bulk_jdl_jobs( self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Required. :type body: IO[bytes] @@ -2281,12 +2281,12 @@ def submit_bulk_jobs( """ @distributed_trace - def submit_bulk_jobs( + def submit_bulk_jdl_jobs( self, body: Union[List[str], IO[bytes]], **kwargs: Any ) -> List[_models.InsertedJob]: - """Submit Bulk Jobs. + """Submit Bulk Jdl Jobs. - Submit Bulk Jobs. + Submit Bulk Jdl Jobs. :param body: Is either a [str] type or a IO[bytes] type. Required. :type body: list[str] or IO[bytes] @@ -2318,7 +2318,7 @@ def submit_bulk_jobs( else: _json = self._serialize.body(body, "[str]") - _request = build_jobs_submit_bulk_jobs_request( + _request = build_jobs_submit_bulk_jdl_jobs_request( content_type=content_type, json=_json, content=_content, diff --git a/diracx-routers/src/diracx/routers/job_manager/__init__.py b/diracx-routers/src/diracx/routers/job_manager/__init__.py index ce563655..bbc3db24 100644 --- a/diracx-routers/src/diracx/routers/job_manager/__init__.py +++ b/diracx-routers/src/diracx/routers/job_manager/__init__.py @@ -102,8 +102,8 @@ class JobID(BaseModel): } -@router.post("/") -async def submit_bulk_jobs( +@router.post("/jdl") +async def submit_bulk_jdl_jobs( job_definitions: Annotated[list[str], Body(openapi_examples=EXAMPLE_JDLS)], job_db: JobDB, job_logging_db: JobLoggingDB, diff --git a/diracx-routers/tests/jobs/test_sandboxes.py b/diracx-routers/tests/jobs/test_sandboxes.py index 64d9b24e..c70ee483 100644 --- a/diracx-routers/tests/jobs/test_sandboxes.py +++ b/diracx-routers/tests/jobs/test_sandboxes.py @@ -130,7 +130,7 @@ def test_assign_then_unassign_sandboxes_to_jobs(normal_user_client: TestClient): # Submit a job: job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == len(job_definitions) job_id = r.json()[0]["JobID"] @@ -225,7 +225,7 @@ def test_malformed_request_to_get_job_sandbox(normal_user_client: TestClient): """Test that a malformed request to get a job sandbox returns an information to help user.""" # Submit a job: job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == len(job_definitions) job_id = r.json()[0]["JobID"] @@ -240,7 +240,7 @@ def test_get_empty_job_sandboxes(normal_user_client: TestClient): """Test that we can get the sandboxes of a job that has no sandboxes assigned.""" # Submit a job: job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == len(job_definitions) job_id = r.json()[0]["JobID"] diff --git a/diracx-routers/tests/test_job_manager.py b/diracx-routers/tests/test_job_manager.py index badb65df..3b777aa9 100644 --- a/diracx-routers/tests/test_job_manager.py +++ b/diracx-routers/tests/test_job_manager.py @@ -98,7 +98,7 @@ def admin_user_client(client_factory): def test_insert_and_list_parametric_jobs(normal_user_client): job_definitions = [TEST_PARAMETRIC_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == 3 # Parameters.JOB_ID is 3 @@ -125,7 +125,7 @@ def test_insert_and_list_parametric_jobs(normal_user_client): ], ) def test_insert_and_list_bulk_jobs(job_definitions, normal_user_client): - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == len(job_definitions) @@ -147,7 +147,7 @@ def test_insert_and_search(normal_user_client): """Test inserting a job and then searching for it.""" # job_definitions = [TEST_JDL%(normal_user_client.dirac_token_payload)] job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) listed_jobs = r.json() assert r.status_code == 200, listed_jobs assert len(listed_jobs) == len(job_definitions) @@ -244,7 +244,7 @@ def test_insert_and_search(normal_user_client): def test_search_distinct(normal_user_client): """Test that the distinct parameter works as expected.""" job_definitions = [TEST_JDL, TEST_JDL, TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) listed_jobs = r.json() assert r.status_code == 200, listed_jobs assert len(listed_jobs) == len(job_definitions) @@ -272,7 +272,7 @@ def test_search_distinct(normal_user_client): def test_search_pagination(normal_user_client): """Test that the pagination works as expected.""" job_definitions = [TEST_JDL] * 20 - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) listed_jobs = r.json() assert r.status_code == 200, listed_jobs assert len(listed_jobs) == len(job_definitions) @@ -340,7 +340,7 @@ def test_user_cannot_submit_parametric_jdl_greater_than_max_parametric_jobs( ): """Test that a user cannot submit a parametric JDL greater than the max parametric jobs.""" job_definitions = [TEST_LARGE_PARAMETRIC_JDL] - res = normal_user_client.post("/api/jobs/", json=job_definitions) + res = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert res.status_code == HTTPStatus.BAD_REQUEST, res.json() @@ -349,7 +349,7 @@ def test_user_cannot_submit_list_of_jdl_greater_than_max_number_of_jobs( ): """Test that a user cannot submit a list of JDL greater than the max number of jobs.""" job_definitions = [TEST_JDL for _ in range(100)] - res = normal_user_client.post("/api/jobs/", json=job_definitions) + res = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert res.status_code == HTTPStatus.BAD_REQUEST, res.json() @@ -360,19 +360,19 @@ def test_user_cannot_submit_list_of_jdl_greater_than_max_number_of_jobs( def test_user_cannot_submit_multiple_jdl_if_at_least_one_of_them_is_parametric( normal_user_client, job_definitions ): - res = normal_user_client.post("/api/jobs/", json=job_definitions) + res = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert res.status_code == HTTPStatus.BAD_REQUEST, res.json() def test_user_without_the_normal_user_property_cannot_submit_job(admin_user_client): - res = admin_user_client.post("/api/jobs/", json=[TEST_JDL]) + res = admin_user_client.post("/api/jobs/jdl", json=[TEST_JDL]) assert res.status_code == HTTPStatus.FORBIDDEN, res.json() @pytest.fixture def valid_job_id(normal_user_client: TestClient): job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == 1 return r.json()[0]["JobID"] @@ -381,7 +381,7 @@ def valid_job_id(normal_user_client: TestClient): @pytest.fixture def valid_job_ids(normal_user_client: TestClient): job_definitions = [TEST_PARAMETRIC_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == 3 return sorted([job_dict["JobID"] for job_dict in r.json()]) @@ -714,7 +714,7 @@ def test_set_job_status_with_invalid_job_id( def test_insert_and_reschedule(normal_user_client: TestClient): job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == len(job_definitions) diff --git a/docs/CLIENT.md b/docs/CLIENT.md index 3c141c08..1fa94c85 100644 --- a/docs/CLIENT.md +++ b/docs/CLIENT.md @@ -63,7 +63,7 @@ Operations are accessible via the `DiracClient`, which manages token refreshment from diracx.client.aio import DiracClient async with DiracClient() as client: - jobs = await client.jobs.submit_bulk_jobs([x.read() for x in jdl]) + jobs = await client.jobs.submit_jobs([x.read() for x in jdl]) ``` ### Configuring the Generated Client diff --git a/docs/SERVICES.md b/docs/SERVICES.md index 0d6d78d4..a9bd6fd3 100644 --- a/docs/SERVICES.md +++ b/docs/SERVICES.md @@ -159,7 +159,7 @@ Each route must have a policy as an argument and call it: from .access_policies import ActionType, CheckWMSPolicyCallable @router.post("/") -async def submit_bulk_jobs( +async def submit_jobs( job_definitions: Annotated[list[str], Body()], job_db: JobDB, check_permissions: CheckWMSPolicyCallable, diff --git a/extensions/gubbins/gubbins-routers/tests/test_gubbins_job_manager.py b/extensions/gubbins/gubbins-routers/tests/test_gubbins_job_manager.py index 96b1650d..e70d926c 100644 --- a/extensions/gubbins/gubbins-routers/tests/test_gubbins_job_manager.py +++ b/extensions/gubbins/gubbins-routers/tests/test_gubbins_job_manager.py @@ -57,7 +57,7 @@ def valid_job_id(normal_user_client: TestClient): """ job_definitions = [TEST_JDL] - r = normal_user_client.post("/api/jobs/", json=job_definitions) + r = normal_user_client.post("/api/jobs/jdl", json=job_definitions) assert r.status_code == 200, r.json() assert len(r.json()) == 1 return r.json()[0]["JobID"]