thorconfiggenengine.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "jexcept.hpp"
  15. #include "jfile.hpp"
  16. #include "jptree.hpp"
  17. #include "xslprocessor.hpp"
  18. #include "thorconfiggenengine.hpp"
  19. //---------------------------------------------------------------------------
  20. // CThorConfigGenEngine
  21. //---------------------------------------------------------------------------
  22. CThorConfigGenEngine::CThorConfigGenEngine(IEnvDeploymentEngine& envDepEngine,
  23. IDeploymentCallback& callback,
  24. IPropertyTree& process,
  25. const char* inputDir,
  26. const char* outputDir)
  27. : CConfigGenEngine(envDepEngine, callback, process, inputDir, outputDir)
  28. {
  29. }
  30. //---------------------------------------------------------------------------
  31. // checkInstance
  32. //---------------------------------------------------------------------------
  33. void CThorConfigGenEngine::check()
  34. {
  35. m_instanceCheck = false;
  36. CDeploymentEngine::check();
  37. const char* dali = m_process.queryProp("@daliServers");
  38. if (!dali || !*dali )
  39. throw MakeStringException(0, "No dali server is defined for thor %s", m_process.queryProp("@name"));
  40. }
  41. //---------------------------------------------------------------------------
  42. // copyInstallFiles
  43. //---------------------------------------------------------------------------
  44. void CThorConfigGenEngine::copyInstallFiles(IPropertyTree& instanceNode, const char* destPath)
  45. {
  46. // Copy install files
  47. CDeploymentEngine::copyInstallFiles(instanceNode, destPath);
  48. EnvMachineOS os = m_envDepEngine.lookupMachineOS(instanceNode);
  49. if (!m_compare)
  50. ensurePath(destPath);
  51. StringBuffer sbDestDir(StringBuffer(destPath).append(m_process.queryProp("@name")).append(PATHSEPCHAR));
  52. // Create slaves and spares files
  53. writeComputerFile("./ThorSlaveProcess", StringBuffer(sbDestDir).append("slaves").str(), os);
  54. writeComputerFile("./ThorSpareProcess", StringBuffer(sbDestDir).append("spares").str(), os);
  55. }
  56. //---------------------------------------------------------------------------
  57. // writeComputerFile
  58. //---------------------------------------------------------------------------
  59. void CThorConfigGenEngine::writeComputerFile(const char* type, const char* filename, EnvMachineOS os/*=MachineOsUnknown*/)
  60. {
  61. StringBuffer str;
  62. Owned<IPropertyTreeIterator> iter = m_process.getElements(type);
  63. for(iter->first(); iter->isValid(); iter->next())
  64. {
  65. StringAttr netAddress;
  66. if (m_envDepEngine.lookupNetAddress(netAddress, iter->query().queryProp("@computer")).length() > 0)
  67. str.appendf("%s\n", netAddress.get());
  68. }
  69. writeFile(filename, str.str(), os);
  70. }