-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Refactor trailblazer scan (#423)(patch)"
This reverts commit 027b716.
- Loading branch information
Showing
21 changed files
with
60 additions
and
227 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,42 +1,9 @@ | ||
from unittest.mock import Mock | ||
import pytest | ||
|
||
from trailblazer.services.analysis_service.analysis_service import AnalysisService | ||
from trailblazer.services.job_service.job_service import JobService | ||
from trailblazer.services.slurm.dtos import SlurmJobInfo | ||
from trailblazer.services.slurm.slurm_cli_service.slurm_cli_service import SlurmCLIService | ||
from trailblazer.services.slurm.slurm_service import SlurmService | ||
from trailblazer.store.store import Store | ||
|
||
|
||
@pytest.fixture | ||
def slurm_completed_job_info() -> SlurmJobInfo: | ||
return SlurmJobInfo( | ||
slurm_id=690994, | ||
name="job", | ||
status="completed", | ||
elapsed=1000, | ||
started_at="2020-10-22T11:43:33", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def slurm_service(slurm_completed_job_info) -> SlurmService: | ||
"""Slurm service reporting all jobs as completed.""" | ||
service = SlurmCLIService(client=Mock()) | ||
service.get_job = Mock(return_value=slurm_completed_job_info) | ||
service.get_jobs = Mock(return_value=[slurm_completed_job_info]) | ||
return service | ||
|
||
|
||
@pytest.fixture | ||
def job_service(store: Store, slurm_service: SlurmService, slurm_job_ids, mocker) -> JobService: | ||
mocker.patch( | ||
"trailblazer.services.job_service.job_service.get_slurm_job_ids", return_value=slurm_job_ids | ||
) | ||
return JobService(store=store, slurm_service=slurm_service) | ||
|
||
|
||
@pytest.fixture | ||
def analysis_service(analysis_store: Store, job_service: JobService) -> AnalysisService: | ||
return AnalysisService(store=analysis_store, job_service=job_service) | ||
def analysis_service(analysis_store: Store) -> AnalysisService: | ||
return AnalysisService(analysis_store) |
This file contains 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 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 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 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 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 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 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 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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,59 +1,13 @@ | ||
from pathlib import Path | ||
from trailblazer.constants import FileFormat, SlurmJobStatus, TrailblazerStatus | ||
from trailblazer.io.controller import ReadFile | ||
from trailblazer.dto.failed_jobs_response import FailedJobsResponse | ||
from trailblazer.dto.job_response import JobResponse | ||
from trailblazer.store.models import Job | ||
|
||
|
||
def get_slurm_job_ids(job_id_file: str) -> list[int]: | ||
job_id_file_path = Path(job_id_file) | ||
content: dict = ReadFile.get_content_from_file( | ||
file_format=FileFormat.YAML, file_path=job_id_file_path | ||
def create_job_response(job: Job) -> JobResponse: | ||
return JobResponse( | ||
slurm_id=job.slurm_id, analysis_id=job.analysis_id, status=job.status, id=job.id | ||
) | ||
job_ids: list[int] = [] | ||
for row in content.values(): | ||
[job_ids.append(job_id) for job_id in row] | ||
return job_ids | ||
|
||
|
||
def get_status(jobs: list[Job]) -> TrailblazerStatus: | ||
if has_same_status(jobs): | ||
return get_single_status(jobs) | ||
is_running: bool = has_running_jobs(jobs) | ||
is_failed: bool = has_failed_jobs(jobs) | ||
if is_failed: | ||
return TrailblazerStatus.ERROR if is_running else TrailblazerStatus.FAILED | ||
return TrailblazerStatus.RUNNING if is_running else TrailblazerStatus.CANCELLED | ||
|
||
|
||
def has_same_status(jobs: list[Job]) -> bool: | ||
if not jobs: | ||
return False | ||
first_status = jobs[0].status | ||
return all(job.status == first_status for job in jobs) | ||
|
||
|
||
def get_single_status(jobs: list[Job]) -> SlurmJobStatus: | ||
single_status = jobs[0].status | ||
return ( | ||
TrailblazerStatus.FAILED | ||
if single_status == SlurmJobStatus.TIME_OUT | ||
else TrailblazerStatus[single_status.upper()] | ||
) | ||
|
||
|
||
def has_running_jobs(jobs: list[Job]) -> bool: | ||
run_statuses = SlurmJobStatus.ongoing_statuses() | ||
return any(job.status in run_statuses for job in jobs) | ||
|
||
|
||
def has_failed_jobs(jobs: list[Job]) -> bool: | ||
fail_statuses = SlurmJobStatus.fail_statuses() | ||
return any(job.status in fail_statuses for job in jobs) | ||
|
||
|
||
def get_progress(jobs: list[Job]) -> float: | ||
total_jobs: int = len(jobs) | ||
if total_jobs == 0: | ||
return 0.0 | ||
completed_jobs: int = len([job for job in jobs if job.status == SlurmJobStatus.COMPLETED]) | ||
return completed_jobs / total_jobs | ||
def create_failed_jobs_response(failed_job_statistics: list[dict]) -> FailedJobsResponse: | ||
return FailedJobsResponse(jobs=failed_job_statistics) |
Oops, something went wrong.