class documentation

class JobQueue(object):

View In Hierarchy

Queue used to manage the jobs.

Class Method SubmitManyJobs Create and store multiple jobs.
Method __init__ Constructor for JobQueue.
Method CancelJob Cancels a job.
Method ChangeJobPriority Changes a job's priority.
Method HasJobBeenFinalized Checks if a job has been finalized.
Method SafeLoadJobFromDisk Load the given job file from disk.
Method UpdateJobUnlocked Update a job's on disk storage.
Instance Variable context Undocumented
Instance Variable depmgr Undocumented
Class Method _GetJobIDsUnlocked Return all known job IDs.
Static Method _CheckRpcResult Verifies the status of an RPC call.
Static Method _DetermineJobDirectories Build list of directories containing job files.
Static Method _GetArchivedJobPath Returns the archived job file for a give job id.
Static Method _GetJobPath Returns the job file for a given job id.
Static Method _ResolveJobDependencies Resolves relative job IDs in dependencies.
Method _GetJobStatusForDependencies Gets the status of a job for dependencies.
Method _GetNodeIp Helper for returning the node name/ip list.
Method _GetRpc Gets RPC runner with context.
Method _LoadJobFromDisk Load the given job file from disk.
Method _LoadJobUnlocked Loads a job from the disk or memory.
Method _ModifyJobUnlocked Modifies a job.
Method _RenameFilesUnlocked Renames a file locally and then replicate the change.
Method _UpdateJobQueueFile Writes a file locally and then replicates it to all nodes.
Instance Variable _memcache Undocumented
Instance Variable _my_hostname Undocumented
Instance Variable _nodes Undocumented
@classmethod
def SubmitManyJobs(cls, jobs):

Create and store multiple jobs.

def __init__(self, context, cfg):

Constructor for JobQueue.

The constructor will initialize the job queue object and then start loading the current jobs from disk, either for starting them (if they were queue) or for aborting them (if they were already running).

Parameters
context:GanetiContextthe context object for access to the configuration data and other ganeti objects
cfgUndocumented
def CancelJob(self, job_id):

Cancels a job.

This will only succeed if the job has not started yet.

Parameters
job_id:intjob ID of job to be cancelled.
def ChangeJobPriority(self, job_id, priority):

Changes a job's priority.

Parameters
job_id:intID of the job whose priority should be changed
priority:intNew priority
def HasJobBeenFinalized(self, job_id):

Checks if a job has been finalized.

Parameters
job_id:intJob identifier
Returns
booleanTrue if the job has been finalized, False if the timeout has been reached, None if the job doesn't exist
def SafeLoadJobFromDisk(self, job_id, try_archived, writable=None):

Load the given job file from disk.

Given a job file, read, load and restore it in a _QueuedJob format. In case of error reading the job, it gets returned as None, and the exception is logged.

Parameters
job_id:intjob identifier
try_archived:boolWhether to try loading an archived job
writableUndocumented
Returns
_QueuedJob or Noneeither None or the job object
def UpdateJobUnlocked(self, job, replicate=True):

Update a job's on disk storage.

After a job has been modified, this function needs to be called in order to write the changes to disk and replicate them to the other nodes.

Parameters
job:_QueuedJobthe changed job
replicate:booleanwhether to replicate the change to remote nodes
context =

Undocumented

depmgr =

Undocumented

@classmethod
def _GetJobIDsUnlocked(cls, sort=True, archived=False):

Return all known job IDs.

The method only looks at disk because it's a requirement that all jobs are present on disk (so in the _memcache we don't have any extra IDs).

Parameters
sort:booleanperform sorting on the returned job ids
archivedUndocumented
Returns
listthe list of job IDs
@staticmethod
def _CheckRpcResult(result, nodes, failmsg):

Verifies the status of an RPC call.

Since we aim to keep consistency should this node (the current master) fail, we will log errors if our rpc fail, and especially log the case when more than half of the nodes fails.

Parameters
resultthe data as returned from the rpc call
nodes:listthe list of nodes we made the call to
failmsg:strthe identifier to be used for logging
@staticmethod
def _DetermineJobDirectories(archived):

Build list of directories containing job files.

Parameters
archived:boolWhether to include directories for archived jobs
Returns
listUndocumented
@staticmethod
def _GetArchivedJobPath(job_id):

Returns the archived job file for a give job id.

Parameters
job_id:strthe job identifier
Returns
strthe path to the archived job file
@staticmethod
def _GetJobPath(job_id):

Returns the job file for a given job id.

Parameters
job_id:strthe job identifier
Returns
strthe path to the job file
@staticmethod
def _ResolveJobDependencies(resolve_fn, deps):

Resolves relative job IDs in dependencies.

Parameters
resolve_fn:callableFunction to resolve a relative job ID
deps:listDependencies
Returns
tuple; (boolean, string or list)If successful (first tuple item), the returned list contains resolved job IDs along with the requested status; if not successful, the second element is an error message
def _GetJobStatusForDependencies(self, job_id):

Gets the status of a job for dependencies.

Parameters
job_id:intJob ID
Raises
errors.JobLostIf job can't be found
def _GetNodeIp(self):

Helper for returning the node name/ip list.

Returns
(list, list)a tuple of two lists, the first one with the node names and the second one with the node addresses
def _GetRpc(self, address_list):

Gets RPC runner with context.

def _LoadJobFromDisk(self, job_id, try_archived, writable=None):

Load the given job file from disk.

Given a job file, read, load and restore it in a _QueuedJob format.

Parameters
job_id:intjob identifier
try_archived:boolWhether to try loading an archived job
writableUndocumented
Returns
_QueuedJob or Noneeither None or the job object
def _LoadJobUnlocked(self, job_id):

Loads a job from the disk or memory.

Given a job id, this will return the cached job object if existing, or try to load the job from the disk. If loading from disk, it will also add the job to the cache.

Parameters
job_id:intthe job id
Returns
_QueuedJob or Noneeither None or the job object
def _ModifyJobUnlocked(self, job_id, mod_fn):

Modifies a job.

Parameters
job_id:intJob ID
mod_fn:callableModifying function, receiving job object as parameter, returning tuple of (status boolean, message string)
def _RenameFilesUnlocked(self, rename):

Renames a file locally and then replicate the change.

This function will rename a file in the local queue directory and then replicate this rename to all the other nodes we have.

Parameters
rename:list of (old, new)List containing tuples mapping old to new names
def _UpdateJobQueueFile(self, file_name, data, replicate):

Writes a file locally and then replicates it to all nodes.

This function will replace the contents of a file on the local node and then replicate it to all the other nodes we have.

Parameters
file_name:strthe path of the file to be replicated
data:strthe new contents of the file
replicate:booleanwhether to spread the changes to the remote nodes
_memcache =

Undocumented

_my_hostname =

Undocumented

_nodes =

Undocumented