ws_packageprocessService.hpp 6.8 KB

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