ATLAS Offline Software
isDSinFAX.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4 
5 from __future__ import print_function
6 
7 import subprocess, threading, os, sys
8 import urllib2
9 import json
10 
11 import argparse
12 
13 parser = argparse.ArgumentParser(description='Checks if dataset is accessible through FAX.')
14 parser.add_argument('dataset', type=str, help='Dataset name')
15 parser.add_argument('-af','--accessfile', action='store_const', const='1', help='try to open the first root file of the dataset using root. ')
16 parser.add_argument('-aa','--accessall', action='store_const', const='1', help='try to open all the root files of the dataset using root. ')
17 
18 args = vars(parser.parse_args())
19 
20 try:
21  import dq2.clientapi.cli.cliutil
22  from dq2.common.cli.DQDashboardTool import DQDashboardTool
23  from dq2.clientapi.cli.cliutil import getDQ2
24  from dq2.filecatalog.lfc.lfcconventions import to_native_lfn
25 except ImportError:
26  print ("Environment not set [error importing DQ2 dependencies]!")
27  sys.exit(1)
28 
29 
30 class Command(object):
31 
32  def __init__(self, cmd):
33  self.cmd = cmd
34  self.process = None
35 
36  def run(self, timeout):
37  def target():
38 # print ('command started: ', self.cmd)
39  self.process = subprocess.Popen(self.cmd, shell=True)
40  self.process.communicate()
41 
42  thread = threading.Thread(target=target)
43  thread.start()
44 
45  thread.join(timeout)
46  if thread.is_alive():
47  print ('Terminating process')
48  self.process.terminate()
49  thread.join()
50  return self.process.returncode
51 
52 
53 #print ('Geting data from AGIS ...')
54 
55 class site:
56  name=''
57  host=''
58  port=1094
59 
60  def __init__(self, na, ho):
61  self.name=na
62  ho=ho.replace("root://","")
63  self.host=ho.split(":")[0]
64  if ho.count(":"):
65  self.port=ho.split(":")[1]
66 
67  def prnt(self, what):
68  if (what>=0 and self.redirector!=what): return
69  print ( 'name:', self.name, '\thost:', self.host, '\tport:', self.port )
70 
71 sites=[];
72 
73 try:
74  req = urllib2.Request("http://atlas-agis-api-0.cern.ch/request/service/query/get_se_services/?json&state=ACTIVE&flavour=XROOTD", None)
75  opener = urllib2.build_opener()
76  f = opener.open(req)
77  res=json.load(f)
78  for s in res:
79 # print (s["name"], s["rc_site"], s["endpoint"])
80  ns = site( s["rc_site"], s["endpoint"] )
81  sites.append(ns)
82 # print (res)
83 # print (' got FAX SEs from AGIS.')
84 
85 except:
86  print ("Unexpected error:", sys.exc_info()[0] )
87 
88 #for s in sites: s.prnt(-1)
89 
90 allddms=set()
91 
92 try:
93  req = urllib2.Request("http://atlas-agis-api-0.cern.ch/request/ddmendpoint/query/list/?json&state=ACTIVE", None)
94  opener = urllib2.build_opener()
95  f = opener.open(req)
96  res=json.load(f)
97  for s in res:
98  for c in sites:
99  if s["rc_site"]==c.name:
100  # print (s["rc_site"], s["name"])
101  allddms.add(s["name"])
102  break
103 # print (' got related ddmendpoints from agis.')
104 
105 except:
106  print ("Unexpected error:", sys.exc_info()[0] )
107 
108 
109 DS=args['dataset']
110 
111 com=Command('dq2-ls -r '+ DS + ' > fax.tmp' )
112 com.run(300)
113 dsets={}
114 cds=''
115 f = open('fax.tmp', 'r')
116 for line in f:
117  if line.startswith('Multiple'): break
118  line=line.strip()
119  if line.count(':')==0:continue
120  line=line.split(":")
121  # print (line)
122 
123  if line[0]=='INCOMPLETE':
124  if len(line[1])==0: continue
125  rep=line[1].split(',')
126  for r in rep:
127  if r in allddms:
128  dsets[cds][0]+=1
129  continue
130 
131  if line[0]=='COMPLETE':
132  if len(line[1])==0: continue
133  rep=line[1].split(',')
134  for r in rep:
135  if r in allddms:
136  dsets[cds][1]+=1
137  continue
138 
139  cds=line[0]
140  dsets[cds]=[0,0]
141 
142 for d in dsets.keys():
143  print (d,'\tcomplete replicas:',dsets[d][1],'\tincomplete:',dsets[d][0])
isDSinFAX.Command.run
def run(self, timeout)
Definition: isDSinFAX.py:36
isDSinFAX.Command.__init__
def __init__(self, cmd)
Definition: isDSinFAX.py:32
isDSinFAX.site.prnt
def prnt(self, what)
Definition: isDSinFAX.py:67
isDSinFAX.site.host
host
Definition: isDSinFAX.py:57
isDSinFAX.site.port
port
Definition: isDSinFAX.py:58
isDSinFAX.site.__init__
def __init__(self, na, ho)
Definition: isDSinFAX.py:60
isDSinFAX.site.name
name
Definition: isDSinFAX.py:56
isDSinFAX.Command
Definition: isDSinFAX.py:30
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:224
Trk::open
@ open
Definition: BinningType.h:40
isDSinFAX.site
Definition: isDSinFAX.py:55
isDSinFAX.Command.process
process
Definition: isDSinFAX.py:34
pickleTool.object
object
Definition: pickleTool.py:30
isDSinFAX.Command.cmd
cmd
Definition: isDSinFAX.py:33
COOLRates.target
target
Definition: COOLRates.py:1106
Trk::split
@ split
Definition: LayerMaterialProperties.h:38