irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rsZoneReport.cpp
Go to the documentation of this file.
1 #include "rcMisc.h"
2 #include "rsGlobalExtern.hpp"
3 #include "rodsErrorTable.h"
4 #include "miscServerFunct.hpp"
5 #include "rsZoneReport.hpp"
6 #include "rsServerReport.hpp"
7 
8 #include "irods_log.hpp"
9 #include "zone_report.h"
10 #include "server_report.h"
16 
17 #include "json.hpp"
18 
19 #include <boost/format.hpp>
20 
22 
23 int _rsZoneReport( rsComm_t* _comm, bytesBuf_t** _bbuf );
24 
25 int rsZoneReport( rsComm_t* _comm, bytesBuf_t** _bbuf ) {
26  rodsServerHost_t* rods_host;
27  int status = getAndConnRcatHost(_comm, MASTER_RCAT, nullptr, &rods_host);
28  if ( status < 0 ) {
29  return status;
30  }
31 
32  if ( rods_host->localFlag == LOCAL_HOST ) {
33  std::string svc_role;
34  irods::error ret = get_catalog_service_role(svc_role);
35  if(!ret.ok()) {
36  irods::log(PASS(ret));
37  return ret.code();
38  }
39 
40  if ( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
41  status = _rsZoneReport( _comm, _bbuf );
42  }
43  else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
45  }
46  else {
47  rodsLog( LOG_ERROR, "role not supported [%s]", svc_role.c_str() );
49  }
50  }
51  else {
52  status = rcZoneReport( rods_host->conn, _bbuf );
53  }
54 
55  if ( status < 0 ) {
56  rodsLog( LOG_ERROR, "rsZoneReport: rcZoneReport failed, status = %d", status );
57  }
58 
59  return status;
60 } // rsZoneReport
61 
63  int _error,
64  const std::string& _host_name,
65  const std::string& _resc_name,
66  json& _resc_arr )
67 {
68  std::stringstream msg;
69  msg << "failed in svrToSvrConnect for resource ["
70  << _resc_name
71  << "], at hostname ["
72  << _host_name
73  << "], error code "
74  << _error;
75 
76  irods::error err = ERROR(_error, msg.str());
77  irods::log( err );
78 
79  _resc_arr.push_back({"ERROR", msg.str()});
80 }
81 
82 static
84 {
85  _resc_arr = json::array();
86 
87  std::map< rodsServerHost_t*, int > svr_reported;
88  rodsServerHost_t* icat_host = 0;
89  char* zone_name = getLocalZoneName();
90  int status = getRcatHost( MASTER_RCAT, zone_name, &icat_host );
91  if ( status < 0 ) {
92  return ERROR(status, "getRcatHost failed");
93  }
94 
96  itr != resc_mgr.end();
97  ++itr)
98  {
99  irods::resource_ptr resc = itr->second;
100 
101  rodsServerHost_t* tmp_host = 0;
102  irods::error ret = resc->get_property< rodsServerHost_t* >( irods::RESOURCE_HOST, tmp_host );
103  if ( !ret.ok() ) {
104  irods::log( PASS( ret ) );
105  continue;
106  }
107 
108  // skip the icat server as that is done separately
109  // also skip null tmp_hosts resources ( coordinating )
110  // skip local host
111  if ( !tmp_host || tmp_host == icat_host || LOCAL_HOST == tmp_host->localFlag ) {
112  continue;
113  }
114 
115  // skip previously reported servers
116  std::map< rodsServerHost_t*, int >::iterator svr_itr =
117  svr_reported.find( tmp_host );
118  if ( svr_itr != svr_reported.end() ) {
119  continue;
120  }
121 
122  std::string resc_name;
123  ret = resc->get_property< std::string >( irods::RESOURCE_NAME, resc_name );
124  if ( !ret.ok() ) {
125  irods::log( PASS( ret ) );
126  continue;
127  }
128 
129  svr_reported[ tmp_host ] = 1;
130 
131  int status = svrToSvrConnect( _comm, tmp_host );
132  if ( status < 0 ) {
134  status,
135  tmp_host->hostName->name,
136  resc_name,
137  _resc_arr);
138  continue;
139  }
140 
141  bytesBuf_t* bbuf = NULL;
142  status = rcServerReport( tmp_host->conn, &bbuf );
143  if ( status < 0 ) {
144  freeBBuf( bbuf );
145  bbuf = NULL;
146  rodsLog(
147  LOG_ERROR,
148  "rcServerReport failed for [%s], status = %d",
149  tmp_host->hostName->name,
150  status );
151  }
152 
153  // possible null termination issues
154  std::string tmp_str = bbuf ? std::string((char*) bbuf->buf, bbuf->len) : std::string();
155 
156  try {
157  _resc_arr.push_back(json::parse(tmp_str));
158  freeBBuf(bbuf);
159  }
160  catch (const json::type_error& e) {
161  std::string msg = "json_loads failed [";
162  msg += e.what();
163  msg += "]";
165  }
166  } // for itr
167 
168  return SUCCESS();
169 } // get_server_reports
170 
171 static
173 {
174  _resources = json::array();
175 
176  for( auto itr = std::begin(resc_mgr); itr != std::end(resc_mgr); ++itr ) {
177  irods::resource_ptr& resc = itr->second;
178 
179  rodsServerHost_t* tmp_host = nullptr;
180  irods::error ret = resc->get_property< rodsServerHost_t* >(
182  tmp_host );
183  if ( !ret.ok() ) {
184  irods::log( PASS( ret ) );
185  continue;
186  }
187 
188  // skip non-null hosts ( not coordinating )
189  if ( tmp_host ) {
190  continue;
191 
192  }
193 
194  auto entry = json::object();
195 
196  ret = serialize_resource_plugin_to_json(itr->second, entry);
197  if(!ret.ok()) {
198  ret = PASS(ret);
199  irods::log(ret);
200  entry["ERROR"] = ret.result();
201  }
202 
203  _resources.push_back(entry);
204  } // for itr
205 
206  return SUCCESS();
207 } // get_coordinating_resources
208 
209 int _rsZoneReport(rsComm_t* _comm, bytesBuf_t** _bbuf)
210 {
211  bytesBuf_t* bbuf = 0;
212  int status = rsServerReport(_comm, &bbuf);
213  if ( status < 0 ) {
214  freeBBuf(bbuf);
215  rodsLog(LOG_ERROR, "_rsZoneReport - rsServerReport failed %d", status);
216  return status;
217  }
218 
219  json cat_svr;
220 
221  try {
222  cat_svr = json::parse(std::string(static_cast<char*>(bbuf->buf), bbuf->len));
223  freeBBuf(bbuf);
224  }
225  catch (const json::type_error& e) {
226  rodsLog(LOG_ERROR, "_rsZoneReport - json::parse failed [%s]", e.what());
227  return ACTION_FAILED_ERR;
228  }
229 
230  json coord_resc;
231  irods::error ret = get_coordinating_resources( _comm, coord_resc );
232  if ( !ret.ok() ) {
233  rodsLog(LOG_ERROR, "_rsZoneReport - get_server_reports failed, status = %d", ret.code());
234  return ret.code();
235  }
236 
237  json svr_arr;
238  ret = get_server_reports( _comm, svr_arr );
239  if ( !ret.ok() ) {
240  rodsLog(LOG_ERROR, "_rsZoneReport - get_server_reports failed, status = %d", ret.code());
241  return ret.code();
242  }
243 
244  cat_svr["coordinating_resources"] = coord_resc;
245 
246  auto zone_obj = json::object();
247  zone_obj["servers"] = svr_arr;
248  zone_obj["icat_server"] = cat_svr;
249 
250  auto zone_arr = json::array();
251  zone_arr.push_back(zone_obj);
252 
253  auto zone = json::object();
254  zone["schema_version"] = (boost::format("%s/%s/zone_bundle.json")
255  % irods::get_server_property<const std::string>("schema_validation_base_uri")
256  % irods::get_server_property<const std::string>("schema_version")).str();
257 
258  zone["zones"] = zone_arr;
259 
260  const auto zr = zone.dump(4);
261  char* tmp_buf = new char[zr.length() + 1]{};
262  std::strncpy(tmp_buf, zr.c_str(), zr.length());
263 
264  *_bbuf = (bytesBuf_t*) malloc(sizeof(bytesBuf_t));
265  if (!*_bbuf) {
266  delete [] tmp_buf;
267  rodsLog( LOG_ERROR, "_rsZoneReport: failed to allocate _bbuf" );
268  return SYS_MALLOC_ERR;
269  }
270 
271  (*_bbuf)->buf = tmp_buf;
272  (*_bbuf)->len = zr.length();
273 
274  return 0;
275 } // _rsZoneReport
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
irods_configuration_keywords.hpp
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
irods::resource_manager::end
iterator end()
Definition: irods_resource_manager.hpp:192
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
irods::RESOURCE_NAME
const std::string RESOURCE_NAME("resource_property_name")
irods_server_properties.hpp
rcServerReport
int rcServerReport(rcComm_t *server_comm_ptr, bytesBuf_t **json_response)
Definition: rcServerReport.cpp:6
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
SYS_MALLOC_ERR
@ SYS_MALLOC_ERR
Definition: rodsErrorTable.h:84
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
server_report.h
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
resc_mgr
irods::resource_manager resc_mgr
Definition: irods_resource_manager.cpp:31
irods::resource_ptr
boost::shared_ptr< resource > resource_ptr
Definition: irods_resource_types.hpp:11
irods::resource_manager::iterator
lookup_table< resource_ptr >::iterator iterator
Definition: irods_resource_manager.hpp:190
rcMisc.h
get_coordinating_resources
static irods::error get_coordinating_resources(rsComm_t *_comm, json &_resources)
Definition: rsZoneReport.cpp:172
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
json
nlohmann::json json
Definition: group.cpp:5
manual_cleanup.zone_name
zone_name
Definition: manual_cleanup.py:16
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
BytesBuf::len
int len
Definition: rodsDef.h:198
irods::experimental::filesystem::client::end
auto end(const collection_iterator &) noexcept -> const collection_iterator
Definition: collection_iterator.hpp:88
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
rsGlobalExtern.hpp
irods::experimental::filesystem::client::begin
auto begin(collection_iterator _iter) noexcept -> collection_iterator
Definition: collection_iterator.hpp:83
irods::error::code
long long code() const
Definition: irods_error.cpp:194
hostName::name
char * name
Definition: rodsConnect.h:38
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
rsZoneReport.hpp
json
nlohmann::json json
Definition: rsZoneReport.cpp:21
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
_rsZoneReport
int _rsZoneReport(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsZoneReport.cpp:209
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
rsServerReport
int rsServerReport(rsComm_t *server_comm_ptr, bytesBuf_t **json_response)
Definition: rsServerReport.cpp:37
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
getRcatHost
int getRcatHost(int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:88
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
BytesBuf
Definition: rodsDef.h:197
rcZoneReport
int rcZoneReport(rcComm_t *server_comm_ptr, bytesBuf_t **json_response)
Definition: rcZoneReport.cpp:6
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
getLocalZoneName
char * getLocalZoneName()
Definition: rodsConnect.cpp:685
irods::resource_manager::begin
iterator begin()
Definition: irods_resource_manager.hpp:191
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
irods::serialize_resource_plugin_to_json
error serialize_resource_plugin_to_json(const resource_ptr &_resc, nlohmann::json &_entry)
Definition: irods_report_plugins_in_json.cpp:88
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
rsServerReport.hpp
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
entry
Definition: ruleAdmin.cpp:22
zone_report.h
ACTION_FAILED_ERR
@ ACTION_FAILED_ERR
Definition: rodsErrorTable.h:664
irods_resource_manager.hpp
get_server_reports
static irods::error get_server_reports(rsComm_t *_comm, json &_resc_arr)
Definition: rsZoneReport.cpp:83
rsZoneReport
int rsZoneReport(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsZoneReport.cpp:25
rodsErrorTable.h
report_server_connect_error
static void report_server_connect_error(int _error, const std::string &_host_name, const std::string &_resc_name, json &_resc_arr)
Definition: rsZoneReport.cpp:62
freeBBuf
int freeBBuf(bytesBuf_t *myBBuf)
Definition: rcMisc.cpp:88
rodsServerHost::hostName
hostName_t * hostName
Definition: rodsConnect.h:63
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::RESOURCE_HOST
const std::string RESOURCE_HOST("resource_property_host")
irods_report_plugins_in_json.hpp
irods::error::result
std::string result() const
Definition: irods_error.cpp:201
irods_log.hpp