Skip to content

Commit

Permalink
Merge pull request #333 from aldbr/main_FEAT_submit-to-submit-jdl
Browse files Browse the repository at this point in the history
feat(jobs): move the submission endpoint from '/' to '/jdl'
  • Loading branch information
fstagni authored Dec 3, 2024
2 parents 4373e53 + e79a1f6 commit 52460ef
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion diracx-cli/src/diracx/cli/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions diracx-client/src/diracx/client/generated/operations/_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions diracx-routers/src/diracx/routers/job_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions diracx-routers/tests/jobs/test_sandboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down
24 changes: 12 additions & 12 deletions diracx-routers/tests/test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()


Expand All @@ -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()


Expand All @@ -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"]
Expand All @@ -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()])
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion docs/CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/SERVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 52460ef

Please sign in to comment.