ftslave.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include "jliball.hpp"
  14. #include "platform.h"
  15. #include "jlib.hpp"
  16. #include "jio.hpp"
  17. #include "jmutex.hpp"
  18. #include "jfile.hpp"
  19. #include "jsocket.hpp"
  20. #include "jdebug.hpp"
  21. #include "fterror.hpp"
  22. #include "dadfs.hpp"
  23. #include "rmtspawn.hpp"
  24. #include "filecopy.hpp"
  25. #include "fttransform.ipp"
  26. #include "daftformat.hpp"
  27. #include "daftcfg.hpp"
  28. #include "mptag.hpp"
  29. bool processPullCommand(ISocket * masterSocket, MemoryBuffer & msg)
  30. {
  31. srand((int)get_cycles_now());
  32. TransferServer server(masterSocket);
  33. server.deserializeAction(msg, FTactionpull);
  34. return server.pull();
  35. }
  36. bool processPushCommand(ISocket * masterSocket, MemoryBuffer & msg)
  37. {
  38. srand((int)get_cycles_now());
  39. TransferServer server(masterSocket);
  40. server.deserializeAction(msg, FTactionpush);
  41. return server.push();
  42. }
  43. bool processPartitionCommand(ISocket * masterSocket, MemoryBuffer & msg, MemoryBuffer & results)
  44. {
  45. FileFormat srcFormat;
  46. FileFormat tgtFormat;
  47. unsigned whichInput;
  48. RemoteFilename fullPath;
  49. offset_t totalSize;
  50. offset_t thisOffset;
  51. offset_t thisSize;
  52. unsigned thisHeaderSize;
  53. unsigned numParts;
  54. bool compressedInput = false;
  55. unsigned compatflags = 0;
  56. srcFormat.deserialize(msg);
  57. tgtFormat.deserialize(msg);
  58. msg.read(whichInput);
  59. fullPath.deserialize(msg);
  60. msg.read(totalSize);
  61. msg.read(thisOffset);
  62. msg.read(thisSize);
  63. msg.read(thisHeaderSize);
  64. msg.read(numParts);
  65. if (msg.remaining())
  66. msg.read(compressedInput);
  67. if (msg.remaining())
  68. msg.read(compatflags); // not yet used
  69. StringAttr decryptkey;
  70. if (msg.remaining())
  71. msg.read(decryptkey);
  72. if (msg.remaining())
  73. {
  74. srcFormat.deserializeExtra(msg, 1);
  75. tgtFormat.deserializeExtra(msg, 1);
  76. }
  77. StringBuffer text;
  78. fullPath.getRemotePath(text);
  79. LOG(MCdebugProgress, unknownJob, "Process partition %d(%s)", whichInput, text.str());
  80. Owned<IFormatProcessor> processor = createFormatProcessor(srcFormat, tgtFormat, true);
  81. Owned<IOutputProcessor> target = createOutputProcessor(tgtFormat);
  82. processor->setTarget(target);
  83. processor->setPartitionRange(totalSize, thisOffset, thisSize, thisHeaderSize, numParts);
  84. processor->setSource(whichInput, fullPath, compressedInput, decryptkey);
  85. processor->calcPartitions(NULL);
  86. PartitionPointArray partition;
  87. processor->getResults(partition);
  88. serialize(partition, results);
  89. return true;
  90. }
  91. class FtSlave : public CRemoteSlave
  92. {
  93. public:
  94. FtSlave() : CRemoteSlave("ftslave", MPTAG_FT_SLAVE, DAFT_VERSION, false) {}
  95. virtual bool processCommand(byte action, ISocket * masterSocket, MemoryBuffer & msg, MemoryBuffer & results)
  96. {
  97. switch (action)
  98. {
  99. case FTactionpartition:
  100. return processPartitionCommand(masterSocket, msg, results);
  101. case FTactionpull:
  102. return processPullCommand(masterSocket, msg);
  103. case FTactionpush:
  104. return processPushCommand(masterSocket, msg);
  105. default:
  106. UNIMPLEMENTED;
  107. }
  108. return false;
  109. }
  110. };
  111. static constexpr const char * defaultYaml = R"!!(
  112. version: "1.0"
  113. ftslave:
  114. name: ftslave
  115. logging:
  116. detail: 50
  117. )!!";
  118. int main(int argc, const char * * argv)
  119. {
  120. InitModuleObjects();
  121. setDaliServixSocketCaching(true);
  122. installDefaultFileHooks(nullptr);
  123. try
  124. {
  125. loadConfiguration(defaultYaml, argv, "ftslave", "FTSLAVE", nullptr, nullptr);
  126. }
  127. catch (IException * e)
  128. {
  129. OERRLOG(e);
  130. e->Release();
  131. return 1;
  132. }
  133. catch(...)
  134. {
  135. OERRLOG("Failed to load configuration");
  136. return 1;
  137. }
  138. FtSlave slave;
  139. slave.run(argc, argv);
  140. return 0;
  141. }