dalideploymentengine.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "jptree.hpp"
  14. #include "dalideploymentengine.hpp"
  15. //---------------------------------------------------------------------------
  16. // CDaliDeploymentEngine
  17. //---------------------------------------------------------------------------
  18. CDaliDeploymentEngine::CDaliDeploymentEngine(IEnvDeploymentEngine& envDepEngine,
  19. IDeploymentCallback& callback,
  20. IPropertyTree& process)
  21. : CDeploymentEngine(envDepEngine, callback, process, "Instance")
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. // startInstance
  26. //---------------------------------------------------------------------------
  27. void CDaliDeploymentEngine::startInstance(IPropertyTree& instanceNode, const char* fileName/*="startup"*/)
  28. {
  29. while (!m_pCallback->processException( m_process.queryName(), m_name, m_curInstance, NULL,
  30. "You must start a Dali server manually!",
  31. "Start Process"));//while retry
  32. }
  33. //---------------------------------------------------------------------------
  34. // stopInstance
  35. //---------------------------------------------------------------------------
  36. void CDaliDeploymentEngine::stopInstance(IPropertyTree& instanceNode, const char* fileName/*="stop"*/)
  37. {
  38. while (!m_pCallback->processException( m_process.queryName(), m_name, m_curInstance,
  39. NULL, "You must stop a Dali server manually!",
  40. "Stop Process"));//while retry
  41. }
  42. //---------------------------------------------------------------------------
  43. // deploy
  44. //---------------------------------------------------------------------------
  45. void CDaliDeploymentEngine::_deploy(bool useTempDir)
  46. {
  47. // Since we may be accessing the dali server that we're trying to deploy to,
  48. // we need to copy the files to a temporary directory, then use a start_dali
  49. // batch file to copy the files from the temporary directory to the real
  50. // directory defore starting the dali process.
  51. // Do deploy
  52. CDeploymentEngine::_deploy(false);
  53. }
  54. //---------------------------------------------------------------------------
  55. // copyInstallFiles
  56. //---------------------------------------------------------------------------
  57. void CDaliDeploymentEngine::copyInstallFiles(IPropertyTree& instanceNode, const char* destPath)
  58. {
  59. const char* computer = instanceNode.queryProp("@computer");
  60. if ((m_deployFlags & DEFLAGS_CONFIGFILES) && computer && *computer)
  61. {
  62. // Create dalisds.xml is not already exists
  63. StringBuffer hostRoot(getHostRoot(computer, NULL));
  64. const char* dir = m_process.queryProp("@dataPath");
  65. if (!dir || !*dir)
  66. dir = instanceNode.queryProp("@directory");
  67. if (dir)
  68. {
  69. if (isPathSepChar(*dir))
  70. dir++;
  71. StringBuffer sDir( dir );
  72. sDir.replace(':', '$');
  73. sDir.replace('/', '\\');
  74. sDir.insert(0, hostRoot.str());
  75. if (!checkFileExists( sDir.str() ))
  76. {
  77. Owned<IPropertyTree> tree = &m_environment.getPTree();
  78. StringBuffer xml("<SDS>");
  79. toXML(tree, xml);
  80. xml.append("</SDS>");
  81. sDir.append( "\\dalisds.xml" );
  82. writeFile(sDir.str(), xml.str());
  83. }
  84. }
  85. }
  86. // Copy install files to deploy subdir
  87. CDeploymentEngine::copyInstallFiles(instanceNode, destPath);
  88. }
  89. //---------------------------------------------------------------------------
  90. // getInstallPath
  91. //---------------------------------------------------------------------------
  92. bool CDaliDeploymentEngine::getInstallPath(const char *filename, StringBuffer& installPath)
  93. {
  94. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  95. //If filename is in deploy folder then compare file in folder above it.
  96. //
  97. StringBuffer machine;
  98. StringBuffer path;
  99. StringBuffer tail;
  100. StringBuffer ext;
  101. bool rc;
  102. splitUNCFilename(filename, &machine, &path, &tail, &ext);
  103. const char* pszPath = path.str();
  104. const char* pattern = "deploy\\";
  105. const unsigned int patternLen = sizeof("deploy\\") - 1;
  106. const char* match = strstr(pszPath, pattern);
  107. if (match && strlen(match)==patternLen)//path ends with "deploy\\"
  108. {
  109. path.remove(match-pszPath, patternLen);
  110. installPath.append(machine).append(path).append(tail).append(ext);
  111. rc = true;
  112. }
  113. else
  114. {
  115. installPath.append(filename);
  116. rc = false;
  117. }
  118. return rc;
  119. }
  120. //---------------------------------------------------------------------------
  121. // setCompare
  122. //---------------------------------------------------------------------------
  123. const char* CDaliDeploymentEngine::setCompare(const char *filename)
  124. {
  125. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  126. //If filename is in deploy folder then compare file in folder above it.
  127. //
  128. StringBuffer installPath;
  129. getInstallPath(filename, installPath);
  130. return CDeploymentEngine::setCompare(installPath.str());
  131. }
  132. //---------------------------------------------------------------------------
  133. // compareFiles
  134. //---------------------------------------------------------------------------
  135. void CDaliDeploymentEngine::compareFiles(const char *newFile, const char *oldFile)
  136. {
  137. //BUG: 9254 - Deploy Wizard's "compare" for Dali looks in wrong folder
  138. //If filename is in deploy folder then compare file in folder above it.
  139. //
  140. StringBuffer installPath;
  141. getInstallPath(oldFile, installPath);
  142. Owned<IDeployTask> task = createDeployTask(*m_pCallback, "Compare File", m_process.queryName(), m_name.get(),
  143. m_curInstance, newFile, installPath.str(), m_curSSHUser.str(), m_curSSHKeyFile.str(),
  144. m_curSSHKeyPassphrase.str(), m_useSSHIfDefined);
  145. m_pCallback->printStatus(task);
  146. task->compareFile(DTC_CRC | DTC_SIZE);
  147. m_pCallback->printStatus(task);
  148. checkAbort(task);
  149. }