ws_packageprocessService.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_packageprocess_HPP__
  14. #define _ESPWIZ_ws_packageprocess_HPP__
  15. #include "ws_packageprocess_esp.ipp"
  16. #include "dasds.hpp"
  17. #include "environment.hpp"
  18. #define THORCLUSTER "thor"
  19. #define HTHORCLUSTER "hthor"
  20. #define ROXIECLUSTER "roxie"
  21. #define PMAS_RELOAD_PACKAGE_SET 0x01
  22. #define PMAS_RELOAD_PACKAGE_MAP 0x02
  23. class PackageMapAndSet : public CInterface, implements ISDSSubscription
  24. {
  25. Owned<IPropertyTree> tree;
  26. SubscriptionId pmChange;
  27. SubscriptionId psChange;
  28. mutable CriticalSection crit;
  29. mutable CriticalSection dirtyCrit; //if there were an atomic_or I would just use atomic
  30. unsigned dirty;
  31. void load(unsigned flags);
  32. void load(const char* path, IPropertyTree* t);
  33. public:
  34. IMPLEMENT_IINTERFACE;
  35. PackageMapAndSet() : pmChange(0), psChange(0), dirty(PMAS_RELOAD_PACKAGE_SET | PMAS_RELOAD_PACKAGE_MAP)
  36. {
  37. tree.setown(createPTree("PackageMapAndSet"));
  38. }
  39. virtual void notify(SubscriptionId subid, const char *xpath, SDSNotifyFlags flags, unsigned valueLen, const void *valueData)
  40. {
  41. Linked<PackageMapAndSet> me = this; // Ensure that I am not released by the notify call (which would then access freed memory to release the critsec)
  42. CriticalBlock b(dirtyCrit);
  43. if (subid == pmChange)
  44. dirty |= PMAS_RELOAD_PACKAGE_MAP;
  45. else if (subid == psChange)
  46. dirty |= PMAS_RELOAD_PACKAGE_SET;
  47. }
  48. virtual bool subscribe()
  49. {
  50. CriticalBlock b(crit);
  51. if (!pmChange)
  52. pmChange = querySDS().subscribe("PackageMaps", *this, true);
  53. if(!psChange)
  54. psChange = querySDS().subscribe("PackageSets", *this, true);
  55. return pmChange != 0 && psChange != 0;
  56. }
  57. virtual bool unsubscribe()
  58. {
  59. CriticalBlock b(crit);
  60. bool success = true;
  61. try
  62. {
  63. if (pmChange)
  64. querySDS().unsubscribe(pmChange);
  65. if (psChange)
  66. querySDS().unsubscribe(psChange);
  67. }
  68. catch (IException *E)
  69. {
  70. E->Release();
  71. success = false;
  72. }
  73. pmChange = 0;
  74. psChange = 0;
  75. return success;
  76. }
  77. IPropertyTree *getTree()
  78. {
  79. CriticalBlock b(crit);
  80. unsigned flags;
  81. {
  82. CriticalBlock b(dirtyCrit);
  83. flags = dirty;
  84. dirty = 0;
  85. }
  86. if (flags)
  87. load(flags);
  88. return LINK(tree);
  89. }
  90. IPropertyTree *getPackageMaps()
  91. {
  92. Owned<IPropertyTree> root = getTree();
  93. return root->getPropTree("PackageMaps");
  94. }
  95. IPropertyTree *getPackageSets()
  96. {
  97. Owned<IPropertyTree> root = getTree();
  98. return root->getPropTree("PackageSets");
  99. }
  100. StringBuffer &toStr(StringBuffer &s)
  101. {
  102. Owned<IPropertyTree> t = getTree();
  103. return toXML(t, s);
  104. }
  105. };
  106. class CWsPackageProcessSoapBindingEx : public CWsPackageProcessSoapBinding
  107. {
  108. public:
  109. CWsPackageProcessSoapBindingEx(IPropertyTree *cfg, const char *name, const char *process, http_soap_log_level llevel=hsl_none) : CWsPackageProcessSoapBinding(cfg, name, process, llevel)
  110. {
  111. }
  112. virtual void getNavigationData(IEspContext &context, IPropertyTree & data)
  113. {
  114. if (queryComponentConfig().getPropBool("@api_only"))
  115. {
  116. CHttpSoapBinding::getNavigationData(context, data);
  117. return;
  118. }
  119. //Add navigation link here
  120. IPropertyTree *folderQueryset = ensureNavFolder(data, "Queries", NULL);
  121. CEspBinding::ensureNavLink(*folderQueryset, "Package Maps", "/esp/files/stub.htm?Widget=PackageMapQueryWidget", "Browse Package Maps", NULL, NULL, 2);
  122. }
  123. int onFinishUpload(IEspContext &ctx, CHttpRequest* request, CHttpResponse* response, const char *service,
  124. const char *method, StringArray& fileNames, StringArray& files, IMultiException *me);
  125. };
  126. class CWsPackageProcessEx : public CWsPackageProcess
  127. {
  128. bool readPackageMapString(const char *packageMapString, StringBuffer &target, StringBuffer &process, StringBuffer &packageMap);
  129. void getPkgInfoById(const char *target, const char *packageMapId, IPropertyTree* tree);
  130. void getPkgInfoById(const char *packageMapId, IPropertyTree* tree);
  131. void deletePackage(const char *packageMap, const char *target, const char *process, bool globalScope, StringBuffer &returnMsg, int &returnCode);
  132. void validatePackage(IEspContext &context, IEspValidatePackageRequest &req, IPropertyTree *packageMapTree, IConstWUClusterInfo *clusterInfo,
  133. StringArray &queriesToVerify, StringArray &queriesToIgnore, IEspValidatePackageResponse *resp, IArrayOf<IEspValidateResult>& results);
  134. public:
  135. IMPLEMENT_IINTERFACE;
  136. virtual ~CWsPackageProcessEx()
  137. {
  138. packageMapAndSet.unsubscribe();
  139. };
  140. virtual void init(IPropertyTree *cfg, const char *process, const char *service);
  141. virtual bool onEcho(IEspContext &context, IEspEchoRequest &req, IEspEchoResponse &resp);
  142. virtual bool onAddPackage(IEspContext &context, IEspAddPackageRequest &req, IEspAddPackageResponse &resp);
  143. virtual bool onCopyPackageMap(IEspContext &context, IEspCopyPackageMapRequest &req, IEspCopyPackageMapResponse &resp);
  144. virtual bool onDeletePackage(IEspContext &context, IEspDeletePackageRequest &req, IEspDeletePackageResponse &resp);
  145. virtual bool onActivatePackage(IEspContext &context, IEspActivatePackageRequest &req, IEspActivatePackageResponse &resp);
  146. virtual bool onDeActivatePackage(IEspContext &context, IEspDeActivatePackageRequest &req, IEspDeActivatePackageResponse &resp);
  147. virtual bool onListPackage(IEspContext &context, IEspListPackageRequest &req, IEspListPackageResponse &resp);
  148. virtual bool onGetPackage(IEspContext &context, IEspGetPackageRequest &req, IEspGetPackageResponse &resp);
  149. virtual bool onValidatePackage(IEspContext &context, IEspValidatePackageRequest &req, IEspValidatePackageResponse &resp);
  150. virtual bool onGetQueryFileMapping(IEspContext &context, IEspGetQueryFileMappingRequest &req, IEspGetQueryFileMappingResponse &resp);
  151. virtual bool onListPackages(IEspContext &context, IEspListPackagesRequest &req, IEspListPackagesResponse &resp);
  152. virtual bool onGetPackageMapSelectOptions(IEspContext &context, IEspGetPackageMapSelectOptionsRequest &req, IEspGetPackageMapSelectOptionsResponse &resp);
  153. virtual bool onGetPackageMapById(IEspContext &context, IEspGetPackageMapByIdRequest &req, IEspGetPackageMapByIdResponse &resp);
  154. virtual bool onAddPartToPackageMap(IEspContext &context, IEspAddPartToPackageMapRequest &req, IEspAddPartToPackageMapResponse &resp);
  155. virtual bool onGetPartFromPackageMap(IEspContext &context, IEspGetPartFromPackageMapRequest &req, IEspGetPartFromPackageMapResponse &resp);
  156. virtual bool onRemovePartFromPackageMap(IEspContext &context, IEspRemovePartFromPackageMapRequest &req, IEspRemovePartFromPackageMapResponse &resp);
  157. virtual bool unsubscribeServiceFromDali() override
  158. {
  159. return packageMapAndSet.unsubscribe();
  160. }
  161. virtual bool subscribeServiceToDali() override
  162. {
  163. return packageMapAndSet.subscribe();
  164. }
  165. PackageMapAndSet packageMapAndSet;
  166. };
  167. #endif //_ESPWIZ_ws_packageprocess_HPP__