ws_smcService.hpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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_WsSMC_HPP__
  14. #define _ESPWIZ_WsSMC_HPP__
  15. #include "ws_smc_esp.ipp"
  16. #include "TpWrapper.hpp"
  17. #include "WUXMLInfo.hpp"
  18. enum BulletType
  19. {
  20. bulletNONE = 0,
  21. bulletOrange = 1,
  22. bulletYellow = 2,
  23. bulletWhite = 3,
  24. bulletGreen = 4,
  25. bulletError = 5
  26. };
  27. enum ClusterStatusType
  28. {
  29. RunningNormal = 0,
  30. QueuePausedOrStoppedWithJobs = 1,
  31. QueuePausedOrStoppedWithNoJob = 2,
  32. QueuePausedOrStoppedNotFound = 3,
  33. QueueRunningNotFound = 4
  34. };
  35. enum WsSMCStatusServerType
  36. {
  37. WsSMCSSTThorLCRCluster = 0,
  38. WsSMCSSTRoxieCluster = 1,
  39. WsSMCSSTHThorCluster = 2,
  40. WsSMCSSTECLagent = 3,
  41. WsSMCSSTterm = 4
  42. };
  43. static const char *WsSMCStatusServerTypeNames[] = { "ThorMaster", "RoxieServer", "HThorServer", "ECLagent" };
  44. class CWsSMCQueue
  45. {
  46. public:
  47. SCMStringBuffer queueName;
  48. StringBuffer queueState, queueStateDetails;
  49. bool foundQueueInStatusServer;
  50. unsigned countRunningJobs;
  51. unsigned countQueuedJobs;
  52. ClusterStatusType statusType;
  53. CWsSMCQueue(bool foundQueue = false): countRunningJobs(0), countQueuedJobs(0), statusType(RunningNormal)
  54. {
  55. foundQueueInStatusServer = foundQueue;
  56. }
  57. virtual ~CWsSMCQueue(){};
  58. };
  59. class CWsSMCTargetCluster : public CInterface
  60. {
  61. public:
  62. ClusterType clusterType;
  63. StringAttr clusterName;
  64. StringAttr queueName;
  65. StringAttr queueStatus;
  66. StringAttr warning;
  67. int clusterSize;
  68. SCMStringBuffer statusServerName;
  69. StringBuffer clusterStatus;
  70. StringBuffer clusterStatusDetails;
  71. CWsSMCQueue clusterQueue;
  72. CWsSMCQueue agentQueue;
  73. CWsSMCQueue serverQueue;
  74. CWsSMCTargetCluster(){};
  75. virtual ~CWsSMCTargetCluster(){};
  76. };
  77. struct ActivityInfo : public CInterface, implements IInterface
  78. {
  79. IMPLEMENT_IINTERFACE;
  80. ActivityInfo() { timeCached.setNow(); };
  81. bool isCachedActivityInfoValid(unsigned timeOutSeconds);
  82. CDateTime timeCached;
  83. CIArrayOf<CWsSMCTargetCluster> thorTargetClusters;
  84. CIArrayOf<CWsSMCTargetCluster> roxieTargetClusters;
  85. CIArrayOf<CWsSMCTargetCluster> hthorTargetClusters;
  86. IArrayOf<IEspActiveWorkunit> aws;
  87. IArrayOf<IEspServerJobQueue> serverJobQueues;
  88. IArrayOf<IEspDFUJob> DFURecoveryJobs;
  89. };
  90. class CWsSMCEx : public CWsSMC
  91. {
  92. long m_counter;
  93. CTpWrapper m_ClusterStatus;
  94. CriticalSection getActivityCrit;
  95. Owned<ActivityInfo> activityInfoCache;
  96. unsigned activityInfoCacheSeconds;
  97. StringBuffer m_ChatURL;
  98. StringBuffer m_Banner;
  99. StringBuffer m_BannerSize;
  100. StringBuffer m_BannerColor;
  101. StringBuffer m_BannerScroll;
  102. StringBuffer m_PortalURL;
  103. int m_BannerAction;
  104. bool m_EnableChatURL;
  105. public:
  106. IMPLEMENT_IINTERFACE;
  107. CWsSMCEx(){}
  108. virtual ~CWsSMCEx(){};
  109. virtual void init(IPropertyTree *cfg, const char *process, const char *service);
  110. bool onMoveJobDown(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp);
  111. bool onMoveJobUp(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp);
  112. bool onMoveJobBack(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp);
  113. bool onMoveJobFront(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp);
  114. bool onRemoveJob(IEspContext &context, IEspSMCJobRequest &req, IEspSMCJobResponse &resp);
  115. bool onStopQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp);
  116. bool onResumeQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp);
  117. bool onPauseQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp);
  118. bool onClearQueue(IEspContext &context, IEspSMCQueueRequest &req, IEspSMCQueueResponse &resp);
  119. bool onIndex(IEspContext &context, IEspSMCIndexRequest &req, IEspSMCIndexResponse &resp);
  120. bool onActivity(IEspContext &context, IEspActivityRequest &req, IEspActivityResponse &resp);
  121. bool onSetJobPriority(IEspContext &context, IEspSMCPriorityRequest &req, IEspSMCPriorityResponse &resp);
  122. bool onGetThorQueueAvailability(IEspContext &context, IEspGetThorQueueAvailabilityRequest &req, IEspGetThorQueueAvailabilityResponse& resp);
  123. bool onSetBanner(IEspContext &context, IEspSetBannerRequest &req, IEspSetBannerResponse& resp);
  124. bool onNotInCommunityEdition(IEspContext &context, IEspNotInCommunityEditionRequest &req, IEspNotInCommunityEditionResponse &resp);
  125. virtual bool onBrowseResources(IEspContext &context, IEspBrowseResourcesRequest & req, IEspBrowseResourcesResponse & resp);
  126. virtual bool onRoxieControlCmd(IEspContext &context, IEspRoxieControlCmdRequest &req, IEspRoxieControlCmdResponse &resp);
  127. private:
  128. void addCapabilities( IPropertyTree* pFeatureNode, const char* access,
  129. IArrayOf<IEspCapability>& capabilities);
  130. void addServerJobQueue(IArrayOf<IEspServerJobQueue>& jobQueues, const char* queueName, const char* serverName,
  131. const char* serverType, const char* networkAddress, unsigned port);
  132. void addServerJobQueue(IArrayOf<IEspServerJobQueue>& jobQueues, const char* queueName, const char* serverName,
  133. const char* serverType, const char* networkAddress, unsigned port, const char* queueState, const char* queueStateDetails);
  134. void readBannerAndChatRequest(IEspContext& context, IEspActivityRequest &req, IEspActivityResponse& resp);
  135. void setBannerAndChatData(double version, IEspActivityResponse& resp);
  136. void getServersAndWUs(IEspContext &context, IEspActivityRequest &req, IPropertyTree* envRoot, CConstWUClusterInfoArray& clusters,
  137. ActivityInfo* activityInfo);
  138. void sortTargetClusters(IArrayOf<IEspTargetCluster>& clusters, const char* sortBy, bool descending);
  139. void createActiveWorkUnit(Owned<IEspActiveWorkunit>& ownedWU, IEspContext &context, const char* wuid, const char* location,
  140. unsigned index, const char* serverName, const char* queueName, const char* instanceName, const char* targetClusterName, bool useContext);
  141. void readDFUWUs(IEspContext &context, const char* queueName, const char* serverName, IArrayOf<IEspActiveWorkunit>& aws);
  142. void readRunningWUsOnECLAgent(IEspContext& context, IPropertyTreeIterator* itStatusECLagent, CConstWUClusterInfoArray& clusters,
  143. CWsSMCTargetCluster& targetCluster, BoolHash& uniqueWUIDs, IArrayOf<IEspActiveWorkunit>& aws);
  144. void readWUsAndStateFromJobQueue(IEspContext& context, CWsSMCTargetCluster& targetCluster, CWsSMCQueue& queue, const char* listQueue, BoolHash& uniqueWUIDs, IArrayOf<IEspActiveWorkunit>& aws);
  145. void addToTargetClusterList(IArrayOf<IEspTargetCluster>& clusters, IEspTargetCluster* cluster, const char* sortBy, bool descending);
  146. bool findQueueInStatusServer(IEspContext& context, IPropertyTree* serverStatusRoot, const char* serverName, const char* queueName);
  147. void getClusterQueueStatus(const CWsSMCTargetCluster& targetCluster, ClusterStatusType& queueStatusType, StringBuffer& queueStatusDetails);
  148. void setClusterStatus(IEspContext& context, const CWsSMCTargetCluster& targetCluster, IEspTargetCluster* returnCluster);
  149. void getTargetClusterAndWUs(IEspContext& context, CConstWUClusterInfoArray& clusters, IConstWUClusterInfo& cluster,
  150. IPropertyTree* serverStatusRoot, IPropertyTreeIterator* itStatusECLagent, IEspTargetCluster* returnCluster, IArrayOf<IEspActiveWorkunit>& aws);
  151. void getWUsNotOnTargetCluster(IEspContext &context, IPropertyTree* serverStatusRoot, IArrayOf<IEspServerJobQueue>& serverJobQueues, IArrayOf<IEspActiveWorkunit>& aws);
  152. void getDFUServersAndWUs(IEspContext &context, IPropertyTree* envRoot, IArrayOf<IEspServerJobQueue>& serverJobQueues, IArrayOf<IEspActiveWorkunit>& aws);
  153. void getDFURecoveryJobs(IEspContext &context, const IPropertyTree* dfuRecoveryRoot, IArrayOf<IEspDFUJob>& jobs);
  154. const char* createQueueActionInfo(IEspContext &context, const char* action, IEspSMCQueueRequest &req, StringBuffer& info);
  155. void setServerJobQueueStatus(double version, IEspServerJobQueue* jobQueue, const char* status, const char* details);
  156. void setServerJobQueueStatus(IEspServerJobQueue* jobQueue, const char* status, const char* details);
  157. void setServerJobQueueStatusDetails(IEspServerJobQueue* jobQueue, const char* status, const char* details);
  158. void readTargetClusterInfo(IEspContext &context, CConstWUClusterInfoArray& clusters, IPropertyTree* serverStatusRoot,
  159. ActivityInfo* activityInfo);
  160. void readTargetClusterInfo(IEspContext& context, IConstWUClusterInfo& cluster, IPropertyTree* serverStatusRoot, CWsSMCTargetCluster* targetCluster);
  161. void readRunningWUsAndQueuedWUs(IEspContext &context, IPropertyTree* envRoot, IPropertyTree* serverStatusRoot,
  162. IPropertyTree* dfuRecoveryRoot, ActivityInfo* activityInfo);
  163. CWsSMCTargetCluster* findWUClusterInfo(IEspContext& context, const char* wuid, bool isOnECLAgent,
  164. CIArrayOf<CWsSMCTargetCluster>& targetClusters, CIArrayOf<CWsSMCTargetCluster>& targetClusters1, CIArrayOf<CWsSMCTargetCluster>& targetClusters2);
  165. CWsSMCTargetCluster* findTargetCluster(const char* clusterName, CIArrayOf<CWsSMCTargetCluster>& targetClusters);
  166. void readRunningWUsOnStatusServer(IEspContext& context, IPropertyTree* serverStatusRoot, WsSMCStatusServerType statusServerType,
  167. CIArrayOf<CWsSMCTargetCluster>& targetClusters, CIArrayOf<CWsSMCTargetCluster>& targetClusters1, CIArrayOf<CWsSMCTargetCluster>& targetClusters2,
  168. BoolHash& uniqueWUIDs, IArrayOf<IEspActiveWorkunit>& aws);
  169. void readWUsAndStateFromJobQueue(IEspContext& context, CWsSMCTargetCluster& targetCluster, BoolHash& uniqueWUIDs, IArrayOf<IEspActiveWorkunit>& aws);
  170. void readWUsAndStateFromJobQueue(IEspContext& context, CIArrayOf<CWsSMCTargetCluster>& targetClusters, BoolHash& uniqueWUIDs, IArrayOf<IEspActiveWorkunit>& aws);
  171. void setESPTargetClusters(IEspContext& context, const CIArrayOf<CWsSMCTargetCluster>& targetClusters, IArrayOf<IEspTargetCluster>& respTargetClusters);
  172. ActivityInfo* createActivityInfo(IEspContext &context, IEspActivityRequest &req);
  173. void clearActivityInfoCache();
  174. ActivityInfo* getActivityInfo(IEspContext &context, IEspActivityRequest &req);
  175. void setActivityResponse(IEspContext &context, ActivityInfo* activityInfo, IEspActivityRequest &req, IEspActivityResponse& resp);
  176. void addWUsToResponse(IEspContext &context, const IArrayOf<IEspActiveWorkunit>& aws, IEspActivityResponse& resp);
  177. const char *getStatusServerTypeName(WsSMCStatusServerType type);
  178. };
  179. class CWsSMCSoapBindingEx : public CWsSMCSoapBinding
  180. {
  181. StringBuffer m_portalURL;
  182. public:
  183. CWsSMCSoapBindingEx(){}
  184. CWsSMCSoapBindingEx(IPropertyTree* cfg, const char *bindname=NULL, const char *procname=NULL):CWsSMCSoapBinding(cfg, bindname, procname)
  185. {
  186. if (!procname || !*procname)
  187. return;
  188. StringBuffer xpath;
  189. xpath.appendf("Software/EspProcess[@name='%s']/@portalurl", procname);
  190. const char* portalURL = cfg->queryProp(xpath.str());
  191. if (portalURL && *portalURL)
  192. m_portalURL.append(portalURL);
  193. }
  194. virtual ~CWsSMCSoapBindingEx(){}
  195. virtual int onGetRoot(IEspContext &context, CHttpRequest* request, CHttpResponse* response)
  196. {
  197. return onGetInstantQuery(context, request, response, "WsSMC", "Activity");
  198. }
  199. virtual int onGetIndex(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service)
  200. {
  201. return onGetInstantQuery(context, request, response, "WsSMC", "Activity");
  202. }
  203. virtual void getNavigationData(IEspContext &context, IPropertyTree & data)
  204. {
  205. data.setProp("@appName", "EclWatch");
  206. data.setProp("@start_page", "/WsSMC/Activity");
  207. IPropertyTree *folder = ensureNavFolder(data, "Clusters", NULL, NULL, false, 1);
  208. ensureNavLink(*folder, "Activity", "/WsSMC/Activity", "Display Activity on all target clusters in an environment", NULL, NULL, 1);
  209. ensureNavLink(*folder, "Scheduler", "/WsWorkunits/WUShowScheduled", "Access the ECL Scheduler to view and manage scheduled workunits or events", NULL, NULL, 2);
  210. #ifndef USE_RESOURCE
  211. if (m_portalURL.length() > 0)
  212. {
  213. IPropertyTree *folderTools = ensureNavFolder(data, "Resources", NULL, NULL, false, 8);
  214. ensureNavLink(*folderTools, "Browse", "/WsSMC/BrowseResources", "Browse a list of resources available for download, such as the ECL IDE, documentation, examples, etc. These are only available if optional packages are installed on the ESP Server.", NULL, NULL, 1);
  215. }
  216. #else
  217. IPropertyTree *folderTools = ensureNavFolder(data, "Resources", NULL, NULL, false, 8);
  218. ensureNavLink(*folderTools, "Browse", "/WsSMC/BrowseResources", "Browse a list of resources available for download, such as the ECL IDE, documentation, examples, etc. These are only available if optional packages are installed on the ESP Server.", NULL, NULL, 1);
  219. #endif
  220. }
  221. virtual void getNavSettings(int &width, bool &resizable, bool &scroll)
  222. {
  223. width=168;
  224. resizable=false;
  225. scroll=true;
  226. }
  227. virtual int onGetForm(IEspContext &context, CHttpRequest* request, CHttpResponse* response, const char *service, const char *method);
  228. };
  229. #endif //_ESPWIZ_WsSMC_HPP__