Revision 1410a389

b/lib/jqueue.py
62 62

  
63 63

  
64 64
JOBQUEUE_THREADS = 25
65
JOBS_PER_ARCHIVE_DIRECTORY = 10000
66 65

  
67 66
# member lock names to be passed to @ssynchronized decorator
68 67
_LOCK = "_lock"
......
1797 1796
    result = self._GetRpc(addrs).call_jobqueue_rename(names, rename)
1798 1797
    self._CheckRpcResult(result, self._nodes, "Renaming files (%r)" % rename)
1799 1798

  
1800
  @staticmethod
1801
  def _FormatJobID(job_id):
1802
    """Convert a job ID to string format.
1803

  
1804
    Currently this just does C{str(job_id)} after performing some
1805
    checks, but if we want to change the job id format this will
1806
    abstract this change.
1807

  
1808
    @type job_id: int or long
1809
    @param job_id: the numeric job id
1810
    @rtype: str
1811
    @return: the formatted job id
1812

  
1813
    """
1814
    if not isinstance(job_id, (int, long)):
1815
      raise errors.ProgrammerError("Job ID '%s' not numeric" % job_id)
1816
    if job_id < 0:
1817
      raise errors.ProgrammerError("Job ID %s is negative" % job_id)
1818

  
1819
    return str(job_id)
1820

  
1821
  @classmethod
1822
  def _GetArchiveDirectory(cls, job_id):
1823
    """Returns the archive directory for a job.
1824

  
1825
    @type job_id: str
1826
    @param job_id: Job identifier
1827
    @rtype: str
1828
    @return: Directory name
1829

  
1830
    """
1831
    return str(int(job_id) / JOBS_PER_ARCHIVE_DIRECTORY)
1832

  
1833 1799
  def _NewSerialsUnlocked(self, count):
1834 1800
    """Generates a new job identifier.
1835 1801

  
......
1850 1816
    self._UpdateJobQueueFile(constants.JOB_QUEUE_SERIAL_FILE,
1851 1817
                             "%s\n" % serial, True)
1852 1818

  
1853
    result = [self._FormatJobID(v)
1819
    result = [jstore.FormatJobID(v)
1854 1820
              for v in range(self._last_serial + 1, serial + 1)]
1855 1821

  
1856 1822
    # Keep it only if we were able to write the file
......
1872 1838
    """
1873 1839
    return utils.PathJoin(constants.QUEUE_DIR, "job-%s" % job_id)
1874 1840

  
1875
  @classmethod
1876
  def _GetArchivedJobPath(cls, job_id):
1841
  @staticmethod
1842
  def _GetArchivedJobPath(job_id):
1877 1843
    """Returns the archived job file for a give job id.
1878 1844

  
1879 1845
    @type job_id: str
......
1883 1849

  
1884 1850
    """
1885 1851
    return utils.PathJoin(constants.JOB_QUEUE_ARCHIVE_DIR,
1886
                          cls._GetArchiveDirectory(job_id), "job-%s" % job_id)
1852
                          jstore.GetArchiveDirectory(job_id),
1853
                          "job-%s" % job_id)
1887 1854

  
1888 1855
  @staticmethod
1889 1856
  def _GetJobIDsUnlocked(sort=True):
......
2220 2187

  
2221 2188
    """
2222 2189
    if not isinstance(job_id, basestring):
2223
      job_id = self._FormatJobID(job_id)
2190
      job_id = jstore.FormatJobID(job_id)
2224 2191

  
2225 2192
    # Not using in-memory cache as doing so would require an exclusive lock
2226 2193

  
b/lib/jstore.py
30 30
from ganeti import utils
31 31

  
32 32

  
33
JOBS_PER_ARCHIVE_DIRECTORY = 10000
34

  
35

  
33 36
def _ReadNumericFile(file_name):
34 37
  """Reads a file containing a number.
35 38

  
......
168 171
    utils.RemoveFile(constants.JOB_QUEUE_DRAIN_FILE)
169 172

  
170 173
  assert (not drain_flag) ^ CheckDrainFlag()
174

  
175

  
176
def FormatJobID(job_id):
177
  """Convert a job ID to string format.
178

  
179
  Currently this just does C{str(job_id)} after performing some
180
  checks, but if we want to change the job id format this will
181
  abstract this change.
182

  
183
  @type job_id: int or long
184
  @param job_id: the numeric job id
185
  @rtype: str
186
  @return: the formatted job id
187

  
188
  """
189
  if not isinstance(job_id, (int, long)):
190
    raise errors.ProgrammerError("Job ID '%s' not numeric" % job_id)
191
  if job_id < 0:
192
    raise errors.ProgrammerError("Job ID %s is negative" % job_id)
193

  
194
  return str(job_id)
195

  
196

  
197
def GetArchiveDirectory(job_id):
198
  """Returns the archive directory for a job.
199

  
200
  @type job_id: str
201
  @param job_id: Job identifier
202
  @rtype: str
203
  @return: Directory name
204

  
205
  """
206
  return str(int(job_id) / JOBS_PER_ARCHIVE_DIRECTORY)

Also available in: Unified diff