BuildSet.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 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 "jfile.hpp"
  15. #include "XMLTags.h"
  16. #include "BuildSet.hpp"
  17. #include "SchemaCommon.hpp"
  18. using namespace CONFIGURATOR;
  19. #define LOOP_THRU_BUILD_SET int len = m_buildSetArray.length(); for (int idx = 0; idx < len; idx++)
  20. static CBuildSetManager *s_pBuildSetManager = nullptr;
  21. CBuildSetManager* CBuildSetManager::getInstance(const char* pBuildSetFile, const char* pBuildSetDirectory)
  22. {
  23. if (s_pBuildSetManager == nullptr)
  24. {
  25. s_pBuildSetManager = new CBuildSetManager();
  26. s_pBuildSetManager->m_buildSetFile.set(pBuildSetFile != nullptr ? pBuildSetFile : DEFAULT_BUILD_SET_XML_FILE);
  27. s_pBuildSetManager->m_buildSetDir.set(pBuildSetDirectory != nullptr ? pBuildSetDirectory : DEFAULT_BUILD_SET_DIRECTORY);
  28. pBuildSetFile = s_pBuildSetManager->m_buildSetFile;
  29. pBuildSetDirectory = s_pBuildSetManager->m_buildSetDir;
  30. s_pBuildSetManager->m_buildSetPath.setf("%s%s%s", pBuildSetDirectory, pBuildSetDirectory[strlen(pBuildSetDirectory)-1] == '/' ? "" : "/", pBuildSetFile);
  31. if (!checkFileExists(s_pBuildSetManager->m_buildSetPath.str()))
  32. return s_pBuildSetManager;
  33. if (s_pBuildSetManager->populateBuildSet() == false)
  34. {
  35. delete s_pBuildSetManager;
  36. s_pBuildSetManager = nullptr;
  37. }
  38. }
  39. return s_pBuildSetManager;
  40. }
  41. CBuildSetManager::CBuildSetManager(const char* pBuildSetFile, const char* pBuildSetDir) : m_buildSetFile(pBuildSetFile), m_buildSetDir(pBuildSetDir)
  42. {
  43. if (pBuildSetFile != nullptr && pBuildSetDir != nullptr)
  44. m_buildSetPath.clear().appendf("%s%s%s", pBuildSetDir, pBuildSetDir[strlen(pBuildSetDir)-1] == '/' ? "" : "/", pBuildSetFile);
  45. }
  46. CBuildSetManager::CBuildSetManager()
  47. {
  48. }
  49. CBuildSetManager::~CBuildSetManager()
  50. {
  51. m_buildSetArray.kill();
  52. }
  53. void CBuildSetManager::getBuildSetComponents(StringArray& buildSetArray) const
  54. {
  55. int nLength = this->getBuildSetComponentCount();
  56. for (int idx = 0; idx < nLength; idx++)
  57. {
  58. buildSetArray.append(this->getBuildSetComponentTypeName(idx));
  59. }
  60. }
  61. void CBuildSetManager::getBuildSetServices(StringArray& buildSetArray) const
  62. {
  63. int nLength = this->getBuildSetServiceCount();
  64. for (int idx = 0; idx < nLength; idx++)
  65. {
  66. buildSetArray.append(this->getBuildSetServiceName(idx));
  67. }
  68. }
  69. const char* CBuildSetManager::getBuildSetServiceName(int index) const
  70. {
  71. if (index >= getBuildSetServiceCount())
  72. return nullptr;
  73. return this->getBuildSetService(index)->getName();
  74. }
  75. const char* CBuildSetManager::getBuildSetServiceFileName(int index) const
  76. {
  77. if (index >= getBuildSetServiceCount())
  78. return nullptr;
  79. return this->getBuildSetService(index)->getSchema();
  80. }
  81. const char* CBuildSetManager::getBuildSetComponentTypeName(int index) const
  82. {
  83. if (index >= this->getBuildSetComponentCount())
  84. return nullptr;
  85. return this->getBuildSetComponent(index)->getName();
  86. }
  87. const char* CBuildSetManager::getBuildSetComponentFileName(int index) const
  88. {
  89. if (index >= this->getBuildSetComponentCount())
  90. return nullptr;
  91. return this->getBuildSetComponent(index)->getSchema();
  92. }
  93. const char* CBuildSetManager::getBuildSetProcessName(int index) const
  94. {
  95. if (index >= this->getBuildSetComponentCount())
  96. return nullptr;
  97. return this->getBuildSetComponent(index)->getProcessName();
  98. }
  99. bool CBuildSetManager::populateBuildSet()
  100. {
  101. StringBuffer xpath;
  102. if (m_buildSetTree.get() != nullptr)
  103. return false;
  104. try
  105. {
  106. m_buildSetTree.set(createPTreeFromXMLFile(m_buildSetPath.str()));
  107. }
  108. catch(...)
  109. {
  110. return false;
  111. }
  112. xpath.setf("./%s/%s/%s", XML_TAG_PROGRAMS, XML_TAG_BUILD, XML_TAG_BUILDSET);
  113. Owned<IPropertyTreeIterator> iter = m_buildSetTree->getElements(xpath.str());
  114. ForEach(*iter)
  115. {
  116. IPropertyTree* pTree = &iter->query();
  117. if ( pTree->queryProp(XML_ATTR_PROCESS_NAME) == nullptr || pTree->queryProp(XML_ATTR_OVERRIDE) != nullptr || ( (pTree->queryProp(XML_ATTR_DEPLOYABLE) != nullptr && \
  118. stricmp(pTree->queryProp(XML_ATTR_DEPLOYABLE), "no") == 0 && stricmp(pTree->queryProp(XML_ATTR_PROCESS_NAME), XML_TAG_ESPSERVICE) != 0) ) )
  119. continue;
  120. Owned<CBuildSet> pBuildSet = new CBuildSet(pTree->queryProp(XML_ATTR_INSTALLSET), pTree->queryProp(XML_ATTR_NAME), pTree->queryProp(XML_ATTR_PROCESS_NAME),\
  121. pTree->queryProp(XML_ATTR_SCHEMA), pTree->queryProp(XML_ATTR_DEPLOYABLE), pTree->queryProp(XML_ATTR_OVERRIDE));
  122. m_buildSetArray.append(*pBuildSet.getLink());
  123. }
  124. return true;
  125. }
  126. void CBuildSetManager::setBuildSetArray(const StringArray &strArray)
  127. {
  128. m_buildSetArray.kill();
  129. for (int idx = 0; idx < strArray.length(); idx++)
  130. {
  131. Owned<CBuildSet> pBSet = new CBuildSet(nullptr, strArray.item(idx), nullptr, strArray.item(idx));
  132. assert (pBSet != nullptr);
  133. m_buildSetArray.append(*pBSet.getClear());
  134. }
  135. }
  136. const char* CBuildSetManager::getBuildSetSchema(int index) const
  137. {
  138. assert(index < m_buildSetArray.length());
  139. if (index < m_buildSetArray.length())
  140. return m_buildSetArray.item(index).getSchema();
  141. else
  142. return nullptr;
  143. }
  144. const int CBuildSetManager::getBuildSetSchemaCount() const
  145. {
  146. return m_buildSetArray.length();
  147. }
  148. const int CBuildSetManager::getBuildSetServiceCount() const
  149. {
  150. int nCount = 0;
  151. LOOP_THRU_BUILD_SET
  152. {
  153. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  154. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  155. nCount++;
  156. }
  157. return nCount;
  158. }
  159. const int CBuildSetManager::getBuildSetComponentCount() const
  160. {
  161. int nCount = 0;
  162. LOOP_THRU_BUILD_SET
  163. {
  164. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  165. ( (m_buildSetArray.item(idx).getDeployable() == nullptr) || (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  166. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  167. nCount++;
  168. }
  169. return nCount;
  170. }
  171. const CBuildSet* CBuildSetManager::getBuildSetComponent(int index) const
  172. {
  173. LOOP_THRU_BUILD_SET
  174. {
  175. if (index == 0)
  176. {
  177. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  178. ( (m_buildSetArray.item(idx).getDeployable() == nullptr) || (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  179. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  180. return &(m_buildSetArray.item(idx));
  181. else
  182. continue;
  183. }
  184. if ( ((m_buildSetArray.item(idx).getProcessName() == nullptr) || (strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) != 0)) && \
  185. ( (m_buildSetArray.item(idx).getDeployable() == nullptr)|| (stricmp(m_buildSetArray.item(idx).getDeployable(), "no") != 0) ) && \
  186. ( (m_buildSetArray.item(idx).getOverride() == nullptr) || (stricmp(m_buildSetArray.item(idx).getOverride(), "no") != 0) ) )
  187. index--;
  188. }
  189. assert(!"index invalid");
  190. return nullptr;
  191. }
  192. const CBuildSet* CBuildSetManager::getBuildSetService(int index) const
  193. {
  194. LOOP_THRU_BUILD_SET
  195. {
  196. if (index == 0)
  197. {
  198. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  199. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  200. return &(m_buildSetArray.item(idx));
  201. else
  202. continue;
  203. }
  204. if (m_buildSetArray.item(idx).getProcessName() != nullptr && strcmp(m_buildSetArray.item(idx).getProcessName(), XML_TAG_ESPSERVICE) == 0 && \
  205. (m_buildSetArray.item(idx).getDeployable() != nullptr && stricmp(m_buildSetArray.item(idx).getDeployable(), "no") == 0))
  206. index--;
  207. }
  208. assert(!"index invalid");
  209. return nullptr;
  210. }