TpCommon.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2021 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. #pragma warning (disable : 4786)
  14. // TpWrapper.cpp: implementation of the CTpWrapper class.
  15. //
  16. //////////////////////////////////////////////////////////////////////
  17. #include "TpWrapper.hpp"
  18. #include <stdio.h>
  19. #include "workunit.hpp"
  20. #include "exception_util.hpp"
  21. #include "portlist.h"
  22. #include "daqueue.hpp"
  23. #include "dautils.hpp"
  24. #include "dameta.hpp"
  25. extern TPWRAPPER_API ISashaCommand* archiveOrRestoreWorkunits(StringArray& wuids, IProperties* params, bool archive, bool dfu)
  26. {
  27. StringBuffer sashaAddress;
  28. if (params && params->hasProp("sashaServerIP"))
  29. {
  30. sashaAddress.set(params->queryProp("sashaServerIP"));
  31. sashaAddress.append(':').append(params->getPropInt("sashaServerPort", DEFAULT_SASHA_PORT));
  32. }
  33. else
  34. getSashaService(sashaAddress, "sasha-wu-archiver", true);
  35. SocketEndpoint ep(sashaAddress);
  36. Owned<INode> node = createINode(ep);
  37. Owned<ISashaCommand> cmd = createSashaCommand();
  38. cmd->setAction(archive ? SCA_ARCHIVE : SCA_RESTORE);
  39. if (dfu)
  40. cmd->setDFU(true);
  41. ForEachItemIn(i, wuids)
  42. cmd->addId(wuids.item(i));
  43. if (!cmd->send(node, 1*60*1000))
  44. throw MakeStringException(ECLWATCH_CANNOT_CONNECT_ARCHIVE_SERVER,
  45. "Sasha (%s) took too long to respond for Archive/restore workunit.",
  46. sashaAddress.str());
  47. return cmd.getClear();
  48. }
  49. extern TPWRAPPER_API IStringIterator* getContainerTargetClusters(const char* processType, const char* processName)
  50. {
  51. Owned<CStringArrayIterator> ret = new CStringArrayIterator;
  52. Owned<IPropertyTreeIterator> queues = getComponentConfigSP()->getElements("queues");
  53. ForEach(*queues)
  54. {
  55. IPropertyTree& queue = queues->query();
  56. if (!isEmptyString(processType))
  57. {
  58. const char* type = queue.queryProp("@type");
  59. if (isEmptyString(type) || !strieq(type, processType))
  60. continue;
  61. }
  62. const char* qName = queue.queryProp("@name");
  63. if (isEmptyString(qName))
  64. continue;
  65. if (!isEmptyString(processName) && !strieq(qName, processName))
  66. continue;
  67. ret->append_unique(qName);
  68. }
  69. if (!isEmptyString(processType) && !strieq("roxie", processType))
  70. return ret.getClear();
  71. Owned<IPropertyTreeIterator> services = getComponentConfigSP()->getElements("services[@type='roxie']");
  72. ForEach(*services)
  73. {
  74. IPropertyTree& service = services->query();
  75. const char* targetName = service.queryProp("@target");
  76. if (isEmptyString(targetName))
  77. continue;
  78. if (!isEmptyString(processName) && !strieq(targetName, processName))
  79. continue;
  80. ret->append_unique(targetName);
  81. }
  82. return ret.getClear();
  83. }