ws_machineService.hpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef _ESPWIZ_ws_machine_HPP__
  14. #define _ESPWIZ_ws_machine_HPP__
  15. #pragma warning (disable : 4786)
  16. #include "ws_machine_esp.ipp"
  17. #include "environment.hpp"
  18. #include <set>
  19. #include <map>
  20. class CMachineInfoThreadParam;
  21. class CRoxieStateInfoThreadParam;
  22. class CMetricsThreadParam;
  23. class CRemoteExecThreadParam;
  24. static const char *legacyFilterStrings[] = {"AttrServerProcess:attrserver", "DaliProcess:daserver",
  25. "DfuServerProcess:dfuserver", "DKCSlaveProcess:dkcslave", "EclServerProcess:eclserver", "EclCCServerProcess:eclccserver",
  26. "EspProcess:esp", "FTSlaveProcess:ftslave", "HoleControlProcess:hoctrl", "HoleSocketProcess:hoserver",
  27. "HoleCollatorProcess:collator", "HoleProcessorProcess:processor", "JobServerProcess:jobserver",
  28. "RoxieServerProcess:roxie", "RoxieSlaveProcess:roxie", "RoxieServerProcess:ccd", "RoxieFarmerProcess:ccd",
  29. "RoxieSlaveProcess:ccd", "SchedulerProcess:scheduler","ThorMasterProcess:thormaster", "ThorSlaveProcess:thorslave",
  30. "SashaServerProcess:saserver", NULL };
  31. struct CEnvironmentConfData
  32. {
  33. StringBuffer m_configsPath;
  34. StringBuffer m_executionPath;
  35. StringBuffer m_runtimePath;
  36. StringBuffer m_lockPath;
  37. StringBuffer m_pidPath;
  38. StringBuffer m_user;
  39. };
  40. static CEnvironmentConfData environmentConfData;
  41. struct CField
  42. {
  43. double Value;
  44. bool Warn;
  45. bool Undefined;
  46. bool Hide;
  47. CField()
  48. : Value(0), Warn(0), Undefined(0)
  49. {
  50. }
  51. void serialize(StringBuffer& xml) const
  52. {
  53. xml.append("<Field>");
  54. xml.appendf("<Value>%f</Value>", Value);
  55. if (Warn)
  56. xml.append("<Warn>1</Warn>");
  57. if (Hide)
  58. xml.append("<Hide>1</Hide>");
  59. if (Undefined)
  60. xml.append("<Undefined>1</Undefined>");
  61. xml.append("</Field>");
  62. }
  63. };
  64. struct CFieldMap : public map<string, CField*>
  65. {
  66. virtual ~CFieldMap()
  67. {
  68. const_iterator iEnd=end();
  69. for (const_iterator i=begin(); i!=iEnd; i++)
  70. delete (*i).second;
  71. }
  72. void serialize(StringBuffer& xml)
  73. {
  74. xml.append("<Fields>");
  75. const_iterator iEnd=end();
  76. for (const_iterator i=begin(); i!=iEnd; i++)
  77. (*i).second->serialize(xml);
  78. xml.append("</Fields>");
  79. }
  80. };
  81. struct CFieldInfo
  82. {
  83. unsigned Count; //N
  84. double SumSquaredDeviations; //SSD
  85. double Mean;
  86. double StandardDeviation;
  87. bool Hide;
  88. CFieldInfo()
  89. : Count(0),
  90. SumSquaredDeviations(0),
  91. Mean(0),
  92. StandardDeviation(0),
  93. Hide(true)
  94. {
  95. }
  96. void serialize(StringBuffer& xml, const char* fieldName) const
  97. {
  98. const char* fieldName0 = fieldName;
  99. if (!strncmp(fieldName, "ibyti", 5))
  100. fieldName += 5;
  101. xml.append("<FieldInfo>");
  102. xml.appendf("<Name>%s</Name>", fieldName0);
  103. xml.append("<Caption>");
  104. const char* pch = fieldName;
  105. if (!strncmp(pch, "lo", 2))
  106. {
  107. xml.append("Low");
  108. pch += 2;
  109. }
  110. else if (!strncmp(pch, "hi", 2))
  111. {
  112. xml.append("High");
  113. pch += 2;
  114. }
  115. else if (!strncmp(pch, "tot", 3))
  116. {
  117. xml.append("Total");
  118. pch += 3;
  119. }
  120. else xml.append( (char)toupper( *pch++) );
  121. while (*pch)
  122. {
  123. if (isupper(*pch))
  124. xml.append(' ');
  125. xml.append(*pch++);
  126. }
  127. xml.append("</Caption>");
  128. xml.appendf("<Mean>%f</Mean>", Mean);
  129. xml.appendf("<StandardDeviation>%f</StandardDeviation>", StandardDeviation);
  130. if (Hide)
  131. xml.appendf("<Hide>1</Hide>");
  132. xml.append("</FieldInfo>");
  133. }
  134. };
  135. struct CFieldInfoMap : public map<string, CFieldInfo*>
  136. {
  137. Mutex m_mutex;
  138. virtual ~CFieldInfoMap()
  139. {
  140. const_iterator iEnd=end();
  141. for (const_iterator i=begin(); i!=iEnd; i++)
  142. delete (*i).second;
  143. }
  144. void serialize(StringBuffer& xml) const
  145. {
  146. const_iterator iEnd=end();
  147. for (const_iterator i=begin(); i!=iEnd; i++)
  148. {
  149. const char* fieldName = (*i).first.c_str();
  150. (*i).second->serialize(xml, fieldName);
  151. }
  152. }
  153. };
  154. class CMetricsParam : public CInterface
  155. {
  156. public:
  157. IMPLEMENT_IINTERFACE;
  158. CMetricsParam( const char* pszAddress) : m_sAddress(pszAddress){}
  159. virtual ~CMetricsParam() {}
  160. StringBuffer m_sAddress;
  161. CFieldMap m_fieldMap;
  162. };
  163. class CProcessData : public CInterface
  164. {
  165. StringAttr m_type;
  166. StringAttr m_name;
  167. StringAttr m_path;
  168. unsigned m_processNumber;
  169. bool m_multipleInstances; //required from ProcessFilter in environment.xml
  170. StringAttr m_pid;
  171. StringAttr m_upTime;
  172. set<string> m_dependencies;
  173. public:
  174. IMPLEMENT_IINTERFACE;
  175. CProcessData()
  176. {
  177. m_processNumber = 0;
  178. m_multipleInstances = false;
  179. m_dependencies.clear();
  180. }
  181. CProcessData(const char* name, const char* type, const char* path, unsigned processNumber):
  182. m_processNumber(processNumber)
  183. {
  184. m_name.set(name);
  185. m_type.set(type);
  186. m_path.set(path);
  187. m_multipleInstances = false;
  188. m_dependencies.clear();
  189. }
  190. virtual ~CProcessData(){}
  191. void setName(const char* name)
  192. {
  193. m_name.set(name);
  194. }
  195. const char* getName()
  196. {
  197. return m_name.str();
  198. }
  199. void setType(const char* type)
  200. {
  201. m_type.set(type);
  202. }
  203. const char* getType()
  204. {
  205. return m_type.str();
  206. }
  207. void setPath(const char* path)
  208. {
  209. m_path.set(path);
  210. }
  211. const char* getPath()
  212. {
  213. return m_path.str();
  214. }
  215. void setPID(const char* pid)
  216. {
  217. m_pid.set(pid);
  218. }
  219. const char* getPID()
  220. {
  221. return m_pid.str();
  222. }
  223. void setUpTime(const char* upTime)
  224. {
  225. m_upTime.set(upTime);
  226. }
  227. const char* getUpTime()
  228. {
  229. return m_upTime.str();
  230. }
  231. void setProcessNumber(unsigned processNumber)
  232. {
  233. m_processNumber = processNumber;
  234. }
  235. const unsigned getProcessNumber()
  236. {
  237. return m_processNumber;
  238. }
  239. void setMultipleInstances(bool multipleInstances)
  240. {
  241. m_multipleInstances = multipleInstances;
  242. }
  243. const bool getMultipleInstances()
  244. {
  245. return m_multipleInstances;
  246. }
  247. set<string>& getDependencies()
  248. {
  249. return m_dependencies;
  250. }
  251. };
  252. class CStorageData : public CInterface
  253. {
  254. StringBuffer m_diskSpaceTitle;
  255. __int64 m_diskSpaceAvailable;
  256. __int64 m_diskSpaceTotal;
  257. int m_diskSpacePercentAvail;
  258. public:
  259. IMPLEMENT_IINTERFACE;
  260. CStorageData()
  261. {
  262. m_diskSpaceTitle.clear();
  263. m_diskSpaceAvailable = 0;
  264. m_diskSpaceTotal = 0;
  265. m_diskSpacePercentAvail = 0;
  266. }
  267. CStorageData(const char* diskSpaceTitle, __int64 diskSpaceAvailable, __int64 diskSpaceTotal, int diskSpacePercentAvail)
  268. : m_diskSpaceAvailable(diskSpaceAvailable), m_diskSpaceTotal(diskSpaceTotal), m_diskSpacePercentAvail(diskSpacePercentAvail)
  269. {
  270. m_diskSpaceTitle = diskSpaceTitle;
  271. }
  272. virtual ~CStorageData(){}
  273. void setDiskSpaceTitle(const char* title)
  274. {
  275. m_diskSpaceTitle.clear().append(title);
  276. }
  277. const char* getDiskSpaceTitle()
  278. {
  279. return m_diskSpaceTitle.str();
  280. }
  281. void setDiskSpaceAvailable(__int64 space)
  282. {
  283. m_diskSpaceAvailable = space;
  284. }
  285. const __int64 getDiskSpaceAvailable()
  286. {
  287. return m_diskSpaceAvailable;
  288. }
  289. void setDiskSpaceTotal(__int64 space)
  290. {
  291. m_diskSpaceTotal = space;
  292. }
  293. const __int64 getDiskSpaceTotal()
  294. {
  295. return m_diskSpaceTotal;
  296. }
  297. void setDiskSpacePercentAvail(int space)
  298. {
  299. m_diskSpacePercentAvail = space;
  300. }
  301. const int getDiskSpacePercentAvail()
  302. {
  303. return m_diskSpacePercentAvail;
  304. }
  305. };
  306. interface IStateHash : extends IInterface
  307. {
  308. virtual unsigned queryID() = 0;
  309. virtual unsigned queryCount() = 0;
  310. virtual void incrementCount() = 0;
  311. };
  312. class CStateHash : public CInterface, implements IStateHash
  313. {
  314. unsigned id;
  315. unsigned count;
  316. public:
  317. IMPLEMENT_IINTERFACE;
  318. CStateHash(unsigned _id, unsigned _count) : id(_id), count(_count) { };
  319. virtual unsigned queryID() { return id; }
  320. virtual unsigned queryCount() { return count; }
  321. virtual void incrementCount() { count++; };
  322. };
  323. typedef MapStringToMyClass<IStateHash> StateHashes;
  324. class CRoxieStateData : public CInterface
  325. {
  326. BoolHash ipAddress;
  327. StringAttr hash;
  328. unsigned hashID; //the position inside cluster's state hash list - used to set the majorHash flag in updateMajorRoxieStateHash().
  329. bool majorHash; //whether its state hash is the same as the most of other roxie cluster nodes or not.
  330. bool ok;
  331. bool attached;
  332. bool detached;
  333. public:
  334. IMPLEMENT_IINTERFACE;
  335. CRoxieStateData(const char* _ipAddress, unsigned _hashID) : hashID(_hashID), majorHash(true), ok(false), attached(false), detached(false)
  336. {
  337. ipAddress.setValue(_ipAddress, true);
  338. };
  339. bool matchIPAddress(const char* _ipAddress)
  340. {
  341. bool* match = ipAddress.getValue(_ipAddress);
  342. return (match && *match);
  343. }
  344. unsigned getHashID() { return hashID; }
  345. const char* getHash() { return hash.get(); }
  346. void setMajorHash(bool _majorHash) { majorHash = _majorHash; }
  347. void setState(bool _ok, bool _attached, bool _detached, const char* _hash)
  348. {
  349. ok = _ok;
  350. attached = _attached;
  351. detached = _detached;
  352. hash.set(_hash);
  353. }
  354. void reportState(StringBuffer& state, StringBuffer& stateDetails)
  355. {
  356. if (!ok)
  357. state.set("Node State: not ok ...");
  358. else if (!hash || !*hash)
  359. state.set("empty state hash ...");
  360. else if (!majorHash)
  361. state.set("State hash mismatch ...");
  362. else if (!attached)
  363. state.set("Not attached to DALI ...");
  364. else
  365. state.set("ok");
  366. if (ok)
  367. stateDetails.appendf("Node State: ok\n");
  368. else
  369. stateDetails.appendf("Node State: not ok\n");
  370. if (!hash || !*hash)
  371. stateDetails.appendf("This node had an empty hash\n");
  372. else
  373. stateDetails.appendf("State hash: %s\n", hash.get());
  374. if (!majorHash)
  375. stateDetails.appendf("State hash: mismatch\n");
  376. if (attached)
  377. stateDetails.appendf("This node attached to DALI\n");
  378. if (detached)
  379. stateDetails.appendf("This node detached from DALI\n");
  380. }
  381. };
  382. class CMachineData : public CInterface
  383. {
  384. char m_pathSep;
  385. EnvMachineOS m_os;
  386. StringBuffer m_networkAddress;
  387. StringBuffer m_networkAddressInEnvSetting; //Used for retrieving domainName/userId for MachineOsW2K
  388. int m_CPULoad;
  389. StringBuffer m_computerUpTime;
  390. CIArrayOf<CStorageData> m_storage;
  391. CIArrayOf<CProcessData> m_processes;
  392. IArrayOf<IEspProcessInfo> m_runningProcesses;
  393. set<string> m_dependencies; //from "any" process filter section in environment.xml
  394. set<string> m_additionalProcesses; //based on additionalProcessFilters in CGetMachineInfoUserOptions;
  395. public:
  396. IMPLEMENT_IINTERFACE;
  397. CMachineData()
  398. {
  399. m_pathSep = '/';
  400. m_os = MachineOsLinux;
  401. m_CPULoad = 0;
  402. m_networkAddress.clear();
  403. m_networkAddressInEnvSetting.clear();
  404. m_computerUpTime.clear();
  405. }
  406. CMachineData(const char* networkAddress, const char* networkAddressInEnvSetting, EnvMachineOS os, char pathSep)
  407. : m_os(os), m_pathSep(pathSep)
  408. {
  409. m_networkAddress = networkAddress;
  410. m_networkAddressInEnvSetting = networkAddressInEnvSetting;
  411. m_CPULoad = 0;
  412. m_computerUpTime.clear();
  413. }
  414. virtual ~CMachineData(){}
  415. void setNetworkAddress(const char* networkAddress)
  416. {
  417. m_networkAddress.clear().append(networkAddress);
  418. }
  419. const char* getNetworkAddress()
  420. {
  421. return m_networkAddress.str();
  422. }
  423. void setNetworkAddressInEnvSetting(const char* networkAddress)
  424. {
  425. m_networkAddressInEnvSetting.clear().append(networkAddress);
  426. }
  427. const char* getNetworkAddressInEnvSetting()
  428. {
  429. return m_networkAddressInEnvSetting.str();
  430. }
  431. void setComputerUpTime(const char* computerUpTime)
  432. {
  433. m_computerUpTime.clear().append(computerUpTime);
  434. }
  435. const char* getComputerUpTime()
  436. {
  437. return m_computerUpTime.str();
  438. }
  439. void setOS(EnvMachineOS os)
  440. {
  441. m_os = os;
  442. }
  443. EnvMachineOS getOS()
  444. {
  445. return m_os;
  446. }
  447. void setPathSep(const char pathSep)
  448. {
  449. m_pathSep = pathSep;
  450. }
  451. const char getPathSep()
  452. {
  453. return m_pathSep;
  454. }
  455. void setCPULoad(int CPULoad)
  456. {
  457. m_CPULoad = CPULoad;
  458. }
  459. const int getCPULoad()
  460. {
  461. return m_CPULoad;
  462. }
  463. CIArrayOf<CStorageData>& getStorage()
  464. {
  465. return m_storage;
  466. }
  467. CIArrayOf<CProcessData>& getProcesses()
  468. {
  469. return m_processes;
  470. }
  471. IArrayOf<IEspProcessInfo>& getRunningProcesses()
  472. {
  473. return m_runningProcesses;
  474. }
  475. set<string>& getDependencies()
  476. {
  477. return m_dependencies; //from "any" process filter section in environment.xml
  478. }
  479. set<string>& getAdditinalProcessFilters()
  480. {
  481. return m_additionalProcesses; //based on additionalProcessFilters in CGetMachineInfoUserOptions;
  482. }
  483. };
  484. class CGetMachineInfoUserOptions : public CInterface
  485. {
  486. StringBuffer m_userName;
  487. StringBuffer m_password;
  488. bool m_getProcessorInfo;
  489. bool m_getStorageInfo;
  490. bool m_localFileSystemsOnly;
  491. bool m_getSoftwareInfo;
  492. bool m_applyProcessFilter;
  493. StringArray m_additionalProcessFilters; //A user may add them using edit box 'Additional processes to filter:'.
  494. public:
  495. IMPLEMENT_IINTERFACE;
  496. CGetMachineInfoUserOptions()
  497. {
  498. m_userName.clear();
  499. m_password.clear();
  500. m_getProcessorInfo = true;
  501. m_getStorageInfo = true;
  502. m_localFileSystemsOnly = true;
  503. m_getSoftwareInfo = true;
  504. m_applyProcessFilter = true;
  505. }
  506. virtual ~CGetMachineInfoUserOptions(){}
  507. void setUserName(const char* userName)
  508. {
  509. m_userName.clear().append(userName);
  510. }
  511. const char* getUserName()
  512. {
  513. return m_userName.str();
  514. }
  515. void setPassword(const char* password)
  516. {
  517. m_password.clear().append(password);
  518. }
  519. const char* getPassword()
  520. {
  521. return m_password.str();
  522. }
  523. void setGetProcessorInfo(bool getProcessorInfo)
  524. {
  525. m_getProcessorInfo = getProcessorInfo;
  526. }
  527. const bool getGetProcessorInfo()
  528. {
  529. return m_getProcessorInfo;
  530. }
  531. void setGetStorageInfo(bool getStorageInfo)
  532. {
  533. m_getStorageInfo = getStorageInfo;
  534. }
  535. const bool getGetStorageInfo()
  536. {
  537. return m_getStorageInfo;
  538. }
  539. void setLocalFileSystemsOnly(bool localFileSystemsOnly)
  540. {
  541. m_localFileSystemsOnly = localFileSystemsOnly;
  542. }
  543. const bool getLocalFileSystemsOnly()
  544. {
  545. return m_localFileSystemsOnly;
  546. }
  547. void setGetSoftwareInfo(bool getSoftwareInfo)
  548. {
  549. m_getSoftwareInfo = getSoftwareInfo;
  550. }
  551. const bool getGetSoftwareInfo()
  552. {
  553. return m_getSoftwareInfo;
  554. }
  555. void setApplyProcessFilter(bool applyProcessFilter)
  556. {
  557. m_applyProcessFilter = applyProcessFilter;
  558. }
  559. const bool getApplyProcessFilter()
  560. {
  561. return m_applyProcessFilter;
  562. }
  563. StringArray& getAdditionalProcessFilters()
  564. {
  565. return m_additionalProcessFilters;
  566. }
  567. };
  568. class CGetMachineInfoData
  569. {
  570. //From request
  571. CIArrayOf<CMachineData> m_machine;
  572. CGetMachineInfoUserOptions m_options;
  573. //For response
  574. IArrayOf<IEspMachineInfoEx> m_machineInfoTable;
  575. StringArray m_machineInfoColumns;
  576. StringArray roxieClusters;
  577. BoolHash uniqueRoxieClusters;
  578. public:
  579. CGetMachineInfoUserOptions& getOptions()
  580. {
  581. return m_options;
  582. }
  583. CIArrayOf<CMachineData>& getMachineData()
  584. {
  585. return m_machine;
  586. }
  587. IArrayOf<IEspMachineInfoEx>& getMachineInfoTable()
  588. {
  589. return m_machineInfoTable;
  590. }
  591. StringArray& getMachineInfoColumns()
  592. {
  593. return m_machineInfoColumns;
  594. }
  595. StringArray& getRoxieClusters()
  596. {
  597. return roxieClusters;
  598. }
  599. void appendRoxieClusters(const char* clusterName)
  600. {
  601. bool* found = uniqueRoxieClusters.getValue(clusterName);
  602. if (found && *found)
  603. return;
  604. roxieClusters.append(clusterName);
  605. uniqueRoxieClusters.setValue(clusterName, true);
  606. }
  607. };
  608. //---------------------------------------------------------------------------------------------
  609. class Cws_machineEx : public Cws_machine
  610. {
  611. public:
  612. IMPLEMENT_IINTERFACE;
  613. virtual void init(IPropertyTree *cfg, const char *process, const char *service);
  614. ~Cws_machineEx() {};
  615. bool onGetMachineInfo(IEspContext &context, IEspGetMachineInfoRequest &req, IEspGetMachineInfoResponse &resp);
  616. bool onGetTargetClusterInfo(IEspContext &context, IEspGetTargetClusterInfoRequest &req, IEspGetTargetClusterInfoResponse &resp);
  617. bool onGetMachineInfoEx(IEspContext &context, IEspGetMachineInfoRequestEx &req, IEspGetMachineInfoResponseEx &resp);
  618. bool onGetComponentStatus(IEspContext &context, IEspGetComponentStatusRequest &req, IEspGetComponentStatusResponse &resp);
  619. bool onUpdateComponentStatus(IEspContext &context, IEspUpdateComponentStatusRequest &req, IEspUpdateComponentStatusResponse &resp);
  620. bool onGetMetrics(IEspContext &context, IEspMetricsRequest &req, IEspMetricsResponse &resp);
  621. bool onStartStop( IEspContext &context, IEspStartStopRequest &req, IEspStartStopResponse &resp);
  622. bool onStartStopBegin( IEspContext &context, IEspStartStopBeginRequest &req, IEspStartStopBeginResponse &resp);
  623. bool onStartStopDone( IEspContext &context, IEspStartStopDoneRequest &req, IEspStartStopResponse &resp);
  624. void getRoxieStateInfo(CRoxieStateInfoThreadParam* param);
  625. void doGetMachineInfo(IEspContext& context, CMachineInfoThreadParam* pReq);
  626. void doGetMetrics(CMetricsThreadParam* pParam);
  627. bool doStartStop(IEspContext &context, StringArray& addresses, char* userName, char* password, bool bStop, IEspStartStopResponse &resp);
  628. IConstEnvironment* getConstEnvironment();
  629. //Used in StartStop/Rexec
  630. void getAccountAndPlatformInfo(const char* address, StringBuffer& userId, StringBuffer& password, bool& bLinux);
  631. IPropertyTree* getComponent(const char* compType, const char* compName);
  632. private:
  633. void setupLegacyFilters();
  634. bool isLegacyFilter(const char* processType, const char* dependency);
  635. bool excludePartition(const char* partition) const;
  636. void appendProcessInstance(const char* name, const char* directory1, const char* directory2, StringArray& machineInstances, StringArray& directories);
  637. void getProcesses(IConstEnvironment* constEnv, IPropertyTree* envRoot, const char* processName, const char* processType, const char* directory, CGetMachineInfoData& machineInfoData, bool isThorOrRoxieProcess, BoolHash& uniqueProcesses, BoolHash* uniqueRoxieProcesses = NULL);
  638. void getThorProcesses(IConstEnvironment* constEnv, IPropertyTree* cluster, const char* processName, const char* processType, const char* directory, CGetMachineInfoData& machineInfoData, BoolHash& uniqueProcesses);
  639. const char* getProcessTypeFromMachineType(const char* machineType);
  640. void readSettingsForTargetClusters(IEspContext& context, StringArray& targetClusters, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClustersOut);
  641. void readTargetClusterProcesses(IPropertyTree& targetClusters, const char* processType, BoolHash& uniqueProcesses, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClustersOut);
  642. void setTargetClusterInfo(IPropertyTree* pTargetClusterTree, IArrayOf<IEspMachineInfoEx>& machineArray, IArrayOf<IEspTargetClusterInfo>& targetClusterInfoList);
  643. void buildPreflightCommand(IEspContext& context, CMachineInfoThreadParam* pParam, StringBuffer& preflightCommand);
  644. int runCommand(IEspContext& context, const char* sAddress, const char *configAddress, EnvMachineOS os, const char* sCommand, const char* sUserId, const char* sPassword, StringBuffer& sResponse);
  645. int invokeProgram(const char *command_line, StringBuffer& response);
  646. void getTimeStamp(char* timeStamp);
  647. void getProcessDisplayName(const char* processName, StringBuffer& displayName);
  648. void readALineFromResult(const char *result, const char *start, StringBuffer& value, bool bTrim = true);
  649. void readMachineInfoRequest(IEspContext& context, bool getProcessorInfo, bool getStorageInfo, bool localFileSystemsOnly, bool getSwInfo, bool applyProcessFilter, StringArray& addresses, const char* addProcessesToFilters, CGetMachineInfoData& machineInfoData);
  650. void readMachineInfoRequest(IEspContext& context, bool getProcessorInfo, bool getStorageInfo, bool localFileSystemsOnly, bool getSwInfo, bool applyProcessFilter, const char* addProcessesToFilters, StringArray& targetClustersIn, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClustersOut);
  651. void getMachineInfo(IEspContext& context, bool getRoxieState, CGetMachineInfoData& machineInfoData);
  652. void getMachineInfo(IEspContext& context, CGetMachineInfoData& machineInfoData);
  653. void setMachineInfoResponse(IEspContext& context, IEspGetMachineInfoRequest& req, CGetMachineInfoData& machineInfoData, IEspGetMachineInfoResponse& resp);
  654. void setTargetClusterInfoResponse(IEspContext& context, IEspGetTargetClusterInfoRequest& req, CGetMachineInfoData& machineInfoData, IPropertyTree* targetClusterTree, IEspGetTargetClusterInfoResponse& resp);
  655. void setProcessRequest(CGetMachineInfoData& machineInfoData, BoolHash& uniqueProcesses, const char* address1, const char* address2, const char* processType, const char* compName, const char* path, unsigned processNumber = 0);
  656. void addProcessRequestToMachineInfoData(CGetMachineInfoData& machineInfoData, const char* address1, const char* address2, const char* processType, const char* compName, const char* path, unsigned processNumber);
  657. void parseProcessString(StringArray& process, StringBuffer& address1, StringBuffer& address2, StringBuffer& processType, StringBuffer& compName, StringBuffer& path, unsigned& processNumber);
  658. void parseAddresses(const char *address, StringBuffer& address1, StringBuffer& address2);
  659. void readPreflightResponse(IEspContext& context, CMachineInfoThreadParam* pParam, const char *response,int error);
  660. void readStorageData(const char* response, CMachineInfoThreadParam* pParam);
  661. void buildProcessPath(StringBuffer &buf, const char * procName,CMachineInfoThreadParam * pParam);
  662. void readProcessData(const char* response, CMachineInfoThreadParam* pParam);
  663. void readRunningProcesses(const char* response, CMachineInfoThreadParam* pParam);
  664. bool readStorageSpace(const char *line, StringBuffer& title, __int64& free, __int64& total, int& percentAvail);
  665. void addProcessData(CMachineData* machine, const char* processType, const char* compName, const char* path, unsigned processNumber);
  666. void setMachineInfo(IEspContext& context, CMachineInfoThreadParam* pParam, const char *response, int error);
  667. void setProcessInfo(IEspContext& context, CMachineInfoThreadParam* pParam, const char* response, int error, CProcessData& process, bool firstProcess, IEspMachineInfoEx* pMachineInfo);
  668. void setProcessComponent(IEspContext& context, CMachineInfoThreadParam* pParam, CProcessData& process, bool firstProcess, IArrayOf<IEspSWRunInfo>& processArray, IEspComponentInfo* pComponentInfo);
  669. void enumerateRunningProcesses(CMachineInfoThreadParam* pParam, CProcessData& process, map<string, Linked<IEspSWRunInfo> >* processMap, bool firstProcess);
  670. //Used in StartStop/Rexec
  671. void ConvertAddress( const char* originalAddress, StringBuffer& newAddress);
  672. void updatePathInAddress(const char* address, StringBuffer& addrStr);
  673. void getRoxieClusterConfig(char const * clusterType, char const * clusterName, char const * processName, StringBuffer& netAddress, int& port);
  674. void doPostProcessing(CFieldInfoMap& myfieldInfoMap, CFieldMap& myfieldMap);
  675. void processValue(const char *oid, const char *value, const bool bShow, CFieldInfoMap& myfieldInfoMap, CFieldMap& myfieldMap);
  676. void addIpAddressesToBuffer( void** buffer, unsigned& count, const char* address);
  677. void readRoxieStatus(const Owned<IPropertyTree> controlResp, CIArrayOf<CRoxieStateData>& roxieStates);
  678. unsigned addRoxieStateHash(const char* hash, StateHashes& stateHashes, unsigned& totalUniqueHashes);
  679. void updateMajorRoxieStateHash(StateHashes& stateHashes, CIArrayOf<CRoxieStateData>& roxieStates);
  680. StringBuffer& getAcceptLanguage(IEspContext& context, StringBuffer& acceptLanguage);
  681. //Still used in StartStop/Rexec, so keep them for now.
  682. enum OpSysType { OS_Windows, OS_Solaris, OS_Linux };
  683. StringBuffer m_sTestStr1;
  684. StringBuffer m_sTestStr2;
  685. bool m_useDefaultHPCCInit;
  686. Owned<IPropertyTree> m_processFilters;
  687. Owned<IThreadPool> m_threadPool;
  688. int m_threadPoolSize;
  689. int m_threadPoolStackSize;
  690. int m_SSHConnectTimeoutSeconds;
  691. bool m_bMonitorDaliFileServer;
  692. set<string> m_excludePartitions;
  693. set<string> m_excludePartitionPatterns;
  694. StringBuffer m_machineInfoFile;
  695. BoolHash m_legacyFilters;
  696. Mutex mutex_machine_info_table;
  697. };
  698. //---------------------------------------------------------------------------------------------
  699. class CWsMachineThreadParam : public CInterface
  700. {
  701. public:
  702. IMPLEMENT_IINTERFACE;
  703. virtual ~CWsMachineThreadParam() {}
  704. StringBuffer m_sAddress;
  705. StringBuffer m_sSecurityString;
  706. StringBuffer m_sUserName;
  707. StringBuffer m_sPassword;
  708. Linked<Cws_machineEx> m_pService;
  709. virtual void doWork() = 0;
  710. protected:
  711. CWsMachineThreadParam(Cws_machineEx* pService) : m_pService(pService)
  712. {
  713. }
  714. CWsMachineThreadParam( const char* pszAddress,
  715. const char* pszSecurityString, Cws_machineEx* pService)
  716. : m_sAddress(pszAddress), m_sSecurityString(pszSecurityString), m_pService(pService)
  717. {
  718. }
  719. CWsMachineThreadParam( const char* pszAddress,
  720. const char* pszUserName, const char* pszPassword, Cws_machineEx* pService)
  721. : m_sAddress(pszAddress), m_sUserName(pszUserName), m_sPassword(pszPassword), m_pService(pService)
  722. {
  723. }
  724. };
  725. //---------------------------------------------------------------------------------------------
  726. //the following class implements a worker thread
  727. //
  728. class CWsMachineThread : public CInterface,
  729. implements IPooledThread
  730. {
  731. public:
  732. IMPLEMENT_IINTERFACE;
  733. CWsMachineThread()
  734. {
  735. }
  736. virtual ~CWsMachineThread()
  737. {
  738. }
  739. virtual void init(void *startInfo) override
  740. {
  741. m_pParam.setown((CWsMachineThreadParam*)startInfo);
  742. }
  743. virtual void threadmain() override
  744. {
  745. m_pParam->doWork();
  746. m_pParam.clear();
  747. }
  748. virtual bool canReuse() const override
  749. {
  750. return true;
  751. }
  752. virtual bool stop() override
  753. {
  754. return true;
  755. }
  756. private:
  757. Owned<CWsMachineThreadParam> m_pParam;
  758. };
  759. //---------------------------------------------------------------------------------------------
  760. class CWsMachineThreadFactory : public CInterface, public IThreadFactory
  761. {
  762. public:
  763. IMPLEMENT_IINTERFACE;
  764. IPooledThread *createNew()
  765. {
  766. return new CWsMachineThread();
  767. }
  768. };
  769. #endif //_ESPWIZ_ws_machine_HPP__