ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ServerConfig.py
Revision: 1.28
Committed: Tue May 4 17:24:59 2010 UTC (15 years ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_8_4, CRAB_2_8_4_pre5, CRAB_2_8_4_pre4, CRAB_2_8_4_pre3, CRAB_2_8_4_pre2, CRAB_2_8_4_pre1, CRAB_2_8_3, CRAB_2_8_3_pre4, CRAB_2_8_3_pre3, CRAB_2_8_3_pre2, CRAB_2_8_3_pre1, CRAB_2_8_2_patch1, CRAB_2_8_2, CRAB_2_8_2_pre5, CRAB_2_8_2_pre4, CRAB_2_8_2_pre3, CRAB_2_8_2_pre2, CRAB_2_8_2_pre1, CRAB_2_8_1, CRAB_2_8_0, CRAB_2_8_0_pre1, CRAB_2_7_10_pre3, CRAB_2_7_9_patch2_pre1, CRAB_2_7_10_pre2, CRAB_2_7_10_pre1, CRAB_2_7_9_patch1, CRAB_2_7_9, CRAB_2_7_9_pre5, CRAB_2_7_9_pre4, CRAB_2_7_9_pre3, CRAB_2_7_9_pre2, CRAB_2_7_8_patch2, CRAB_2_7_9_pre1, CRAB_2_7_8_patch2_pre1, CRAB_2_7_8_patch1, CRAB_2_7_8_patch1_pre1, CRAB_2_7_8, CRAB_2_7_8_pre3, CRAB_2_7_8_pre2, CRAB_2_7_8_dash3, CRAB_2_7_8_dash2, CRAB_2_7_8_dash, CRAB_2_7_7_patch1, CRAB_2_7_7_patch1_pre1, CRAB_2_7_8_pre1, CRAB_2_7_7, CRAB_2_7_7_pre2, CRAB_2_7_7_pre1, CRAB_2_7_6_patch1, CRAB_2_7_6, CRAB_2_7_6_pre1, CRAB_2_7_5_patch1, CRAB_2_7_5, CRAB_2_7_5_pre3, CRAB_2_7_5_pre2, CRAB_2_7_5_pre1, CRAB_2_7_4_patch1, CRAB_2_7_4, CRAB_2_7_4_pre6, CRAB_2_7_4_pre5, CRAB_2_7_4_pre4, CRAB_2_7_4_pre3, CRAB_2_7_4_pre2, CRAB_2_7_4_pre1, CRAB_2_7_3, CRAB_2_7_3_pre3, CRAB_2_7_3_pre3_beta, CRAB_2_7_3_pre2, CRAB_2_7_3_pre2_beta, CRAB_2_7_3_pre1, CRAB_2_7_3_beta3, CRAB_2_7_3_beta2, CRAB_2_7_3_beta1, CRAB_2_7_3_beta
Changes since 1.27: +3 -3 lines
Log Message:
merge 2.7.1_branch

File Contents

# User Rev Content
1 farinafa 1.1 from crab_exceptions import *
2     from crab_util import *
3     import common
4 spiga 1.25 from Downloader import Downloader
5 farinafa 1.1 import os, time
6    
7     class ServerConfig:
8 spiga 1.2 def __init__(self, serverName):
9 slacapra 1.15 import string
10 spiga 1.26 self.serverName = string.lower(serverName)
11     common.logger.debug('Calling ServerConfig '+self.serverName)
12 slacapra 1.15
13 spiga 1.25 url ='http://cmsdoc.cern.ch/cms/LCG/crab/config/'
14    
15 spiga 1.26 self.downloader = Downloader(url)
16 spiga 1.25
17 spiga 1.24
18 spiga 1.26 def config(self):
19 spiga 1.25 """
20     """
21 spiga 1.26 if 'default' in self.serverName:
22     self.serverName = self.selectServer()
23     if 'server_' in self.serverName:
24     configFileName = '%s.conf'%self.serverName
25 farinafa 1.6 else:
26 spiga 1.26 configFileName = 'server_%s.conf'%self.serverName
27    
28     serverConfig = eval(self.downloader.config(configFileName))
29    
30 spiga 1.25 if not serverConfig:
31     serverConfig = {}
32 spiga 1.26 serverConfig['serverGenericName']=self.serverName
33 spiga 1.25
34 spiga 1.26 return serverConfig
35    
36 spiga 1.25 def selectServer(self):
37     """
38     """
39     common.logger.debug('getting serverlist from web')
40     # get a list of available servers
41 spiga 1.28 serverListFileName ='AvailableServerList'
42 spiga 1.26
43     serverListFile = self.downloader.config(serverListFileName)
44    
45 spiga 1.25 if not serverListFile:
46     msg = 'List of avalable Server '+serverListFileName+' from '+self.url+' is empty\n'
47     msg += 'Please report to CRAB feedback hypernews hn-cms-crabFeedback@cern.ch'
48     raise CrabException(msg)
49     # clean up empty lines and comments
50     serverList=[]
51 spiga 1.28 [serverList.append(string.split(string.strip(it))) for it in serverListFile.split('\n') if (it.strip() and not it.strip()[0]=="#")]
52 spiga 1.25 common.logger.debug('All avaialble servers: '+str(serverList))
53 spiga 1.26
54 spiga 1.25 # select servers from client version
55     compatibleServerList=[]
56     for s in serverList:
57 farinafa 1.27 #vv=string.split(s[1],'-')
58     if len(s)<2:
59     continue
60     vv=s[1].split('-')
61 spiga 1.25 if len(vv[0])==0: vv[0]='0.0.0'
62     if len(vv[1])==0: vv[1]='99.99.99'
63     for i in 0,1:
64     tmp=[]
65     [tmp.append(int(t)) for t in vv[i].split('.')]
66     vv[i]=tuple(tmp)
67    
68     if vv[0]<=common.prog_version and common.prog_version<=vv[1] and common.scheduler.name()==string.lower(s[2]):
69     compatibleServerList.append(s[0])
70 spiga 1.26
71 spiga 1.28 common.logger.debug('All avaialble servers compatible with %s: '%common.prog_version_str +str(compatibleServerList))
72 spiga 1.25 if len(compatibleServerList)==0:
73     msg = "No compatible server available with client version %s\n"%common.prog_version_str
74     msg += "Exiting"
75     raise CrabException(msg)
76 spiga 1.26
77 spiga 1.25 # if more than one, pick up a random one, waiting for something smarter (SiteDB)
78     import random
79     serverName = random.choice(compatibleServerList)
80     common.logger.debug('Avaialble servers: '+str(compatibleServerList)+' choosen: '+serverName)
81 spiga 1.26
82 spiga 1.25 return serverName