deploy.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 DEPLOY_HPP_INCL
  14. #define DEPLOY_HPP_INCL
  15. #ifdef DEPLOY_EXPORTS
  16. #define DEPLOY_API DECL_EXPORT
  17. #else
  18. #define DEPLOY_API DECL_IMPORT
  19. #endif
  20. //disable the harmless warning about very long symbol names > 255 chars in debug mode
  21. //this is typical with STL
  22. #pragma warning( disable : 4786 )
  23. #include "jiface.hpp"
  24. #include "jthread.hpp"
  25. #include "environment.hpp"
  26. interface IPropertyTree;
  27. interface IXslProcessor;
  28. interface IXslTransform;
  29. interface IConstEnvironment;
  30. interface IEnvDeploymentEngine;
  31. interface IDeploymentCallback;
  32. class StringAttr;
  33. enum
  34. {
  35. DT_SOURCE=0,
  36. DT_TARGET=1
  37. };
  38. #define DTC_SIZE 0x01 // compare file size
  39. #define DTC_TIME 0x02 // compare file timestamp
  40. #define DTC_CRC 0x04 // compare file crc
  41. #define DTC_ALL (DTC_SIZE | DTC_TIME | DTC_CRC)
  42. #define DTC_DEL_WRONG_CASE 0x08// delete files with incorrect file name case
  43. interface IDeployTask : extends IInterface
  44. {
  45. virtual const char* getCaption() const = 0;
  46. virtual const char* getCompName() const = 0;
  47. virtual const char* getInstanceName() const = 0;
  48. virtual const char* getFileSpec(int idx) const = 0;
  49. virtual const char* getFileName(int idx) const = 0;
  50. virtual const char* getFileExt(int idx) const = 0;
  51. virtual StringAttr getFilePath(int idx) const = 0;
  52. virtual bool getFileExists(int idx) const = 0;
  53. virtual offset_t getFileSize(int idx) const = 0;
  54. virtual EnvMachineOS getMachineOS() const = 0;
  55. virtual const char* getSSHUser() const = 0;
  56. virtual const char* getSSHKeyFile() const = 0;
  57. virtual bool isProcessed() const = 0;
  58. virtual DWORD getErrorCode() const = 0;
  59. virtual const char* getErrorString() const = 0;
  60. virtual const char* getWarnings() const = 0;
  61. virtual void setErrorCode(DWORD) = 0;
  62. virtual void setErrorString(const char*) = 0;
  63. virtual void setWarnings(const char*) = 0;
  64. virtual void setProcessed(bool bProcessed = true) = 0;
  65. virtual void setCaption(const char* caption) = 0;
  66. virtual void setFileSpec(int idx, const char* file) = 0;
  67. virtual bool getAbort() const = 0;
  68. virtual IDeploymentCallback& getCallback() const = 0;
  69. virtual unsigned getFlags() const = 0;
  70. virtual void setFlags(unsigned) = 0;
  71. virtual void setUpdateProgress(bool flag) = 0;
  72. virtual bool createFile(const char* text) = 0;
  73. virtual bool transformFile(IXslProcessor& processor, IXslTransform& transform, const char* tempPath) = 0;
  74. virtual bool copyFile(unsigned mode) = 0;
  75. virtual bool renameFile() = 0;
  76. virtual bool deleteFile() = 0;
  77. virtual bool compareFile(unsigned mode) = 0;
  78. virtual bool createDirectory() = 0;
  79. virtual bool copyDirectory() = 0;
  80. virtual bool connectTarget(const char* user, const char* pwd, bool bInteractiveMode=true) = 0;
  81. virtual bool disconnectTarget() = 0;
  82. virtual bool createProcess(bool wait, const char* user=NULL, const char* pwd=NULL) = 0;
  83. virtual bool execSSHCmd(const char* ip, const char* cmd, StringBuffer& output, StringBuffer& errmsg) = 0;
  84. };
  85. interface IDeployLog : extends IInterface
  86. {
  87. virtual IPropertyTree* addTask(IDeployTask& task) = 0;
  88. virtual IPropertyTree* addDirList(const char* comp, const char* path) = 0;
  89. };
  90. interface IDeployTaskThread : extends IPooledThread
  91. {
  92. virtual void setTask(IDeployTask*) = 0;
  93. virtual IDeployTask* getTask() const = 0;
  94. };
  95. const unsigned int DEPLOY_THREAD_POOL_SIZE = 10;
  96. #define DEFLAGS_NONE 0x00
  97. #define DEFLAGS_CONFIGFILES 0x01
  98. #define DEFLAGS_BUILDFILES 0x02
  99. #define DEFLAGS_ALL 0x03
  100. //deploy conditions - can be mixed with DEFLAGS above
  101. #define DCFLAGS_NONE 0x00
  102. #define DCFLAGS_TIME (DTC_SIZE << 2)
  103. #define DCFLAGS_SIZE (DTC_TIME << 2)
  104. #define DCFLAGS_CRC (DTC_CRC << 2)
  105. #define DCFLAGS_ALL (DCFLAGS_TIME | DCFLAGS_SIZE | DCFLAGS_CRC)
  106. enum BackupMode { DEBACKUP_NONE=0, DEBACKUP_COPY, DEBACKUP_RENAME };
  107. enum StatusType { STATUS_NORMAL, STATUS_INCOMPLETE, STATUS_OK, STATUS_ERROR, STATUS_WARN };
  108. interface IDeploymentEngine : extends IInterface
  109. {
  110. virtual void setXsl(IXslProcessor* processor, IXslTransform* transform) = 0;
  111. virtual void start() = 0;
  112. virtual void stop() = 0;
  113. virtual void check() = 0;
  114. virtual void compare(unsigned flags) = 0;
  115. virtual void deploy(unsigned flags, bool useTempDir) = 0;
  116. virtual void renameDirs() = 0;
  117. virtual void backupDirs() = 0;
  118. virtual void abort() = 0;
  119. virtual void resetInstances() = 0;
  120. virtual void addInstance(const char* tagName, const char* name) = 0;
  121. virtual const IArrayOf<IPropertyTree>& getInstances() const = 0;
  122. virtual IEnvDeploymentEngine& getEnvDepEngine() const = 0;
  123. virtual IDeploymentCallback& getCallback() const = 0;
  124. virtual int getInstallFileCount() = 0;
  125. virtual offset_t getInstallFileSize() = 0;
  126. };
  127. interface IDeploymentCallback : extends IInterface
  128. {
  129. virtual void printStatus(IDeployTask* task) = 0;
  130. virtual void printStatus(StatusType type, const char* processType, const char* comp,
  131. const char* instance, const char* msg=NULL, ...) __attribute__((format(printf, 6, 7))) = 0;
  132. virtual bool onDisconnect(const char* target) = 0;
  133. virtual bool getAbortStatus() const = 0;
  134. virtual void setAbortStatus(bool bAbort) = 0;
  135. virtual void setEnvironmentUpdated() = 0;
  136. virtual void getSshAccountInfo(StringBuffer& userid, StringBuffer& password) const = 0;
  137. //the following throws exception on abort, returns true for ignore
  138. virtual bool processException(const char* processType, const char* process, const char* instance,
  139. IException* e, const char* szMessage=NULL, const char* szCaption=NULL,
  140. IDeployTask* pTask = NULL ) = 0;
  141. virtual IEnvDeploymentEngine* getEnvDeploymentEngine() const = 0;
  142. virtual void* getWindowHandle() const = 0;
  143. virtual void installFileListChanged() = 0;
  144. virtual void fileSizeCopied(offset_t size, bool bWholeFileDone) = 0;
  145. };
  146. interface IEnvDeploymentEngine : extends IInterface
  147. {
  148. virtual IConstEnvironment& getEnvironment() const = 0;
  149. virtual IDeploymentEngine* addProcess(const char* processType, const char* processName) = 0;
  150. virtual void setInteractiveMode(bool bSet) = 0;
  151. virtual bool getInteractiveMode() const = 0;
  152. virtual void archive(const char* filename) = 0;
  153. virtual void setLog(const char* filename, const char* envname) = 0;
  154. virtual void start() = 0;
  155. virtual void stop() = 0;
  156. virtual void check() = 0;
  157. virtual void compare(unsigned flags) = 0;
  158. virtual void deploy(unsigned flags, BackupMode backupMode, bool bStop, bool bStart) = 0;
  159. virtual void abort() = 0;
  160. virtual int incrementTempFileCount() = 0;
  161. virtual int incrementEspModuleCount() = 0;
  162. virtual bool isLinuxDeployment() const = 0;
  163. virtual IDeploymentCallback& getCallback() const = 0;
  164. virtual IDeployLog* getDeployLog() = 0;
  165. virtual void addTempFile(const char* filePath) = 0;
  166. virtual void addTempDirectory(const char* dirPath) = 0;
  167. virtual void setDeployToFolder(const char*) = 0;
  168. virtual StringAttr& lookupNetAddress(StringAttr& str, const char* computer) const = 0;
  169. virtual EnvMachineOS lookupMachineOS(IPropertyTree& node) const = 0;
  170. virtual void getAccountInfo(const char* computer, StringAttr& user, StringAttr& pwd) const = 0;
  171. virtual const char* getDeployToFolder() const = 0;
  172. virtual void getDeployToAccountInfo(const char*& user, const char*& pswd) const = 0;
  173. virtual void setSourceDaliAddress( const char* addr ) = 0;
  174. virtual const char* getSourceDaliAddress() = 0;
  175. virtual IArrayOf<IDeploymentEngine>& queryProcesses() = 0;
  176. virtual bool IsPersistentConnection(const char* path) const = 0;
  177. virtual void getSSHAccountInfo(const char* computer, StringAttr& user, StringAttr& sshKey, StringAttr& sshKeyPassphrase) const = 0;
  178. };
  179. //---------------------------------------------------------------------------
  180. // Factory functions
  181. //---------------------------------------------------------------------------
  182. extern DEPLOY_API IEnvDeploymentEngine* createEnvDeploymentEngine(IConstEnvironment& environment,
  183. IDeploymentCallback& callback,
  184. IPropertyTree* pSelectedComponents);
  185. extern DEPLOY_API IDeployTask* createDeployTask(IDeploymentCallback& callback, const char* caption,
  186. const char* processType, const char* comp, const char* instance,
  187. const char* source, const char* target,
  188. const char* sshUser, const char* sshPubKeyFile,
  189. const char* sshPubKeyPassphrase, bool useSsh,
  190. EnvMachineOS os = MachineOsUnknown,
  191. const char* processName=NULL);
  192. extern DEPLOY_API IDeployLog* createDeployLog(IDeploymentCallback& callback, const char* filename, const char* envFilename);
  193. extern DEPLOY_API IThreadFactory* createDeployTaskThreadFactory();
  194. extern DEPLOY_API IEnvDeploymentEngine* createConfigGenMgr(IConstEnvironment& env,
  195. IDeploymentCallback& callback,
  196. IPropertyTree* pSelectedComponents,
  197. const char* inputDir,
  198. const char* outputDir,
  199. const char* compName,
  200. const char* compType,
  201. const char* ipAddr);
  202. extern DEPLOY_API IPropertyTree* getInstances(const IPropertyTree* pEnvRoot,
  203. const char* compName,
  204. const char* compType,
  205. const char* ipAddr,
  206. bool listall=false);
  207. extern DEPLOY_API bool matchDeployAddress(const char* searchIP, const char *envIP);
  208. //---------------------------------------------------------------------------
  209. // Module globals
  210. //---------------------------------------------------------------------------
  211. extern const char* findFileExtension(const char* pszPath);
  212. extern void removeTrailingPathSepChar(char* pszPath);
  213. extern void getTempPath(char* tempPath, unsigned int bufsize, const char* subdir=NULL);
  214. extern DWORD getLastError();
  215. extern void initializeMultiThreadedCopying();
  216. extern void stripNetAddr(const char* dir, StringBuffer& destpath, StringBuffer& destip, bool makeLinux=true);
  217. #endif // DEPLOYENV_HPP_INCL