rmtspawn.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 RMTSPAWN_HPP
  14. #define RMTSPAWN_HPP
  15. #ifdef REMOTE_EXPORTS
  16. #define REMOTE_API __declspec(dllexport)
  17. #else
  18. #define REMOTE_API __declspec(dllimport)
  19. #endif
  20. #define SLAVE_LISTEN_FOR_MASTER_TIMEOUT 5 * 60 * 1000 // 2 minutes
  21. #define MASTER_CONNECT_SLAVE_TIMEOUT 5 * 60 * 1000
  22. #define RMTTIME_CLOSEDOWN 1000 * 1000 // How long slave to wait for acknowledge of closedown notification
  23. #define RMTTIME_CONNECT_SLAVE 1000 * 1000 // How long to wait for connection from slave
  24. #define RMTTIME_RESPONSE_MASTER 10 * 60 * 1000 // How long to wait for a response from master - should be immediate!
  25. enum SpawnKind
  26. {
  27. SPAWNdfu, SPAWNlast
  28. };
  29. interface IAbortRequestCallback;
  30. extern REMOTE_API ISocket * spawnRemoteChild(SpawnKind kind, const char * exe, const SocketEndpoint & remoteEP, unsigned version, const char *logdir, IAbortRequestCallback * abort = NULL, const char *extra=NULL);
  31. extern REMOTE_API void setRemoteSpawnSSH(
  32. const char *identfilename,
  33. const char *username, // if NULL then disable SSH
  34. const char *passwordenc,
  35. unsigned timeout,
  36. unsigned retries,
  37. const char *exeprefix);
  38. extern REMOTE_API void getRemoteSpawnSSH(
  39. StringAttr &identfilename,
  40. StringAttr &username, // if isEmpty then disable SSH
  41. StringAttr &passwordenc,
  42. unsigned &timeout,
  43. unsigned &retries,
  44. StringAttr &exeprefix);
  45. class REMOTE_API CRemoteParentInfo
  46. {
  47. public:
  48. CRemoteParentInfo();
  49. ISocket * queryMasterSocket() { return socket; }
  50. bool processCommandLine(int argc, char * argv[], StringBuffer &logdir);
  51. void log();
  52. bool sendReply(unsigned version);
  53. public:
  54. Owned<ISocket> socket;
  55. SocketEndpoint parent;
  56. unsigned replyTag;
  57. unsigned port;
  58. SpawnKind kind;
  59. };
  60. class REMOTE_API CRemoteSlave
  61. {
  62. public:
  63. CRemoteSlave(const char * name, unsigned _tag, unsigned _version, bool _stayAlive);
  64. void run(int argc, char * argv[]);
  65. virtual bool processCommand(byte action, ISocket * masterSocket, MemoryBuffer & msg, MemoryBuffer & results) = 0;
  66. protected:
  67. void stopRunning() { stayAlive = false; }
  68. protected:
  69. StringAttr slaveName;
  70. unsigned tag;
  71. bool stayAlive;
  72. unsigned version;
  73. };
  74. //extern REMOTE_API void checkForRemoteAbort(ICommunicator * communicator, mptag_t tag);
  75. //extern REMOTE_API void sendRemoteAbort(INode * node, mptag_t tag);
  76. extern REMOTE_API void checkForRemoteAbort(ISocket * socket);
  77. extern REMOTE_API bool sendRemoteAbort(ISocket * socket);
  78. #endif