ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SITECOMM/DDT/calculate_links.py
Revision: 1.2
Committed: Fri Nov 12 16:13:39 2010 UTC (14 years, 5 months ago) by magini
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +2 -2 lines
Log Message:
Change datasvc url to https in ddt link monitor

File Contents

# User Rev Content
1 phedex 1.1 #! /usr/bin/env python
2    
3     import sys, time, datetime, logging
4     from phedex_monitor.service.calculate_links import DDTCommissionCalculator
5     from phedex_monitor.model.state import State
6     from phedex_monitor.service.data_parser import DDTDataParser
7     from phedex_monitor.service.link_status_parser import DDTLinkStatusParser
8    
9     log = logging.getLogger()
10     #log.addHandler( logging.StreamHandler() )
11     log.setLevel( logging.INFO )
12     log.propagate = False
13    
14     """ @author: Brian Bockelman """
15    
16     def parseOpts( args ):
17     # Stupid python 2.2 on SLC3 doesn't have optparser...
18     keywordOpts = {}
19     passedOpts = []
20     givenOpts = []
21     length = len(args)
22     optNum = 0
23     while ( optNum < length ):
24     opt = args[optNum]
25     hasKeyword = False
26     if len(opt) > 2 and opt[0:2] == '--':
27     keyword = opt[2:]
28     hasKeyword = True
29     elif opt[0] == '-':
30     keyword = opt[1:]
31     hasKeyword = True
32     if hasKeyword:
33     if keyword.find('=') >= 0:
34     keyword, value = keyword.split('=', 1)
35     keywordOpts[keyword] = value
36     elif optNum + 1 == length:
37     passedOpts.append( keyword )
38     elif args[optNum+1][0] == '-':
39     passedOpts.append( keyword )
40     else:
41     keywordOpts[keyword] = args[optNum+1]
42     optNum += 1
43     else:
44     givenOpts.append( args[optNum] )
45     optNum += 1
46     return keywordOpts, passedOpts, givenOpts
47    
48     def printHelp():
49     help = """
50     The calculate_links.py script calculates the status of various PhEDEx links
51     according to the rules set forth by the DDT starting from 1st of June 2007
52    
53     Options:
54     -url=<URL>\t\tManually set the data feed to <URL>.
55     -debug_links=<link1>,<link2>\tComma-separated list of links to enable debugging.
56     -debug\t\t\tEnable debug for calculator and parser on the debug links.
57     -debug_calc\t\tEnable just the debug on the calculator for the debug links.
58     -debug_parser\t\tEnable just the debug on the parser for the debug links
59     -y=<year> \t\tyear of end cutoff date
60     -m=<month> \t\tmonth of end cutoff date
61     -d=<day>\t\tday of end cutoff date
62     -sy=<year> \t\tyear of start cutoff date
63     -sm=<month> \t\tmonth of start cutoff date
64     -sd=<day>\t\tday of start cutoff date
65     -dd\t\tdaily data span
66     """
67     print help
68    
69     if __name__ == '__main__':
70     kwOpts, passedOpts, givenOpts = parseOpts( sys.argv[1:] )
71    
72     if 'h' in passedOpts or 'help' in passedOpts:
73     printHelp()
74     sys.exit(-1)
75    
76    
77     #surl = 'http://t2.unl.edu/phedex/xml/enabled?from_node=.*&excludefrom=XT%7CCH_CAF&excludeto=XT%7CCH_CAF&to_node=.*&conn=Prod%2FNEBRASKA'
78 magini 1.2 surl='https://cmsweb.cern.ch/phedex/datasvc/xml/prod/links'
79     durl2='https://cmsweb.cern.ch/phedex/datasvc/xml/debug/transferhistory?binwidth=%s&starttime=%s&endtime=%s'
80 phedex 1.1
81     year = kwOpts.get('y')
82     month = kwOpts.get('m')
83     day = kwOpts.get('d')
84     if year != None and month != None and day != None:
85     year, month, day = int(year),int(month),int(day)
86     etime = int(time.mktime(datetime.datetime(year,month,day).timetuple()))
87     edate = datetime.datetime( year, month, day, 0 )
88     else:
89     etime = int(time.time())
90     edate = datetime.datetime.today()
91    
92     start_year = kwOpts.get('sy')
93     start_month = kwOpts.get('sm')
94     start_day = kwOpts.get('sd')
95    
96     if start_year != None and start_month != None and start_day != None:
97     start_year, start_month, start_day = int(start_year),int(start_month),int(start_day)
98     stime = max(int(time.mktime(datetime.datetime(start_year,start_month,start_day).timetuple())),int(time.time() - 15*86400))
99     sdate = datetime.date( start_year, start_month, start_day )
100     else:
101     #Default starting date is 3 days ago
102     #stime = 1180645200 # 2008-12-01
103     stime = int(time.time() - 3*86400)
104    
105     if ('dd' in passedOpts):
106     span=str(86400)
107     else:
108     span=str(3600)
109    
110     url = durl2 % (span,stime,etime)
111    
112     log.info( "Using URL: %s" % url )
113     log.info( "Using URL for current link status: %s" % surl )
114    
115     set_debug = 'debug' in passedOpts
116     debug_links = [i.strip() for i in kwOpts.get('debug_links','').split(',')]
117    
118     if ('debug_parser' in passedOpts) or set_debug:
119     log.setLevel( logging.DEBUG )
120    
121     data_parser = DDTDataParser( url )
122     data_parser.run( debug_links )
123     data = data_parser.getData()
124    
125     if ('debug_calc' in passedOpts) or set_debug:
126     log.setLevel( logging.DEBUG )
127     else:
128     log.setLevel( logging.INFO )
129    
130     status_parser = DDTLinkStatusParser( surl )
131     status_parser.run()
132     statusdata = status_parser.getCommissionedLinks()
133     print "\nLink state as defined by https://twiki.cern.ch/twiki/bin/view/CMS/DDTLinkStateChangeProcedure"
134     print "\nPreviously COMMISSIONED links:"
135     status_parser.print_all_links_in_state( State.COMMISSIONED )
136    
137    
138     calc = DDTCommissionCalculator( data, statusdata, edate )
139     calc.run( debug_links )
140     print "\nLink state as defined by https://twiki.cern.ch/twiki/bin/view/CMS/DDTLinkStateChangeProcedure"
141     print "\nCommissioned links (COMMISSIONED):"
142     calc.print_all_links_in_state( State.COMMISSIONED )
143     print "\nCommissioned links in danger of uncommissioning (COMMISSIONED-" \
144     "DANGER):"
145     calc.print_all_links_in_state(State.COMMISSIONED_DANGER)
146     print "\nLinks out of commission due to low rate (PROBLEM-RATE):"
147     calc.print_all_links_in_state( State.PROBLEM_RATE )
148     print "\nLinks not in commission due to inability to keep target rate for a full day (PENDING-RATE):"
149     calc.print_all_links_in_state( State.PENDING_RATE )
150     print "\nLinks pending commissioning (PENDING-COMMISSIONING):"
151     calc.print_all_links_in_state( State.PENDING_COMMISSIONING )
152     print "\n NEW Links in state COMMISSIONIED:"
153     calc.print_all_new_links_in_commissioned_state()