def __call__(self, environ, start_response): """ Process GET queries """ self.setEnviron(environ) if self.method() == "GET" or self.method() == "POST": # self.server().branchUrl() = self.assmemblerUrl('host') pmstate().script = self.script() pmstate().dev = True # Standalone version is dev print "=== pmMain 88 pandamon query <%s> thread=%s static = %s " % (self.path(), threading.currentThread(), self._staticServer) # self.show() # print "----COOKIES ---- <%s> " % self.cookie() static = self.static( environ, start_response) if static: return static requesthandler = self._requesthandler requesthandler.starting() ( page, format,cached ) = requesthandler.do_GET() requesthandler.finishing() tmptmptime = datetime.utcnow() courseness = 10 mindiff = tmptmptime.minute - int( tmptmptime.minute / courseness ) * courseness someminutes = timedelta( minutes=mindiff ) lastmodtime = tmptmptime - someminutes expireminutes = timedelta( minutes=5 ) expiretime = tmptmptime + expireminutes # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html headers = [ ('Content-type' , 'text/plain'), ('Date' , email.utils.formatdate(time.time())), # ("Last-Modified", lastmodtime.strftime("%a, %d %b %Y %H:%M:00 GMT") ), # ("Expires" , expiretime.strftime("%a, %d %b %Y %H:%M:%S GMT") ), ] try: if cached == None: cached = timedelta(seconds=300) if isinstance(cached,timedelta) : headers.append(('Cache-Control', 's-maxage=%s' % 0 )) # for varnish headers.append(('Cache-Control', 'max-age=%s' % cached.seconds)) # for the client elif isinstance(cached,str): headers.append(('Cache-Control', '%s' % cached)) else: for c,v in cached.iteritems(): headers.append(('Cache-Control', '%s=%s' % (c,v))) except: raise ValueError("Wrong cache control value %s ", cached ) headersIface = Headers(headers) headersIface['Content-type']=mmCode(format) start_response('200 OK', headers) else: raise ValueError("Can not process the client %s request yet" % self.environ('REQUEST_METHOD')) return [page]
def doQuery(url,tstart=None,tend=None,hours=None,days=None,columns=None, where=None,details=None): """ Process the query request """ pmstate().windowTitle = "pLogs" title = 'Incident log' nav = None menuinfo = None maintxt = '' if len(pmstate().params) == 0: # Main page maintxt += logMain(url,hours=hours,details=details) else: # custom summary maintxt += logSummary(url,tstart,tend,hours,days,columns,where,details) return title, menuinfo, nav, maintxt, 'html'
def buildMain(self, title, menuinfo, navtxt, maintxt, mode="html"): """ Build main page """ print " 203 ---- ", mode leftbox = None topbar = None menu = None if mode == "html": sc = pmstate().script if sc != '': sc = "<br><small>(%s's version)</small>" % sc[2:] leftbox = " <a title='Go to the site home page' href='%s'>PanDA Monitor</a> %s<br><div style='font-size: 12px; font-weight: normal'>Times are in UTC</div>" % ( "http://pandamon.xxxx.xx", sc) topbar = self.buildDashboards() menu = self.buildMenu() return self.buildMainFull( title, menuinfo, navtxt, menu, maintxt, leftbox=leftbox, topbar=topbar, topleft= "<span style='padding:0;text-align:center;'><a href='http://www.bnl.gov/itd/webapps/browsercache.asp' title='To be able to use the latest Monitor version one needs to remove the old one by cleaning his/her local Web Browser cache'><span class='ui-icon ui-icon-info' style='display:inline;'> </span>JavaScript cache</a></center>" ) else: return self.buildMainFullJson(title, menuinfo, navtxt, menu, maintxt, leftbox=leftbox, topbar=topbar)
def doJson(self): """ Combine together the json view of the 3 parts of the Web page layout """ """ { "data" : %(main)s } is to be short cut for the [{ "id" : "main" , "json" : %(main)s }] """ self.publishTitle('Hello Database status') self.publishNav('"Archival job database in use is %s"' % pmstate().jobarchive) self.doMain() self.publish("%s/%s" % (self.server().fileScriptURL(),"hellodb.js"),role="script")
def foot(self, description='', stopwatch=None): """HTML page footer""" if description == '': version = "Code $Rev: 13140 $" version = version.replace('$', '') description = version htmlstr = "<div id='foot' style='font-size: 11px'>" htmlstr += "<br> Module: %s/%s" % (pmstate().context, pmstate().module) htmlstr += "<br> %s" % pmstate().timer if not stopwatch == None: htmlstr += "<br> Build time: %s" % stopwatch htmlstr += "<br> Page created %s" % datetime.utcnow( ).strftime("%m-%d %H:%M:%S") if description != '': htmlstr += "<br> %s" % description pandaUsername = pwd.getpwuid(os.getuid())[0] hostname = socket.gethostbyaddr(socket.gethostname()) if pandaUsername != 'root': htmlstr += "<br> Run by %s @ %s" % \ ( pandaUsername, os.environ.get("HOSTNAME") ) if not stopwatch == None: htmlstr += ". To produce this page our server spent: %s at %s. " % ( stopwatch, datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S UTC")) # if os.environ.has_key('HOSTNAME'): htmlstr += "<br> Host: %s" % os.environ.get("HOSTNAME") htmlstr += """ <br> <a href='https://savannah.xxxx.xx/bugs/?func=additem&group=panda'>Report a problem</a> <a href='mailto:[email protected]'>Email list for help</a> <br> <a href='mailto:[email protected]'>Webmaster</a></div> """ analytics = """ <!-- Google analytics take it out. It slows down the JQuery !!! [[ and you consider that an analytics problem rather than jQuery problem?? - TW ]] <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-4802332-1"); pageTracker._initData(); pageTracker._trackPageview(); </script> --> """ # htmlstr += analytics htmlstr += "</body></html>" return htmlstr
def doJson(self): """ Combine together the json view of the 3 parts of the Web page layout """ """ { "data" : %(main)s } is to be short cut for the [{ "id" : "main" , "json" : %(main)s }] """ self.publishTitle('Hello Database status') self.publishNav('"Archival job database in use is %s"' % pmstate().jobarchive) self.doMain() self.publish("%s/%s" % (self.server().fileScriptURL(), "hellodb.js"), role="script")
def queryLogs(where, selection, db=''): """ pass user query to back end DB and return the results """ results = [] if db == '': db = pmstate().jobarchive if db == 'SimpleDB': import pmUtils.pmSimpleDB as sdb print "\n\n --- 21 ------- ", where, selection results = sdb.getLogRecords(filter=where, selection=selection, limit=3000) return results
def buildDashboards(self): """ Return the list of dashboard links along the top of the monitor """ txt = '' for m in config.modules: try: mh = pmstate().moduleHandle[m] txt += "%s " % mh.topMenu except: pass return txt
def logSummary(url,tstart=None,tend=None,hours=None,days=None,columns=None,where=None,details=None): ## Perform the query txt = '' selection = 'NAME, TYPE, LEVELNAME' if details!=None: selection += ",TIME, MESSAGE" pmstate().jobarchive = 'SimpleDB' wherev, desc, tstartv, tendv = buildWhereClause(tstart,tend,hours,days,columns,where) txt += utils.pageSection(desc) logs = queryLogs(wherev, selection) print "Retrieved %s log records" % len(logs) txt += showLogs(logs, tstartv, tendv,details,url) return txt
def doQuery(url, tstart=None, tend=None, hours=None, days=None, columns=None, where=None, details=None): """ Process the query request """ pmstate().windowTitle = "pLogs" title = 'Incident log' nav = None menuinfo = None maintxt = '' if len(pmstate().params) == 0: # Main page maintxt += logMain(url, hours=hours, details=details) else: # custom summary maintxt += logSummary(url, tstart, tend, hours, days, columns, where, details) return title, menuinfo, nav, maintxt, 'html'
def logSummary(url, tstart=None, tend=None, hours=None, days=None, columns=None, where=None, details=None): ## Perform the query txt = '' selection = 'NAME, TYPE, LEVELNAME' if details != None: selection += ",TIME, MESSAGE" pmstate().jobarchive = 'SimpleDB' wherev, desc, tstartv, tendv = buildWhereClause(tstart, tend, hours, days, columns, where) txt += utils.pageSection(desc) logs = queryLogs(wherev, selection) print "Retrieved %s log records" % len(logs) txt += showLogs(logs, tstartv, tendv, details, url) return txt
def doQuery(self): """ Process the query request This is the redundant method. It was left here for the sake of the backward compatibiity """ title = 'Database status' nav = 'Archival job database in use is %s' % pmstate().jobarchive maintxt = '' dbstats = sdb.getDBStats() maintxt += "<p>Total size: %s MB" % dbstats['size'] maintxt += "<p>Total items: %s M" % int(dbstats['items']/1000000) maintxt += "<p>Average item size: %s bytes" % dbstats['itemsize'] maintxt += "<p>Number of domains: %s" % dbstats['ndomains'] maintxt += "<p>Domain info:" dkeys = dbstats['domainstats'].keys() dkeys.sort() for d in dkeys: dinfo = dbstats['domainstats'][d] maintxt += "<br> %s: %2.1f M items %s MB %s bytes/item Attribute names: %s values: %s M" % \ ( d, dinfo['items']/1000000., dinfo['size'], dinfo['itemsize'], dinfo['attrnames'], int(dinfo['attrvalues']/1000000) ) self.publishPage(title,nav,maintxt)
def doQuery(self): """ Process the query request This is the redundant method. It was left here for the sake of the backward compatibiity """ title = 'Database status' nav = 'Archival job database in use is %s' % pmstate().jobarchive maintxt = '' dbstats = sdb.getDBStats() maintxt += "<p>Total size: %s MB" % dbstats['size'] maintxt += "<p>Total items: %s M" % int(dbstats['items'] / 1000000) maintxt += "<p>Average item size: %s bytes" % dbstats['itemsize'] maintxt += "<p>Number of domains: %s" % dbstats['ndomains'] maintxt += "<p>Domain info:" dkeys = dbstats['domainstats'].keys() dkeys.sort() for d in dkeys: dinfo = dbstats['domainstats'][d] maintxt += "<br> %s: %2.1f M items %s MB %s bytes/item Attribute names: %s values: %s M" % \ ( d, dinfo['items']/1000000., dinfo['size'], dinfo['itemsize'], dinfo['attrnames'], int(dinfo['attrvalues']/1000000) ) self.publishPage(title, nav, maintxt)
def buildMenu(self, logged='no'): """ Build left menu bar of monitor """ txt = '' style = " style='padding:0;' " if self._menu != None: txt += self._menu.leftMenu() else: txt += "<div id='menu' class='ui-widget ui-widget-content ui-cornel-all' style='margin:0px;padding:0px'></div>" # txt += self.buildClassicMenu() txt += """ <script> $(document).ready(function() { var active = $.cookie('#pandaLeftMenuId'); if ( active == undefined ) { active = 0; } function bindCookiEvent(event, ui) { $.cookie('#pandaLeftMenuId',ui.options.active,{ expires: 7, path: '/' }); } var opt = { header: 'h3' ,"active" : parseInt(active, 10) , change: bindCookiEvent //, clearStyle: true }; $("#pandaLeftMenuId").accordion(opt); }); </script> """ return txt for m in config.modules: try: mh = pmstate().moduleHandle[m] txt += "<p>%s" % mh.leftMenu() except: pass return txt
def doNavigation(self): self.publishNav('Archival job database in use is %s' % pmstate().jobarchive)
def scripts(self): """ Javascript used in monitor page """ clientCN = self.server().ssl('CLIENT_S_DN_CN') adfs = self.server().environ('ADFS_LOGIN') if clientCN == None: clientCN = 'undefined' if adfs == None: adfs = clientCN else: a = "%s" % adfs[0].upper() if len(adfs) > 1: a += "%s" % adfs[1:] adfs = "'%s'" % a else: c = "%s" % clientCN[0].upper() if len(clientCN) > 1: c += "%s" % clientCN[1:] clientCN = "'%s'" % c adfs = 'undefined' google = None try: if config.google: google = '' except: pass if google == None: google = '' else: google = """ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-%(account)s']); _gaq.push(['_setDomainName', '%(domain)s']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); """ % { 'account': config.google['property'], 'domain': config.google['domain'] } htmlstr = """ <!--Load the JQUERY/FLOT --> <link type="text/css" href='%(css)s/%(ui_css)s' rel='stylesheet' /> <link type="text/css" href='%(css)s/%(dt_css)s' rel='stylesheet' /> <!-- <link type="text/css" href='%(url)s/%(dt_css)s' rel='stylesheet' /> <link type="text/css" href='%(url)s/%(dt_roller_css)s' rel='stylesheet' /> --> <link id="favicon" type='image/x-icon' href='%(images)s/favicon.ico' rel='shortcut icon' /> <script src='%(script)s/%(dateformat)s'></script> <script src='%(script)s/%(moment)s'></script> <script src='%(cdn)s/%(jquery)s'></script> <script src='%(script)s/%(jquery-url)s'></script> <script src='%(script)s/%(cookie)s'></script> <script src='%(cdn)s/%(datapicker)s'></script> <script src='%(script)s/%(flot)s'></script> <script src='%(script)s/%(crosshair)s'></script> <script src='%(script)s/%(stack)s'></script> <script src='%(script)s/%(timers)s'></script> <script src='%(url)s/%(datatable)s'></script> <script src='%(script)s/%(uid)s'></script> <script src='%(script)s/%(sparkline)s'></script> <script src='%(script)s/%(jsuri)s'></script> <!-- <script src='%(script)s/%(encoder)s'></script> --> <!--Load the PANDA API--> <script src='%(script)s/%(pmMonitor)s'> </script> <script src='%(script)s/%(utils)s'> </script> <script src='%(script)s/%(views)s'> </script> <script src='%(script)s/%(plot)s'> </script> <script src='%(script)s/%(sm)s'> </script> <script src='%(script)s/%(ajaxrender)s'> </script> <style> .ui-widget { font-size: 9pt; } </style> <script> // JQuery init jQuery.fn.log = function (msg) { console.log("%%s: %%o", JSON.stringify(msg,undefined,2), this); return this; }; document.pandaURL = '%(url)s'; // JQuery init $(document).ready(function() { $(this).log('Activate JQuery'); utils(); var pm = new Pm('%(wscript)s'); pm._topElement.ChangeStatus('modified'); var person=%(person)s; var adfs = %(adfs)s; if (person != undefined) { var lg = $('#loginID'); lg.attr('title', person + ' logout'); lg.click(function() {if (window.crypto) window.crypto.logout();$(this).hide();}); lg.show(); } else if (adfs != undefined) { var lg = $('#loginID'); lg.attr('title', adfs + ' logout'); lg.click(function() { $(this).hide(); window.location ='https://login.xxxx.xx/adfs/ls/?wa=wsignout1.0';}); lg.show(); } %(status)s }); <!--Load the Google / Analytics--> %(google)s </script> """ % { 'url': self.server().fileURL(), 'script': self.server().fileScriptURL(), 'images': self.server().fileImageURL(), 'cdn': 'https://ajax.googleapis.com/ajax/libs', 'msn': 'http://ajax.aspnetcdn.com/ajax', 'jqcdn': 'http://code.jquery.com', 'utils': 'PandaMonitorUtils.js', 'views': 'PandaMonitorViews.js', 'plot': 'pmPlot.js', 'pmMonitor': 'pmMonitor.js', 'jquery': 'jquery/1.7.2/jquery.min.js', 'jquery-url': 'jquery/jquery.ba-bbq.min.js', 'flot': 'flot/jquery.flot.js', 'crosshair': 'flot/jquery.flot.crosshair.js', 'stack': 'flot/jquery.flot.stack.js' # ,'excanvas' : 'jquery/excanvas.min.js' , 'timers': 'jquery/jquery.timers.js', 'datapicker': 'jqueryui/1.8.18/jquery-ui.min.js' # ,'datatable': 'jquery.dataTables/1.9.1/jquery.dataTables.min.js' # ,'datatable': 'jquery.dataTables/1.9.4/jquery.dataTables.min.js' , 'datatable': 'jquery.dataTables/1.9.4/media/js/jquery.dataTables.min.js', 'css': self.server().fileScriptCSS(), 'ui_css': 'ui-lightness/jquery-ui.css', 'dt_css': 'demo_table_jui.css' # ,'dt_css' : 'jquery.dataTables/1.9.4/media/css/demo_table_jui.css' , 'dt_roller_css': 'jquery.dataTables/1.9.4/media/css/jquery.dataTables_themeroller.css', 'dateformat': 'date.format.js', 'moment': '3dparty/moment/moment.min.js', 'encoder': 'jquery/jquery.encoder.js', 'uid': 'jquery/jquery.unique-element-id.js', 'wscript': pmstate().script, 'google': google, 'cookie': 'jquery/jquery.cookie.js', 'sm': '3dparty/state-machine/state-machine.js', 'ajaxrender': 'core/ajaxrender.js', 'sparkline': 'jquery/jquery.sparkline.min.js', 'jsuri': '3dparty/jsuri/jsuri-1.1.1.min.js', 'person': clientCN, 'adfs': adfs, 'status': self.jobStatusBar() } ## If the active module has any custom scripts, add that too. try: mh = pmstate().moduleHandle[pmstate().module] htmlstr += mh.scripts() except: pass return htmlstr
def head(self, toptxt='Panda monitor and browser'): """ Build page header """ tmpdatestring = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") if pmstate().windowTitle != '': toptxt = pmstate().windowTitle ## If the active module has custom header material, include it try: mh = pmstate().moduleHandle[pmstate().module] modheader = mh.header() except: modheader = '' htmlstr = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> <html><head id='head'><title>%s</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=9" > <!-- Enable IE9 Standards mode --> <!-- meta http-equiv="X-UA-Compatible" content="IE=edge" --> <meta name="robots" content="noindex,nofollow" /> <meta name="description" content="Panda monitor" /> <meta name="date" content="%s"> <meta http-equiv="Content-Script-Type" content="text/javascript"> <link rel=start href="%s" title="Panda monitor home page"> <style type="text/css"> td {font-family: sans-serif; font-size: 12px;} #tophome #topleft{text-align: center; vertical-align: middle;} #topheader #topbar{text-align: left; vertical-align: middle;} #browsertitle{visibility: hidden;} #homeup{text-align: center; vertical-align: middle; font-family: sans-serif; font-size: 18px; font-weight: bold;} #hometop{text-align: center; vertical-align: middle; } #homedown #menuinfo{text-align: center; vertical-align: middle;} #titleheader{text-align: left; vertical-align: middle; font-family: sans-serif; font-size: 20px; font-weight: bold;} #nav #navright{vertical-align: middle; font-family: sans-serif;} #menu{vertical-align: top; font-family: sans-serif;} #foot{font-size: 12px; font-family: sans-serif;} .top { font-family: sans-serif; font-size: 12px; } .headerbar {background: #e3e3e3; font-family: sans-serif;} .topheader {background: #376797; font-family: sans-serif; font-size: 12px;} .menubartop {background: #4A7FB4; font-family: sans-serif; font-size: 12px; opacity:0.99; } .menubar {background: #e3e3e3; font-family: sans-serif; font-size: 12px;} .overlap {background: #d3d3d3; font-family: sans-serif; font-size: 12px; opacity:0.99; } .mainpage {text-align: left; vertical-align: top; background: white; font-family: sans-serif; font-size: 12px;} body.wait *, body.wait {cursor:progress !important; } .bigpandamonbanner { border: 5px red solid; text-align: center; text-valign: middle; font-weight:bold; } .jedititle{ font-size: large; color: red; color: red; } </style> <style media="all" type="text/css"> .alignRight { text-align: right; } .nomargin {margin: 0px; } </style> <!-- Module-specific header insertion --> %s %s </head> <noscript> JavaScript must be enabled in order for you to use this browser. </noscript> """ % (toptxt, tmpdatestring, self.server().branchUrl(), modheader, self.scripts()) # htmlstr += scripts() return htmlstr
def buildMainFull( self, title='<a href="http://pandamon.xxxx.xx">PanDA Monitor</a>', menuinfo=None, nav=None, menu=None, main=None, topleft=None, leftbox=None, upleft=None, upright=None, titleleft='', navright=None, topbar=None): """ Build main page """ """ Main page layout ------------------------------------------------------------------------- | 3px | tophome.topleft | topheader. topbar | ------------------------------------------------------------------------- | 12px | hometop.titleleft | topright.upleft | topright.upright | ------------------------------------------------------------------------- | 40px | homeup | titleheader.title | ------------------------------------------------------------------------- | 20px | homedown (menuifo) | nav | nav.navright | nav.navhelp | ------------------------------------------------------------------------- | | topmenu | | | | classic menu | main | | | menu | | ------------------------------------------------------------------------- | foot | ------------------------------------------------------------------------- """ # def buildMainFull(title='PanDA Monitor', menuinfo=None, nav=None, menu=None, # main=None, topleft=None,leftbox=None,upleft=None, # upright=None,titleleft='',navright=None,topbar=None): def dflt(a): if a == None: a = " " return a title = dflt(title) menuinfo = dflt(menuinfo) nav = dflt(nav) menu = dflt(menu) main = dflt(main) topleft = dflt(topleft) leftbox = dflt(leftbox) upleft = dflt(upleft) upright = dflt(upright) titleleft = dflt(titleleft) navright = dflt(navright) topbar = dflt(topbar) htmlstr = '' upleft += "" # " " if pmstate().navmain != '': pmstate().navmain = "<br>" + pmstate().navmain if pmstate().navmain != '': nav += '<br>%s' % pmstate().navmain if pmstate().navright != '': navright = pmstate().navright pmstate().navright = ' ' if pmstate().titleleft != '': titleleft = pmstate().titleleft pmstate().titleleft = '' htmlstr += """ <body marginwidth=0 marginheight=0> <table id="pmMainFrame" border=0 width="100%%" cellspacing=0 cellpadding=5> <!-- <tr class="topheader nomargin" style="padding:0; font-family: sans-serif; font-size:3px;"><td width="3px"></td><td style='padding:0;' class=menubartop><center> <a href='http://www.bnl.gov/itd/webapps/browsercache.asp' title='To be able to use the latest Monitor version one needs to remove the old one by cleaning his/her local Web Browser cache'><span class='ui-icon ui-icon-info' style='display:inline;'> </span>JavaScript cache</a></td><td style='padding:0 0 0 50px;' colspan=5><span class="topheader nomargin" nowrap id=topanalysisid style='padding:0px;display:inline'></span><span id=topproductionid style='padding:0px;display:inline'></span></center></td></tr> --> <tr height="10px" style="font-family: sans-serif; font-size: 8px;"> <td width="3px" class="topheader"></td> <!-- <div id="pmTopCollapse" class="ui-icon ui-icon-triangle-1-w" style="display:inline-box;width:3px;padding:0;background-position: -102px -16px;" onclick="$('#pmTopCollapse').toggleClass('ui-icon-triangle-1-w ui-icon-triangle-1-e','slow').css('background-position','-102px -16px'); $('#pmMainFrame tr *:nth-child(2)').toggle();"/></td> --> <td id="tophome" class="menubartop nomargin" nowrap> <b> <span id='topleft'>%(topleft)s</span> </b> </td> <td id="topheader_row" class="topheader nomargin" width="100%%" colspan=2 nowrap> <table class="nomargin" border="0" > <tr class="nomargin"> <!-- <td class="nomargin" > <span title="The URL of this page" id="urlIconId" style="cursor:pointer;" class="ui-icon ui-widget-header ui-icon-link nomargin"></span> <span id="urlID" style="display:none; cursor:pointer;" class="ui-state-highlight ui-corner-all"> <span id="url_qr_id"></span><span id="url_text_id"></span> </span> </td> --> <td><span id="navhelpbuttonId" style="cursor:help; display:inline-block;" title="Click to see the help" class="ui-icon ui-widget-header ui-corner-all ui-icon-help"> </span></td> <td id="topheader"></td> <td width="90%%"><span id='topbar'>%(topbar)s</span></td> <td> <span id='navright'>%(navright)s</span> <div align="left" style="float:right; width:550px;" class="ui-widget"> <div id="navhelp" style="display:none" class="ui-state-highlight ui-corner-all"> Help </div> </div> </td> <td><span id="loginID" style="cursor:pointer; display:None;" title="logout" class="ui-icon ui-widget-header ui-icon-person"> </span></td> <td><span id="savejsonID" style="cursor:pointer; display:inline-block; " title="Save the data in json format" class="ui-icon ui-widget-header ui-corner-all ui-icon-disk"> </span></td> </tr> </table> </td> </tr> <tr> <td height="6px" class="headerbar"></td> <td id="hometop" class="overlap" nowrap><span id='titleleft'>%(titleleft)s</span></td> <td id="topright" class="headerbar" align="left" width="75%%"> <span id='upleft'>%(upleft)s</span></td> <td id="topright" class="headerbar" align="right" style="vertical-align:top"> <span id='upright'>%(upright)s</span></td> </tr> <tr> <td height="40px" class="headerbar"></td> <td id="homeup" class="overlap" nowrap>%(leftbox)s</td> <td id="titleheader" class="headerbar" colspan=2><span id ='title'>%(title)s</span></td> </tr> <tr> <td height="10px" class="headerbar" rowspan="2"></td> <td id="homedown" class="overlap" nowrap rowspan="2"> %(menuinfo)s</td> <td id="nav" class="headerbar" align="left"> %(nav)s</td> <td id="nav" class="headerbar" align="right" style="vertical-align:bottom"> <div style="display:inline-box;" id='navright'>%(navright)s</div> </td> </tr> <tr> <td colspan="2" class="bigpandamonbanner"> <br/><br/><br/><br/> <div class="jedititle"><span class="jedititle">JEDI is the default analysis backend since August 12 2014!</span></div> <br/><br/> JEDI tasks/jobs can be monitored on <a href="http://bigpanda.xxxx.xx/" target="_blank">http://bigpanda.xxxx.xx/</a>. <br/> Submission to JEDI is the default setup using Panda/Ganga tools from CVMFS since August 12, 2014!<br/> <br/> JEDI instruction are available on TWiki <a href="https://twiki.xxxx.xx/twiki/bin/view/PanDA/PandaJediAnalysis" target="_blank">PandaJediAnalysis</a>. <br/><br/><br/><br/> </td> </tr> <tr> <td></td> <td id="topmenu" class="ui-widget menubar" style="vertical-align:text-top;padding:1px;"> %(menu)s </td> <td id="main" class="mainpage" colspan=2> %(main)s</td> </tr></table> """ % { 'topleft': topleft, 'topbar': topbar, 'titleleft': titleleft, 'upleft': upleft, 'upright': upright, 'leftbox': leftbox, 'title': title, 'menuinfo': menuinfo, 'nav': nav, 'navright': navright, 'menu': menu, 'main': main } return htmlstr
def do_GET(self, urlquery=None, req=None, mode=None, cli=None): srv = self.server() if urlquery == None: urlquery = srv.assmemblerUrl('query') if mode == None: mode = srv.mode() if cli == None: cli = srv.cli() # self.ls() """ Process the GET query """ # Set up state for this query pmstate().initForQuery(urlquery) if mode != 'html': pmstate().setModule() else: pmstate().module = 'home' titletxt = 'pandamon' menuinfo = navtxt = maintxt = jsonpage = None mname = None published = None cached = None security.parseQueryString(urlquery) # params = security.parseQueryString(urlquery) # qlocation = urlquery.find('?') # if qlocation>=0: # (values,keys,syskeys,extraValue) = self.param2Args(urlquery) # pmstate().setParams(keys) # if no module just show the home page if pmstate().module == '': titletxt, menuinfo, navtxt, maintxt = self._browser.frontPage() elif mode == 'html': bp = self._browser.buildPage(mode=mode) self.debug("Returning the home page") return bp else: srvname = srv.path().strip().lstrip('/') if srvname == '': if srv.query().replace('_get=json', '').strip() == '': try: srvname = self.config().config.frontpage['home'] except: srvname = 'home' else: srvname = 'old' elif '&_old' in srv.query(): srvname = 'old' hMethod = self.factory(srvname, parent=self) if hMethod: params = srv.query().strip() p = '' if not srvname == 'old' and not srvname == 'login': qlocation = urlquery.find('?') if qlocation >= 0: (values, keys, syskeys, extraValue) = self.param2Args( urlquery[qlocation + 1:]) pmstate().setParams(keys) p = params f = hMethod.callUI(p, mode) if cli == False and mode != 'script' and not self.server( ).jsonp(): hMethod.makeHelpUI(f) #hMethod.publishHelp(utils.makeDocUI(f,self.server())) hMethod.publishFooter() published = hMethod.published() cached = hMethod.cached() hMethod.empty() else: self.debug("Requested module '%s' not found" % srvname) # No python? Maybe there's html mfile = "%s/pandamon/pmModules/%s.html" % (pmstate().pandadir, pmstate().module) if os.path.exists(mfile): print "Got html module %s at %s" % (pmstate().module, mfile) fh = open(mfile) data = fh.read() fh.close() mode = 'page' # Treat it as a complete web page maintxt = data else: titletxt = "Requested module '%s/%s' not found" % ( pmstate().context, pmstate().module) if False: self.debug("------- Module %s" % pmstate().module) # try to load and pass control to the module mname = pmstate().module self.debug("------- getting Module mode=%s" % (mode)) if '&_old' in srv.query(): mname = 'old' mhandle = utils.getModule(mname) if mode != 'html': if mhandle != None: pmstate().moduleHandle[mname] = mhandle utils.addModule(mname) cl = mhandle.__dict__[mname] hMethod = cl(parent=self) p = '' if mname != 'old': params = urlquery.split('?', 1) if len(params) > 1: p = params[len(params) - 1] f = hMethod.callUI(p, mode) if cli == False and mode != 'script' and pmstate( ).callback == None: hMethod.makeHelpUI(f) #hMethod.publishHelp(utils.makeDocUI(f,self.server())) hMethod.publishFooter() published = hMethod.published() cached = hMethod.cached() hMethod.empty() # self.info("try %s" % published) else: self.debug("Requested module '%s/%s' not found" % (pmstate().context, pmstate().module)) # No python? Maybe there's html mfile = "%s/pandamon/pmModules/%s.html" % ( pmstate().pandadir, pmstate().module) if os.path.exists(mfile): print "Got html module %s at %s" % ( pmstate().module, mfile) fh = open(mfile) data = fh.read() fh.close() mode = 'page' # Treat it as a complete web page maintxt = data else: titletxt = "Requested module '%s/%s' not found" % ( pmstate().context, pmstate().module) else: bp = self._browser.buildPage(mode=mode) self.debug("Returning the home page") return bp pmstate().timer.printme() # print "pmHandler: 85 mode=%s\n published= %s\ncache=%s\n" % ( mode, published,hMethod.cached()), if mode in ('json'): try: # self.debug("--- > json %s" % json.dumps(published)) def default(o): s = "%s" % o return s page = ' { "pm" : %s }' % json.dumps( published, separators=(',', ':'), cls=pmJsonEncoder) #page = page.replace(',0,',',,').replace(',0,',',,') # compress 0s This can not pass the JSON.parser :( if self.server().jsonp(): # wrap into JSONP format page = "%(callback)s(%(page)s);" % { 'callback': pmstate().callback, 'page': page } except: raise # ValueError(" Sorry, the module's author needs to simplify the output.\n The python 'json' module was not able to create the json representation\n for the published data: name=<%s> for module=<%s> mode=%s urlquery=%s . . . " % (mname,pmstate().module,mode,urlquery )) return (page, mode, cached) elif mode in 'script': # print "pmHandler: 97", published jscript = self.wrapScript(published[0]['script']) return (jscript, mode, cached)
elif isinstance(cached,str): headers.append(('Cache-Control', '%s' % cached)) else: for c,v in cached.iteritems(): headers.append(('Cache-Control', '%s=%s' % (c,v))) except: raise ValueError("Wrong cache control value %s ", cached ) headersIface = Headers(headers) headersIface['Content-type']=mmCode(format) start_response('200 OK', headers) else: raise ValueError("Can not process the client %s request yet" % self.environ('REQUEST_METHOD')) return [page] if __name__ == '__main__': pmstate().instanceName = 'dev' debugmode = True if pmstate().host == 'localhost': # URLs will be built using localhost, but server runs against real host host = commands.getoutput('/bin/hostname') else: host = pmstate().host if len(sys.argv) > 1 and sys.argv[1] == 'local': myinstance = 'local' else: myinstance = '' print "Running Panda monitor daemon at http://%s:%s" % (host, int(pmstate().port)) # wgsi_server(host, int(pmstate().port)) httpd = BaseHTTPServer.HTTPServer((host, int(pmstate().port)), PythonHTTPHandler) httpd.serve_forever()