def isCredentialRequired(credObj): """ The logic to decide if a given invalid credential should trigger the deactivation of Ganga internal services. """ from Ganga.Runtime import Workspace_runtime from Ganga.Runtime import Repository_runtime if getName(credObj) == 'AfsToken': return Workspace_runtime.requiresAfsToken() or Repository_runtime.requiresAfsToken() if getName(credObj) == 'GridProxy': from Ganga.Core.GangaRepository import getRegistryProxy from Ganga.Runtime.GPIFunctions import typename from Ganga.GPIDev.Base.Proxy import stripProxy from Ganga.GPIDev.Lib.Job.Job import lazyLoadJobBackend, lazyLoadJobStatus for j in getRegistryProxy('jobs'): ji = stripProxy(j) this_status = lazyLoadJobStatus(ji) if this_status in ['submitted', 'running', 'completing']: this_backend = lazyLoadJobBackend(ji) if getName(this_backend) == 'LCG': return True return False log.warning("Unknown credential object : %s" % credObj)
def isCredentialRequired(credObj): """ The logic to decide if a given invalid credential should trigger the deactivation of Ganga internal services. """ from Ganga.Runtime import Workspace_runtime from Ganga.Runtime import Repository_runtime if getName(credObj) == 'AfsToken': return Workspace_runtime.requiresAfsToken( ) or Repository_runtime.requiresAfsToken() if getName(credObj) == 'GridProxy': from Ganga.Core.GangaRepository import getRegistryProxy from Ganga.Runtime.GPIFunctions import typename from Ganga.GPIDev.Base.Proxy import stripProxy from Ganga.GPIDev.Lib.Job.Job import lazyLoadJobBackend, lazyLoadJobStatus for j in getRegistryProxy('jobs'): ji = stripProxy(j) this_status = lazyLoadJobStatus(ji) if this_status in ['submitted', 'running', 'completing']: this_backend = lazyLoadJobBackend(ji) if getName(this_backend) == 'LCG': return True return False log.warning("Unknown credential object : %s" % credObj)
def __defaultActiveBackendsFunc(self): log.debug("__defaultActiveBackendsFunc") active_backends = {} # FIXME: this is not thread safe: if the new jobs are added then # iteration exception is raised fixed_ids = self.registry.ids() #log.debug("Registry: %s" % str(self.registry)) log.debug("Running over fixed_ids: %s" % str(fixed_ids)) for i in fixed_ids: try: j = stripProxy(self.registry(i)) job_status = lazyLoadJobStatus(j) backend_obj = lazyLoadJobBackend(j) backend_name = getName(backend_obj) if job_status in ['submitted', 'running' ] or (j.master and (job_status in ['submitting'])): if self.enabled is True and self.alive is True: active_backends.setdefault(backend_name, []) active_backends[backend_name].append(j) except RegistryKeyError as err: log.debug("RegistryKeyError: The job was most likely removed") log.debug("RegError %s" % str(err)) except RegistryLockError as err: log.debug("RegistryLockError: The job was most likely removed") log.debug("Reg LockError%s" % str(err)) summary = '{' for backend, these_jobs in active_backends.iteritems(): summary += '"' + str(backend) + '" : [' for this_job in these_jobs: #stripProxy(this_job)._getWriteAccess() summary += str( stripProxy(this_job).id) + ', ' #getFQID('.')) + ', ' summary += '], ' summary += '}' log.debug("Returning active_backends: %s" % summary) return active_backends
def __defaultActiveBackendsFunc(self): log.debug("__defaultActiveBackendsFunc") active_backends = {} # FIXME: this is not thread safe: if the new jobs are added then # iteration exception is raised fixed_ids = self.registry.ids() #log.debug("Registry: %s" % str(self.registry)) log.debug("Running over fixed_ids: %s" % str(fixed_ids)) for i in fixed_ids: try: j = stripProxy(self.registry(i)) job_status = lazyLoadJobStatus(j) backend_obj = lazyLoadJobBackend(j) backend_name = getName(backend_obj) if job_status in ['submitted', 'running'] or (j.master and (job_status in ['submitting'])): if self.enabled is True and self.alive is True: active_backends.setdefault(backend_name, []) active_backends[backend_name].append(j) except RegistryKeyError as err: log.debug("RegistryKeyError: The job was most likely removed") log.debug("RegError %s" % str(err)) except RegistryLockError as err: log.debug("RegistryLockError: The job was most likely removed") log.debug("Reg LockError%s" % str(err)) summary = '{' for backend, these_jobs in active_backends.iteritems(): summary += '"' + str(backend) + '" : [' for this_job in these_jobs: #stripProxy(this_job)._getWriteAccess() summary += str(stripProxy(this_job).id) + ', '#getFQID('.')) + ', ' summary += '], ' summary += '}' log.debug("Returning active_backends: %s" % summary) return active_backends
def test_b_JobNotLoaded(self): """ Second get the job and check that getting it via jobs doesn't cause it to be loaded""" from Ganga.GPI import jobs from Ganga.GPIDev.Base.Proxy import stripProxy from Ganga.GPIDev.Lib.Job.Job import lazyLoadJobApplication, lazyLoadJobBackend, lazyLoadJobStatus, lazyLoadJobFQID self.assertEqual(len(jobs), numJobs) print("len: %s" % len(jobs)) for j in jobs: if j.id != 9: raw_j = stripProxy(j) has_loaded_job = raw_j._getRegistry().has_loaded(raw_j) self.assertFalse(has_loaded_job) for j in jobs: if j.id != 9: raw_j = stripProxy(j) print("job: %s status = %s" % (j.id, j.status)) app = lazyLoadJobApplication(raw_j) back = lazyLoadJobBackend(raw_j) stat = lazyLoadJobStatus(raw_j) fq = lazyLoadJobFQID(raw_j) has_loaded_job = raw_j._getRegistry().has_loaded(raw_j) self.assertFalse(has_loaded_job)