ConsumerList Class Reference

#include <ConsumerList.h>

List of all members.

Classes

struct  ConsumerEntry

Public Types

enum  {
  Unknown = 0, Dead = 1, Running = 2, Stopped = 3,
  Crashed = 4, Finished = 5
}

Public Member Functions

 ConsumerList (TString sitename="")
 ~ConsumerList ()
int nEntries () const
const TString & consumername (int i) const
const TString & hostname (int i) const
int port (int i) const
int nevents (int i) const
int runnumber (int i) const
int status (int i) const
const char * statusString (int i) const
const TString & updateTime (int i) const
int readWebPage ()
void setPort (int i, int port)
void setNevents (int i, int nev)
void setStatus (int i, int status)
void setRunnumber (int i, int runn)
void setUpdateTime (int i, char *tm)
int watchServers (const int port, const char *filename)
void test ()
void print (std::ostream &output=std::cout) const
void addEntry (TString nam, TString hostnam, int port, int nev, int runn, int stat, TString tm="")
void removeEntry (const char *hostname, int port)
int sendList (const char *host, const int port)
int writeWebPage (const char *filename)

Static Public Member Functions

static bool sortbyName (const ConsumerEntry a, const ConsumerEntry b)

Private Member Functions

 ConsumerList (const ConsumerList &sm)

Private Attributes

std::vector< ConsumerEntry_consumerlist
TString _websitename
const char * _statusnames [6]

Detailed Description

Definition at line 29 of file ConsumerList.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
Unknown 
Dead 
Running 
Stopped 
Crashed 
Finished 

Definition at line 57 of file ConsumerList.h.

00058   {
00059     Unknown  = 0, 
00060     Dead     = 1,
00061     Running  = 2,
00062     Stopped  = 3,
00063     Crashed  = 4,
00064     Finished = 5
00065   };


Constructor & Destructor Documentation

ConsumerList::ConsumerList ( TString  sitename = ""  ) 

Definition at line 37 of file ConsumerList.cc.

References _statusnames, Crashed, Dead, Finished, Running, Stopped, and Unknown.

00037                                            : _websitename(sitename)
00038 {
00039   _statusnames[Unknown] = "Unknown";
00040   _statusnames[Dead]    = "Dead";
00041   _statusnames[Running] = "Running";
00042   _statusnames[Stopped] = "Stopped";
00043   _statusnames[Crashed] = "Crashed";
00044   _statusnames[Finished] = "Finished";
00045 }

ConsumerList::~ConsumerList (  ) 

Definition at line 47 of file ConsumerList.cc.

00048 {
00049 }

ConsumerList::ConsumerList ( const ConsumerList sm  )  [private]

Definition at line 51 of file ConsumerList.cc.

00052 {
00053 }


Member Function Documentation

void ConsumerList::addEntry ( TString  nam,
TString  hostnam,
int  port,
int  nev,
int  runn,
int  stat,
TString  tm = "" 
)

Definition at line 402 of file ConsumerList.cc.

References _consumerlist, and removeEntry().

Referenced by DisplayServer::updateStateManager().

00404 {
00405   //try to remove old entry first
00406   removeEntry(hostnam,port);
00407   _consumerlist.push_back(ConsumerEntry(nam,hostnam,port,nev,runn,stat,tm));
00408 }

const TString & ConsumerList::consumername ( int  i  )  const

Definition at line 60 of file ConsumerList.cc.

References _consumerlist.

00061 {
00062   return _consumerlist[i].name;
00063 }

const TString & ConsumerList::hostname ( int  i  )  const

Definition at line 65 of file ConsumerList.cc.

References _consumerlist.

00066 {
00067   return _consumerlist[i].hostname;
00068 }

int ConsumerList::nEntries (  )  const

Definition at line 55 of file ConsumerList.cc.

References _consumerlist.

00056 {
00057   return _consumerlist.size();
00058 }

int ConsumerList::nevents ( int  i  )  const

Definition at line 75 of file ConsumerList.cc.

References _consumerlist.

00076 {
00077   return  _consumerlist[i].nevents;
00078 }

int ConsumerList::port ( int  i  )  const

Definition at line 70 of file ConsumerList.cc.

References _consumerlist.

00071 {
00072   return  _consumerlist[i].port;
00073 }

void ConsumerList::print ( std::ostream &  output = std::cout  )  const

Definition at line 328 of file ConsumerList.cc.

References _consumerlist, and _statusnames.

Referenced by HistoDisplay::MenuConnectStatus().

00329 {
00330   output << "ConsumerList:" << endl;
00331   output.width(15);
00332   output.setf(ios::left,ios::adjustfield);
00333   output << "name"; 
00334   output.width(30);
00335   output.setf(ios::left,ios::adjustfield);
00336   output << "hostname";
00337   output.width(6);
00338   output.setf(ios::right,ios::adjustfield);
00339   output << "port";
00340   output.width(7);
00341   output.setf(ios::right,ios::adjustfield);
00342   output << " runn";
00343   output.width(8);
00344   output.setf(ios::right,ios::adjustfield);
00345   output << "events";
00346   output.width(10);
00347   output.setf(ios::right,ios::adjustfield);
00348   output <<  " status" << endl; 
00349   for(std::vector<ConsumerEntry>::const_iterator iter = _consumerlist.begin();
00350       iter != _consumerlist.end(); ++iter)    
00351     {
00352       output.width(15);
00353       output.setf(ios::left,ios::adjustfield);
00354       output << iter->name; 
00355       output.width(30);
00356       output.setf(ios::left,ios::adjustfield);
00357       output << iter->hostname;
00358       output.width(6);
00359       output.setf(ios::right,ios::adjustfield);
00360       output << iter->port;
00361       output.width(7);
00362       output.setf(ios::right,ios::adjustfield);
00363       output << iter->runnumber;
00364       output.width(8);
00365       output.setf(ios::right,ios::adjustfield);
00366       output << iter->nevents;
00367       output.width(10);
00368       output.setf(ios::right,ios::adjustfield);
00369       output << _statusnames[iter->status] << endl;
00370     }
00371 }

int ConsumerList::readWebPage (  ) 

Definition at line 202 of file ConsumerList.cc.

References _consumerlist, _statusnames, _websitename, ConsumerList::ConsumerEntry::hostname, ConsumerList::ConsumerEntry::name, ConsumerList::ConsumerEntry::nevents, ConsumerList::ConsumerEntry::port, ConsumerList::ConsumerEntry::runnumber, and ConsumerList::ConsumerEntry::status.

Referenced by HistoDisplay::MenuConnectStatus().

00203 {
00204   ostrstream message;
00205   string page,temp;
00206   unsigned int pos,last,pos2=0;
00207   char buffer[5000];
00208   TUrl website(_websitename);
00209   //open Socket connection
00210   TSocket sock(website.GetHost(),website.GetPort());
00211   if(!(sock.IsValid())) return 0;
00212   // build request
00213   message << "GET " << website.GetFile() << " HTTP/1.0\rHost:"
00214           << website.GetHost() << ":" << website.GetPort() 
00215           << "\n\rAccept: */*\n\r\n\r" << ends;
00216   // get page
00217   temp = message.str();
00218   if (sock.SendRaw(temp.c_str(),temp.length()) != (Int_t)temp.length())
00219     return 0;
00220   sock.RecvRaw(buffer,5000);
00221   sock.Close();
00222   // check title
00223   page = buffer;
00224   pos  = page.find("<title>")+7;
00225   temp = page.substr(pos,page.find("</title>")-pos);
00226   if (temp != "Consumer Status Page") return 0;
00227   //fill the consumerlist
00228   _consumerlist.erase(_consumerlist.begin(),_consumerlist.end());
00229   pos = page.find("<tr>");
00230   last = page.rfind("</tr>");
00231   if (pos==page.rfind("<tr>")) return 0; //no entries
00232   pos = page.find("<tr>",pos+3);
00233   while(pos<last)
00234     {
00235       //read line
00236       ConsumerEntry ent;
00237       pos = page.find("<td>",pos) + 4;
00238       temp = page.substr(pos,page.find("</td>",pos)-pos).c_str();
00239       pos2 = temp.find(">");
00240       cout << temp << "  " << pos2 << endl;
00241       if(pos2 > 0)
00242           ent.name = temp.substr(pos2 + 1,temp.rfind("</font>")-pos2-1).c_str();
00243       else ent.name = temp.c_str();
00244       pos = page.find("<td>",pos) + 4; 
00245       temp = page.substr(pos,page.find("</td>",pos)-pos).c_str();
00246       pos2 = temp.find(">");cout << temp << "  " << pos2 << endl;
00247       if(pos2 > 0)
00248           ent.hostname = temp.substr(pos2 + 1,temp.rfind("</font>")-pos2-1).c_str();
00249       else ent.hostname = temp.c_str();
00250       pos = page.find("<td>",pos) + 4;
00251       ent.port = atoi(page.substr(pos,page.find("</td>",pos)-pos).c_str());
00252       pos = page.find("<td>",pos) + 4;
00253       ent.runnumber = atoi(page.substr(pos,page.find("</td>",pos)-pos).c_str());
00254       pos = page.find("<td>",pos) + 4;
00255       ent.nevents = atoi(page.substr(pos,page.find("</td>",pos)-pos).c_str());
00256       pos = page.find("<td>",pos) + 4;
00257       temp = page.substr(pos,page.find("</td>",pos)-pos);
00258       pos2 = temp.find(">") ;cout << temp << "  " << pos2 << endl;
00259       if(pos2 > 0)
00260         temp = temp.substr(pos2 + 1,temp.rfind("</font>") - pos2 - 1).c_str();
00261       for(int i = 0; i < 6; i++)
00262         if (strcmp(temp.c_str(),_statusnames[i])==0) 
00263           {
00264             ent.status = i;
00265             break;
00266           }
00267       pos =  page.find("</tr>",pos);
00268       _consumerlist.push_back(ent);
00269     }
00270   return 1;
00271 }

void ConsumerList::removeEntry ( const char *  hostname,
int  port 
)

Definition at line 126 of file ConsumerList.cc.

References _consumerlist.

Referenced by addEntry(), and watchServers().

00127 {
00128   std::vector<ConsumerEntry>::iterator pos = 
00129     _consumerlist.end();
00130   for(std::vector<ConsumerEntry>::iterator iter = _consumerlist.begin();
00131       iter != _consumerlist.end(); ++iter)
00132     if((iter->hostname == hostname)&&(iter->port == port)) pos = iter;
00133   if(pos!=_consumerlist.end()) _consumerlist.erase(pos);
00134 }

int ConsumerList::runnumber ( int  i  )  const

Definition at line 80 of file ConsumerList.cc.

References _consumerlist.

00081 {
00082   return  _consumerlist[i].runnumber;
00083 }

int ConsumerList::sendList ( const char *  host,
const int  port 
)

Definition at line 373 of file ConsumerList.cc.

References _consumerlist.

00374 {
00375   ostrstream message;
00376   string temp;
00377 
00378   TSocket sock(host,port);
00379   if (!(sock.IsValid())) 
00380     {
00381       cout << "ConsumerList::sendList: socket not valid" << endl;
00382       return 0;
00383     }
00384   message << "ConsumerList" << endl;
00385   for(std::vector<ConsumerEntry>::const_iterator iter = _consumerlist.begin();
00386       iter != _consumerlist.end(); ++iter)
00387     message << iter->name << endl << iter->hostname << endl 
00388             << iter->port << endl << iter->runnumber << endl 
00389             << iter->nevents << endl << iter->status << endl;
00390   message << "END" << endl;
00391   temp = message.str();
00392   if (sock.SendRaw(temp.c_str(),temp.length()) != (Int_t)temp.length())
00393     {
00394       sock.Close();
00395       return 0;
00396     }
00397   sock.Close();
00398   return 1;
00399 }

void ConsumerList::setNevents ( int  i,
int  nev 
)

Definition at line 105 of file ConsumerList.cc.

References _consumerlist.

Referenced by timer().

00106 {
00107   _consumerlist[i].nevents = nev;
00108 }

void ConsumerList::setPort ( int  i,
int  port 
)

Definition at line 100 of file ConsumerList.cc.

References _consumerlist.

00101 {
00102   _consumerlist[i].port = port;
00103 }

void ConsumerList::setRunnumber ( int  i,
int  runn 
)

Definition at line 115 of file ConsumerList.cc.

References _consumerlist.

Referenced by timer().

00116 {
00117   _consumerlist[i].runnumber = runn;
00118 }

void ConsumerList::setStatus ( int  i,
int  status 
)

Definition at line 110 of file ConsumerList.cc.

References _consumerlist.

Referenced by abbruch(), and DisplayServer::pollConsumer().

00111 {
00112   _consumerlist[i].status = status;
00113 }

void ConsumerList::setUpdateTime ( int  i,
char *  tm 
)

Definition at line 120 of file ConsumerList.cc.

References _consumerlist.

00121 {
00122   _consumerlist[i].time = tm;
00123 }

bool ConsumerList::sortbyName ( const ConsumerEntry  a,
const ConsumerEntry  b 
) [static]

Definition at line 424 of file ConsumerList.cc.

References ConsumerList::ConsumerEntry::name.

Referenced by writeWebPage().

00426 { 
00427   return a.name < b.name;
00428 }

int ConsumerList::status ( int  i  )  const

Definition at line 85 of file ConsumerList.cc.

References _consumerlist.

00086 {
00087   return  _consumerlist[i].status;
00088 }

const char * ConsumerList::statusString ( int  i  )  const

Definition at line 90 of file ConsumerList.cc.

References _consumerlist, and _statusnames.

00091 {
00092    return  _statusnames[_consumerlist[i].status];
00093 }

void ConsumerList::test (  ) 

Definition at line 191 of file ConsumerList.cc.

00192 {
00193   //unused:  const time_t zeit = time(0);
00194   /*
00195   _consumerlist.push_back(ConsumerEntry("YMon","b0dau31.fnal.gov"
00196                                         ,9090,10,10001,1,ctime(&zeit)));
00197   _consumerlist.push_back(ConsumerEntry("WedgeMon","b0dap30.fnal.gov",9091,110,10001,Crashed,ctime(&zeit)));
00198   _consumerlist.push_back(ConsumerEntry("XMon","b0dap30.fnal.gov",9092,200,10001,Running,ctime(&zeit)));
00199   */
00200 }

const TString & ConsumerList::updateTime ( int  i  )  const

Definition at line 95 of file ConsumerList.cc.

References _consumerlist.

00096 {
00097   return _consumerlist[i].time;
00098 }

int ConsumerList::watchServers ( const int  port,
const char *  filename 
)

Definition at line 136 of file ConsumerList.cc.

References _consumerlist, Crashed, ConsumerList::ConsumerEntry::hostname, ConsumerList::ConsumerEntry::name, ConsumerList::ConsumerEntry::nevents, ConsumerList::ConsumerEntry::port, removeEntry(), Running, ConsumerList::ConsumerEntry::runnumber, ConsumerList::ConsumerEntry::status, ConsumerList::ConsumerEntry::time, Unknown, and writeWebPage().

00137 {
00138   //unused:  TMonitor *monitor = new TMonitor;
00139   // open sockets
00140   TServerSocket ss(port,kTRUE);
00141   if(!(ss.IsValid())) 
00142     {
00143       cout << "ConsumerList::watchServers: serversocket not valid" << endl;
00144       return 0;
00145     }
00146   writeWebPage(filename);
00147   while(1)
00148     {
00149       //cout << "waiting for first connection" << endl;
00150       TSocket *sock = ss.Accept();
00151       //cout << "connected from " << sock->GetInetAddress().GetHostName() << endl;
00152       char buffer[1000];
00153       string word;
00154       sock->RecvRaw(buffer,1000);
00155       istrstream message(buffer);
00156       //cout << buffer << endl;
00157       message >> word;
00158       if(word=="ConsumerList")
00159         {
00160           message >> word;
00161           while((word != "END") && message)
00162             {
00163               // search for name and remove old entry
00164               // add new entry
00165               ConsumerEntry entry;
00166               entry.name = word.c_str();
00167               message >> entry.hostname;
00168               message >> entry.port;
00169               message >> entry.runnumber; 
00170               message >> entry.nevents;
00171               message >> entry.status;
00172               message >> word;
00173               // search for hostname and port and remove old entry
00174               removeEntry(entry.hostname,entry.port);
00175               const time_t zeit = time(0);
00176               entry.time = ctime(&zeit);
00177               if((entry.status==Running)||(entry.status==Crashed)||
00178                  (entry.status==Unknown) && message) _consumerlist.push_back(entry);
00179               //cout << word << endl;
00180             }
00181           //print();
00182           writeWebPage(filename);
00183         }
00184       // remove connection
00185       sock->Close();
00186       delete sock;
00187     }
00188 }

int ConsumerList::writeWebPage ( const char *  filename  ) 

Definition at line 273 of file ConsumerList.cc.

References _consumerlist, _statusnames, _websitename, Crashed, and sortbyName().

Referenced by watchServers().

00274 {
00275   // sort consumerlist
00276   std::sort(_consumerlist.begin(),_consumerlist.end(),sortbyName);
00277   
00278   const time_t zeit = time(0);
00279   //open file
00280   
00281   std::ofstream page(filename);
00282   if (!page) return 0;
00283   //write head of page 
00284   page << "<html> \n <head> \n <title>Consumer Status Page</title>" << endl;;
00285   page << "<meta http-equiv=\"cache-control\" content=\"no-cache\">" << endl;
00286   page << "<meta http-equiv=\"pragma\" content=\"no-cache\">" << endl;
00287   page << "<meta http-equiv=\"Refresh\" content=\"30;url=" << _websitename 
00288        << "\" >" << endl;                            
00289   page << "<br><br><br><center><h1><u><font color=\"#FF0000\"> Consumer Status Page</center></font></u></h1> \n";
00290   page << "\n </head> \n <body background=\"home/cdfii_ybgr.jpg\"> \n ";
00291   page << "<img src=\"home/cdfii_logo.gif\" align=right alt=\"CDF II\" height=100 width=100> \n";
00292   page << "<br><br><br><br><br><br><br><br><br> \n Status of Consumer Processes: \n";
00293   page << "<br> \n <center> <table BORDER COLS=7 WIDTH=\"100%\" NOSAVE> \n";
00294   page << "<tr> \n <td> Consumer </td> \n \n";
00295   page << "<td>Hostname</td> \n \n <td>Port</td> \n \n";
00296   page << "<td>Run number</td> \n \n" ;
00297   page << "<td># of Events processed</td> \n \n <td>Status</td>";
00298   page << "\n \n <td>Time</td> \n </tr> \n";
00299   
00300   // fill table
00301   for(std::vector<ConsumerEntry>::const_iterator iter = _consumerlist.begin();
00302       iter != _consumerlist.end(); ++iter)
00303     {
00304       if(iter->status == Crashed)
00305         page << "<tr> \n <td>" << "<font color=\"#FF0000\">"
00306              << iter->name << "</font></td><td>" << "<font color=\"#FF0000\">"
00307              << iter->hostname << "</font>"
00308              << "</td><td>" << iter->port <<  "</td><td>"
00309              << iter->runnumber << "</td><td>"
00310              << iter->nevents << "</td><td>" << "<font color=\"#FF0000\">"
00311              <<_statusnames[iter->status] << "</font>"  
00312              << "</td><td>" << iter->time << "</td></tr>\n";
00313       else
00314         page << "<tr> \n <td>" << iter->name << "</td><td>" << iter->hostname
00315              << "</td><td>" << iter->port <<  "</td><td>"
00316              << iter->runnumber << "</td><td>"
00317              << iter->nevents << "</td><td>" << _statusnames[iter->status] 
00318              << "</td><td>" << iter->time << "</td></tr>\n";
00319     }
00320   // write end of page , time stamp 
00321   page << "</center> </table>\n";
00322   page << "<br> <br> <br> \n Last Update:" << ctime(&zeit) << "<br> \n";
00323   page << "</body>\n </html> \n";
00324   page.close();
00325   return 1;
00326 }


Member Data Documentation

const char* ConsumerList::_statusnames[6] [private]

Definition at line 85 of file ConsumerList.h.

Referenced by ConsumerList(), print(), readWebPage(), statusString(), and writeWebPage().

TString ConsumerList::_websitename [private]

Definition at line 84 of file ConsumerList.h.

Referenced by readWebPage(), and writeWebPage().


The documentation for this class was generated from the following files:

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1