1 |
paus |
1.1 |
#---------------------------------------------------------------------------------------------------
|
2 |
|
|
# Python Module File to translate storage/computing elements into meta site names
|
3 |
|
|
#
|
4 |
|
|
# Author: C.Paus (Jun 16, 2010)
|
5 |
|
|
#---------------------------------------------------------------------------------------------------
|
6 |
|
|
import os,sys,re,string
|
7 |
|
|
|
8 |
|
|
#---------------------------------------------------------------------------------------------------
|
9 |
|
|
"""
|
10 |
|
|
Class: Translator(table)
|
11 |
|
|
Each SubTask in CRAB can be described through this class
|
12 |
|
|
"""
|
13 |
|
|
#---------------------------------------------------------------------------------------------------
|
14 |
|
|
class Translator:
|
15 |
|
|
"Translator for the storage and computing elements to the "
|
16 |
|
|
# variable to be determined
|
17 |
|
|
ceTable = 'undefined' # compute elements translation table
|
18 |
|
|
seTable = 'undefined' # storage elements translation table
|
19 |
|
|
ces = {}
|
20 |
|
|
ses = {}
|
21 |
|
|
#-----------------------------------------------------------------------------------------------
|
22 |
|
|
# constructor to connect with existing setup
|
23 |
|
|
#-----------------------------------------------------------------------------------------------
|
24 |
|
|
def __init__(self,ceTable,seTable):
|
25 |
|
|
self.ceTable = ceTable
|
26 |
|
|
self.seTable = seTable
|
27 |
|
|
if os.path.exists(self.seTable):
|
28 |
|
|
self.ses = self.readTable(self.seTable)
|
29 |
|
|
else:
|
30 |
|
|
print ' WARNING -- SE table file not found.'
|
31 |
|
|
if os.path.exists(self.ceTable):
|
32 |
|
|
self.ces = self.readTable(self.ceTable)
|
33 |
|
|
else:
|
34 |
|
|
print ' WARNING -- CE table file not found.'
|
35 |
|
|
|
36 |
|
|
#self.show()
|
37 |
|
|
|
38 |
|
|
def readTable(self,file):
|
39 |
|
|
table = {}
|
40 |
|
|
cmd = 'grep -v ^# ' + file + ' | tr -d \' \''
|
41 |
|
|
print ' Loading table: ' + cmd
|
42 |
|
|
for line in os.popen(cmd).readlines():
|
43 |
|
|
line = line[:-1]
|
44 |
|
|
# decode the storage directory name
|
45 |
|
|
names = line.split(":")
|
46 |
|
|
if names[1] in table:
|
47 |
|
|
print ' Site already in tables %s (%s)'%(names[1],names[0])
|
48 |
|
|
table[names[1]] = names[0]
|
49 |
|
|
|
50 |
|
|
return table
|
51 |
|
|
|
52 |
|
|
def translateSes(self,seString):
|
53 |
|
|
sites = seString.split(",")
|
54 |
|
|
newString = ''
|
55 |
|
|
#print ' Looping through sites %s'%(seString)
|
56 |
|
|
for site in sites:
|
57 |
|
|
if site in self.ses:
|
58 |
|
|
#print ' -> %s == %s'%(site,self.ses[site])
|
59 |
|
|
if newString == '':
|
60 |
|
|
newString = self.ses[site]
|
61 |
|
|
else:
|
62 |
|
|
newString = "%s,%s"%(newString,self.ses[site])
|
63 |
|
|
else:
|
64 |
|
|
print ' dropping %s because it is not in our table'%(site)
|
65 |
|
|
|
66 |
|
|
#print 'Translated: %s'%(newString)
|
67 |
|
|
return newString
|
68 |
|
|
|
69 |
|
|
def translateCes(self,ceString):
|
70 |
|
|
sites = ceString.split(",")
|
71 |
|
|
newString = ''
|
72 |
|
|
#print ' Looping through sites %s'%(ceString)
|
73 |
|
|
for site in sites:
|
74 |
|
|
if site in self.ces:
|
75 |
|
|
#print ' -> %s == %s'%(site,self.ces[site])
|
76 |
|
|
if newString == '':
|
77 |
|
|
newString = self.ces[site]
|
78 |
|
|
else:
|
79 |
|
|
newString = "%s,%s"%(newString,self.ces[site])
|
80 |
|
|
else:
|
81 |
|
|
print ' dropping %s because it is not in our table'%(site)
|
82 |
|
|
|
83 |
|
|
#print 'Translated: %s'%(newString)
|
84 |
|
|
return newString
|
85 |
|
|
|
86 |
|
|
#-----------------------------------------------------------------------------------------------
|
87 |
|
|
# present the current crab subtask
|
88 |
|
|
#-----------------------------------------------------------------------------------------------
|
89 |
|
|
def show(self):
|
90 |
|
|
print ' Translator (CE Table: %s, SE Table: %s) ===='%(self.ceTable,self.seTable)
|
91 |
|
|
print ' ==== Compute Elements'
|
92 |
|
|
for name,hostname in self.ces.iteritems():
|
93 |
|
|
print ' Site: %s --> CE: %s'%(name,hostname)
|
94 |
|
|
print ' ==== Storage Elements'
|
95 |
|
|
for name,hostname in self.ses.iteritems():
|
96 |
|
|
print ' Site: %s --> SE: %s'%(name,hostname)
|