Exemplo n.º 1
0
    def __init__(self, config, name):
        glite_path = os.environ.get('GLITE_WMS_LOCATION',
                                    os.environ.get('GLITE_LOCATION', ''))
        stored_sys_path = list(sys.path)
        for p in [
                'lib', 'lib64',
                os.path.join('lib', 'python'),
                os.path.join('lib64', 'python')
        ]:
            sys.path.append(os.path.join(glite_path, p))

        try:  # gLite 3.2
            import wmsui_api
            glStates = wmsui_api.states_names

            def getStatusDirect(wmsID):
                try:  # new parameter json
                    jobStatus = wmsui_api.getStatus(
                        wmsui_api.getJobIdfromList(None, [wmsID])[0], 0)
                except Exception:
                    jobStatus = wmsui_api.getStatus(
                        wmsui_api.getJobIdfromList([wmsID])[0], 0)
                return lmap(
                    lambda name: (name.lower(
                    ), jobStatus.getAttribute(glStates.index(name))), glStates)
        except Exception:  # gLite 3.1
            try:
                from glite_wmsui_LbWrapper import Status
                import Job
                wrStatus = Status()
                jobStatus = Job.JobStatus(wrStatus)

                def getStatusDirect(wmsID):
                    wrStatus.getStatus(wmsID, 0)
                    err, apiMsg = wrStatus.get_error()
                    if err:
                        raise BackendError(apiMsg)
                    info = wrStatus.loadStatus()
                    return lzip(imap(str.lower, jobStatus.states_names),
                                info[0:jobStatus.ATTR_MAX])
            except Exception:
                getStatusDirect = None
        sys.path = stored_sys_path

        checkExecutor = None
        if getStatusDirect:
            checkExecutor = GliteWMSDirect_CheckJobs(config, getStatusDirect)
        GliteWMS.__init__(self, config, name, checkExecutor=checkExecutor)