tdaq-develop-2025-02-12
SupervisorInfo.cc
1 #include "otsdaq/SupervisorInfo/SupervisorInfo.h"
2 
3 using namespace ots;
4 
5 const std::string SupervisorInfo::APP_STATUS_UNKNOWN = "UNKNOWN";
6 const std::string SupervisorInfo::APP_STATUS_NOT_MONITORED = "Not Monitored";
7 
8 //=====================================================================================
9 void SupervisorInfo::setStatus(const std::string& status,
10  const unsigned int progress,
11  const std::string& detail)
12 {
13  status_ = status;
14  progress_ = progress;
15  detail_ = detail;
16  if(status !=
18  APP_STATUS_UNKNOWN) // if unknown, then do not consider it a status update
19  lastStatusTime_ = time(0);
20 } // end setStatus()
21 
22 //=====================================================================================
23 void SupervisorInfo::setSubappStatus(const std::string& name,
24  const std::string& status,
25  const unsigned int progress,
26  const std::string& detail)
27 {
28  subapps_[name].name = name;
29  subapps_[name].status = status;
30  subapps_[name].progress = progress;
31  subapps_[name].detail = detail;
32  if(status !=
34  APP_STATUS_UNKNOWN) // if unknown, then do not consider it a status update
35  subapps_[name].lastStatusTime = time(0);
36 } // end setSubappStatus()
37 
38 //=====================================================================================
39 void SupervisorInfo::copySubappStatus(const SubappInfo& info)
40 {
41  subapps_[info.name] = info;
42 } // end setSubappStatus()
43 
44 //=====================================================================================
45 void SupervisorInfo::clear(void)
46 {
47  descriptor_ = 0;
48  progress_ = 0;
49  contextDescriptor_ = 0;
50  name_ = "";
51  id_ = 0;
52  contextName_ = "";
53  status_ = SupervisorInfo::APP_STATUS_UNKNOWN;
54 } // end clear()
55 
56 //=====================================================================================
57 std::string SupervisorInfo::extractHostname(const std::string& URL)
58 {
59  //__COUTV__(URL);
60  size_t i = URL.find("://");
61  if(i == std::string::npos)
62  i = 0;
63  else
64  i += 3;
65  //__COUTV__(i);
66  size_t j = URL.find(":", i);
67  if(j != std::string::npos)
68  j -= i;
69  //__COUTV__(j);
70  //__COUTV__(URL.substr(i,j));
71  return URL.substr(i, j);
72 } // end extractHostname
73 
74 //=====================================================================================
75 std::string SupervisorInfo::serializeSubappInfos(std::vector<SubappInfo> infos)
76 {
77  std::ostringstream ostr;
78  for(auto& info : infos)
79  {
80  ostr << info.name << "\n";
81  ostr << info.detail << "\n";
82  ostr << info.progress << "\n";
83  ostr << info.status << "\n";
84  ostr << info.lastStatusTime << "\n";
85  ostr << info.url << "\n";
86  ostr << info.class_name << "\n";
87  }
88  return ostr.str();
89 }
90 
91 //=====================================================================================
92 std::vector<SupervisorInfo::SubappInfo> SupervisorInfo::deserializeSubappInfos(
93  std::string info_string)
94 {
95  std::vector<SubappInfo> infos;
96  std::istringstream istr(info_string);
97  std::string line;
98  while(std::getline(istr, line))
99  {
100  SubappInfo thisInfo;
101  thisInfo.name = line;
102  std::getline(istr, line);
103  thisInfo.detail = line;
104  std::getline(istr, line);
105  std::istringstream converter(line);
106  converter >> thisInfo.progress;
107  std::getline(istr, line);
108  thisInfo.status = line;
109  std::getline(istr, line);
110  converter = std::istringstream(line);
111  converter >> thisInfo.lastStatusTime;
112  std::getline(istr, line);
113  thisInfo.url = line;
114  std::getline(istr, line);
115  thisInfo.class_name = line;
116  infos.push_back(thisInfo);
117  }
118 
119  return infos;
120 }
void setStatus(const std::string &status, const unsigned int progress, const std::string &detail="")
Setters ----------------—.