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