Beispiel #1
0
def _dirac_check_proxy(renew=True, shouldRaise=True):
    """
    This function checks the validity of the DIRAC proxy
    Args:
        renew (bool): When True this will require a proxy to be valid before we proceed. False means raise Exception when expired
    """
    global last_modified_valid
    global proxy
    if proxy is None:
        proxy = getCredential('GridProxy')
    _isValid = proxy.isValid()
    if not _isValid:
        if renew is True:
            proxy.renew()
            if not proxy.isValid():
                last_modified_valid = False
                if shouldRaise:
                    raise GangaException(
                        'Can not execute DIRAC API code w/o a valid grid proxy.'
                    )
            else:
                last_modified_valid = True
        else:
            last_modified_valid = False
    else:
        last_modified_valid = True
Beispiel #2
0
    def check_proxy(self):
        '''Check the proxy and prompt the user to refresh it'''

        if self.credential is None:
            self.credential = getCredential('GridProxy',self.middleware)

        if self.middleware == 'GLITE':
            self.credential.voms = self.config['VirtualOrganisation'];
            self.credential = getCredential('GridProxy', 'GLITE')

        status = self.credential.renew(maxTry=3)

        if not status:
            logger.warning("Could not get a proxy, giving up after 3 retries")
            return False

        return True
Beispiel #3
0
 def __init__(self):
     self.end_data_str = '###END-DATA-TRANS###'
     self.port_min = 49512 # Mininum dynamic/private port number.
     self.port_max = 65535 # Maximum port number.
     self.server = None
     self.socket = None
     self.port = None        
     self.path = os.path.dirname(inspect.getsourcefile(DiracServer))
     logger.debug('Set DiracServer.path = %s' % self.path)
     self.server_id = random.randrange(0,os.sys.maxint)
     self.show_stdout = None
     self.proxy = getCredential('GridProxy', '')
Beispiel #4
0
    def execute(self, runid):
        # check for grid proxy
        
        GPcred = getCredential(name = 'GridProxy', create = 'False')

        timeleft = float(GPcred.timeleft("seconds"))

        # Get maxumin time tests allowed to take
        config = getConfig('TestRobot')
        MaxTestTime = config['JobTimeOut']
        
        if ( timeleft < MaxTestTime ):
            raise GangaRobotBreakError("Grid Proxy valid for %8.0f seconds but %d might be required to finish testing. Breaking." % (timeleft, MaxTestTime), Exception)
Beispiel #5
0
    def execute(self, runid):
        # check for grid proxy

        GPcred = getCredential(name='GridProxy', create='False')

        timeleft = float(GPcred.timeleft("seconds"))

        # Get maxumin time tests allowed to take
        config = getConfig('TestRobot')
        MaxTestTime = config['JobTimeOut']

        if (timeleft < MaxTestTime):
            raise GangaRobotBreakError(
                "Grid Proxy valid for %8.0f seconds but %d might be required to finish testing. Breaking."
                % (timeleft, MaxTestTime), Exception)
Beispiel #6
0
def _dirac_check_proxy( renew = True, shouldRaise = True):
    """
    This function checks the validity of the DIRAC proxy
    Args:
        renew (bool): When True this will require a proxy to be valid before we proceed. False means raise Exception when expired
    """
    global last_modified_valid
    global proxy
    if proxy is None:
        proxy = getCredential('GridProxy')
    _isValid = proxy.isValid()
    if not _isValid:
        if renew is True:
            proxy.renew()
            if not proxy.isValid():
                last_modified_valid = False
                if shouldRaise:
                    raise GangaException('Can not execute DIRAC API code w/o a valid grid proxy.')
            else:
                last_modified_valid = True
        else:
            last_modified_valid = False
    else:
        last_modified_valid = True
Beispiel #7
0
# Add errors to public interface
exportToPublicInterface('GangaAttributeError', GangaAttributeError,
                        'Exceptions')
exportToPublicInterface('ProtectedAttributeError', ProtectedAttributeError,
                        'Exceptions')
exportToPublicInterface('ReadOnlyObjectError', ReadOnlyObjectError,
                        'Exceptions')
exportToPublicInterface('JobError', JobError, 'Exceptions')

# ------------------------------------------------------------------------------------
# Import Monitoring Services
import Ganga.GPIDev.MonitoringServices

# ------------------------------------------------------------------------------------
# only the available credentials are exported
credential = getCredential(name='GridProxy', create=False)
if credential:
    exportToPublicInterface('gridProxy', GPIProxyObjectFactory(credential),
                            'Objects', 'Grid proxy management object.')

credential = getCredential('AfsToken')
if credential:
    exportToPublicInterface('afsToken', GPIProxyObjectFactory(credential),
                            'Objects', 'AFS token management object.')

# ------------------------------------------------------------------------------------
# Add Misc functions to public interface
exportToPublicInterface('license', ganga_license, 'Functions')
exportToPublicInterface('load', load, 'Functions')
exportToPublicInterface('export', export, 'Functions')
exportToPublicInterface('typename', typename, 'Functions')
Beispiel #8
0
 def __get_unique_fname__(self):
     """gets an unique filename"""
     cred = getCredential("GridProxy", self.middleware)
     uid = re.sub(r"[\:\-\(\)]{1,}", "", cred.identity()).lower()
     fname = "user.%s.%s" % (uid, get_uuid())
     return fname
Beispiel #9
0
import threading
import pickle
import signal
from Ganga.Utility.Config import getConfig
from Ganga.Utility.logging import getLogger
from Ganga.Core.exceptions import GangaException
from Ganga.GPIDev.Credentials import getCredential
import Ganga.Utility.execute as gexecute


import time
import math
import copy

logger = getLogger()
proxy = getCredential('GridProxy', '')

# Cache
# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
DIRAC_ENV = {}
DIRAC_INCLUDE = ''
Dirac_Env_Lock = threading.Lock()
Dirac_Proxy_Lock = threading.Lock()

# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


def getDiracEnv(force=False):
    global DIRAC_ENV
    global Dirac_Env_Lock
    lock = Dirac_Env_Lock
Beispiel #10
0
# except Exception as x:
#     raise Ganga.Utility.Config.ConfigError('Check configuration. Unable to set default Batch backend alias (%s)' % str(x))
# else:
#     allPlugins.add(batch_default, 'backends', 'Batch')
#     exportToPublicInterface('Batch', batch_default._proxyClass, 'Classes')

# ------------------------------------------------------------------------------------
# Add errors to public interface
exportToPublicInterface('GangaAttributeError', GangaAttributeError, 'Exceptions')
exportToPublicInterface('ProtectedAttributeError', ProtectedAttributeError, 'Exceptions')
exportToPublicInterface('ReadOnlyObjectError', ReadOnlyObjectError, 'Exceptions')
exportToPublicInterface('JobError', JobError, 'Exceptions')

# ------------------------------------------------------------------------------------
# only the available credentials are exported
credential = getCredential(name='GridProxy', create=False)
if credential:
    exportToPublicInterface('gridProxy', GPIProxyObjectFactory(credential), 'Objects', 'Grid proxy management object.')

credential = getCredential('AfsToken')
if credential:
    exportToPublicInterface('afsToken', GPIProxyObjectFactory(credential), 'Objects', 'AFS token management object.')

# ------------------------------------------------------------------------------------
# Add Misc functions to public interface
exportToPublicInterface('license', ganga_license, 'Functions')
exportToPublicInterface('load', load, 'Functions')
exportToPublicInterface('export', export, 'Functions')
exportToPublicInterface('typename', typename, 'Functions')
exportToPublicInterface('categoryname', categoryname, 'Functions')
exportToPublicInterface('plugins', plugins, 'Functions')
Beispiel #11
0
def credential():
    return getCredential('GridProxy')
Beispiel #12
0
    def __init__(self, job_info):
        IMonitoringService.__init__(self, job_info)

        if isinstance(job_info, DictionaryType):
            # we are on the worker node. We just need
            # to get values from the dictionary

            try:
                self.gangaJobId = job_info['gangaJobId']
                self.gangaTaskId = job_info['gangaTaskId']
                self.gridBackend = job_info['gridBackend']
                self.gridCertificate = job_info['gridCertificate']
                self.VO = job_info['VO']
                self._complete = True
            except KeyError as msg:
                # too bad, we will not monitor the job
                return
            # on the WN, we get the job ID from envar
            self.gridJobId = safe_getenv('EDG_WL_JOBID')
            if self.gridJobId == 'unknown':
                self.gridJobId = safe_getenv('GLITE_WL_JOBID')
                if self.gridJobId == 'unknown':
                    self._complete = False

        else:
            # we are in the client session. job_info is a Job()

            from Ganga.Utility.logging import getLogger
            self._logger = getLogger()

            job = job_info

            self.gridBackend = getattr(job, 'backend')._name
            if self.gridBackend not in ['LCG']:
                self._logger.debug('not sending monitoring because not in LCG')
                return

            self._logger.debug(job.backend)
            self._logger.debug(job.backend.id)
            self.gridJobId = job.backend.id

            # we compute the "jobID" and "taskID"
            # (which is the gangaJobId followed by the user@repository

            # the repository unique ID:
            from Ganga.Utility.Config import getConfig, ConfigError
            config = getConfig('Configuration')
            rep_type = config['repositorytype']
            rep_login = config['user']
            if 'Local' in rep_type:
                from Ganga.Runtime import Repository_runtime
                rep_dir = Repository_runtime.getLocalRoot()
                sys_config = getConfig('System')
                rep_hostname = sys_config['GANGA_HOSTNAME']
                rep_location = rep_hostname + ':' + rep_dir
            elif 'Remote' in rep_type:
                remote_config = getConfig(rep_type + "_Repository")
                rep_host = remote_config['host']
                rep_port = remote_config['port']
                rep_location = rep_host + ':' + rep_port
            else:
                return
            repository_id = rep_login + '@' + rep_location

            master_job = job.master

            if master_job is not None:
                master_id = master_job.id
                self._logger.debug('found master: %d' % master_id)
                self.gangaTaskId = self.taskPrefix + '_' + \
                    str(master_id) + '_' + repository_id
                self.gangaJobId = str(job.id)
            else:
                self.gangaTaskId = self.taskPrefix + \
                    '_' + str(job.id) + '_' + repository_id
                self.gangaJobId = '0'

            self._logger.debug('task_id = %s' % self.gangaTaskId)
            self._logger.debug('task_job_id = %s' % self.gangaJobId)

            backendConfig = getConfig(self.gridBackend)
            try:
                self.VO = backendConfig['VirtualOrganisation']
            except KeyError:
                self._logger.debug('VirtualOrganisation not configured')
                # we need it, it's too dangerous if we are not sure
                return

            from Ganga.GPIDev.Credentials import getCredential

            proxy = getCredential('GridProxy')
            self.gridCertificate = proxy.info('-subject')
            if self.gridCertificate is None:
                self._logger.debug('error: grid certificate not known')
                return

            if self.gridJobId is None:
                self._logger.debug('normal: grid job ID is None')

            self._logger.debug('job is complete')
            self._complete = True

        # we can now initialize the dashboard communication thing
        if self.gridJobId is not None:
            try:
                self.dashboard = DashboardAPI(
                    self.gangaTaskId, self.gangaJobId + '_' + self.gridJobId)
            except TypeError:
                self.dashboard = DashboardAPI(
                    self.gangaTaskId, self.gangaJobId + '_' + '_'.join(self.gridJobId))
Beispiel #13
0
import subprocess
import threading
import pickle
import signal
from Ganga.Utility.Config import getConfig
from Ganga.Utility.logging import getLogger
from Ganga.Core.exceptions import GangaException
from Ganga.GPIDev.Credentials import getCredential
import Ganga.Utility.execute as gexecute

import time
import math
import copy

logger = getLogger()
proxy = getCredential('GridProxy', '')

# Cache
# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
DIRAC_ENV = {}
DIRAC_INCLUDE = ''
Dirac_Env_Lock = threading.Lock()
Dirac_Proxy_Lock = threading.Lock()

# /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


def getDiracEnv(force=False):
    global DIRAC_ENV
    global Dirac_Env_Lock
    lock = Dirac_Env_Lock
Beispiel #14
0
 def __get_unique_fname__(self):
     '''gets an unique filename'''
     cred = getCredential('GridProxy', self.middleware)
     uid = re.sub(r'[\:\-\(\)]{1,}', '', cred.identity()).lower()
     fname = 'user.%s.%s' % (uid, get_uuid())
     return fname
Beispiel #15
0
def credential():
    return getCredential("GridProxy")
Beispiel #16
0
 def __get_unique_fname__(self):
     '''gets an unique filename'''
     cred = getCredential('GridProxy', self.middleware)
     uid = re.sub(r'[\:\-\(\)]{1,}', '', cred.identity()).lower()
     fname = 'user.%s.%s' % (uid, get_uuid())
     return fname