ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/ServerConfig.py
Revision: 1.26
Committed: Sun Jan 17 19:05:52 2010 UTC (15 years, 3 months ago) by spiga
Content type: text/x-python
Branch: MAIN
CVS Tags: CRAB_2_7_1_pre5, CRAB_2_7_1_wmbs_pre4, CRAB_2_7_1_pre4, CRAB_2_7_1_pre3
Branch point for: CRAB_2_7_1_branch
Changes since 1.25: +22 -23 lines
Log Message:
use default cache definition

File Contents

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