1 |
gutsche |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
|
3 |
|
|
import sys, os, getopt
|
4 |
|
|
|
5 |
|
|
import dbsCgiApi
|
6 |
|
|
import dbsApi
|
7 |
|
|
|
8 |
|
|
import dlsApi
|
9 |
|
|
import dlsClient
|
10 |
|
|
from dlsDataObjects import DlsLocation, DlsFileBlock, DlsEntry
|
11 |
|
|
import xml.dom.ext.reader
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
def main(argv) :
|
15 |
|
|
"""
|
16 |
|
|
|
17 |
|
|
DBSDLSQuery
|
18 |
|
|
|
19 |
|
|
query DBS and DLS to discovery datasets
|
20 |
|
|
|
21 |
|
|
required parameters
|
22 |
|
|
--pattern <pattern> : pattern to restrict discovery
|
23 |
|
|
|
24 |
|
|
optional parameters :
|
25 |
|
|
--help (-h) : help
|
26 |
|
|
--debug (-d) : debug statements
|
27 |
|
|
|
28 |
|
|
"""
|
29 |
|
|
|
30 |
|
|
# default
|
31 |
|
|
pattern = ''
|
32 |
|
|
debug = 0
|
33 |
|
|
|
34 |
|
|
try:
|
35 |
|
|
opts, args = getopt.getopt(argv, "", ["help", "debug", "pattern="])
|
36 |
|
|
except getopt.GetoptError:
|
37 |
|
|
print main.__doc__
|
38 |
|
|
sys.exit(2)
|
39 |
|
|
|
40 |
|
|
# check command line parameter
|
41 |
|
|
for opt, arg in opts :
|
42 |
|
|
if opt == "--help" :
|
43 |
|
|
print main.__doc__
|
44 |
|
|
sys.exit()
|
45 |
|
|
elif opt == "--debug" :
|
46 |
|
|
debug = 1
|
47 |
|
|
elif opt == "--pattern" :
|
48 |
|
|
pattern = arg
|
49 |
|
|
|
50 |
|
|
if pattern == '' :
|
51 |
|
|
print main.__doc__
|
52 |
|
|
sys.exit(2)
|
53 |
|
|
|
54 |
|
|
# guarantee that pattern has "*" at beginning and end
|
55 |
|
|
if pattern[0] != '*' :
|
56 |
|
|
pattern = '*'+pattern
|
57 |
|
|
if pattern[-1] != '*' :
|
58 |
|
|
pattern = pattern+'*'
|
59 |
|
|
|
60 |
|
|
# DBS initialization
|
61 |
|
|
dbs_url="http://cmsdoc.cern.ch/cms/test/aprom/DBS/CGIServer/prodquery"
|
62 |
|
|
dbs_instance = {'instance' : 'MCGlobal/Writer'}
|
63 |
|
|
dbs = dbsCgiApi.DbsCgiApi(dbs_url, dbs_instance)
|
64 |
|
|
|
65 |
|
|
# DLS initialization
|
66 |
|
|
type = "DLS_TYPE_DLI"
|
67 |
|
|
endpoint="prod-lfc-cms-central.cern.ch/grid/cms/DLS/LFC"
|
68 |
|
|
dls = dlsClient.getDlsApi(dls_type=type,dls_endpoint=endpoint)
|
69 |
|
|
|
70 |
|
|
# DBS query for datasets
|
71 |
|
|
try:
|
72 |
|
|
dbsDatasets = dbs.listProcessedDatasets(pattern)
|
73 |
|
|
except dbsApi.InvalidDataTier, ex:
|
74 |
|
|
raise DBSInvalidDataTierError(ex.getClassName(),ex.getErrorMessage())
|
75 |
|
|
except dbsApi.DbsApiException, ex:
|
76 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
77 |
|
|
except dbsCgiApi.DbsCgiToolError , ex:
|
78 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
79 |
|
|
except dbsCgiApi.DbsCgiBadResponse , ex:
|
80 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
81 |
|
|
|
82 |
|
|
for dbsDataset in dbsDatasets:
|
83 |
|
|
dataset = dbsDataset.get('datasetPathName')
|
84 |
|
|
|
85 |
|
|
# DBS query for fileblocks
|
86 |
|
|
eventsPerBlock = {}
|
87 |
|
|
try:
|
88 |
|
|
fileBlocks = dbs.getDatasetContents(dataset)
|
89 |
|
|
except dbsApi.DbsApiException, ex:
|
90 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
91 |
|
|
except dbsCgiApi.DbsCgiBadResponse, ex:
|
92 |
|
|
raise DBSError(ex.getClassName(),ex.getErrorMessage())
|
93 |
|
|
for fileBlock in fileBlocks:
|
94 |
|
|
## get the event collections for each block
|
95 |
|
|
nevts = 0
|
96 |
|
|
eventCollectionList = fileBlock.get('eventCollectionList')
|
97 |
|
|
for eventCollection in eventCollectionList:
|
98 |
|
|
nevts = nevts + eventCollection.get('numberOfEvents')
|
99 |
|
|
|
100 |
|
|
eventsPerBlock[fileBlock.get('blockName')]=nevts
|
101 |
|
|
|
102 |
|
|
siteDictionary = {}
|
103 |
|
|
for fileBlock in eventsPerBlock.keys() :
|
104 |
|
|
if eventsPerBlock[fileBlock] > 0 :
|
105 |
|
|
# query DLS
|
106 |
|
|
try:
|
107 |
|
|
locationList = dls.getLocations([fileBlock])
|
108 |
|
|
except dlsApi.DlsApiError, inst:
|
109 |
|
|
msg = "Error in the DLS query: %s." % str(inst)
|
110 |
|
|
pass
|
111 |
|
|
|
112 |
|
|
for locationItem in locationList:
|
113 |
|
|
for location in locationItem.locations:
|
114 |
|
|
host = str(location.host)
|
115 |
|
|
if host in siteDictionary.keys() :
|
116 |
|
|
siteDictionary[host].append(fileBlock)
|
117 |
|
|
else :
|
118 |
|
|
siteDictionary[host] = [fileBlock]
|
119 |
|
|
|
120 |
|
|
for site in siteDictionary.keys() :
|
121 |
|
|
events = 0
|
122 |
|
|
for block in siteDictionary[site] :
|
123 |
|
|
events += eventsPerBlock[block]
|
124 |
|
|
print dataset,site,events
|
125 |
|
|
|
126 |
|
|
if __name__ == '__main__' :
|
127 |
|
|
main(sys.argv[1:])
|