ws_dfuXRefService.hpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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_WsDfuXRef_HPP__
  14. #define _ESPWIZ_WsDfuXRef_HPP__
  15. #include "ws_dfuXref_esp.ipp"
  16. #include "XRefNodeManager.hpp"
  17. #include "TpWrapper.hpp"
  18. #include "dfuxreflib.hpp"
  19. #include "jqueue.tpp"
  20. class CXRefExBuilderThread : public Thread
  21. {
  22. bool stopThread = false;
  23. bool xRefRunning = false;
  24. CriticalSection critRunningStatus;
  25. CriticalSection critQueue;
  26. Semaphore m_sem;
  27. SafeQueueOf<IXRefNode, false> nodeQueue;
  28. StringBuffer currentClusterName;
  29. void setRunningStatus(bool status)
  30. {
  31. CriticalBlock b(critRunningStatus);
  32. xRefRunning = status;
  33. }
  34. IXRefNode* readNodeQueue()
  35. {
  36. CriticalBlock b(critQueue);
  37. return (IXRefNode*)nodeQueue.dequeue();
  38. }
  39. void writeNodeQueue(IXRefNode* xRefNode)
  40. {
  41. if (!xRefNode)
  42. return;
  43. CriticalBlock b(critQueue);
  44. nodeQueue.enqueue(LINK(xRefNode));
  45. }
  46. public:
  47. IMPLEMENT_IINTERFACE;
  48. CXRefExBuilderThread() { };
  49. ~CXRefExBuilderThread(){DBGLOG("Destroyed XRef thread");};
  50. virtual void queueRequest(IXRefNode* xRefNode, const char* cluster)
  51. {
  52. if (!xRefNode || isEmptyString(cluster))
  53. return;
  54. xRefNode->setCluster(cluster);
  55. writeNodeQueue(xRefNode);
  56. m_sem.signal();
  57. }
  58. virtual int run()
  59. {
  60. Link();
  61. while (!stopThread)
  62. {
  63. m_sem.wait();
  64. runXRef();
  65. }
  66. Release();
  67. return 0;
  68. }
  69. void runXRef()
  70. {
  71. //catch all exceptions so we can signal for the new build to start
  72. try
  73. {
  74. while (true)
  75. {
  76. Owned<IXRefNode> xRefNode = readNodeQueue();
  77. if (!xRefNode)
  78. break;
  79. if (xRefNode->useSasha()) // if sasha processing just set submitted
  80. xRefNode->setStatus("Submitted");
  81. else
  82. {
  83. setRunningStatus(true);
  84. xRefNode->getCluster(currentClusterName);
  85. Owned<IPropertyTree> tree = runXRefCluster(currentClusterName.str(), xRefNode);
  86. DBGLOG("finished run XRef for %s", currentClusterName.str());
  87. currentClusterName.clear();
  88. setRunningStatus(false);
  89. }
  90. }
  91. }
  92. catch(IException* e)
  93. {
  94. StringBuffer errorStr;
  95. e->errorMessage(errorStr);
  96. ERRLOG("Exception thrown while running XREF: %s", errorStr.str());
  97. e->Release();
  98. }
  99. catch(...)
  100. {
  101. ERRLOG("Unknown Exception thrown from XREF");
  102. }
  103. }
  104. virtual bool isRunning()
  105. {
  106. CriticalBlock b(critRunningStatus);
  107. return xRefRunning;
  108. }
  109. virtual bool isQueued(const char* clusterName)
  110. {
  111. if (isEmptyString(clusterName))
  112. return false;
  113. if (!currentClusterName.isEmpty() && streq(currentClusterName, clusterName))
  114. return true;
  115. CriticalBlock b(critQueue);
  116. ForEachItemIn(x, nodeQueue)
  117. {
  118. IXRefNode* Item = nodeQueue.item(x);
  119. StringBuffer cachedCluster;
  120. Item->getCluster(cachedCluster);
  121. if (streq(cachedCluster, clusterName))
  122. return true;
  123. }
  124. return false;
  125. }
  126. virtual void cancel()
  127. {
  128. CriticalBlock b(critQueue);
  129. while (nodeQueue.ordinality() > 0)
  130. {
  131. Owned<IXRefNode> xRefNode = (IXRefNode*)nodeQueue.dequeue();
  132. }
  133. m_sem.signal();
  134. }
  135. virtual void stop()
  136. {
  137. stopThread = true;
  138. m_sem.signal();
  139. join();
  140. }
  141. };
  142. class CWsDFUXRefSoapBindingEx : public CWsDFUXRefSoapBinding
  143. {
  144. public:
  145. CWsDFUXRefSoapBindingEx(IPropertyTree *cfg, const char *name, const char *process, http_soap_log_level llevel=hsl_none) : CWsDFUXRefSoapBinding(cfg, name, process, llevel){}
  146. virtual void getNavigationData(IEspContext &context, IPropertyTree & data)
  147. {
  148. }
  149. };
  150. class CWsDfuXRefEx : public CWsDFUXRef
  151. {
  152. private:
  153. StringBuffer user_;
  154. StringBuffer password_;
  155. Owned<IXRefNodeManager> XRefNodeManager;
  156. Owned<CXRefExBuilderThread> m_XRefbuilder;
  157. private:
  158. IXRefFilesNode* getFileNodeInterface(IXRefNode& XRefNode,const char* nodeType);
  159. void addXRefNode(const char* name, IPropertyTree* pXRefNodeTree);
  160. void readLostFileQueryResult(IEspContext &context, StringBuffer& buf);
  161. bool addUniqueXRefNode(const char* processName, BoolHash& uniqueProcesses, IPropertyTree* pXRefNodeTree);
  162. public:
  163. IMPLEMENT_IINTERFACE;
  164. CWsDfuXRefEx(){}
  165. virtual ~CWsDfuXRefEx(){};
  166. virtual void init(IPropertyTree *cfg, const char *process, const char *service);
  167. bool onDFUXRefList(IEspContext &context, IEspDFUXRefListRequest &req, IEspDFUXRefListResponse &resp);
  168. bool onDFUXRefBuild(IEspContext &context, IEspDFUXRefBuildRequest &req, IEspDFUXRefBuildResponse &resp);
  169. bool onDFUXRefLostFiles(IEspContext &context, IEspDFUXRefLostFilesQueryRequest &req, IEspDFUXRefLostFilesQueryResponse &resp);
  170. bool onDFUXRefFoundFiles(IEspContext &context, IEspDFUXRefFoundFilesQueryRequest &req, IEspDFUXRefFoundFilesQueryResponse &resp);
  171. bool onDFUXRefOrphanFiles(IEspContext &context, IEspDFUXRefOrphanFilesQueryRequest &req, IEspDFUXRefOrphanFilesQueryResponse &resp);
  172. bool onDFUXRefMessages(IEspContext &context, IEspDFUXRefMessagesQueryRequest &req, IEspDFUXRefMessagesQueryResponse &resp);
  173. bool onDFUXRefArrayAction(IEspContext &context, IEspDFUXRefArrayActionRequest &req, IEspDFUXRefArrayActionResponse &resp);
  174. bool onDFUXRefBuildCancel(IEspContext &context, IEspDFUXRefBuildCancelRequest &req, IEspDFUXRefBuildCancelResponse &resp);
  175. bool onDFUXRefDirectories(IEspContext &context, IEspDFUXRefDirectoriesQueryRequest &req, IEspDFUXRefDirectoriesQueryResponse &resp);
  176. bool onDFUXRefCleanDirectories(IEspContext &context, IEspDFUXRefCleanDirectoriesRequest &req, IEspDFUXRefCleanDirectoriesResponse &resp);
  177. bool onDFUXRefUnusedFiles(IEspContext &context, IEspDFUXRefUnusedFilesRequest &req, IEspDFUXRefUnusedFilesResponse &resp);
  178. };
  179. #endif //_ESPWIZ_WsDfu_HPP__