summaryrefslogtreecommitdiffstats
path: root/src/python/openlmi/common/JobManager.py
diff options
context:
space:
mode:
authorJan Safranek <jsafrane@redhat.com>2013-04-16 12:35:00 +0200
committerJan Safranek <jsafrane@redhat.com>2013-04-16 13:03:48 +0200
commitd34456742a7ca374716dafc0b5ea2328f2a789ec (patch)
tree233b9de334249c943526946a0b956562e6483ba7 /src/python/openlmi/common/JobManager.py
parent05d7ef102e0af91d342c2cb05998a0f8dce91dc8 (diff)
downloadopenlmi-providers-d34456742a7ca374716dafc0b5ea2328f2a789ec.tar.gz
openlmi-providers-d34456742a7ca374716dafc0b5ea2328f2a789ec.tar.xz
openlmi-providers-d34456742a7ca374716dafc0b5ea2328f2a789ec.zip
Remove whitespaces.
Diffstat (limited to 'src/python/openlmi/common/JobManager.py')
-rw-r--r--src/python/openlmi/common/JobManager.py150
1 files changed, 75 insertions, 75 deletions
diff --git a/src/python/openlmi/common/JobManager.py b/src/python/openlmi/common/JobManager.py
index 6dd26ba..1d1c7f7 100644
--- a/src/python/openlmi/common/JobManager.py
+++ b/src/python/openlmi/common/JobManager.py
@@ -19,10 +19,10 @@
"""
Basic infrastructure for asynchronous jobs. All necessary CIM classes and
indications are implemented here.
-
+
.. autoclass:: JobManager
:members:
-
+
.. autoclass:: Job
:members:
@@ -31,7 +31,7 @@
.. autoclass:: LMI_OwningJobElement
:members:
-
+
.. autoclass:: LMI_AffectedJobElement
:members:
@@ -59,10 +59,10 @@ class Job(object):
It remembers input and output arguments, affected ManagedElements and
owning ManagedElement (to be able to create associations to them)
and all CIM_ConcreteJob properties.
-
- Due to multiple threads processing the job, each job has its own
+
+ Due to multiple threads processing the job, each job has its own
lock to guard its status changes. It is expected that number of jobs
- is quite low.
+ is quite low.
"""
DEFAULT_TIME_BEFORE_REMOVAL = 60 # in seconds
@@ -84,7 +84,7 @@ class Job(object):
method_name, affected_elements, owning_element):
"""
Create new storage job.
-
+
:param job_manager: (``JobManager``) Reference to ``JobManager``, which
will manage this job.
:param job_name: (``string``) User-friendly name of the job.
@@ -185,11 +185,11 @@ class Job(object):
expected that the callback will take some time to execute. The callback
must change state of the job and set output parameters and error in a
thread-safe way, i.e. by calling ``finish_method()``.
-
+
:param callback: (``function``) Reference to callback to call.
:param args, kwargs: All other parameters will be passed to the
callback. It is highly recommended to add reference to the job
- to the callback.
+ to the callback.
"""
self._execute = callback
self._execargs = args
@@ -200,11 +200,11 @@ class Job(object):
"""
Set callbacks, which will be called when the job is to be
cancelled. The callback must be quick, the job is already locked!
-
+
:param callback: (``function``) Reference to callback to call.
:param args, kwargs: All other parameters will be passed to the
callback. It is highly recommended to add reference to the job
- to the callback.
+ to the callback.
"""
self._cancel = callback
self._cancelargs = args
@@ -217,7 +217,7 @@ class Job(object):
Mark the job as finished, with given return value, output parameters and
error.
This method is thread-safe.
-
+
:param new_state: (``Job.STATE_* value``) Resulting state of the job.
:param return_value: (``string``) Return value of the job, encoded
into string. Can be None when the job does not return any value.
@@ -249,7 +249,7 @@ class Job(object):
Change state of a job. (Re-)calculate various times based on the state
change. Send indications as necessary.
This method is thread-safe.
-
+
:param new_state: (``Job.STATE_* value``) New state of the job.
It can be the same as the previous state to indicate progress of
the job.
@@ -367,7 +367,7 @@ class Job(object):
@cmpi_logging.trace_method
def lock(self):
- """
+ """
Lock internal mutex. Other threads will block on subsequent lock().
The lock is recursive, i.e. can be called multiple times from
single thread.
@@ -384,7 +384,7 @@ class Job(object):
"""
Start executing the job. It calls the execute callback, set by
``set_execute_action()``.
-
+
job_state must be already set to STATE_RUNNING.
Any exception is translated to CIMError and appropriate state is set.
"""
@@ -417,7 +417,7 @@ class Job(object):
def get_name(self):
"""
Return CIMInstanceName of the job.
-
+
:rtype: ``CIMInstanceName``
"""
name = pywbem.CIMInstanceName(
@@ -432,7 +432,7 @@ class Job(object):
def get_instance_id(self, classname=None):
"""
Return InstanceID.
-
+
:param classname: (``string``) Optional classname to generate InstanceID
for different class, e.g. for LMI_<name>MethodResult.
:rtype: ``string``
@@ -445,7 +445,7 @@ class Job(object):
def parse_instance_id(instance_id, job_manager, classname=None):
"""
Return the last part of instance_id.
-
+
:param instance_id: (``string``) InstanceID to parse.
:param job_manager: (``JobManager``) JobManager to query for Job's
classname.
@@ -453,7 +453,7 @@ class Job(object):
JobManager's job_classname will be used for parsing. Other
classnames may be used to parse e.g. LMI_<name>MethodResult
InstanceIDs.
-
+
:rtype: ``string`` or None if the ``instance_id`` has wrong format.
"""
if classname is None:
@@ -471,10 +471,10 @@ class Job(object):
@cmpi_logging.trace_method
def get_pre_call(self):
- """
+ """
Return indication that describes the pre-execution values of the
job's invocation.
-
+
:rtype: ``CIMInstance of CIM_InstMethodCall``
"""
path = pywbem.CIMInstanceName(
@@ -496,10 +496,10 @@ class Job(object):
@cmpi_logging.trace_method
def get_post_call(self):
- """
+ """
Return indication that describes the post-execution values of the
job's invocation.
-
+
:rtype: ``CIMInstance of CIM_InstMethodCall``
"""
path = pywbem.CIMInstanceName(
@@ -540,7 +540,7 @@ class Job(object):
def _get_cim_instance(self):
"""
Return CIMInstance of this job.
-
+
:rtype: CIMInstance
"""
return self.job_manager.get_job_instance(self)
@@ -598,45 +598,45 @@ class Job(object):
class JobManager(object):
"""
Container of all queued, running or finished ``LMI_ConcreteJobs``.
-
+
Usage:
1. Create MOF file for these classes:
-
+
* ``LMI_<name>Job``
-
+
* ``LMI_<name>MethodResult``
-
+
* ``LMI_Affected<name>JobElement``
-
+
* ``LMI_Owning<name>JobElement``
-
+
* ``LMI_Associated<name>JobMethodResult``
-
+
Where ``<name>`` is prefix of your classes, for example 'Storage'
2. During initialization, initialize ``TimerManager`` and create
``JobManager``.
-
+
3. When needed. create new Job instance:
4. Set its execute callback using ``set_execute_action()``. This callback
will be called when the job is to be executed. It will be called in
context of ``JobManager`` worker thread!
-
+
5. Optionally, set cancel callback using ``set_execute_action()``. This
callback will be called when the job is still queued and is cancelled by
application. This callback will be called in context of CIMOM callback
and should be quick!
-
+
6. Enqueue the job using ``JobManager.add_job()`` method.
-
+
7. When your execute callback is called, you can optionally call
``job.change_state()`` to update percentage of completion.
-
+
8. When your execute callback is finished, don't forget to set method
result using ``job.finish_method()``.
-
+
* ``JobManager`` automatically sends all job-related indications.
* ``Job`` automatically tracks various timestamps.
* By default, the job automatically disappears after 60 seconds after it
@@ -653,16 +653,16 @@ class JobManager(object):
@cmpi_logging.trace_method
def __init__(self, name, namespace, indication_manager, timer_manager):
- """
+ """
Initialize new Manager. It automatically registers all job-related
filters to indication_manager and starts a worker thread.
-
+
:param name: (``string``) String with classname infix. For example
'Storage' for ``LMI_StorageJob``, ``LMI_StorageJobMethodResult``
etc.
- :param namespace: (``string``) Namespace of all providers.
+ :param namespace: (``string``) Namespace of all providers.
:param indication_manager: (``IndicationManager``): a manager where
- indications and filters should be added.
+ indications and filters should be added.
:param timer_manager: (``TimerManager``): Timer manager instance.
"""
# List of all jobs. Dictionary job_id -> Job.
@@ -752,7 +752,7 @@ class JobManager(object):
* ``LMI_Affected<name>JobElement``
* ``LMI_Owning<name>JobElement``
* ``LMI_Associated<name>JobMethodResult``
-
+
:rtype: dictionary class_name -> CIMProvider2
"""
@@ -783,7 +783,7 @@ class JobManager(object):
def add_job(self, job):
"""
Enqueue new job. Send indication when needed.
-
+
:param job: (``Job``) A job to enqueue.
"""
cmpi_logging.logger.debug("Job %s: '%s' enqueued"
@@ -803,7 +803,7 @@ class JobManager(object):
"""
Send InstModification. This is helper method called by ``Job`` when
needed.
-
+
:param prev_instance: Instance of ``LMI_<name>Job`` before it was
modified.
:param current_instance: Instance of ``LMI_<name>Job`` after it was
@@ -818,7 +818,7 @@ class JobManager(object):
"""
Remove existing job. Note that jobs are removed automatically after a
timeout, providers should not call this method directly.
-
+
:param job: (``Job``) Job to remove.
"""
cmpi_logging.logger.debug("Job %s: '%s' removed from queue."
@@ -832,7 +832,7 @@ class JobManager(object):
def get_job_for_instance_id(self, instance_id, classname=None):
"""
Return Job for given InstanceID or None when no such Job exist.
-
+
:param instance_id: (``string``) InstanceID value to parse.
:param classname: (``string``) Optional classname to parse the
InstanceID (e.g. when parsing InstanceID of
@@ -881,7 +881,7 @@ class JobManager(object):
def get_next_id(self):
"""
Return next unused job id.
-
+
:rtype: string
"""
self.last_instance_id += 1
@@ -891,7 +891,7 @@ class JobManager(object):
def get_job_instance(self, job):
"""
Return CIMInstance for given job.
-
+
:param job: (``Job``)
:rtype: ``CIMInstance``
"""
@@ -931,7 +931,7 @@ class LMI_ConcreteJob(CIMProvider2):
def get_job_states(self, job):
"""
Return JobState and OperationalStatus property values.
-
+
:param job: (``int``) Job.STATE_* value.
:rtype: tuple ``(JobState, OperationalStatus)`` values.
"""
@@ -1036,12 +1036,12 @@ class LMI_ConcreteJob(CIMProvider2):
"""Return a newly created or modified instance.
:param env: Provider Environment (pycimmb.ProviderEnvironment)
- :param instance: The new pywbem.CIMInstance. If modifying an existing
- instance, the properties on this instance have been filtered by
+ :param instance: The new pywbem.CIMInstance. If modifying an existing
+ instance, the properties on this instance have been filtered by
the PropertyList from the request.
:param modify_existing: True if ModifyInstance, False if CreateInstance
- Return the new instance. The keys must be set on the new instance.
+ Return the new instance. The keys must be set on the new instance.
"""
if not modify_existing:
raise pywbem.CIMError(pywbem.CIM_ERR_NOT_SUPPORTED,
@@ -1089,7 +1089,7 @@ class LMI_ConcreteJob(CIMProvider2):
"""Delete an instance.
:param env: Provider Environment (pycimmb.ProviderEnvironment)
- :param instance_name: A pywbem.CIMInstanceName specifying the instance
+ :param instance_name: A pywbem.CIMInstanceName specifying the instance
to delete.
"""
job = self.job_manager.get_job_for_instance_id(
@@ -1109,23 +1109,23 @@ class LMI_ConcreteJob(CIMProvider2):
If JobState is "Completed" and Operational Status is "Completed"
then no instance of CIM_Error is returned.
-
+
If JobState is "Exception" then GetErrors may return intances of
CIM_Error related to the execution of the procedure or method invoked by
the job.
-
+
If Operatational Status is not "OK" or "Completed" then
GetErrors may return CIM_Error instances related to the running of
the job.
-
+
:param env: -- Provider Environment (pycimmb.ProviderEnvironment)
- :param object_name: -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method GetErrors()
+ :param object_name: -- A pywbem.CIMInstanceName or pywbem.CIMCLassName
+ specifying the object on which the method GetErrors()
should be invoked.
Output parameters:
-
- * Errors -- (type pywbem.CIMInstance(classname='CIM_Error', ...))
+
+ * Errors -- (type pywbem.CIMInstance(classname='CIM_Error', ...))
If the OperationalStatus on the Job is not "OK", then this
method will return one or more CIM Error instance(s).
Otherwise, when the Job is "OK", null is returned.
@@ -1161,17 +1161,17 @@ class LMI_ConcreteJob(CIMProvider2):
Requests that the state of the job be changed to the value
specified in the RequestedState parameter. Invoking the
RequestStateChange method multiple times could result in earlier
- requests being overwritten or lost.
-
+ requests being overwritten or lost.
+
If 0 is returned, then the
task completed successfully. Any other return code indicates an
error condition.
-
+
:param env: Provider Environment (pycimmb.ProviderEnvironment)
- :param object_name: A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method RequestStateChange()
+ :param object_name: A pywbem.CIMInstanceName or pywbem.CIMCLassName
+ specifying the object on which the method RequestStateChange()
should be invoked.
- :param param_requestedstate: The input parameter RequestedState (type pywbem.Uint16 self.Values.RequestStateChange.RequestedState)
+ :param param_requestedstate: The input parameter RequestedState (type pywbem.Uint16 self.Values.RequestStateChange.RequestedState)
RequestStateChange changes the state of a job. The possible
values are as follows: Start (2) changes the state to
\'Running\'. Suspend (3) stops the job temporarily. The
@@ -1184,8 +1184,8 @@ class LMI_ConcreteJob(CIMProvider2):
data or preserve the state. Service (6) puts the job into a
vendor-specific service state. It might be possible to restart
the job.
-
- :param param_timeoutperiod: -- The input parameter TimeoutPeriod (type pywbem.CIMDateTime)
+
+ :param param_timeoutperiod: -- The input parameter TimeoutPeriod (type pywbem.CIMDateTime)
A timeout period that specifies the maximum amount of time that
the client expects the transition to the new state to take.
The interval format must be used to specify the TimeoutPeriod.
@@ -1251,21 +1251,21 @@ class LMI_ConcreteJob(CIMProvider2):
GetError is deprecated because Error should be an array,not a
scalar.
-
+
When the job is executing or has terminated without
error, then this method returns no CIM_Error instance. However, if
the job has failed because of some internal problem or because the
job has been terminated by a client, then a CIM_Error instance is
returned.
-
+
:param env: Provider Environment (pycimmb.ProviderEnvironment)
- :param object_name: A pywbem.CIMInstanceName or pywbem.CIMCLassName
- specifying the object on which the method GetError()
+ :param object_name: A pywbem.CIMInstanceName or pywbem.CIMCLassName
+ specifying the object on which the method GetError()
should be invoked.
Output parameters:
-
- * Error -- (``pywbem.CIMInstance(classname='CIM_Error', ...)``)
+
+ * Error -- (``pywbem.CIMInstance(classname='CIM_Error', ...)``)
If the OperationalStatus on the Job is not "OK", then this
method will return a CIM Error instance. Otherwise, when the
Job is "OK", null is returned.
@@ -1539,7 +1539,7 @@ class LMI_MethodResult(CIMProvider2):
yield self.get_instance(env, model, job)
class LMI_AssociatedJobMethodResult(CIMProvider2):
- """
+ """
Instrumentation of LMI_AssociatedJobMethodResult class and its
subclasses.
"""