dalideploymentengine.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "jptree.hpp"
  15. #include "dalideploymentengine.hpp"
  16. //---------------------------------------------------------------------------
  17. // CDaliDeploymentEngine
  18. //---------------------------------------------------------------------------
  19. CDaliDeploymentEngine::CDaliDeploymentEngine(IEnvDeploymentEngine& envDepEngine,
  20. IDeploymentCallback& callback,
  21. IPropertyTree& process)
  22. : CDeploymentEngine(envDepEngine, callback, process, "Instance")
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. // startInstance
  27. //---------------------------------------------------------------------------
  28. void CDaliDeploymentEngine::startInstance(IPropertyTree& instanceNode, const char* fileName/*="startup"*/)
  29. {
  30. while (!m_pCallback->processException( m_process.queryName(), m_name, m_curInstance, NULL,
  31. "You must start a Dali server manually!",
  32. "Start Process"));//while retry
  33. }
  34. //---------------------------------------------------------------------------
  35. // stopInstance
  36. //---------------------------------------------------------------------------
  37. void CDaliDeploymentEngine::stopInstance(IPropertyTree& instanceNode, const char* fileName/*="stop"*/)
  38. {
  39. while (!m_pCallback->processException( m_process.queryName(), m_name, m_curInstance,
  40. NULL, "You must stop a Dali server manually!",
  41. "Stop Process"));//while retry
  42. }
  43. //---------------------------------------------------------------------------
  44. // deploy
  45. //---------------------------------------------------------------------------
  46. void CDaliDeploymentEngine::_deploy(bool useTempDir)
  47. {
  48. // Since we may be accessing the dali server that we're trying to deploy to,
  49. // we need to copy the files to a temporary directory, then use a start_dali
  50. // batch file to copy the files from the temporary directory to the real
  51. // directory defore starting the dali process.
  52. // Do deploy
  53. CDeploymentEngine::_deploy(false);
  54. }
  55. //---------------------------------------------------------------------------
  56. // copyInstallFiles
  57. //---------------------------------------------------------------------------
  58. void CDaliDeploymentEngine::copyInstallFiles(IPropertyTree& instanceNode, const char* destPath)
  59. {
  60. const char* computer = instanceNode.queryProp("@computer");
  61. if ((m_deployFlags & DEFLAGS_CONFIGFILES) && computer && *computer)
  62. {
  63. // Create dalisds.xml is not already exists
  64. StringBuffer hostRoot(getHostRoot(computer, NULL));
  65. const char* dir = m_process.queryProp("@dataPath");
  66. if (!dir || !*dir)
  67. dir = instanceNode.queryProp("@directory");
  68. if (dir)
  69. {
  70. if (isPathSepChar(*dir))
  71. dir++;
  72. StringBuffer sDir( dir );
  73. sDir.replace(':', '$');
  74. sDir.replace('/', '\\');
  75. sDir.insert(0, hostRoot.str());
  76. if (!checkFileExists( sDir.str() ))
  77. {
  78. Owned<IPropertyTree> tree = &m_environment.getPTree();
  79. StringBuffer xml("<SDS>");
  80. toXML(tree, xml);
  81. xml.append("</SDS>");
  82. sDir.append( "\\dalisds.xml" );
  83. writeFile(sDir.str(), xml.str());
  84. }
  85. }
  86. }
  87. // Copy install files to deploy subdir
  88. CDeploymentEngine::copyInstallFiles(instanceNode, destPath);
  89. }
  90. //---------------------------------------------------------------------------
  91. // getInstallPath
  92. //---------------------------------------------------------------------------
  93. bool CDaliDeploymentEngine::getInstallPath(const char *filename, StringBuffer& installPath)
  94. {
  95. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  96. //If filename is in deploy folder then compare file in folder above it.
  97. //
  98. StringBuffer machine;
  99. StringBuffer path;
  100. StringBuffer tail;
  101. StringBuffer ext;
  102. bool rc;
  103. splitUNCFilename(filename, &machine, &path, &tail, &ext);
  104. const char* pszPath = path.str();
  105. const char* pattern = "deploy\\";
  106. const unsigned int patternLen = sizeof("deploy\\") - 1;
  107. const char* match = strstr(pszPath, pattern);
  108. if (match && strlen(match)==patternLen)//path ends with "deploy\\"
  109. {
  110. path.remove(match-pszPath, patternLen);
  111. installPath.append(machine).append(path).append(tail).append(ext);
  112. rc = true;
  113. }
  114. else
  115. {
  116. installPath.append(filename);
  117. rc = false;
  118. }
  119. return rc;
  120. }
  121. //---------------------------------------------------------------------------
  122. // setCompare
  123. //---------------------------------------------------------------------------
  124. const char* CDaliDeploymentEngine::setCompare(const char *filename)
  125. {
  126. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  127. //If filename is in deploy folder then compare file in folder above it.
  128. //
  129. StringBuffer installPath;
  130. getInstallPath(filename, installPath);
  131. return CDeploymentEngine::setCompare(installPath.str());
  132. }
  133. //---------------------------------------------------------------------------
  134. // compareFiles
  135. //---------------------------------------------------------------------------
  136. void CDaliDeploymentEngine::compareFiles(const char *newFile, const char *oldFile)
  137. {
  138. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  139. //If filename is in deploy folder then compare file in folder above it.
  140. //
  141. StringBuffer installPath;
  142. getInstallPath(oldFile, installPath);
  143. Owned<IDeployTask> task = createDeployTask(*m_pCallback, "Compare File", m_process.queryName(), m_name.get(),
  144. m_curInstance, newFile, installPath.str(), m_curSSHUser.sget(), m_curSSHKeyFile.sget(),
  145. m_curSSHKeyPassphrase.sget(), m_useSSHIfDefined);
  146. m_pCallback->printStatus(task);
  147. task->compareFile(DTC_CRC | DTC_SIZE);
  148. m_pCallback->printStatus(task);
  149. checkAbort(task);
  150. }