Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 def _getColour(self, obj):
     if isType(obj, Job):
         from Ganga.GPIDev.Lib.Job.Job import lazyLoadJobStatus
         status_attr = lazyLoadJobStatus(stripProxy(obj))
     elif isType(obj, str):
         status_attr = obj
     elif isType(obj, dict):
         if 'display:status' in obj.keys():
             status_attr = obj['display:status']
         elif 'status' in obj.keys():
             status_attr = obj['status']
         else:
             status_attr = None
     else:
         status_attr = obj
     try:
         returnable = self.status_colours.get(status_attr, self.fx.normal)
     except Exception:
         returnable = self.status_colours.get(self.fx.normal)
     return returnable
Ejemplo n.º 4
0
 def _getColour(self, obj):
     if isType(obj, Job):
         from Ganga.GPIDev.Lib.Job.Job import lazyLoadJobStatus
         status_attr = lazyLoadJobStatus(stripProxy(obj))
     elif isType(obj, str):
         status_attr = obj
     elif isType(obj, dict):
         if 'display:status' in obj:
             status_attr = obj['display:status']
         elif 'status' in obj:
             status_attr = obj['status']
         else:
             status_attr = None
     else:
         status_attr = obj
     try:
         returnable = self.status_colours.get(status_attr, self.fx.normal)
     except Exception:
         returnable = self.status_colours.get(self.fx.normal)
     return returnable
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)