diff options
author | Michal Minar <miminar@redhat.com> | 2013-04-18 22:04:03 +0200 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2013-04-26 10:18:18 +0200 |
commit | 272c051e8453d0a98771d8741e08478f18bbf638 (patch) | |
tree | a56724b4537491217700576678b1b93d68dd7292 /src/software/openlmi | |
parent | 59e8bf604c382b9269b4448f10223de631b40036 (diff) | |
download | openlmi-providers-272c051e8453d0a98771d8741e08478f18bbf638.tar.gz openlmi-providers-272c051e8453d0a98771d8741e08478f18bbf638.tar.xz openlmi-providers-272c051e8453d0a98771d8741e08478f18bbf638.zip |
modified indication filters
And moved software static filters to shared JobManager.
Indication filters now reflect the name of indication class, which is
instrumented by particular provider. This ensures, that cimom knows,
which provider to call and does not bother the others. So instead of
selecting indication instances from general class CIM_InstModification,
it will be LMI_SoftwareInstModification. This is a common pattern for
indication queries.
Avoided another shortcoming of sfcbmof parser:
/* comment */ something useful is also ignored :-(
Static filters of JobManager made more generic for any provider
to use. Software jobmanager is now using them. This reduces redundation
of code.
Diffstat (limited to 'src/software/openlmi')
-rw-r--r-- | src/software/openlmi/software/cimom_entry.py | 7 | ||||
-rw-r--r-- | src/software/openlmi/software/yumdb/jobmanager.py | 81 |
2 files changed, 13 insertions, 75 deletions
diff --git a/src/software/openlmi/software/cimom_entry.py b/src/software/openlmi/software/cimom_entry.py index ad944c8..d507a01 100644 --- a/src/software/openlmi/software/cimom_entry.py +++ b/src/software/openlmi/software/cimom_entry.py @@ -26,6 +26,7 @@ Entry module for OpenLMI Software providers. from multiprocessing import Queue from openlmi.common import cmpi_logging +from openlmi.common import JobManager from openlmi.common.IndicationManager import IndicationManager from openlmi.software.core import InstallationJob from openlmi.software.LMI_SoftwareIdentity import LMI_SoftwareIdentity @@ -113,7 +114,7 @@ def get_providers(env): # daemon. That means it does not have to be cleaned up. im = IndicationManager.get_instance( env, "Software", "root/cimv2", queue=Queue()) - jobmanager.register_filters(im) + JobManager.register_filters("LMI_SoftwareInstallationJob", im) return providers @@ -123,11 +124,11 @@ def authorize_filter(env, fltr, ns, classes, owner): def activate_filter (env, fltr, ns, classes, first_activation): IndicationManager.get_instance().activate_filter( - env, fltr, ns, classes, first_activation) + env, fltr, class_name, class_path, first_activation) def deactivate_filter(env, fltr, ns, classes, last_activation): IndicationManager.get_instance().deactivate_filter( - env, fltr, ns, classes, last_activation) + env, fltr, class_name, class_path, last_activation) def enable_indications(env): IndicationManager.get_instance().enable_indications(env) diff --git a/src/software/openlmi/software/yumdb/jobmanager.py b/src/software/openlmi/software/yumdb/jobmanager.py index 7283d05..977b38f 100644 --- a/src/software/openlmi/software/yumdb/jobmanager.py +++ b/src/software/openlmi/software/yumdb/jobmanager.py @@ -39,8 +39,8 @@ import threading import time import traceback -from openlmi.common import cmpi_logging from openlmi.common.IndicationManager import IndicationManager +from openlmi.common.JobManager import JobManager as JM from openlmi.software.yumdb import errors, jobs from openlmi.software.yumdb.util import trace_function @@ -56,69 +56,6 @@ MINIMUM_TIME_BEFORE_REMOVAL = 10 # replacement for cmpi_logging.logger LOG = None -IND_JOB_PERCENT_UPDATED = "PercentUpdated" -IND_JOB_SUCCEEDED = "Succeeded" -IND_JOB_FAILED = "Failed" -IND_JOB_CHANGED = "Changed" -IND_JOB_CREATED = "Created" - -IND_FILTERS = { - IND_JOB_PERCENT_UPDATED: { - "Query" : "SELECT * FROM CIM_InstModification WHERE " - "SourceInstance ISA %(classname)s AND " - "SourceInstance.CIM_ConcreteJob::PercentComplete <> " - "PreviousInstance.CIM_ConcreteJob::PercentComplete", - "Description" : "Modification of Percentage Complete for a " - "Concrete Job.", - }, - IND_JOB_SUCCEEDED: { - "Query" : "SELECT * FROM CIM_InstModification WHERE " - "SourceInstance ISA %(classname)s AND " - "SourceInstance ISA LMI_SoftwareInstallationJob AND " - "SourceInstance.CIM_ConcreteJob::JobState = 17", - # symbolic constants not supported by sfcb - #"CIM_ConcreteJob.JobState#'Completed'" - "Description": "Modification of Operational Status for a " - "Concrete Job to 'Complete' and 'OK'.", - }, - IND_JOB_FAILED: { - "Query" : "SELECT * FROM CIM_InstModification WHERE " - "SourceInstance ISA %(classname)s AND " - "SourceInstance.CIM_ConcreteJob::JobState = 10", - # symbolic constants not supported by sfcb - #"CIM_ConcreteJob.JobState#'Exception'", - "Description": "Modification of Operational Status for a " - "Concrete Job to 'Complete' and 'Error'.", - }, - IND_JOB_CHANGED: { - "Query" : "SELECT * FROM CIM_InstModification WHERE " - "SourceInstance ISA %(classname)s AND " - "SourceInstance.CIM_ConcreteJob::JobState <> " - "PreviousInstance.CIM_ConcreteJob::JobState", - "Description": "Modification of Job State for a ConcreteJob.", - }, - IND_JOB_CREATED: { - "Query" : "SELECT * FROM CIM_InstCreation WHERE " - "SourceInstance ISA %(classname)s", - "Description": "Creation of a ConcreteJob.", - }, -} - -@cmpi_logging.trace_function -def register_filters(indication_manager): - """ - This function registers static indication filters at IndicationManager. - It should be called upon provider's initialization. - """ - to_register = {} - for fltr_id, fltr in IND_FILTERS.items(): - if not indication_manager.is_registered(JOB_CLASSNAME, fltr_id): - fltr["Query"] = fltr["Query"] % {"classname" : JOB_CLASSNAME } - to_register[fltr_id] = fltr - if to_register: - indication_manager.add_filters(JOB_CLASSNAME, - to_register, ensure_installed=False) - # ***************************************************************************** # Decorators # ***************************************************************************** @@ -183,7 +120,7 @@ class JobIndicationSender(object): """ def __init__(self, indication_manager, job, - indications=IND_JOB_CHANGED, new=None): + indications=JM.IND_JOB_CHANGED, new=None): """ :param job (``YumJob``) Is job instance, which will be immediately snapshoted as old instance and later as a new one. @@ -258,11 +195,11 @@ class JobIndicationSender(object): "can not send any indication without id") if make_snapshot: self.snapshot() - if ( IND_JOB_CHANGED in self._indications + if ( JM.IND_JOB_CHANGED in self._indications and self._new_instance is None): raise errors.IndicationError("no snapshot made for modified job") for fltr_id in self._indications: - if fltr_id == IND_JOB_CREATED: + if fltr_id == JM.IND_JOB_CREATED: LOG.debug("sending instance creation indication for job %s", self._job) self._indication_manager.send_instcreation( @@ -368,7 +305,7 @@ class JobManager(threading.Thread): LOG.debug('job %s enqued for YumWorker to handle', job) heapq.heappush(self._job_queue, job) if getattr(job, 'async', False) is True: - ind = self._prepare_indication_for(job, IND_JOB_CREATED) + ind = self._prepare_indication_for(job, JM.IND_JOB_CREATED) self._async_jobs[job.jobid] = job ind.send() self._job_enqueued.notify() @@ -557,7 +494,7 @@ class JobManager(threading.Thread): 'can not finish not started job "%s"' % job) if getattr(job, 'async', False): ind = self._prepare_indication_for(job, - (IND_JOB_CHANGED, IND_JOB_PERCENT_UPDATED)) + (JM.IND_JOB_CHANGED, JM.IND_JOB_PERCENT_UPDATED)) job.finish(result, result_data) if getattr(job, 'async', False): if job.delete_on_completion: @@ -566,9 +503,9 @@ class JobManager(threading.Thread): self._schedule_event(schedule_at, job.jobid, self.ACTION_REMOVE) if result == job.RESULT_SUCCESS: - ind.add_indication_ids(IND_JOB_SUCCEEDED) + ind.add_indication_ids(JM.IND_JOB_SUCCEEDED) elif result == job.RESULT_ERROR: - ind.add_indication_ids(IND_JOB_FAILED) + ind.add_indication_ids(JM.IND_JOB_FAILED) ind.send(True) else: LOG.debug("sending reply for %s: (%s, %s)", job, @@ -598,7 +535,7 @@ class JobManager(threading.Thread): if job is not None: if getattr(job, "async", False): ind = self._prepare_indication_for(job, - (IND_JOB_CHANGED, IND_JOB_PERCENT_UPDATED)) + (JM.IND_JOB_CHANGED, JM.IND_JOB_PERCENT_UPDATED)) job.start() ind.send(True) else: |