-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Implement PilotAgents schema #292
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8587d6c
feat: Implement PilotAgents schema
martynia 9281158
fix: add a default value for GridRequirements column
martynia f552417
feat: addPilotReferences
martynia ce8dfc0
fix: modify schema to match Dirac 9.0
martynia 86d0f4c
fix: modify db.py to match Dirac 9.0
martynia b2b0232
fix: avoid mutable default values as arguments + unit test
martynia 71395f4
fix: Apply suggestions from code review
martynia 0adb6b3
fix: Apply suggestions from code review (2)
martynia 34a33c6
fix: move EnumBackedBool to utils/__init__
martynia 69cf73a
test: extend tests for empty pilot stamps
martynia 4d4fbe2
feat: use bulk insert
martynia 9953ddb
feat: use bulk insert with a stmt compile step
martynia 09475e7
fix: change method name
martynia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| from __future__ import annotations | ||
|
|
||
| __all__ = ("AuthDB", "JobDB", "JobLoggingDB", "SandboxMetadataDB", "TaskQueueDB") | ||
| __all__ = ( | ||
| "AuthDB", | ||
| "JobDB", | ||
| "JobLoggingDB", | ||
| "PilotAgentsDB", | ||
| "SandboxMetadataDB", | ||
| "TaskQueueDB", | ||
| ) | ||
|
|
||
| from .auth.db import AuthDB | ||
| from .job.db import JobDB | ||
| from .job_logging.db import JobLoggingDB | ||
| from .pilot_agents.db import PilotAgentsDB | ||
| from .sandbox_metadata.db import SandboxMetadataDB | ||
| from .task_queue.db import TaskQueueDB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime, timezone | ||
|
|
||
| from sqlalchemy import insert | ||
|
|
||
| from ..utils import BaseSQLDB | ||
| from .schema import PilotAgents, PilotAgentsDBBase | ||
|
|
||
|
|
||
| class PilotAgentsDB(BaseSQLDB): | ||
| metadata = PilotAgentsDBBase.metadata | ||
|
|
||
| async def addPilotReferences( | ||
| self, | ||
| pilot_ref: list[str], | ||
| vo: str, | ||
| grid_type: str = "DIRAC", | ||
| pilot_stamps: dict | None = None, | ||
| ) -> None: | ||
|
|
||
| if pilot_stamps is None: | ||
| pilot_stamps = {} | ||
|
|
||
| now = datetime.now(tz=timezone.utc) | ||
|
|
||
| # Prepare the list of dictionaries for bulk insertion | ||
| values = [ | ||
| { | ||
| "PilotJobReference": ref, | ||
| "VO": vo, | ||
| "GridType": grid_type, | ||
| "SubmissionTime": now, | ||
| "LastUpdateTime": now, | ||
| "Status": "Submitted", | ||
| "PilotStamp": pilot_stamps.get(ref, ""), | ||
| } | ||
| for ref in pilot_ref | ||
| ] | ||
|
|
||
| # Insert multiple rows in a single execute call | ||
| stmt = insert(PilotAgents).values(values) | ||
| await self.conn.execute(stmt) | ||
| return | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| from sqlalchemy import ( | ||
| DateTime, | ||
| Double, | ||
| Index, | ||
| Integer, | ||
| String, | ||
| Text, | ||
| ) | ||
| from sqlalchemy.orm import declarative_base | ||
|
|
||
| from ..utils import Column, EnumBackedBool, NullColumn | ||
|
|
||
| PilotAgentsDBBase = declarative_base() | ||
|
|
||
|
|
||
| class PilotAgents(PilotAgentsDBBase): | ||
| __tablename__ = "PilotAgents" | ||
|
|
||
| PilotID = Column("PilotID", Integer, autoincrement=True, primary_key=True) | ||
| InitialJobID = Column("InitialJobID", Integer, default=0) | ||
| CurrentJobID = Column("CurrentJobID", Integer, default=0) | ||
| PilotJobReference = Column("PilotJobReference", String(255), default="Unknown") | ||
| PilotStamp = Column("PilotStamp", String(32), default="") | ||
| DestinationSite = Column("DestinationSite", String(128), default="NotAssigned") | ||
| Queue = Column("Queue", String(128), default="Unknown") | ||
| GridSite = Column("GridSite", String(128), default="Unknown") | ||
| VO = Column("VO", String(128)) | ||
| GridType = Column("GridType", String(32), default="LCG") | ||
| BenchMark = Column("BenchMark", Double, default=0.0) | ||
| SubmissionTime = NullColumn("SubmissionTime", DateTime) | ||
| LastUpdateTime = NullColumn("LastUpdateTime", DateTime) | ||
| Status = Column("Status", String(32), default="Unknown") | ||
| StatusReason = Column("StatusReason", String(255), default="Unknown") | ||
| AccountingSent = Column("AccountingSent", EnumBackedBool(), default=False) | ||
|
aldbr marked this conversation as resolved.
|
||
|
|
||
| __table_args__ = ( | ||
| Index("PilotJobReference", "PilotJobReference"), | ||
| Index("Status", "Status"), | ||
| Index("Statuskey", "GridSite", "DestinationSite", "Status"), | ||
| ) | ||
|
|
||
|
|
||
| class JobToPilotMapping(PilotAgentsDBBase): | ||
| __tablename__ = "JobToPilotMapping" | ||
|
|
||
| PilotID = Column("PilotID", Integer, primary_key=True) | ||
| JobID = Column("JobID", Integer, primary_key=True) | ||
| StartTime = Column("StartTime", DateTime) | ||
|
|
||
| __table_args__ = (Index("JobID", "JobID"), Index("PilotID", "PilotID")) | ||
|
|
||
|
|
||
| class PilotOutput(PilotAgentsDBBase): | ||
| __tablename__ = "PilotOutput" | ||
|
|
||
| PilotID = Column("PilotID", Integer, primary_key=True) | ||
| StdOutput = Column("StdOutput", Text) | ||
| StdError = Column("StdError", Text) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from diracx.db.sql.pilot_agents.db import PilotAgentsDB | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def pilot_agents_db(tmp_path) -> PilotAgentsDB: | ||
| agents_db = PilotAgentsDB("sqlite+aiosqlite:///:memory:") | ||
| async with agents_db.engine_context(): | ||
| async with agents_db.engine.begin() as conn: | ||
| await conn.run_sync(agents_db.metadata.create_all) | ||
| yield agents_db | ||
|
|
||
|
|
||
| async def test_insert_and_select(pilot_agents_db: PilotAgentsDB): | ||
|
|
||
| async with pilot_agents_db as pilot_agents_db: | ||
| # Add a pilot reference | ||
| refs = [f"ref_{i}" for i in range(10)] | ||
| stamps = [f"stamp_{i}" for i in range(10)] | ||
| stamp_dict = dict(zip(refs, stamps)) | ||
|
|
||
| await pilot_agents_db.addPilotReferences( | ||
| refs, "test_vo", grid_type="DIRAC", pilot_stamps=stamp_dict | ||
| ) | ||
|
|
||
| await pilot_agents_db.addPilotReferences( | ||
| refs, "test_vo", grid_type="DIRAC", pilot_stamps=None | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.