Skip to content

Commit

Permalink
deprecate old schema change checks
Browse files Browse the repository at this point in the history
  • Loading branch information
LuiggiTenorioK committed Dec 19, 2024
1 parent de70f18 commit bacd5f6
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 117 deletions.
2 changes: 1 addition & 1 deletion autosubmit_api/autosubmit_legacy/job/job_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def get_job_times_collection(basic_config: APIBasicConfig, allJobs, expid, job_t
job_data = None
try:
experiment_history = ExperimentHistoryDirector(ExperimentHistoryBuilder(expid)).build_reader_experiment_history()
job_data = experiment_history.manager.get_all_last_job_data_dcs() if experiment_history.is_header_ready() else None
job_data = experiment_history.manager.get_all_last_job_data_dcs()
except Exception:
print(traceback.print_exc())
# Result variables
Expand Down
3 changes: 0 additions & 3 deletions autosubmit_api/builders/experiment_history_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ def make_experiment_history(self) -> ExperimentHistory:
self._validate_basic_config()
if not self.experiment_history_db_manager:
raise Exception("Experiment Database Manager is missing")
else:
if not self.experiment_history_db_manager.my_database_exists():
raise Exception("Job/Runs database does not exist")
if not self.logger:
raise Exception("Logging is missing.")
return ExperimentHistory(self.expid, self.basic_config, self.experiment_history_db_manager, self.logger)
Expand Down
1 change: 0 additions & 1 deletion autosubmit_api/experiment/common_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def get_experiment_data(expid):
if experiment_run and experiment_run.total > 0:
result["total_jobs"] = experiment_run.total
result["completed_jobs"] = experiment_run.completed
result["db_historic_version"] = experiment_history.manager.db_version
except Exception as exc:
logger.warning((traceback.format_exc()))
logger.warning((f"Warning: Error in get_experiment_data while reading historical data: {exc}"))
Expand Down
78 changes: 0 additions & 78 deletions autosubmit_api/history/database_managers/database_manager.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,32 @@

# You should have received a copy of the GNU General Public License
# along with Autosubmit. If not, see <http://www.gnu.org/licenses/>.
import os

from autosubmit_api.persistance.experiment import ExperimentPaths
from autosubmit_api.history.database_managers import database_models as Models
from autosubmit_api.history.data_classes.job_data import JobData
from autosubmit_api.history.data_classes.experiment_run import ExperimentRun
from autosubmit_api.config.basicConfig import APIBasicConfig
from autosubmit_api.history.database_managers.database_manager import DatabaseManager
from typing import List, Optional
from collections import namedtuple

from autosubmit_api.repositories.experiment_run import create_experiment_run_repository
from autosubmit_api.repositories.job_data import create_experiment_job_data_repository

class ExperimentHistoryDbManager(DatabaseManager):
class ExperimentHistoryDbManager:
""" Manages actions directly on the database.
"""
def __init__(self, expid: str, basic_config: APIBasicConfig):
""" Requires expid and jobdata_dir_path. """
super(ExperimentHistoryDbManager, self).__init__(expid, basic_config)
exp_paths = ExperimentPaths(expid)
self.historicaldb_file_path = exp_paths.job_data_db
if self.my_database_exists():
self.set_db_version_models()
""" Requires expid """
self.expid = expid
self.set_db_version_models()

self.runs_repo = create_experiment_run_repository(expid)
self.jobs_repo = create_experiment_job_data_repository(expid)

def set_db_version_models(self):
self.db_version = self._get_pragma_version()
self.experiment_run_row_model = Models.get_experiment_row_model(self.db_version)
self.job_data_row_model = Models.get_job_data_row_model(self.db_version)

def my_database_exists(self):
return os.path.exists(self.historicaldb_file_path)

def is_header_ready_db_version(self):
if self.my_database_exists():
return self._get_pragma_version() >= Models.DatabaseVersion.EXPERIMENT_HEADER_SCHEMA_CHANGES.value
return False
# From version 3.13.0 of Autosubmit, latest model is used.
self.experiment_run_row_model = Models.ExperimentRunRow
self.job_data_row_model = Models.JobDataRow

def get_experiment_run_dc_with_max_id(self):
""" Get Current (latest) ExperimentRun data class. """
Expand Down Expand Up @@ -148,11 +134,3 @@ def _get_job_data_by_name(self, job_name: str) -> List[namedtuple]:
self.job_data_row_model(**(job_data.model_dump()))
for job_data in job_data_rows
]

def _get_pragma_version(self) -> int:
""" Gets current pragma version as int. """
statement = "pragma user_version;"
pragma_result = self.get_from_statement(self.historicaldb_file_path, statement)
if len(pragma_result) <= 0:
raise Exception("Error while getting the pragma version. This might be a signal of a deeper problem. Review previous errors.")
return int(Models.PragmaVersion(*pragma_result[0]).version)
5 changes: 0 additions & 5 deletions autosubmit_api/history/experiment_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ def __init__(self, expid: str, basic_config: APIBasicConfig, experiment_history_
self._log.log(str(exp), traceback.format_exc())
self.manager = None

def is_header_ready(self):
if self.manager:
return self.manager.is_header_ready_db_version()
return False

def get_historic_job_data(self, job_name: str) -> List[Dict[str, Any]]:
result = []
all_job_data_dcs = self.manager.get_job_data_dcs_by_name(job_name)
Expand Down

0 comments on commit bacd5f6

Please sign in to comment.