Revision 07cd723a

b/daemons/ganeti-masterd
216 216
      job_id = args
217 217
      return queue.ArchiveJob(job_id)
218 218

  
219
    elif method == luxi.REQ_AUTOARCHIVE_JOBS:
220
      age = args
221
      return queue.AutoArchiveJobs(age)
222

  
219 223
    elif method == luxi.REQ_WAIT_FOR_JOB_CHANGE:
220 224
      (job_id, fields, prev_job_info, prev_log_serial, timeout) = args
221 225
      return queue.WaitForJobChanges(job_id, fields, prev_job_info,
b/lib/cli.py
47 47
           "USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT", "SUBMIT_OPT",
48 48
           "ListTags", "AddTags", "RemoveTags", "TAG_SRC_OPT",
49 49
           "FormatError", "SplitNodeOption", "SubmitOrSend",
50
           "JobSubmittedException", "FormatTimestamp",
50
           "JobSubmittedException", "FormatTimestamp", "ParseTimespec",
51 51
           ]
52 52

  
53 53

  
b/lib/jqueue.py
666 666
    finally:
667 667
      self.UpdateJobUnlocked(job)
668 668

  
669
  @utils.LockedMethod
670 669
  @_RequireOpenQueue
671
  def ArchiveJob(self, job_id):
670
  def _ArchiveJobUnlocked(self, job_id):
672 671
    """Archives a job.
673 672

  
674 673
    @type job_id: string
675 674
    @param job_id: Job ID of job to be archived.
676 675

  
677 676
    """
678
    logging.debug("Archiving job %s", job_id)
677
    logging.info("Archiving job %s", job_id)
679 678

  
680 679
    job = self._LoadJobUnlocked(job_id)
681 680
    if not job:
......
695 694

  
696 695
    logging.debug("Successfully archived job %s", job.id)
697 696

  
697
  @utils.LockedMethod
698
  @_RequireOpenQueue
699
  def ArchiveJob(self, job_id):
700
    """Archives a job.
701

  
702
    @type job_id: string
703
    @param job_id: Job ID of job to be archived.
704

  
705
    """
706
    return self._ArchiveJobUnlocked(job_id)
707

  
708
  @utils.LockedMethod
709
  @_RequireOpenQueue
710
  def AutoArchiveJobs(self, age):
711
    """Archives all jobs based on age.
712

  
713
    The method will archive all jobs which are older than the age
714
    parameter. For jobs that don't have an end timestamp, the start
715
    timestamp will be considered. The special '-1' age will cause
716
    archival of all jobs (that are not running or queued).
717

  
718
    @type age: int
719
    @param age: the minimum age in seconds
720

  
721
    """
722
    logging.info("Archiving jobs with age more than %s seconds", age)
723

  
724
    now = time.time()
725
    for jid in self._GetJobIDsUnlocked(archived=False):
726
      job = self._LoadJobUnlocked(jid)
727
      if job.CalcStatus() not in (constants.OP_STATUS_SUCCESS,
728
                                  constants.OP_STATUS_ERROR,
729
                                  constants.OP_STATUS_CANCELED):
730
        continue
731
      if job.end_timestamp is None:
732
        if job.start_timestamp is None:
733
          job_age = job.received_timestamp
734
        else:
735
          job_age = job.start_timestamp
736
      else:
737
        job_age = job.end_timestamp
738

  
739
      if age == -1 or now - job_age[0] > age:
740
        self._ArchiveJobUnlocked(jid)
741

  
698 742
  def _GetJobInfoUnlocked(self, job, fields):
699 743
    row = []
700 744
    for fname in fields:
b/lib/luxi.py
47 47
REQ_WAIT_FOR_JOB_CHANGE = "WaitForJobChange"
48 48
REQ_CANCEL_JOB = "CancelJob"
49 49
REQ_ARCHIVE_JOB = "ArchiveJob"
50
REQ_AUTOARCHIVE_JOBS = "AutoArchiveJobs"
50 51
REQ_QUERY_JOBS = "QueryJobs"
51 52
REQ_QUERY_INSTANCES = "QueryInstances"
52 53
REQ_QUERY_NODES = "QueryNodes"
......
290 291
  def ArchiveJob(self, job_id):
291 292
    return self.CallMethod(REQ_ARCHIVE_JOB, job_id)
292 293

  
294
  def AutoArchiveJobs(self, age):
295
    return self.CallMethod(REQ_AUTOARCHIVE_JOBS, age)
296

  
293 297
  def WaitForJobChange(self, job_id, fields, prev_job_info, prev_log_serial):
294 298
    timeout = (DEF_RWTO - 1) / 2
295 299
    while True:
b/scripts/gnt-job
116 116
  return 0
117 117

  
118 118

  
119
def AutoArchiveJobs(opts, args):
120
  client = GetClient()
121

  
122
  age = args[0]
123

  
124
  if age == 'all':
125
    age = -1
126
  else:
127
    age = ParseTimespec(age)
128

  
129
  client.AutoArchiveJobs(age)
130
  return 0
131

  
132

  
119 133
def CancelJobs(opts, args):
120 134
  client = GetClient()
121 135

  
......
261 275
              [DEBUG_OPT],
262 276
              "<job-id> [<job-id> ...]",
263 277
              "Archive specified jobs"),
278
  'autoarchive': (AutoArchiveJobs, ARGS_ONE,
279
              [DEBUG_OPT],
280
              "<age>",
281
              "Auto archive jobs older than the given age"),
264 282
  'cancel': (CancelJobs, ARGS_ANY,
265 283
             [DEBUG_OPT],
266 284
             "<job-id> [<job-id> ...]",

Also available in: Unified diff