Commit f9366424 authored by Romain Therville's avatar Romain Therville 🐭

Update for issue #129

The srcipt had to be reworked, the retention period was relative to
"today", we wanted it relative to "the run or analysis's creation date".
Also, a message is raised and the process is stopped if the project
already belongs to the given space_id.

issue #129
parent 2e82534c
......@@ -116,7 +116,7 @@ class NG6ConfigReader(object):
def get_retention_date(self, space_id="default"):
"""
return the directory corresponding to space_id
return the retention corresponding to space_id
@return: space_dir
"""
date = None
......@@ -131,7 +131,28 @@ class NG6ConfigReader(object):
return date
except:
raise Exception("Failed when parsing the config file !")
raise ValueError("Failed while gnerating retention date!")
raise ValueError("Failed while generating retention date!")
def compute_new_retention_date(self, space_id="default", old_retention = None):
"""
return the retention corresponding to space_id
@return: space_dir
"""
date = None
try :
nb_month=self.reader.getint('space_'+space_id,"retention_period")
retention_date = time.mktime((datetime.datetime.fromtimestamp(old_retention)+ relativedelta(months=nb_month)).timetuple())
logging.getLogger("config_reader.compute_new_retention_date").error("IN retention period")
return retention_date
except:
try :
(d,m,y)=self.reader.get('space_'+space_id,"retention_date").split('/')
date = time.mktime(datetime.date(int(y),int(m),int(d)).timetuple())
logging.getLogger("config_reader.compute_new_retention_date").error("IN retention date")
return date
except:
raise Exception("Failed when parsing the config file !")
raise ValueError("Failed while generating retention date!")
def get_log_file_path(self):
"""
......
......@@ -1031,64 +1031,38 @@ class t3MySQLdb(object):
self.update_fields('tx_nG6_purge_demand',demand_ids,
["processed_date","demand_state"],
[date,"deleted"])
def set_run_retention_from_duration(self, run_id, duration):
"""
Updates a run's retention from a given duration (in months)
@param run_id : the run id
@param duration : the duration (in months)
"""
sql = "UPDATE tx_nG6_run SET retention_date = UNIX_TIMESTAMP(TIMESTAMPADD(MONTH,%s,FROM_UNIXTIME(crdate))) WHERE uid= '%s' "% ( duration, run_id )
self.execute(sql, commit = True )
def set_analysis_retention_from_duration(self, analysis_id, duration):
"""
Updates a run's retention from a given duration (in months)
@param analysis_id : the analysis id
@param duration : the duration (in months)
"""
sql = "UPDATE tx_nG6_analyze SET retention_date = UNIX_TIMESTAMP(TIMESTAMPADD(MONTH,%s,FROM_UNIXTIME(crdate))) WHERE uid= '%s' "% ( duration, analysis_id )
self.execute(sql, commit = True )
def set_run_retention_from_date(self, run_id, date):
"""
Updates a run's retention from a given date
@param run_id : the run id
@param date : the date (format dd/mm/yyyy)
"""
sql = "UPDATE tx_nG6_run SET retention_date = UNIX_TIMESTAMP( str_to_date('%s','%d/%m/%Y')) WHERE uid= '%s' "% ( date, run_id )
self.execute(sql, commit = True )
def set_analysis_retention_from_date(self, analysis_id, date):
"""
Updates a run's retention from a given date
@param analysis_id : the analysis id
@param date : the date (format dd/mm/yyyy)
"""
sql = "UPDATE tx_nG6_analyze SET retention_date = UNIX_TIMESTAMP( str_to_date('%s','%d/%m/%Y')) WHERE uid= '%s' "% ( date, analysis_id )
self.execute(sql, commit = True )
def set_run_retention_from_epoch_timestamp(self, run_id, date):
"""
Updates a run's retention from a given duration (in months)
@param run_id : the run id
@param duration : the duration (in months)
@param duration : the epoch timestamp
"""
sql = "UPDATE tx_nG6_run SET retention_date = '%s' WHERE uid= '%s' "% ( date, run_id )
self.execute(sql, commit = True )
def set_analysis_retention_from_depoch_timestamp(self, analysis_id, duration):
def set_analysis_retention_from_epoch_timestamp(self, analysis_id, date):
"""
Updates a run's retention from a given duration (in months)
@param analysis_id : the analysis id
@param duration : the duration (in months)
@param duration : the epoch timestamp
"""
sql = "UPDATE tx_nG6_analyze SET retention_date = '%s' WHERE uid= '%s' "% ( duration, analysis_id )
sql = "UPDATE tx_nG6_analyze SET retention_date = '%s' WHERE uid= '%s' "% ( date, analysis_id )
self.execute(sql, commit = True )
def get_run_analyzes_id_from_project(self, project_id):
sql = "SELECT analyze_id FROM tx_nG6_view_project_run_analyze WHERE project_id='%s'" % project_id
qresult = self.execute(sql)
return [ r[0] for r in qresult.rows ]
return [ r[0] for r in qresult.rows ]
def get_run_creation_date(self, run_id):
sql = "SELECT crdate FROM tx_nG6_run WHERE uid='%s'" % run_id
qresult = self.execute(sql)
return [ r[0] for r in qresult.rows ]
def get_analysis_creation_date(self, analysis_id):
sql = "SELECT crdate FROM tx_nG6_analyze WHERE uid='%s'" % analysis_id
qresult = self.execute(sql)
return [ r[0] for r in qresult.rows ]
\ No newline at end of file
......@@ -50,6 +50,11 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
self.project = Project.get_from_id(self.project_id)
old_space_id = self.project.space_id
#We raise an error and return None if the project already has the given space_id
if str(old_space_id) == str(self.space_id) :
raise Exception("The project " + self.project.name + " already belongs to the space_id '" + str(self.space_id) + "'" )
return None
#Update to the projcet's space_id
t3mysql = t3MySQLdb()
t3mysql.update_fields('tx_nG6_project', str(self.project_id), ['space_id'], [str(self.space_id)] )
......@@ -59,7 +64,9 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
old_directory = ng6conf.get_space_directory(old_space_id)
new_directory = ng6conf.get_space_directory(self.space_id)
new_retention = ng6conf.get_retention_date(self.space_id)
#new_retention = ng6conf.get_retention_date(self.space_id)
#new_retention = ng6conf.compute_new_retention_date(self.space_id, old_retention)
base_path = ng6conf.get_save_directory()
#Process for the project's runs
......@@ -88,6 +95,8 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
os.rmdir(path_old_run_directory)
#Update the retention in DB
old_retention = t3mysql.get_run_creation_date(run_id)
new_retention = ng6conf.compute_new_retention_date(self.space_id, next(iter(old_retention)))
t3mysql.set_run_retention_from_epoch_timestamp(run_id, new_retention)
#Process for the project's analyzes
......@@ -116,7 +125,9 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
os.rmdir(path_old_analysis_directory)
#Update the retention in DB
t3mysql.set_analysis_retention_from_depoch_timestamp(analysis_id, new_retention)
old_retention = t3mysql.get_analysis_creation_date(analysis_id)
new_retention = ng6conf.compute_new_retention_date(self.space_id, next(iter(old_retention)))
t3mysql.set_analysis_retention_from_epoch_timestamp(analysis_id, new_retention)
#Process for the project's run's analyzes
run_analyzes_ids = t3mysql.get_run_analyzes_id_from_project(self.project_id)
......@@ -144,4 +155,6 @@ class SwitchProjectSpaceId (BasicNG6Workflow):
os.rmdir(path_old_analysis_directory)
#Update the retention in DB
t3mysql.set_analysis_retention_from_depoch_timestamp(analysis_id, new_retention)
\ No newline at end of file
old_retention = t3mysql.get_analysis_creation_date(analysis_id)
new_retention = ng6conf.compute_new_retention_date(self.space_id, next(iter(old_retention)))
t3mysql.set_analysis_retention_from_epoch_timestamp(analysis_id, new_retention)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment